Browse Source

CLDC-1285: Setting pregnancy to yes is allowed if a tenant's age is unknown (#638)

pull/644/head v0.1.17
Stéphane Meny 3 years ago committed by GitHub
parent
commit
4d96381dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/models/case_log.rb
  2. 10
      app/models/validations/household_validations.rb
  3. 39
      spec/models/validations/household_validations_spec.rb

16
app/models/case_log.rb

@ -433,6 +433,18 @@ class CaseLog < ApplicationRecord
end end
end end
def age_known?(person_num)
return false unless person_num.is_a?(Integer)
!!public_send("age#{person_num}_known")&.zero?
end
def age_unknown?(person_num)
return false unless person_num.is_a?(Integer)
public_send("age#{person_num}_known") == 1
end
private private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new
@ -568,10 +580,6 @@ private
public_send("age#{person_num}") && public_send("age#{person_num}") < 16 public_send("age#{person_num}") && public_send("age#{person_num}") < 16
end end
def age_known?(person_num)
!!public_send("age#{person_num}_known")&.zero?
end
def process_postcode_changes! def process_postcode_changes!
self.postcode_full = upcase_and_remove_whitespace(postcode_full) self.postcode_full = upcase_and_remove_whitespace(postcode_full)
process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la") process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la")

10
app/models/validations/household_validations.rb

@ -134,12 +134,18 @@ private
def women_of_child_bearing_age_in_household(record) def women_of_child_bearing_age_in_household(record)
(1..8).any? do |n| (1..8).any? do |n|
next if record["sex#{n}"].nil? || record["age#{n}"].nil? next if record["sex#{n}"].nil?
(record["sex#{n}"]) == "F" && record["age#{n}"] >= 11 && record["age#{n}"] <= 65 record["sex#{n}"] == "F" && (in_pregnancy_age_range?(record, n) || record.age_unknown?(n))
end end
end end
def in_pregnancy_age_range?(record, person_num)
return false if record["age#{person_num}"].nil?
record["age#{person_num}"] >= 11 && record["age#{person_num}"] <= 65
end
def women_in_household(record) def women_in_household(record)
(1..8).any? do |n| (1..8).any? do |n|
record["sex#{n}"] == "F" record["sex#{n}"] == "F"

39
spec/models/validations/household_validations_spec.rb

@ -74,10 +74,9 @@ RSpec.describe Validations::HouseholdValidations do
context "when there are female tenants" do context "when there are female tenants" do
context "but they are older than 65" do context "but they are older than 65" do
before { record.assign_attributes(sex1: "F", age1: 66, preg_occ: 1) }
it "validates that pregnancy cannot be yes" do it "validates that pregnancy cannot be yes" do
record.preg_occ = 1
record.sex1 = "F"
record.age1 = 66
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]) expect(record.errors["preg_occ"])
.to include(match I18n.t("validations.household.preg_occ.no_female")) .to include(match I18n.t("validations.household.preg_occ.no_female"))
@ -85,39 +84,41 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "and they are the lead tenant and under 65" do context "and they are the lead tenant and under 65" do
it "pregnancy can be yes" do before { record.assign_attributes(sex1: "F", age1: 64, preg_occ: 1) }
record.preg_occ = 1
record.sex1 = "F" it "allows pregnancy to be set to yes" do
record.age1 = 64
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]).to be_empty expect(record.errors["preg_occ"]).to be_empty
end end
end end
context "and they are another household member and under 51" do context "and they are another household member and under 51" do
it "pregnancy can be yes" do before { record.assign_attributes(sex1: "M", age1: 25, sex3: "F", age3: 64, preg_occ: 1) }
record.preg_occ = 1
record.sex1 = "M" it "allows pregnancy to be set to yes" do
record.age1 = 25
record.sex3 = "F"
record.age3 = 64
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]).to be_empty expect(record.errors["preg_occ"]).to be_empty
end end
end end
context "and they are another household member and under 11" do context "and they are another household member and under 11" do
it "pregnancy can be yes" do before { record.assign_attributes(sex1: "M", age1: 25, sex3: "F", age3: 10, preg_occ: 1) }
record.preg_occ = 1
record.sex1 = "M" it "validates that pregnancy cannot be yes" do
record.age1 = 25
record.sex3 = "F"
record.age3 = 10
household_validator.validate_pregnancy(record) household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]) expect(record.errors["preg_occ"])
.to include(match I18n.t("validations.household.preg_occ.no_female")) .to include(match I18n.t("validations.household.preg_occ.no_female"))
end end
end end
context "and one tenant's age is unknown" do
before { record.assign_attributes(sex1: "F", age1: nil, age1_known: 1, preg_occ: 1) }
it "allows pregnancy to be set to yes" do
household_validator.validate_pregnancy(record)
expect(record.errors["preg_occ"]).to be_empty
end
end
end end
end end

Loading…
Cancel
Save