GithubHelp home page GithubHelp logo

edr's People

Contributors

clemensp avatar fitzsimmons avatar mbriggs avatar prognostikos avatar vsavkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

edr's Issues

Testing wrapped associations w/out persistence

I want to test some behavior in my model/entity in the most isolated way that I can.

For example, imagine that the Order class from spec/test_data.rb had an additional method to calculate the total for all of the items for the order:

class Order
  include Edr::Model

  fields :id, :amount, :deliver_at
  wrap_associations :items

  def item_total
    items.map{|i| i.amount}.reduce(0, :+)
  end

  def add_item attrs
    repository.create_item self, attrs
  end
end

The only way I can see to test this is to instantiate a new ItemData object and use it in a test as follows:

  describe "Testing wrapped associations w/out persistence" do
    example do
      item  = ItemData.new(amount: 4)
      order = Order.build OpenStruct.new(items: [item])
      order.item_total.should eq 4
    end

    example do
      order = Order.build OpenStruct.new(items: [])
      order.item_total.should eq 0
    end
  end

This works, but it seems like it needs AR, checks if the ItemData table exists, etc.

I would like to do something like:

describe "Testing wrapped associations w/out persistence" do
   example do
      item = double('item')
      item.should_receive(:amount).and_return(2)
      order = Order.new
      order.items = [item]
      order.item_total.should eq 4
    end
end

(this gives me a NoMethodError for items=)

or

describe "Testing wrapped associations w/out persistence" do
     example do
      item = double('item')
      item.should_receive(:amount).and_return(2)
      order = Order.build OpenStruct.new(items: [item])
      order.item_total.should eq 4
    end
end

(this tells me that there's no model class for RSpec::Mocks::Mock)

Am I just running into limitations of what Edr is supposed to do, or should this work?

Or to put it another way, how do you test Entity methods that use associated data in the most isolated way possible?

Edr::Model should support entity equality

Comparing two Edr::Models fails even though they may have the same id.

Consider adding the following method to Edr::Model:

  def ==(other)
    other.instance_of?(self.class) && other.id == self.id
  end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.