Browse Source

CLDC-2890 Clear LA if it's no longer valid (#2789)

* Clear LA if it's no longer valid

* lint

* lint
pull/2807/head^2
kosiakkatrina 1 month ago committed by GitHub
parent
commit
f7cf3a1641
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      app/models/derived_variables/lettings_log_variables.rb
  2. 5
      app/models/derived_variables/sales_log_variables.rb
  3. 15
      spec/models/lettings_log_spec.rb
  4. 17
      spec/models/sales_log_spec.rb

5
app/models/derived_variables/lettings_log_variables.rb

@ -124,6 +124,11 @@ module DerivedVariables::LettingsLogVariables
self.nationality_all = nationality_all_group if nationality_uk_or_prefers_not_to_say?
if startdate_changed? && !LocalAuthority.active(startdate).where(code: la).exists?
self.la = nil
self.is_la_inferred = false
end
reset_address_fields! if is_supported_housing?
end

5
app/models/derived_variables/sales_log_variables.rb

@ -75,6 +75,11 @@ module DerivedVariables::SalesLogVariables
self.nationality_all = nationality_all_group if nationality_uk_or_prefers_not_to_say?
self.nationality_all_buyer2 = nationality_all_buyer2_group if nationality2_uk_or_prefers_not_to_say?
if saledate_changed? && !LocalAuthority.active(saledate).where(code: la).exists?
self.la = nil
self.is_la_inferred = false
end
set_encoded_derived_values!(DEPENDENCIES)
end

15
spec/models/lettings_log_spec.rb

@ -809,6 +809,21 @@ RSpec.describe LettingsLog do
expect { lettings_log.update!(nationality_all_group: nil, declaration: 1) }.not_to change(lettings_log, :nationality_all)
end
end
context "when form year changes and LA is no longer active" do
before do
LocalAuthority.find_by(code: "E08000003").update!(end_date: Time.zone.today)
end
it "removes the LA" do
lettings_log.update!(startdate: Time.zone.yesterday, la: "E08000003")
expect(lettings_log.reload.la).to eq("E08000003")
lettings_log.update!(startdate: Time.zone.tomorrow)
expect(lettings_log.reload.la).to eq(nil)
expect(lettings_log.reload.is_la_inferred).to eq(false)
end
end
end
describe "optional fields" do

17
spec/models/sales_log_spec.rb

@ -978,5 +978,22 @@ RSpec.describe SalesLog, type: :model do
end
end
end
context "when form year changes and LA is no longer active" do
let!(:sales_log) { create(:sales_log) }
before do
LocalAuthority.find_by(code: "E08000003").update!(end_date: Time.zone.today)
end
it "removes the LA" do
sales_log.update!(saledate: Time.zone.yesterday, la: "E08000003")
expect(sales_log.reload.la).to eq("E08000003")
sales_log.update!(saledate: Time.zone.tomorrow)
expect(sales_log.reload.la).to eq(nil)
expect(sales_log.reload.is_la_inferred).to eq(false)
end
end
end
# rubocop:enable RSpec/MessageChain

Loading…
Cancel
Save