diff --git a/spec/models/spree/order/state_machine_spec.rb b/spec/models/spree/order/state_machine_spec.rb index 3426532cb116..91b44e721c8a 100644 --- a/spec/models/spree/order/state_machine_spec.rb +++ b/spec/models/spree/order/state_machine_spec.rb @@ -20,36 +20,37 @@ allow(order).to receive_messages process_payments!: true end - context "when payment processing succeeds" do - before { allow(order).to receive_messages process_payments!: true } - - it "should finalize order when transitioning to complete state" do + context "when current state is confirmation" do + before do order.next expect(order.state).to eq "confirmation" - expect(order).to receive(:finalize!) - order.next! end - context "when credit card processing fails" do - before { allow(order).to receive_messages process_payments!: false } + context "when payment processing succeeds" do + before { allow(order).to receive_messages process_payments!: true } - it "should still complete the order" do - order.next - expect(order.state).to eq "confirmation" - order.next - expect(order.state).to eq "complete" + it "should finalize order when transitioning to complete state" do + expect(order).to receive(:finalize!) + order.next! + end + + context "when credit card processing fails" do + before { allow(order).to receive_messages process_payments!: false } + + it "should still complete the order" do + order.next + expect(order.state).to eq "complete" + end end end - end - context "when payment processing fails" do - before { allow(order).to receive_messages process_payments!: false } + context "when payment processing fails" do + before { allow(order).to receive_messages process_payments!: false } - it "can transition to complete" do - order.next - expect(order.state).to eq "confirmation" - order.next - expect(order.state).to eq "complete" + it "can transition to complete" do + order.next + expect(order.state).to eq "complete" + end end end end