From 944915256d1896f143c6ed875855aabb9830baa6 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 14 Feb 2022 14:55:23 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20inferring=20postcode=20(it=20works=20?= =?UTF-8?q?=F0=9F=A4=B7=E2=80=8D=E2=99=80=EF=B8=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/form.rb | 4 +++- spec/features/form/accessible_autocomplete_spec.rb | 2 ++ spec/features/form/check_answers_page_spec.rb | 2 ++ spec/fixtures/forms/2021_2022.json | 8 +++++++- spec/models/form/subsection_spec.rb | 2 ++ spec/requests/case_logs_controller_spec.rb | 2 ++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index b3562a727..eb522e468 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -114,9 +114,11 @@ class Form end def invalidated_page_questions(case_log) + #we're already treating address fields as a special case and reset their values upon saving a case_log + address_questions = %w[postcode_known la previous_postcode_known prevloc property_postcode previous_postcode] pages_that_are_routed_to = pages.select { |p| p.routed_to?(case_log) } enabled_question_ids = pages_that_are_routed_to.flat_map(&:questions).map(&:id) || [] - invalidated_pages(case_log).flat_map(&:questions).reject { |q| enabled_question_ids.include?(q.id) } || [] + invalidated_pages(case_log).flat_map(&:questions).reject { |q| enabled_question_ids.include?(q.id) || address_questions.include?(q.id) } || [] end def invalidated_conditional_questions(case_log) diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb index 4f96b79ab..4f2f15c46 100644 --- a/spec/features/form/accessible_autocomplete_spec.rb +++ b/spec/features/form/accessible_autocomplete_spec.rb @@ -8,6 +8,8 @@ RSpec.describe "Accessible Automcomplete" do FactoryBot.create( :case_log, :in_progress, + la_known: "Yes", + is_la_inferred: false, owning_organisation: user.organisation, managing_organisation: user.organisation, ) diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index b92153877..1e2f3e97a 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -17,6 +17,8 @@ RSpec.describe "Form Check Answers Page" do let(:empty_case_log) do FactoryBot.create( :case_log, + la_known: "Yes", + is_la_inferred: false, owning_organisation: user.organisation, managing_organisation: user.organisation, ) diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 2495baf7a..3bd4edd21 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -251,7 +251,13 @@ "E06000014": "York" } } - } + }, + "depends_on": [ + { + "la_known": "Yes", + "is_la_inferred": false + } + ] }, "condition_effects": { "questions": { diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index d086356f4..23527a5cd 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -70,6 +70,8 @@ RSpec.describe Form::Subsection, type: :model do case_log.armedforces = "No" case_log.illness = "No" case_log.housingneeds_a = "Yes" + case_log.la_known = "Yes" + case_log.is_la_inferred = false case_log.la = "York" case_log.illness_type_1 = "Yes" expect(sub_section.answered_questions(case_log).map(&:id)).to eq(expected_questions) diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index b9ae0105b..463757b05 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -278,6 +278,8 @@ RSpec.describe CaseLogsController, type: :request do case_log = FactoryBot.create(:case_log, owning_organisation: organisation, managing_organisation: organisation, + la_known: "Yes", + is_la_inferred: true, postcode_known: "Yes", property_postcode: "PO5 3TE") id = case_log.id