From ede9beb38563c021318afe9b268a40726a69cee7 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Fri, 16 Jun 2023 12:56:02 +0100 Subject: [PATCH] Only set @interruption_page_id if http referrer is provided (#1697) --- app/controllers/form_controller.rb | 2 +- spec/requests/form_controller_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 5bd151181..07ec12c5d 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -46,7 +46,7 @@ class FormController < ApplicationController end def show_page - if request.params["referrer"] == "interruption_screen" + if request.params["referrer"] == "interruption_screen" && request.headers["HTTP_REFERER"].present? @interruption_page_id = URI.parse(request.headers["HTTP_REFERER"]).path.split("/").last.underscore @interruption_page_referrer_type = referrer_from_query end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 5d9042c7c..a2c06c4f1 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -582,6 +582,31 @@ RSpec.describe FormController, type: :request do end end end + + context "when requesting a soft validation page without a http referrer header" do + before do + get "/lettings-logs/#{lettings_log.id}/#{page_path}?referrer=interruption_screen", headers: + end + + context "when the page is routed to" do + let(:page_path) { page_id.dasherize } + + it "directs to the question page" do + expect(response.body).to include("What is the tenant’s age?") + expect(response.body).to include("Skip for now") + end + end + + context "when the page is not routed to" do + let(:page_path) { "person-2-working-situation" } + + it "redirects to the log page" do + follow_redirect! + expect(response.body).to include("Before you start") + expect(response.body).not_to include("Skip for now") + end + end + end end context "with checkbox questions" do