Browse Source

Remove relevant lettings 2023 validations from 24

pull/2256/head
Kat 2 years ago
parent
commit
b7e5d8eb0b
  1. 8
      app/models/validations/household_validations.rb
  2. 72
      spec/models/validations/household_validations_spec.rb

8
app/models/validations/household_validations.rb

@ -56,7 +56,7 @@ module Validations::HouseholdValidations
end
def validate_person_1_economic(record)
return unless record.age1 && record.ecstat1
return unless record.age1 && record.ecstat1 && !record.form.start_year_after_2024?
if record.age1 < 16 && !economic_status_is_child_other_or_refused?(record.ecstat1)
record.errors.add "ecstat1", I18n.t("validations.household.ecstat.child_under_16", person_num: 1)
@ -69,6 +69,8 @@ module Validations::HouseholdValidations
end
def validate_person_age_matches_economic_status(record)
return if record.form.start_year_after_2024?
(2..8).each do |person_num|
age = record.public_send("age#{person_num}")
economic_status = record.public_send("ecstat#{person_num}")
@ -86,6 +88,8 @@ module Validations::HouseholdValidations
end
def validate_person_age_matches_relationship(record)
return if 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}")
@ -99,6 +103,8 @@ module Validations::HouseholdValidations
end
def validate_person_age_and_relationship_matches_economic_status(record)
return if record.form.start_year_after_2024?
(2..8).each do |person_num|
age = record.public_send("age#{person_num}")
economic_status = record.public_send("ecstat#{person_num}")

72
spec/models/validations/household_validations_spec.rb

@ -334,6 +334,29 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["age2"]).to be_empty
end
end
context "with 2024 logs" do
before do
Timecop.freeze(Time.zone.local(2024, 4, 1))
Singleton.__init__(FormHandler)
record.update!(startdate: Time.zone.local(2024, 4, 1))
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "does not run the validation" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"])
.not_to include(match I18n.t("validations.household.relat.child_under_16_lettings", person_num: 2))
expect(record.errors["age2"])
.not_to include(match I18n.t("validations.household.age.child_under_16_relat_lettings", person_num: 2))
end
end
end
describe "#validate_person_age_matches_economic_status" do
@ -367,6 +390,29 @@ RSpec.describe Validations::HouseholdValidations do
.to include(match I18n.t("validations.household.age.child_over_16", person_num: 2))
end
end
context "with 2024 logs" do
before do
Timecop.freeze(Time.zone.local(2024, 4, 1))
Singleton.__init__(FormHandler)
record.update!(startdate: Time.zone.local(2024, 4, 1))
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "does not run the validation" do
record.age2 = 14
record.ecstat2 = 1
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.not_to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.not_to include(match I18n.t("validations.household.age.child_under_16_ecstat", person_num: 2))
end
end
end
describe "#validate_person_age_and_relationship_matches_economic_status" do
@ -437,6 +483,32 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
end
context "with 2024 logs" do
before do
Timecop.freeze(Time.zone.local(2024, 4, 1))
Singleton.__init__(FormHandler)
record.update!(startdate: Time.zone.local(2024, 4, 1))
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "does not run the validation" 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(match I18n.t("validations.household.ecstat.student_16_19.must_be_student", person_num: 2))
expect(record.errors["age2"])
.not_to include(match I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student", person_num: 2))
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))
end
end
end
describe "condition effects validation" do

Loading…
Cancel
Save