diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 1ff8f3ed1..618e16e7b 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -36,7 +36,7 @@ module Validations::HouseholdValidations end def validate_pregnancy(record) - if (record.has_pregnancy? || record.pregnancy_refused?) && !women_of_child_bearing_age_in_household(record) + if (record.has_pregnancy? || record.pregnancy_refused?) && women_in_household(record) && !women_of_child_bearing_age_in_household(record) record.errors.add :preg_occ, I18n.t("validations.household.preg_occ.no_female") end end @@ -136,7 +136,13 @@ private (1..8).any? do |n| next if record["sex#{n}"].nil? || record["age#{n}"].nil? - (record["sex#{n}"]) == "F" && record["age#{n}"] >= 16 && record["age#{n}"] <= 50 + (record["sex#{n}"]) == "F" && record["age#{n}"] >= 11 && record["age#{n}"] <= 65 + end + end + + def women_in_household(record) + (1..8).any? do |n| + record["sex#{n}"] == "F" end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 367a11658..4581ec05f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -157,7 +157,7 @@ en: question_required: "You must answer whether the person is still serving in the UK armed forces as you told us they’re a current or former regular" question_not_required: "You cannot answer whether the person is still serving in the UK armed forces as you told us they’re not a current or former regular" preg_occ: - no_female: "You must answer ‘no’ as there are no females aged 16-50 in the household" + no_female: "You must answer ‘no’ as there are no females aged 11-65 in the household" age: retired_male: "Male tenant who is retired must be 65 or over" retired_female: "Female tenant who is retired must be 60 or over" @@ -227,7 +227,6 @@ en: not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household" joint_more_than_one_member: "There must be more than one person in the household as you've told us this is a joint tenancy" - declaration: missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log." @@ -241,9 +240,9 @@ en: message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" rent: min: - hint_text: "

You told us the rent is %{brent}

The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.

" + hint_text: '

You told us the rent is %{brent}

The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.

' max: - hint_text: "

You told us the rent is %{brent}

The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.

" + hint_text: '

You told us the rent is %{brent}

The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.

' retirement: min: title: "You told us this person is under %{age} and retired" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 34493137f..8780d0746 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -57,40 +57,38 @@ RSpec.describe Validations::HouseholdValidations do describe "pregnancy validations" do context "when there are no female tenants" do - it "validates that pregnancy cannot be yes" do + it "validates that pregnancy can be yes" do record.preg_occ = 1 record.sex1 = "M" household_validator.validate_pregnancy(record) - expect(record.errors["preg_occ"]) - .to include(match I18n.t("validations.household.preg_occ.no_female")) + expect(record.errors["preg_occ"]).to be_empty end - it "validates that pregnancy cannot be prefer not to say" do + it "validates that pregnancy can be prefer not to say" do record.preg_occ = 3 record.sex1 = "M" household_validator.validate_pregnancy(record) - expect(record.errors["preg_occ"]) - .to include(match I18n.t("validations.household.preg_occ.no_female")) + expect(record.errors["preg_occ"]).to be_empty end end context "when there are female tenants" do - context "but they are older than 50" do + context "but they are older than 65" do it "validates that pregnancy cannot be yes" do record.preg_occ = 1 record.sex1 = "F" - record.age1 = 51 + record.age1 = 66 household_validator.validate_pregnancy(record) expect(record.errors["preg_occ"]) .to include(match I18n.t("validations.household.preg_occ.no_female")) end end - context "and they are the lead tenant and under 51" do + context "and they are the lead tenant and under 65" do it "pregnancy can be yes" do - record.preg_occ = 0 + record.preg_occ = 1 record.sex1 = "F" - record.age1 = 32 + record.age1 = 64 household_validator.validate_pregnancy(record) expect(record.errors["preg_occ"]).to be_empty end @@ -98,15 +96,28 @@ RSpec.describe Validations::HouseholdValidations do context "and they are another household member and under 51" do it "pregnancy can be yes" do - record.preg_occ = 0 + record.preg_occ = 1 record.sex1 = "M" record.age1 = 25 record.sex3 = "F" - record.age3 = 32 + record.age3 = 64 household_validator.validate_pregnancy(record) expect(record.errors["preg_occ"]).to be_empty end end + + context "and they are another household member and under 11" do + it "pregnancy can be yes" do + record.preg_occ = 1 + record.sex1 = "M" + record.age1 = 25 + record.sex3 = "F" + record.age3 = 10 + household_validator.validate_pregnancy(record) + expect(record.errors["preg_occ"]) + .to include(match I18n.t("validations.household.preg_occ.no_female")) + end + end end end