From b9f60494d3a8608e8e3887463258a089ef9ff83f Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Thu, 23 Dec 2021 16:00:07 +0000 Subject: [PATCH] Redirect to tasklist page if section or question is not enabled yet (#183) --- app/controllers/form_controller.rb | 6 +++++- spec/requests/form_controller_spec.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 1ddafa4e9..573c8631a 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -35,7 +35,11 @@ class FormController < ApplicationController if @case_log @subsection = @case_log.form.subsection_for_page(page) @page = @case_log.form.get_page(page.id) - render "form/page" + if @page.routed_to?(@case_log) && @page.subsection.enabled?(@case_log) + render "form/page" + else + redirect_to case_log_path(@case_log) + end else render_not_found end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 2435209ac..5e6160098 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -76,6 +76,20 @@ RSpec.describe FormController, type: :request do end end end + + context "a question that in a section that isn't enabled yet" do + it "routes back to the tasklist page" do + get "/logs/#{case_log.id}/declaration", headers: headers, params: {} + expect(response).to redirect_to("/logs/#{case_log.id}") + end + end + + context "a question that isn't enabled yet" do + it "routes back to the tasklist page" do + get "/logs/#{case_log.id}/conditional-question-no-second-page", headers: headers, params: {} + expect(response).to redirect_to("/logs/#{case_log.id}") + end + end end describe "Submit Form" do