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