From 27395cea159a446a7315168e692b193e26bd55d9 Mon Sep 17 00:00:00 2001 From: fumimowdan Date: Mon, 2 Oct 2023 13:44:37 +0100 Subject: [PATCH] Avoid jumping in the middle of an application form flow --- app/services/step_flow.rb | 1 + spec/services/step_flow_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/services/step_flow.rb b/app/services/step_flow.rb index 0dbf9190..f3ac1139 100644 --- a/app/services/step_flow.rb +++ b/app/services/step_flow.rb @@ -30,6 +30,7 @@ def matches?(request) end def current_step(form, requested_step_name) + return if form.blank? && requested_step_name != ApplicationRouteStep::ROUTE_KEY return ApplicationRouteStep.new(Form.new) unless form STEPS.fetch(requested_step_name).new(form) diff --git a/spec/services/step_flow_spec.rb b/spec/services/step_flow_spec.rb index ae872d7d..d660b320 100644 --- a/spec/services/step_flow_spec.rb +++ b/spec/services/step_flow_spec.rb @@ -82,6 +82,13 @@ let(:form) { nil } let(:step_name) { "personal-details" } + it { is_expected.to be_nil } + end + + context "when form is nil and requested step is application-route" do + let(:form) { nil } + let(:step_name) { "application-route" } + it { is_expected.to be_instance_of(ApplicationRouteStep) } end