Browse Source

feat: add inference for 24/25 and test

CLDC-3147-update-pregnancy-for-24-25
natdeanlewissoftwire 11 months ago
parent
commit
25b4be0276
  1. 5
      app/models/derived_variables/lettings_log_variables.rb
  2. 15
      app/models/lettings_log.rb
  3. 51
      spec/models/lettings_log_spec.rb

5
app/models/derived_variables/lettings_log_variables.rb

@ -91,8 +91,9 @@ module DerivedVariables::LettingsLogVariables
self.prevten = 30 if owning_organisation&.provider_type == "LA"
end
end
if form.start_year_after_2024? && is_bedsit?
self.beds = 1
if form.start_year_after_2024?
self.beds = 1 if is_bedsit?
self.preg_occ = 2 if preg_occ.nil? && hhmemb.present? && (all_male_household? || no_women_or_non_binary_between_11_and_60?)
end
child_under_16_constraints!

15
app/models/lettings_log.rb

@ -664,6 +664,21 @@ class LettingsLog < Log
LettingsLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:)
end
def all_male_household?
(1..hhmemb).all? do |n|
public_send("sex#{n}") == "M"
end
end
def no_women_or_non_binary_between_11_and_60?
(1..hhmemb).none? do |n|
sex = public_send("sex#{n}")
age = public_send("age#{n}")
%w[F X].include?(sex) && age.present? && age.between?(11, 60)
end
end
private
def reset_invalid_unresolved_log_fields!

51
spec/models/lettings_log_spec.rb

@ -2367,6 +2367,57 @@ 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 inferring pregnancy" do
around do |example|
Timecop.freeze(now) do
Singleton.__init__(FormHandler)
example.run
end
end
context "when before 2024/25" do
let(:now) { Time.zone.local(2024, 1, 1) }
let!(:lettings_log) { create(:lettings_log, :setup_completed, startdate: now, preg_occ: nil, declaration: 1, hhmemb: 3) }
it "does not infer pregnancy for all male households" do
lettings_log.update!(sex1: "M", sex2: "M", sex3: "M")
expect(lettings_log.preg_occ).to be_nil
end
it "does not infer pregnancy when no woman or non-binary person in the household is 11 to 60" do
lettings_log.update!(sex1: "F", sex2: "X", sex3: "M", age1: 61, age2: 10, age3: 55)
expect(lettings_log.preg_occ).to be_nil
end
end
context "when in 2024/25" do
let(:now) { Time.zone.local(2024, 5, 1) }
let!(:lettings_log) { create(:lettings_log, :setup_completed, startdate: now, preg_occ: nil, declaration: 1, hhmemb: 3) }
it "infers no pregnancy for all male households" do
lettings_log.update!(sex1: "M", sex2: "M", sex3: "M")
expect(lettings_log.preg_occ).to eq(2)
end
it "infers no pregnancy when no woman or non-binary person in the household is 11 to 60" do
lettings_log.update!(sex1: "F", sex2: "X", sex3: "M", age1: 61, age2: 10, age3: 55)
expect(lettings_log.preg_occ).to eq(2)
end
it "does not override user entered data when household is all male" do
lettings_log.update!(preg_occ: 1)
lettings_log.update!(sex1: "M", sex2: "M", sex3: "M")
expect(lettings_log.preg_occ).to eq(1)
end
it "does not override user entered data when no woman or non-binary person in the household is 11 to 60" do
lettings_log.update!(preg_occ: 1)
lettings_log.update!(sex1: "F", sex2: "X", sex3: "M", age1: 61, age2: 10, age3: 55)
expect(lettings_log.preg_occ).to eq(1)
end
end
end
end
describe "optional fields" do

Loading…
Cancel
Save