From ad101f619a28a71245026e2ef83fa73f4e112aee Mon Sep 17 00:00:00 2001 From: Guillem Arias Date: Thu, 14 May 2026 22:54:05 +0200 Subject: [PATCH] fix(goals): test pledge new across both turbo-frame and full-page paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- test/controllers/goal_pledges_controller_test.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/controllers/goal_pledges_controller_test.rb b/test/controllers/goal_pledges_controller_test.rb index 9de4ad443..af9227ad5 100644 --- a/test/controllers/goal_pledges_controller_test.rb +++ b/test/controllers/goal_pledges_controller_test.rb @@ -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: {