Browse Source

Fix bug where the UPRN/address questions were not shown after switching from a confidential to a non-confidential scheme

pull/3373/head
oscric 4 weeks ago
parent
commit
3d50f4e080
  1. 1
      app/models/derived_variables/lettings_log_variables.rb
  2. 42
      spec/models/lettings_log_derived_fields_spec.rb

1
app/models/derived_variables/lettings_log_variables.rb

@ -185,7 +185,6 @@ module DerivedVariables::LettingsLogVariables
reset_address_fields! reset_address_fields!
self.uprn_selection = nil self.uprn_selection = nil
self.postcode_known = nil self.postcode_known = nil
self.manual_address_entry_selected = nil
end end
clear_gender_description_unless_gender_not_same_as_sex! if form.start_year_2026_or_later? clear_gender_description_unless_gender_not_same_as_sex! if form.start_year_2026_or_later?

42
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(:county) }.from(county).to(nil)
.and change { log.read_attribute(:postcode_full) }.from(postcode_full).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(:uprn_selection) }.from(uprn_selection).to(nil)
.and change { log.read_attribute(:postcode_known) }.from(postcode_known).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) 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
context "when the log is a new-build first let" do 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(:county) }.from(county).to(nil)
.and change { log.read_attribute(:postcode_full) }.from(postcode_full).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(:uprn_selection) }.from(uprn_selection).to(nil)
.and change { log.read_attribute(:postcode_known) }.from(postcode_known).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) 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 end
end end
@ -1690,6 +1698,32 @@ RSpec.describe LettingsLog, type: :model do
.to change(log, :manual_address_entry_selected).from(false).to(true) .to change(log, :manual_address_entry_selected).from(false).to(true)
end end
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 end
describe "#infer_at_most_one_relationship!" do describe "#infer_at_most_one_relationship!" do

Loading…
Cancel
Save