Reorder specs

This commit is contained in:
Rohan Mitchell
2013-01-17 15:13:41 +11:00
parent 8f17df0e45
commit 12dad2468d

View File

@@ -2,62 +2,6 @@ require 'open_food_web/order_cycle_form_applicator'
module OpenFoodWeb
describe OrderCycleFormApplicator do
context "integration specs" do
before(:all) do
require 'spec_helper'
end
it "checks whether exchanges exist" do
oc = FactoryGirl.create(:simple_order_cycle)
exchange = FactoryGirl.create(:exchange, order_cycle: oc)
applicator = OrderCycleFormApplicator.new(oc)
applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id).should be_true
applicator.send(:exchange_exists?, exchange.receiver_id, exchange.sender_id).should be_false
applicator.send(:exchange_exists?, exchange.sender_id, 999).should be_false
applicator.send(:exchange_exists?, 999, exchange.receiver_id).should be_false
applicator.send(:exchange_exists?, 999, 888).should be_false
end
it "adds 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)
applicator.send(:touched_exchanges=, [])
applicator.send(:add_exchange, sender.id, receiver.id, [variant1.id, variant2.id])
exchange = Exchange.last
exchange.sender.should == sender
exchange.receiver.should == receiver
exchange.variants.sort.should == [variant1, variant2].sort
applicator.send(:touched_exchanges).should == [exchange]
end
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
it "creates new exchanges for incoming_exchanges" do
coordinator_id = 123
@@ -122,5 +66,61 @@ module OpenFoodWeb
applicator.send(:exchange_variant_ids, {:enterprise_id => 123, :variants => {'1' => true, '2' => false, '3' => true}}).should == [1, 3]
end
end
context "integration specs" do
before(:all) do
require 'spec_helper'
end
it "checks whether exchanges exist" do
oc = FactoryGirl.create(:simple_order_cycle)
exchange = FactoryGirl.create(:exchange, order_cycle: oc)
applicator = OrderCycleFormApplicator.new(oc)
applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id).should be_true
applicator.send(:exchange_exists?, exchange.receiver_id, exchange.sender_id).should be_false
applicator.send(:exchange_exists?, exchange.sender_id, 999).should be_false
applicator.send(:exchange_exists?, 999, exchange.receiver_id).should be_false
applicator.send(:exchange_exists?, 999, 888).should be_false
end
it "adds 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)
applicator.send(:touched_exchanges=, [])
applicator.send(:add_exchange, sender.id, receiver.id, [variant1.id, variant2.id])
exchange = Exchange.last
exchange.sender.should == sender
exchange.receiver.should == receiver
exchange.variants.sort.should == [variant1, variant2].sort
applicator.send(:touched_exchanges).should == [exchange]
end
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
end
end