Skip to content

Commit

Permalink
Attempt to spec for error
Browse files Browse the repository at this point in the history
I'm trying to replicate issue openfoodfoundation#12693, but am not sure how to.
Hmm, maybe it should be mocking an exception during payment, which causes the rollback.
  • Loading branch information
dacook committed Jul 22, 2024
1 parent 5caeb16 commit 95c36e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def check_payments_adjustments

def clear_invalid_payments
@order.payments.with_state(:invalid).delete_all
# todo: delete all invalid payments, and somehow remove them from the association without reloading any valid payments?

Check warning on line 71 in app/controllers/checkout_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [123/100] Raw Output: app/controllers/checkout_controller.rb:71:101: C: Layout/LineLength: Line is too long. [123/100]
# how about loop through them, delete and reload one by one.
end

def confirm_order
Expand Down
17 changes: 17 additions & 0 deletions spec/controllers/checkout_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@
expect(response).to redirect_to checkout_step_path(:summary)
end
end

context "with existing invalid payments" do
let(:invalid_payments) { [

Check warning on line 311 in spec/controllers/checkout_controller_spec.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Block body expression is on the same line as the block start. Raw Output: spec/controllers/checkout_controller_spec.rb:311:36: C: Layout/MultilineBlockLayout: Block body expression is on the same line as the block start.
create(:payment, state: :failed),

Check warning on line 312 in spec/controllers/checkout_controller_spec.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is. Raw Output: spec/controllers/checkout_controller_spec.rb:312:15: C: Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is.
create(:payment, state: :void),
] }

Check warning on line 314 in spec/controllers/checkout_controller_spec.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Indent the right bracket the same as the start of the line where the left bracket is. Raw Output: spec/controllers/checkout_controller_spec.rb:314:13: C: Layout/FirstArrayElementIndentation: Indent the right bracket the same as the start of the line where the left bracket is.

Check warning on line 314 in spec/controllers/checkout_controller_spec.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Expression at 314, 15 should be on its own line. Raw Output: spec/controllers/checkout_controller_spec.rb:314:15: C: Layout/BlockEndNewline: Expression at 314, 15 should be on its own line.

before do
order.payments = invalid_payments
end

it "deletes invalid payments" do
expect{
put(:update, params:)
}.to change { order.payments.to_a }.from(invalid_payments)
end
end
end

context "with no payment source" do
Expand Down

0 comments on commit 95c36e0

Please sign in to comment.