Browse Source

Update validations for 2024 lettings

pull/2256/head
Kat 2 years ago
parent
commit
0dd87f1cb2
  1. 41
      app/models/validations/household_validations.rb
  2. 4
      app/views/layouts/application.html.erb
  3. 8
      config/locales/en.yml
  4. 197
      spec/models/validations/household_validations_spec.rb

41
app/models/validations/household_validations.rb

@ -88,8 +88,6 @@ module Validations::HouseholdValidations
end end
def validate_person_age_matches_relationship(record) def validate_person_age_matches_relationship(record)
return if record.form.start_year_after_2024?
(2..8).each do |person_num| (2..8).each do |person_num|
age = record.public_send("age#{person_num}") age = record.public_send("age#{person_num}")
relationship = record.public_send("relat#{person_num}") relationship = record.public_send("relat#{person_num}")
@ -99,12 +97,15 @@ module Validations::HouseholdValidations
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16_lettings", person_num:) record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16_lettings", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat_lettings", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat_lettings", person_num:)
end end
if record.form.start_year_after_2024? && (age > 19 && tenant_is_child?(relationship))
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_over_19", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_19_relat", person_num:)
end
end end
end end
def validate_person_age_and_relationship_matches_economic_status(record) def validate_person_age_and_relationship_matches_economic_status(record)
return if record.form.start_year_after_2024?
(2..8).each do |person_num| (2..8).each do |person_num|
age = record.public_send("age#{person_num}") age = record.public_send("age#{person_num}")
economic_status = record.public_send("ecstat#{person_num}") economic_status = record.public_send("ecstat#{person_num}")
@ -117,19 +118,47 @@ module Validations::HouseholdValidations
child = tenant_is_child?(relationship) child = tenant_is_child?(relationship)
if age_between_16_19 && !(student || economic_status_refused) && child if age_between_16_19 && !(student || economic_status_refused) && child
if record.form.start_year_after_2024?
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student_2024", person_num:)
else
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student") record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student") # 1 record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student") # 1
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student")
end end
end
next unless !age_between_16_19 && student && child if !age_between_16_19 && student && child
if record.form.start_year_after_2024?
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_16_19_2024", person_num:)
else
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_16_19") # 2 record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_16_19") # 2
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19") record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19") record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19")
end end
end end
if student && age_between_16_19 && !child && record.form.start_year_after_2024?
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.must_be_child_2024", person_num:)
end
end
end
def validate_child_12_years_younger(record)
return unless record.form.start_year_after_2024?
(2..8).each do |person_num|
age = record.public_send("age#{person_num}")
relationship = record.public_send("relat#{person_num}")
next unless age && record.age1 && relationship
next unless age > record.age1 - 12 && tenant_is_child?(relationship)
record.errors.add "age1", I18n.t("validations.household.age.age1_child_12_years_younger_2024", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_12_years_younger_2024", person_num:)
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_12_years_younger_2024", person_num:)
end
end
def validate_condition_effects(record) def validate_condition_effects(record)
all_options = [record.illness_type_1, record.illness_type_2, record.illness_type_3, record.illness_type_4, record.illness_type_5, record.illness_type_6, record.illness_type_7, record.illness_type_8, record.illness_type_9, record.illness_type_10] all_options = [record.illness_type_1, record.illness_type_2, record.illness_type_3, record.illness_type_4, record.illness_type_5, record.illness_type_6, record.illness_type_7, record.illness_type_8, record.illness_type_9, record.illness_type_10]
if all_options.count(1) >= 1 && household_no_illness?(record) if all_options.count(1) >= 1 && household_no_illness?(record)

4
app/views/layouts/application.html.erb

@ -7,10 +7,6 @@
<%= tag.meta name: "viewport", content: "width=device-width, initial-scale=1" %> <%= tag.meta name: "viewport", content: "width=device-width, initial-scale=1" %>
<%= tag.meta property: "og:image", content: asset_path("images/govuk-opengraph-image.png") %> <%= tag.meta property: "og:image", content: asset_path("images/govuk-opengraph-image.png") %>
<%= tag.meta name: "theme-color", content: "#0b0c0c" %> <%= tag.meta name: "theme-color", content: "#0b0c0c" %>
<%= favicon_link_tag asset_path("images/favicon.ico"), type: nil, sizes: "48x48" %>
<%= favicon_link_tag asset_path("images/favicon.svg"), type: "image/svg+xml", sizes: "any" %>
<%= favicon_link_tag asset_path("images/govuk-icon-mask.svg"), rel: "mask-icon", color: "#0b0c0c", type: nil %>
<%= favicon_link_tag asset_path("images/govuk-icon-180.png"), rel: "apple-touch-icon", type: nil %>
<%= stylesheet_link_tag "application" %> <%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/html5shiv.min.js" %> <%= javascript_include_tag "vendor/html5shiv.min.js" %>
<script> <script>

8
config/locales/en.yml

@ -463,13 +463,17 @@ en:
child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘" child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘"
child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’" child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’"
child_12_years_younger: "A child must be at least 12 years younger than their parent" child_12_years_younger: "A child must be at least 12 years younger than their parent"
child_12_years_younger_2024: "Age must be at least 12 years younger than the lead tenant as person %{person_num}'s relationship to lead tenant is child."
age1_child_12_years_younger_2024: "Age must be at least 12 years older than person %{person_num}'s age as person %{person_num}'s relationship to lead tenant is child."
not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student" not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student"
student_16_19: student_16_19:
cannot_be_16_19: cannot_be_16_19:
child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student" child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student"
must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’" must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’"
must_be_16_19_2024: "Person %{person_num}'s age must be 16-19 as their working situation is student and their relationship to the lead tenant is child"
lead: lead:
over_25: "The lead tenant must be under 26 as you told us their housing situation immediately before this letting was a children’s home or foster care" over_25: "The lead tenant must be under 26 as you told us their housing situation immediately before this letting was a children’s home or foster care"
child_over_19_relat: "Age must be 19 or under as you told us person 2's relationship to the lead tenant is child"
ecstat: ecstat:
retired_over_70: "Person %{person_num} must be retired if over 70" retired_over_70: "Person %{person_num} must be retired if over 70"
child_under_16: "Person %{person_num}’s working situation must be ‘child under 16’, ‘other’ or ‘prefers not to say’ as you told us they’re under 16" child_under_16: "Person %{person_num}’s working situation must be ‘child under 16’, ‘other’ or ‘prefers not to say’ as you told us they’re under 16"
@ -479,6 +483,7 @@ en:
cannot_be_student: cannot_be_student:
child_not_16_19: "Person cannot be a student if they are not aged 16-19 but have relationship ‘child’" child_not_16_19: "Person cannot be a student if they are not aged 16-19 but have relationship ‘child’"
must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’" must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’"
must_be_student_2024: "Person %{person_num}'s working situation must be student or prefers not to say, as their age is 16-19 and their relationship to the lead tenant is child"
retired_male: "Answer cannot be ‘retired’ as the male tenant is under 65" retired_male: "Answer cannot be ‘retired’ as the male tenant is under 65"
retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60" retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60"
relat: relat:
@ -491,6 +496,9 @@ en:
cannot_be_child: cannot_be_child:
student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19" student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19"
16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student" 16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student"
must_be_child_2024: "Person %{person_num}'s relationship to the lead tenant must be child as their working situation is student and their age is 16-19"
child_over_19: "Answer cannot be child as you told us person %{person_num} is over 19"
child_12_years_younger_2024: "Relationship cannot be child, as person %{person_num} is less than 12 years younger than the lead tenant"
housingneeds_a: housingneeds_a:
one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’" one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’"
housingneeds_type: housingneeds_type:

197
spec/models/validations/household_validations_spec.rb

@ -315,6 +315,19 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "#validate_person_age_matches_relationship" do describe "#validate_person_age_matches_relationship" do
context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when the household contains a person under 16" do context "when the household contains a person under 16" do
it "validates that person must be a child of the tenant" do it "validates that person must be a child of the tenant" do
record.age2 = 14 record.age2 = 14
@ -334,12 +347,14 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["age2"]).to be_empty expect(record.errors["age2"]).to be_empty
end end
end end
end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) }
before do before do
Timecop.freeze(Time.zone.local(2024, 4, 1)) Timecop.freeze(log_date)
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
record.update!(startdate: Time.zone.local(2024, 4, 1))
end end
after do after do
@ -347,14 +362,24 @@ RSpec.describe Validations::HouseholdValidations do
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
end end
it "does not run the validation" do it "validates person under 16 is not partner" do
record.age2 = 14 record.age2 = 14
record.relat2 = "P" record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record) household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]) expect(record.errors["relat2"])
.not_to include(match I18n.t("validations.household.relat.child_under_16_lettings", person_num: 2)) .to include("Answer cannot be ‘partner’ as you told us person 2's age is under 16")
expect(record.errors["age2"])
.not_to include("Age cannot be under 16 as you told us person 2's relationship to the lead tenant is partner.")
end
it "validates person over 19 is not child" do
record.age2 = 20
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["age2"]) expect(record.errors["age2"])
.not_to include(match I18n.t("validations.household.age.child_under_16_relat_lettings", person_num: 2)) .to include("Age must be 19 or under as you told us person 2's relationship to the lead tenant is child")
expect(record.errors["relat2"])
.not_to include("Answer cannot be child, as you told us person 2 is over 19")
end end
end end
end end
@ -416,6 +441,19 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "#validate_person_age_and_relationship_matches_economic_status" do describe "#validate_person_age_and_relationship_matches_economic_status" do
context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when the household contains a tenant’s child between the ages of 16 and 19" do context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "validates that person's economic status must be full time student or refused" do it "validates that person's economic status must be full time student or refused" do
record.age2 = 17 record.age2 = 17
@ -484,11 +522,22 @@ RSpec.describe Validations::HouseholdValidations do
.to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")) .to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
end end
it "does not set 2024 errors" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 1
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"])
.not_to include("Person 2's working situation must be student or prefers not to say, as their age is 16-19 and their relationship to the lead tenant is child")
end
end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) }
before do before do
Timecop.freeze(Time.zone.local(2024, 4, 1)) Timecop.freeze(log_date)
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
record.update!(startdate: Time.zone.local(2024, 4, 1))
end end
after do after do
@ -496,7 +545,7 @@ RSpec.describe Validations::HouseholdValidations do
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
end end
it "does not run the validation" do it "does not add 2023 errors" do
record.age2 = 17 record.age2 = 17
record.relat2 = "C" record.relat2 = "C"
record.ecstat2 = 1 record.ecstat2 = 1
@ -508,6 +557,138 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["relat2"]) expect(record.errors["relat2"])
.not_to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student", person_num: 2)) .not_to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student", person_num: 2))
end end
context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "validates that person's economic status must be full time student or refused" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 1
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include("Person 2's working situation must be student or prefers not to say, as their age is 16-19 and their relationship to the lead tenant is child")
expect(record.errors["age2"])
.to be_empty
expect(record.errors["relat2"])
.to be_empty
end
it "expects that person can be a full time student" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 7
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
it "expects that person can refuse to share their work status" do
record.age2 = 17
record.relat2 = "C"
record.ecstat2 = 10
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the lead tenant" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "adds errors for a person who is a child of the lead tenant and a student but not aged 16-19" do
record.age2 = 14
record.ecstat2 = "7"
record.relat2 = "C"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"])
.to be_empty
expect(record.errors["age2"])
.to include("Person 2's age must be 16-19 as their working situation is student and their relationship to the lead tenant is child")
expect(record.errors["ecstat2"])
.to be_empty
end
it "adds errors for a person who is a student and aged 16-19 but not child" do
record.age2 = 17
record.ecstat2 = "7"
record.relat2 = "X"
household_validator.validate_person_age_and_relationship_matches_economic_status(record)
expect(record.errors["relat2"])
.to include("Person 2's relationship to the lead tenant must be child as their working situation is student and their age is 16-19")
expect(record.errors["age2"])
.to be_empty
expect(record.errors["ecstat2"])
.to be_empty
end
end
end
describe "#validate_child_12_years_younger" do
context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "does not run the validation" do
record.age1 = 20
record.age2 = 17
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end
context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "validates that child is at least 12 year younger than lead tenant" do
record.age1 = 20
record.age2 = 17
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age1"])
.to include("Age must be at least 12 years older than person 2's age as person 2's relationship to lead tenant is child.")
expect(record.errors["age2"])
.to include("Age must be at least 12 years younger than the lead tenant as person 2's relationship to lead tenant is child.")
expect(record.errors["relat2"])
.to include("Relationship cannot be child, as person 2 is less than 12 years younger than the lead tenant")
end
it "expects that child is at least 12 years younger than lead tenant" do
record.age1 = 30
record.age2 = 17
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end end
end end

Loading…
Cancel
Save