Prevent exception when payment has been cleared

Note that in the real world, this avoids a crash, but still requires the user to click the button two more times before it will work, with no hints as to why. So not a great help.
This commit is contained in:
David Cook
2025-03-06 17:19:49 +11:00
parent 25eb00f69c
commit f37742d84a
2 changed files with 4 additions and 3 deletions

View File

@@ -92,7 +92,10 @@ module Orders
# Verifies if the in-memory payment state is different from the one stored in the database
# This is be done without reloading the payment so that in-memory data is not changed
def different_from_db_payment_state?(in_memory_payment_state, payment_id)
in_memory_payment_state != Spree::Payment.find(payment_id).state
# Re-load payment from the DB (unless it was cleared by clear_invalid_payments)
db_payment = Spree::Payment.find_by(id: payment_id)
db_payment.present? && in_memory_payment_state != db_payment.state
end
end
end

View File

@@ -368,8 +368,6 @@ RSpec.describe CheckoutController, type: :controller do
end
it "deletes invalid (old) payments" do
pending "#12693 ActiveRecord::RecordNotFound: Couldn't find Spree::Payment"
put(:update, params:)
order.payments.reload
expect(order.payments).not_to include other_payment