Stub OrderPaymentFinder to return correct object

OrderPaymentFinder was re-fetching the payment object from the database, so the subsequent line that stubs #authorize! on that payment was not being applied to the correct object.
This commit is contained in:
Matt-Yorkley
2021-04-10 20:35:30 +01:00
parent 31fc6201fc
commit 4888f1cd06

View File

@@ -38,6 +38,8 @@ describe Checkout::StripeRedirect do
it "returns the redirect path" do
stripe_payment = create(:payment, payment_method_id: payment_method.id)
order.payments << stripe_payment
allow(OrderPaymentFinder).to receive_message_chain(:new, :last_pending_payment).
and_return(stripe_payment)
allow(stripe_payment).to receive(:authorize!) do
# Authorization moves the payment state from checkout/processing to pending
stripe_payment.state = 'pending'