Fix broken #payment_intent spec in donations controller#13802
Merged
manuthecoder merged 1 commit intoMay 26, 2026
Merged
Conversation
The test added in #13705 had two bugs: 1. `create(:donation, in_person: true)` triggers the `before_create :create_stripe_payment_intent` callback (recurring? is false), which calls StripeService::Customer.create and StripeService::PaymentIntent.create. WebMock is active in tests, so those unmocked HTTP calls raised WebMock::NetConnectNotAllowedError. Fix: add `before { stub_donation_payment_intent_creation }` so the Stripe calls are intercepted before the donation is created. 2. The controller renders `render json: {...}` without a `status:` keyword, defaulting to HTTP 200. The test asserted `have_http_status(:created)` (201). Fix: assert `:ok` instead. Also removed the spurious `allow(StripeService::PaymentIntent).to receive(:create)` stub placed after `create(:donation)` — the `payment_intent` action reads `donation.stripe_payment_intent_id` from the DB and never calls that method, so the mock had no effect and the hardcoded expected values were wrong. https://claude.ai/code/session_01ANVXcC1VdckGJ2aYcaw3Ag
00d2e8f
into
mxg-improve-receipt-card-locking-requirements
24 of 25 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test added in #13705 had two bugs:
create(:donation, in_person: true)triggers thebefore_create :create_stripe_payment_intentcallback (recurring? is false), which calls StripeService::Customer.create and StripeService::PaymentIntent.create. WebMock is active in tests, so those unmocked HTTP calls raised WebMock::NetConnectNotAllowedError. Fix: addbefore { stub_donation_payment_intent_creation }so the Stripe calls are intercepted before the donation is created.The controller renders
render json: {...}without astatus:keyword, defaulting to HTTP 200. The test assertedhave_http_status(:created)(201). Fix: assert:okinstead.Also removed the spurious
allow(StripeService::PaymentIntent).to receive(:create)stub placed aftercreate(:donation)— thepayment_intentaction readsdonation.stripe_payment_intent_idfrom the DB and never calls that method, so the mock had no effect and the hardcoded expected values were wrong.https://claude.ai/code/session_01ANVXcC1VdckGJ2aYcaw3Ag
Summary of the problem
Describe your changes