From 62a7a0db7c2ae3f61daaaa9453c5cecc3626190a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 9 Jan 2013 10:50:17 +1100 Subject: [PATCH] Add spec for updating exchanges --- .../order_cycle_form_applicator_spec.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb b/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb index f73c693a84..26804d06aa 100644 --- a/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb +++ b/spec/lib/open_food_web/order_cycle_form_applicator_spec.rb @@ -38,7 +38,24 @@ module OpenFoodWeb applicator.send(:touched_exchanges).should == [exchange] end - it "updates exchanges" + it "updates exchanges" do + oc = FactoryGirl.create(:simple_order_cycle) + applicator = OrderCycleFormApplicator.new(oc) + sender = FactoryGirl.create(:enterprise) + receiver = FactoryGirl.create(:enterprise) + variant1 = FactoryGirl.create(:variant) + variant2 = FactoryGirl.create(:variant) + variant3 = FactoryGirl.create(:variant) + + exchange = FactoryGirl.create(:exchange, order_cycle: oc, sender: sender, receiver: receiver, variant_ids: [variant1, variant2]) + + applicator.send(:touched_exchanges=, []) + applicator.send(:update_exchange, sender.id, receiver.id, [variant1.id, variant3.id]) + + exchange.reload + exchange.variant_ids.should == [variant1.id, variant3.id] + applicator.send(:touched_exchanges).should == [exchange] + end end context "unit specs" do