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