From 4888f1cd06880fa8bc6d9aa9273f569a801f69c8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 20:35:30 +0100 Subject: [PATCH] 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. --- spec/services/checkout/stripe_redirect_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/services/checkout/stripe_redirect_spec.rb b/spec/services/checkout/stripe_redirect_spec.rb index 05b46dfe25..6d5830e3c9 100644 --- a/spec/services/checkout/stripe_redirect_spec.rb +++ b/spec/services/checkout/stripe_redirect_spec.rb @@ -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'