From 3d50f4e080ebda4147d3c8e8ead12de7e41b2ee2 Mon Sep 17 00:00:00 2001 From: oscric Date: Thu, 13 Aug 2026 09:06:46 +0100 Subject: [PATCH] Fix bug where the UPRN/address questions were not shown after switching from a confidential to a non-confidential scheme --- .../lettings_log_variables.rb | 1 - .../lettings_log_derived_fields_spec.rb | 42 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 4b6ed27af..230b2a1dc 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -185,7 +185,6 @@ module DerivedVariables::LettingsLogVariables reset_address_fields! self.uprn_selection = nil self.postcode_known = nil - self.manual_address_entry_selected = nil end clear_gender_description_unless_gender_not_same_as_sex! if form.start_year_2026_or_later? diff --git a/spec/models/lettings_log_derived_fields_spec.rb b/spec/models/lettings_log_derived_fields_spec.rb index 50d0d86e5..51063e11a 100644 --- a/spec/models/lettings_log_derived_fields_spec.rb +++ b/spec/models/lettings_log_derived_fields_spec.rb @@ -1637,8 +1637,12 @@ RSpec.describe LettingsLog, type: :model do .and change { log.read_attribute(:county) }.from(county).to(nil) .and change { log.read_attribute(:postcode_full) }.from(postcode_full).to(nil) .and change { log.read_attribute(:uprn_selection) }.from(uprn_selection).to(nil) - .and change { log.read_attribute(:postcode_known) }.from(postcode_known).to(nil) - .and change { log.read_attribute(:manual_address_entry_selected) }.from(manual_address_entry_selected).to(nil) + .and(change { log.read_attribute(:postcode_known) }.from(postcode_known).to(nil)) + end + + it "does not reset `manual_address_entry_selected`;" do + expect { log.set_derived_fields! } + .not_to(change { log.read_attribute(:manual_address_entry_selected) }) end context "when the log is a new-build first let" do @@ -1664,8 +1668,12 @@ RSpec.describe LettingsLog, type: :model do .and change { log.read_attribute(:county) }.from(county).to(nil) .and change { log.read_attribute(:postcode_full) }.from(postcode_full).to(nil) .and change { log.read_attribute(:uprn_selection) }.from(uprn_selection).to(nil) - .and change { log.read_attribute(:postcode_known) }.from(postcode_known).to(nil) - .and change { log.read_attribute(:manual_address_entry_selected) }.from(manual_address_entry_selected).to(nil) + .and(change { log.read_attribute(:postcode_known) }.from(postcode_known).to(nil)) + end + + it "does not reset `manual_address_entry_selected`;" do + expect { log.set_derived_fields! } + .not_to(change { log.read_attribute(:manual_address_entry_selected) }) end end end @@ -1690,6 +1698,32 @@ RSpec.describe LettingsLog, type: :model do .to change(log, :manual_address_entry_selected).from(false).to(true) end end + + context "when a log is changed from a confidential to a non-confidential scheme" do + # The confidential logic must leave manual_address_entry_selected in a + # routable state (default false), otherwise neither address page routes after the + # switch and the address question is never shown again. + let(:confidential_scheme) { create(:scheme, sensitive: 1) } + let(:non_confidential_scheme) { create(:scheme, sensitive: 0) } + let(:confidential_location) { create(:location, scheme: confidential_scheme) } + let(:non_confidential_location) { create(:location, scheme: non_confidential_scheme) } + + before do + log.assign_attributes(manual_address_entry_selected: false) + log.scheme = confidential_scheme + log.location = confidential_location + log.set_derived_fields! + + log.scheme = non_confidential_scheme + log.location = non_confidential_location + log.set_derived_fields! + end + + it "asks the address question again with a routable value for `manual_address_entry_selected` (i.e., not nil)" do + expect(log.is_address_asked?).to be true + expect(log.manual_address_entry_selected).to be false + end + end end describe "#infer_at_most_one_relationship!" do