nulogy / edr Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
You don't want to define registries in a test context, if the registry isn't there, it complains about a class variable not being there. Workaround is Edr::Registry.define {}
in the spec helper
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?
The following link is broken: http://engineering.nulogy.com/posts/building-rich-domain-models-in-rails-separating-persistence
It would be great if you folks could release a new gem since PR #5 has been merged.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.