Browse Source

Infer nationality where appropriate

pull/2193/head
Kat 2 years ago
parent
commit
2e698cd531
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 3
      app/models/derived_variables/sales_log_variables.rb
  3. 4
      app/models/log.rb
  4. 4
      app/models/sales_log.rb
  5. 37
      spec/models/lettings_log_spec.rb
  6. 19
      spec/models/sales_log_spec.rb

2
app/models/derived_variables/lettings_log_variables.rb

@ -115,6 +115,8 @@ module DerivedVariables::LettingsLogVariables
self.uprn_known = 0 self.uprn_known = 0
end end
self.nationality_all = nationality_all_group if nationality_uk_or_prefers_not_to_say?
reset_address_fields! if is_supported_housing? reset_address_fields! if is_supported_housing?
end end

3
app/models/derived_variables/sales_log_variables.rb

@ -35,6 +35,9 @@ module DerivedVariables::SalesLogVariables
self.uprn_known = 0 self.uprn_known = 0
end end
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?
set_encoded_derived_values!(DEPENDENCIES) set_encoded_derived_values!(DEPENDENCIES)
end end

4
app/models/log.rb

@ -209,6 +209,10 @@ class Log < ApplicationRecord
end end
end end
def nationality_uk_or_prefers_not_to_say?
nationality_all_group == 13 || nationality_all_group == 826
end
private private
# Handle logs that are older than previous collection start date # Handle logs that are older than previous collection start date

4
app/models/sales_log.rb

@ -473,4 +473,8 @@ class SalesLog < Log
def duplicates def duplicates
SalesLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:) SalesLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:)
end end
def nationality2_uk_or_prefers_not_to_say?
nationality_all_buyer2_group == 13 || nationality_all_buyer2_group == 826
end
end end

37
spec/models/lettings_log_spec.rb

@ -2330,6 +2330,43 @@ RSpec.describe LettingsLog do
expect(record_from_db["irproduct"]).to eq(nil) expect(record_from_db["irproduct"]).to eq(nil)
end end
end end
context "when updating nationality_all_group" do
let!(:lettings_log) do
described_class.create({
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
startdate: Time.zone.local(2024, 4, 10),
needstype: 1,
renewal: 1,
rent_type: 1,
})
end
before do
Timecop.freeze(Time.zone.local(2024, 4, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "correctly derives nationality_all when it's UK" do
expect { lettings_log.update!(nationality_all_group: 826, declaration: 1) }.to change(lettings_log, :nationality_all).to 826
end
it "correctly derives nationality_all when it's prefers not to say" do
expect { lettings_log.update!(nationality_all_group: 13, declaration: 1) }.to change(lettings_log, :nationality_all).to 13
end
it "does not derive nationality_all when it's other or not given" do
expect { lettings_log.update!(nationality_all_group: 12, declaration: 1) }.not_to change(lettings_log, :nationality_all)
expect { lettings_log.update!(nationality_all_group: nil, declaration: 1) }.not_to change(lettings_log, :nationality_all)
end
end
end end
describe "optional fields" do describe "optional fields" do

19
spec/models/sales_log_spec.rb

@ -577,6 +577,25 @@ RSpec.describe SalesLog, type: :model do
end end
end end
end end
context "when deriving nationality variables" do
it "correctly derives nationality_all/nationality_all_buyer2 when it's UK" do
expect { sales_log.update!(nationality_all_group: 826) }.to change(sales_log, :nationality_all).to 826
expect { sales_log.update!(nationality_all_buyer2_group: 826) }.to change(sales_log, :nationality_all_buyer2).to 826
end
it "correctly derives nationality_all/nationality_all_buyer2 when buyer prefers not to say" do
expect { sales_log.update!(nationality_all_group: 13) }.to change(sales_log, :nationality_all).to 13
expect { sales_log.update!(nationality_all_buyer2_group: 13) }.to change(sales_log, :nationality_all_buyer2).to 13
end
it "does not derive nationality_all/nationality_all_buyer2 when it is other or not given" do
expect { sales_log.update!(nationality_all_group: 12) }.not_to change(sales_log, :nationality_all)
expect { sales_log.update!(nationality_all_buyer2_group: 12) }.not_to change(sales_log, :nationality_all_buyer2)
expect { sales_log.update!(nationality_all_group: nil) }.not_to change(sales_log, :nationality_all)
expect { sales_log.update!(nationality_all_buyer2_group: nil) }.not_to change(sales_log, :nationality_all_buyer2)
end
end
end end
context "when saving addresses" do context "when saving addresses" do

Loading…
Cancel
Save