Skip to content

Commit

Permalink
DRY up code
Browse files Browse the repository at this point in the history
  • Loading branch information
dacook committed Jun 8, 2023
1 parent d888809 commit e68a246
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions spec/models/spree/order/state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e68a246

Please sign in to comment.