Browse Source

CLDC-4515: don't reset address fields when location was changed from nil (i.e. on bulk upload log creation)

pull/3383/head
Nat Dean-Lewis 4 weeks ago
parent
commit
cc565b6424
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 33
      spec/models/lettings_log_derived_fields_spec.rb

2
app/models/derived_variables/lettings_log_variables.rb

@ -176,7 +176,7 @@ module DerivedVariables::LettingsLogVariables
if !form.start_year_2026_or_later? && is_supported_housing?
reset_address_fields!
elsif form.start_year_2026_or_later? && location_changed?
elsif form.start_year_2026_or_later? && location_changed? && location_id_was.present?
reset_address_fields!
self.la = nil
end

33
spec/models/lettings_log_derived_fields_spec.rb

@ -1583,6 +1583,39 @@ RSpec.describe LettingsLog, type: :model do
end
end
end
context "when it is 2026 and the log is new, with a location assigned for the first time (e.g. bulk upload)", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) }
let(:location_a) { create(:location) }
let(:log) { build(:lettings_log, startdate:, assigned_to: user) }
let(:la) { "E09000003" }
around do |example|
Timecop.freeze(collection_start_date_for_year(2026)) do
Singleton.__init__(FormHandler)
example.run
end
end
before do
allow(location_a).to receive(:lookup_postcode!).and_return(nil)
log.assign_attributes(location: location_a, uprn:, uprn_known:, uprn_confirmed:, address_line1:, address_line2:, town_or_city:, county:, postcode_full:, la:, manual_address_entry_selected:)
end
it "does not reset the address fields" do
expect { log.set_derived_fields! }
.to not_change { log.read_attribute(:uprn) }
.and not_change { log.read_attribute(:uprn_known) }
.and not_change { log.read_attribute(:uprn_confirmed) }
.and not_change { log.read_attribute(:address_line1) }
.and not_change { log.read_attribute(:address_line2) }
.and not_change { log.read_attribute(:town_or_city) }
.and not_change { log.read_attribute(:county) }
.and(not_change { log.read_attribute(:postcode_full) })
.and(not_change { log.read_attribute(:la) })
end
end
end
describe "address field behaviour for confidential schemes", metadata: { year: 26 } do

Loading…
Cancel
Save