Clearing the cart when order cycle is changed

This commit is contained in:
Will Marshall
2014-04-09 15:40:02 +10:00
parent 2bfbce65d8
commit 093004a460
2 changed files with 8 additions and 4 deletions

View File

@@ -85,6 +85,7 @@ Spree::Order.class_eval do
def set_order_cycle!(order_cycle)
self.order_cycle = order_cycle
self.distributor = nil unless order_cycle.nil? || order_cycle.has_distributor?(distributor)
self.empty!
save!
end

View File

@@ -181,14 +181,19 @@ describe Spree::Order do
end
describe "setting the order cycle" do
let(:oc) { create(:simple_order_cycle) }
it "empties the cart when changing the order cycle" do
subject.should_receive(:empty!)
subject.set_order_cycle! oc
end
it "sets the order cycle when no distributor is set" do
oc = create(:simple_order_cycle)
subject.set_order_cycle! oc
subject.order_cycle.should == oc
end
it "keeps the distributor when it is available in the new order cycle" do
oc = create(:simple_order_cycle)
d = create(:distributor_enterprise)
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d, incoming: false)
@@ -200,7 +205,6 @@ describe Spree::Order do
end
it "clears the distributor if it is not available at that order cycle" do
oc = create(:simple_order_cycle)
d = create(:distributor_enterprise)
subject.distributor = d
@@ -211,7 +215,6 @@ describe Spree::Order do
end
it "clears the order cycle when setting to nil" do
oc = create(:simple_order_cycle)
d = create(:distributor_enterprise)
subject.set_order_cycle! oc
subject.distributor = d