ruby on rails 3.2 - Fabrication gem with associations undefined method error -
i have started using fabrication gem rspec , on whole have had great success. however, don't seem able association fabrication work.
i using ruby 1.9.3, rails 3.2.12, rspec 2.13.0, , fabrication 2.7.0
models
class redistributionsale < activerecord::base belongs_to :account belongs_to :customer has_many :red_sale_itemisations, :dependent => :destroy has_many :materials, :through => :red_sale_itemisations class redsaleitemisation < activerecord::base belongs_to :redistribution_sale belongs_to :material fabricator
fabricator(:redistribution_sale) invoice_number { sequence(:invoice_number) { |i| } } status "sales receipt" end fabricator(:red_sale_itemisation) quantity 1 material_id 1 redistribution_sale_id 1 end at point can fabricate either of 2 models independently. want build them @ same time test model code
i have following test
it "returns correct unit prices with" material_1 = fabricate(:material, l1price: 7.7, l2price: 8.8, discount: false) redistribution_sale = fabricate(:redistribution_sale, ) red_sale_itemisations { fabricate(:red_sale_itemisation, material_id: material_1.id, quantity: 2 ) } end expect(redistribution_sale.total_value).to eq 17.6 end however, following error
failures: 1) redistributionsale calculated fields returns correct unit prices failure/error: redistribution_sale = fabricate(:redistribution_sale) nomethoderror: undefined method `each' #<redsaleitemisation:0x00000008308d58> # ./spec/models/redistribution_sale_spec.rb:87:in `block (3 levels) in <top (required)>' is has been seen before, or doing horribly wrong?
michael
this bug in fabrication think. can past error wrapping contents of red_sale_itemisations in array, so:
it "returns correct unit prices with" material_1 = fabricate(:material, l1price: 7.7, l2price: 8.8, discount: false) redistribution_sale = fabricate(:redistribution_sale, ) red_sale_itemisations { [fabricate(:red_sale_itemisation, material_id: material_1.id, quantity: 2 )] } end expect(redistribution_sale.total_value).to eq 17.6 end
Comments
Post a Comment