diff --git a/app/models/form.rb b/app/models/form.rb index 16c896e4c..5e33cc94b 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -126,6 +126,9 @@ class Form if log.status == "completed" return first_question_in_last_subsection(subsection_ids) + elsif log.calculate_status == "completed" + log.update(status: "completed") + return first_question_in_last_subsection(subsection_ids) end next_subsection = next_subsection(subsection, log, subsection_ids) diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb index ec119fbdc..8cb459117 100644 --- a/spec/factories/lettings_log.rb +++ b/spec/factories/lettings_log.rb @@ -146,6 +146,8 @@ FactoryBot.define do joint { 3 } address_line1 { "fake address" } town_or_city { "London" } + ppcodenk { 0 } + tshortfall_known { 1 } end trait :export do tenancycode { "987654" } diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index b63d05f62..696a8d400 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -190,8 +190,6 @@ RSpec.describe Form, type: :model do FormHandler.instance.use_real_forms! example.run - - FormHandler.instance.use_fake_forms! end it "finds the path to the section after" do @@ -202,6 +200,21 @@ RSpec.describe Form, type: :model do expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("joint") end end + + context "when a log has status in progress but all subsections are complete" do + let(:lettings_log) { build(:lettings_log, :completed, status: "in_progress") } + let(:subsection) { form.get_subsection("setup") } + + around do |example| + FormHandler.instance.use_real_forms! + + example.run + end + + it "should not raise a Stack Error" do + expect { form.next_incomplete_section_redirect_path(subsection, lettings_log) }.not_to raise_error + end + end end describe "#reset_not_routed_questions_and_invalid_answers" do