forked from spree/spree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Order state changes are now tracked after all transitions, exactly li…
…ke shipments and payment state transitions Fixes spree#3850
- Loading branch information
Showing
4 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
describe Spree::Order do | ||
let(:order) { Spree::Order.new } | ||
|
||
def assert_state_changed(order, from, to) | ||
state_change_exists = order.state_changes.where(:previous_state => from, :next_state => to).exists? | ||
assert state_change_exists, "Expected order to transition from #{from} to #{to}, but didn't." | ||
end | ||
|
||
context "with default state machine" do | ||
let(:transitions) do | ||
[ | ||
|
@@ -87,6 +92,7 @@ | |
order.line_items << FactoryGirl.create(:line_item) | ||
order.email = "[email protected]" | ||
order.next! | ||
assert_state_changed(order, 'cart', 'address') | ||
order.state.should == "address" | ||
end | ||
|
||
|
@@ -120,6 +126,7 @@ | |
it "transitions to delivery" do | ||
order.stub(:ensure_available_shipping_rates => true) | ||
order.next! | ||
assert_state_changed(order, 'address', 'delivery') | ||
order.state.should == "delivery" | ||
end | ||
|
||
|
@@ -146,6 +153,7 @@ | |
it "transitions to payment" do | ||
order.should_receive(:set_shipments_cost) | ||
order.next! | ||
assert_state_changed(order, 'delivery', 'payment') | ||
order.state.should == 'payment' | ||
end | ||
end | ||
|
@@ -174,6 +182,7 @@ | |
|
||
it "transitions to confirm" do | ||
order.next! | ||
assert_state_changed(order, 'payment', 'confirm') | ||
order.state.should == "confirm" | ||
end | ||
end | ||
|
@@ -187,6 +196,7 @@ | |
it "transitions to complete" do | ||
order.should_receive(:process_payments!).once.and_return true | ||
order.next! | ||
assert_state_changed(order, 'payment', 'complete') | ||
order.state.should == "complete" | ||
end | ||
end | ||
|
@@ -200,6 +210,7 @@ | |
it "does not call process payments" do | ||
order.should_not_receive(:process_payments!) | ||
order.next! | ||
assert_state_changed(order, 'payment', 'complete') | ||
order.state.should == "complete" | ||
end | ||
end | ||
|
@@ -222,6 +233,7 @@ class SubclassedOrder < Spree::Order | |
order.should_receive(:process_payments!).once | ||
order.state = "payment" | ||
order.next! | ||
assert_state_changed(order, 'payment', 'complete') | ||
order.state.should == "complete" | ||
end | ||
end | ||
|
@@ -275,6 +287,7 @@ class SubclassedOrder < Spree::Order | |
order.should_not_receive(:payment_required?) | ||
order.should_not_receive(:process_payments!) | ||
order.next! | ||
assert_state_changed(order, 'cart', 'complete') | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters