Browse Source

protect against stack level errors in the case where a log has the status in progress but due to changes in the form should now have the status completed

further update the lettings log factory as the :completed trait was producing logs that were not copmlete
pull/1698/head
Arthur Campbell 3 years ago
parent
commit
d6d046904f
  1. 3
      app/models/form.rb
  2. 2
      spec/factories/lettings_log.rb
  3. 17
      spec/models/form_spec.rb

3
app/models/form.rb

@ -126,6 +126,9 @@ class Form
if log.status == "completed" if log.status == "completed"
return first_question_in_last_subsection(subsection_ids) 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 end
next_subsection = next_subsection(subsection, log, subsection_ids) next_subsection = next_subsection(subsection, log, subsection_ids)

2
spec/factories/lettings_log.rb

@ -146,6 +146,8 @@ FactoryBot.define do
joint { 3 } joint { 3 }
address_line1 { "fake address" } address_line1 { "fake address" }
town_or_city { "London" } town_or_city { "London" }
ppcodenk { 0 }
tshortfall_known { 1 }
end end
trait :export do trait :export do
tenancycode { "987654" } tenancycode { "987654" }

17
spec/models/form_spec.rb

@ -190,8 +190,6 @@ RSpec.describe Form, type: :model do
FormHandler.instance.use_real_forms! FormHandler.instance.use_real_forms!
example.run example.run
FormHandler.instance.use_fake_forms!
end end
it "finds the path to the section after" do 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") expect(form.next_incomplete_section_redirect_path(subsection, lettings_log)).to eq("joint")
end end
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 end
describe "#reset_not_routed_questions_and_invalid_answers" do describe "#reset_not_routed_questions_and_invalid_answers" do

Loading…
Cancel
Save