Samuel Young 1 week ago committed by GitHub
parent
commit
10deeb972f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/models/validations/soft_validations.rb
  2. 116
      spec/models/validations/soft_validations_spec.rb

9
app/models/validations/soft_validations.rb

@ -76,7 +76,8 @@ module Validations::SoftValidations
end end
def no_household_member_likely_to_be_pregnant? def no_household_member_likely_to_be_pregnant?
all_male_tenants_in_a_pregnant_household? || non_males_in_pregnant_household_not_in_pregnancy_range? # in this 2026 check we used a wider age range
all_male_tenants_in_a_pregnant_household? || non_males_in_pregnant_household_not_in_range?(13, 55)
end end
def all_male_tenants_in_a_pregnant_household? def all_male_tenants_in_a_pregnant_household?
@ -84,7 +85,7 @@ module Validations::SoftValidations
end end
def non_males_in_pregnant_household_not_in_pregnancy_range? def non_males_in_pregnant_household_not_in_pregnancy_range?
all_tenants_age_and_gender_information_completed? && non_males_in_the_household? && !any_non_male_in_expected_pregnancy_age_range(16, 50) && preg_occ == 1 non_males_in_pregnant_household_not_in_range?(16, 50)
end end
TWO_YEARS_IN_DAYS = 730 TWO_YEARS_IN_DAYS = 730
@ -252,6 +253,10 @@ private
public_send("details_known_#{tenant_number}").zero? public_send("details_known_#{tenant_number}").zero?
end end
def non_males_in_pregnant_household_not_in_range?(min, max)
all_tenants_age_and_gender_information_completed? && non_males_in_the_household? && !any_non_male_in_expected_pregnancy_age_range(min, max) && preg_occ == 1
end
def any_non_male_in_expected_pregnancy_age_range(min, max) def any_non_male_in_expected_pregnancy_age_range(min, max)
person_count = hhmemb || 8 person_count = hhmemb || 8

116
spec/models/validations/soft_validations_spec.rb

@ -180,7 +180,7 @@ RSpec.describe Validations::SoftValidations do
end end
end end
context "when all tenants are male and household members are over 8" do context "when all tenants are male and more than 8 household members" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
(1..8).each do |n| (1..8).each do |n|
record.send("sex#{n}=", "M") record.send("sex#{n}=", "M")
@ -196,7 +196,7 @@ RSpec.describe Validations::SoftValidations do
context "when female tenants are under 16" do context "when female tenants are under 16" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.age2 = 14 record.age2 = 15
record.sex2 = "F" record.sex2 = "F"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 2 record.hhmemb = 2
@ -209,9 +209,20 @@ RSpec.describe Validations::SoftValidations do
end end
end end
context "when female tenants are 16 and over" do
it "does not show the interruption screen" do
record.age1 = 16
record.sex1 = "F"
record.preg_occ = 1
record.hhmemb = 1
record.age1_known = 0
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be false
end
end
context "when female tenants are over 50" do context "when female tenants are over 50" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.age1 = 54 record.age1 = 51
record.sex1 = "F" record.sex1 = "F"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 1 record.hhmemb = 1
@ -220,9 +231,20 @@ RSpec.describe Validations::SoftValidations do
end end
end end
context "when female tenants are 50 or under" do
it "shows the interruption screen" do
record.age1 = 50
record.sex1 = "F"
record.preg_occ = 1
record.hhmemb = 1
record.age1_known = 0
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be false
end
end
context "when non-binary tenants are under 16" do context "when non-binary tenants are under 16" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.age2 = 14 record.age2 = 15
record.sex2 = "X" record.sex2 = "X"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 2 record.hhmemb = 2
@ -237,7 +259,7 @@ RSpec.describe Validations::SoftValidations do
context "when non-binary tenants are over 50" do context "when non-binary tenants are over 50" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.age1 = 54 record.age1 = 51
record.sex1 = "X" record.sex1 = "X"
record.preg_occ = 1 record.preg_occ = 1
record.hhmemb = 1 record.hhmemb = 1
@ -298,7 +320,7 @@ RSpec.describe Validations::SoftValidations do
end end
it "shows the interruption screen" do it "shows the interruption screen" do
expect(record.all_male_tenants_in_a_pregnant_household?).to be true expect(record.no_household_member_likely_to_be_pregnant?).to be true
end end
end end
@ -310,11 +332,11 @@ RSpec.describe Validations::SoftValidations do
end end
it "shows the interruption screen" do it "shows the interruption screen" do
expect(record.all_male_tenants_in_a_pregnant_household?).to be true expect(record.no_household_member_likely_to_be_pregnant?).to be true
end end
end end
context "when all tenants are male and household members are over 8" do context "when all tenants are male and more than 8 household members" do
before do before do
(1..8).each do |n| (1..8).each do |n|
record.send("sexrab#{n}=", "M") record.send("sexrab#{n}=", "M")
@ -328,11 +350,23 @@ RSpec.describe Validations::SoftValidations do
end end
it "does not show the interruption screen" do it "does not show the interruption screen" do
expect(record.all_male_tenants_in_a_pregnant_household?).to be false expect(record.no_household_member_likely_to_be_pregnant?).to be false
end end
end end
context "when female tenants are under 16" do context "when female tenants are 13 or over" do
before do
record.age1 = 13
record.sexrab1 = "F"
record.gender_same_as_sex1 = 1
end
it "does not show the interruption screen" do
expect(record.no_household_member_likely_to_be_pregnant?).to be false
end
end
context "when female tenants are under 13" do
before do before do
record.age1 = 12 record.age1 = 12
record.sexrab1 = "F" record.sexrab1 = "F"
@ -340,23 +374,48 @@ RSpec.describe Validations::SoftValidations do
end end
it "shows the interruption screen" do it "shows the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be true expect(record.no_household_member_likely_to_be_pregnant?).to be true
end end
end end
context "when female tenants are over 50" do context "when female tenants are 55 or under" do
before do
record.age1 = 55
record.sexrab1 = "F"
record.gender_same_as_sex1 = 1
end
it "does not show the interruption screen" do
expect(record.no_household_member_likely_to_be_pregnant?).to be false
end
end
context "when female tenants are over 55" do
before do before do
record.age1 = 60 record.age1 = 56
record.sexrab1 = "F" record.sexrab1 = "F"
record.gender_same_as_sex1 = 1 record.gender_same_as_sex1 = 1
end end
it "shows the interruption screen" do it "shows the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be true expect(record.no_household_member_likely_to_be_pregnant?).to be true
end
end
context "when non binary tenants are 13 or over" do
before do
record.age1 = 13
record.sexrab1 = "M"
record.gender_same_as_sex1 = 2
record.gender_description1 = "Non-binary"
end
it "does not show the interruption screen" do
expect(record.no_household_member_likely_to_be_pregnant?).to be false
end end
end end
context "when non binary tenants are under 16" do context "when non binary tenants are under 13" do
before do before do
record.age1 = 12 record.age1 = 12
record.sexrab1 = "M" record.sexrab1 = "M"
@ -365,20 +424,33 @@ RSpec.describe Validations::SoftValidations do
end end
it "shows the interruption screen" do it "shows the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be true expect(record.no_household_member_likely_to_be_pregnant?).to be true
end end
end end
context "when non binary tenants are over 50" do context "when non binary tenants are 55 or under" do
before do before do
record.age1 = 60 record.age1 = 55
record.sexrab1 = "M"
record.gender_same_as_sex1 = 2
record.gender_description1 = "Non-binary"
end
it "does not show the interruption screen" do
expect(record.no_household_member_likely_to_be_pregnant?).to be false
end
end
context "when non binary tenants are over 55" do
before do
record.age1 = 56
record.sexrab1 = "M" record.sexrab1 = "M"
record.gender_same_as_sex1 = 2 record.gender_same_as_sex1 = 2
record.gender_description1 = "Non-binary" record.gender_description1 = "Non-binary"
end end
it "shows the interruption screen" do it "shows the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be true expect(record.no_household_member_likely_to_be_pregnant?).to be true
end end
end end
@ -390,7 +462,7 @@ RSpec.describe Validations::SoftValidations do
end end
it "does not show the interruption screen" do it "does not show the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be false expect(record.no_household_member_likely_to_be_pregnant?).to be false
end end
end end
@ -405,7 +477,7 @@ RSpec.describe Validations::SoftValidations do
end end
it "does not show the interruption screen" do it "does not show the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be false expect(record.no_household_member_likely_to_be_pregnant?).to be false
end end
end end
@ -423,7 +495,7 @@ RSpec.describe Validations::SoftValidations do
end end
it "does not show the interruption screen" do it "does not show the interruption screen" do
expect(record.non_males_in_pregnant_household_not_in_pregnancy_range?).to be false expect(record.no_household_member_likely_to_be_pregnant?).to be false
end end
end end
end end

Loading…
Cancel
Save