From ec7512ba36f6a6ba675e249a528a9baffa100117 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Fri, 18 Sep 2026 10:05:04 +0300 Subject: [PATCH] Redirect forms-runner to 'Edit question routes' page when multiple branches enabled Currently when previewing a draft form with a route that goes backwards, forms-runner shows an error page instead of trapping the user in an infinite loop. The error page has a link to forms-admin, using the `redirect_from_forms_runner#routes` URL [[1]]. When the multiple branches feature is enabled for a form, we want the link from forms-runner to edit the routes for a question to go to the new 'Edit question routes' page, rather than the old routes journey. [1]: https://github.com/govuk-forms/forms-runner/blob/cfc34640ad85d2be9f7f21f055a3fd8212c47886/app/controllers/forms/step_controller.rb#L202). --- .../forms/redirect_from_forms_runner_controller.rb | 7 ++++++- .../redirect_from_forms_runner_controller_spec.rb | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/forms/redirect_from_forms_runner_controller.rb b/app/controllers/forms/redirect_from_forms_runner_controller.rb index fb80b775f6..143612d2f2 100644 --- a/app/controllers/forms/redirect_from_forms_runner_controller.rb +++ b/app/controllers/forms/redirect_from_forms_runner_controller.rb @@ -10,7 +10,12 @@ def edit_question def routes page_external_id = params.require(:page_external_id) page = current_form.pages.find_by!(external_id: page_external_id) - redirect_to show_routes_path(current_form.id, page.id) + + if FeatureService.new(group: current_form.group).enabled?(:multiple_branches) + redirect_to routes_path(current_form.id, anchor: page.page_position_id) + else + redirect_to show_routes_path(current_form.id, page.id) + end end private diff --git a/spec/requests/forms/redirect_from_forms_runner_controller_spec.rb b/spec/requests/forms/redirect_from_forms_runner_controller_spec.rb index 5aa9947601..63c6293919 100644 --- a/spec/requests/forms/redirect_from_forms_runner_controller_spec.rb +++ b/spec/requests/forms/redirect_from_forms_runner_controller_spec.rb @@ -81,8 +81,16 @@ expect(response).to have_http_status(302) end - it "redirects to the show routes page" do - expect(response).to redirect_to(show_routes_path(form_id: form.id, page_id: page.id)) + context "when the multiple branches feature is not enabled", feature_multiple_branches: false do + it "redirects to the show routes page" do + expect(response).to redirect_to(show_routes_path(form_id: form.id, page_id: page.id)) + end + end + + context "when the multiple branches feature is enabled", :feature_multiple_branches do + it "redirects to the edit routes page" do + expect(response).to redirect_to(routes_path(form_id: form.id, anchor: page.page_position_id)) + end end end