From 6b98cf354fa657dfbc9fe43b0d6b4e7f227ee3d1 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 11 Feb 2022 18:33:37 +0000 Subject: [PATCH] Fix page invalidation when no form set --- app/models/case_log.rb | 2 ++ spec/models/case_log_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index d95a9cc89..7bc032a0e 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -226,6 +226,8 @@ private end def reset_invalidated_dependent_fields! + return unless form + form.invalidated_page_questions(self).each do |question| public_send("#{question.id}=", nil) if respond_to?(question.id.to_s) end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 169822824..6151c248a 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -656,6 +656,10 @@ RSpec.describe CaseLog do case_log.update(age1: 25) end + it "validates start date" do + expect(validator).to receive(:validate_startdate) + end + it "validates ages" do expect(validator).to receive(:validate_person_1_age) expect(validator).to receive(:validate_household_number_of_other_members) @@ -1039,6 +1043,14 @@ RSpec.describe CaseLog do expect(case_log.cbl).to eq("Yes") end end + + context "when the case log does not have a valid form set yet" do + let(:case_log) { FactoryBot.create(:case_log) } + + it "does not throw an error" do + expect { case_log.update(startdate: Time.zone.local(2015, 1, 1)) }.not_to raise_error + end + end end describe "paper trail" do