Browse Source

CLDC-4515: Bulk upload address data clearing bug fix (#3383)

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

* CLDC-4515: update lettings log controller and lettings cya tests

* CLDC-4515: update lettings log spec and use persisted? for cleanliness

* CLDC-4515: use location postcode in spec over nil postcode
pull/3376/merge v0.6.20
Nat Dean-Lewis 2 weeks ago committed by GitHub
parent
commit
4e23c719be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 1
      spec/features/form/check_answers_page_lettings_logs_spec.rb
  3. 33
      spec/models/lettings_log_derived_fields_spec.rb
  4. 4
      spec/models/lettings_log_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? if !form.start_year_2026_or_later? && is_supported_housing?
reset_address_fields! reset_address_fields!
elsif form.start_year_2026_or_later? && location_changed? elsif form.start_year_2026_or_later? && location_changed? && persisted?
reset_address_fields! reset_address_fields!
self.la = nil self.la = nil
end end

1
spec/features/form/check_answers_page_lettings_logs_spec.rb

@ -18,6 +18,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
needstype: 2, needstype: 2,
scheme:, scheme:,
location:, location:,
postcode_full: location.postcode,
) )
end end
let(:empty_lettings_log) do let(:empty_lettings_log) do

33
spec/models/lettings_log_derived_fields_spec.rb

@ -1583,6 +1583,39 @@ RSpec.describe LettingsLog, type: :model do
end end
end 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 end
describe "address field behaviour for confidential schemes", metadata: { year: 26 } do describe "address field behaviour for confidential schemes", metadata: { year: 26 } do

4
spec/models/lettings_log_spec.rb

@ -1965,8 +1965,8 @@ RSpec.describe LettingsLog do
context "when there is a duplicate supported housing log" do context "when there is a duplicate supported housing log" do
let(:scheme) { create(:scheme, owning_organisation: organisation) } let(:scheme) { create(:scheme, owning_organisation: organisation) }
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
let!(:supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation) } let!(:supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation, postcode_full: location.postcode) }
let!(:duplicate_supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation) } let!(:duplicate_supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation, postcode_full: location.postcode) }
it "returns the log as a duplicate" do it "returns the log as a duplicate" do
expect(duplicate_sets).to contain_exactly( expect(duplicate_sets).to contain_exactly(

Loading…
Cancel
Save