fix(goals): test pledge new across both turbo-frame and full-page paths

CI failure on the prior commit: `GoalPledgesControllerTest#
test_new_renders_the_pledge_form` expected 200 but got a 302 to
the goal show page. The recently-added non-frame guard on
`GoalPledgesController#new` redirects direct GETs (F5, bookmark)
back to the goal so the dialog doesn't render standalone, and the
test wasn't sending the `Turbo-Frame` header that the modal flow
uses in production.

Split the test into the two paths the controller actually serves:

- `new renders the pledge form inside a turbo frame` passes a
  `Turbo-Frame: modal` header and asserts 200 — the real modal
  flow.
- `new redirects to the goal show page on a non-frame GET` asserts
  the 302 to `goal_path(@goal)` — the guard's intended branch.

Together they cover the controller's actual contract.
This commit is contained in:
Guillem Arias
2026-05-14 22:54:05 +02:00
parent afc67d07ae
commit ad101f619a

View File

@@ -9,11 +9,16 @@ class GoalPledgesControllerTest < ActionDispatch::IntegrationTest
ensure_tailwind_build
end
test "new renders the pledge form" do
get new_goal_pledge_url(@goal)
test "new renders the pledge form inside a turbo frame" do
get new_goal_pledge_url(@goal), headers: { "Turbo-Frame" => "modal" }
assert_response :success
end
test "new redirects to the goal show page on a non-frame GET" do
get new_goal_pledge_url(@goal)
assert_redirected_to goal_path(@goal)
end
test "create opens a pledge with default kind" do
assert_difference -> { GoalPledge.count } => 1 do
post goal_pledges_url(@goal), params: {