Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

872 lines
34 KiB

require "rails_helper"
RSpec.describe Validations::HouseholdValidations do
subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:log_date) { Time.zone.now }
let(:record) { FactoryBot.create(:lettings_log, :setup_completed, startdate: log_date) }
before do
Timecop.freeze(log_date + 1)
end
after do
Timecop.return
end
describe "reasonable preference validations" do
context "when reasonable preference is not given" do
it "validates that no reason is needed" do
record.reasonpref = 1
record.rp_homeless = 0
household_validator.validate_reasonable_preference(record)
expect(record.errors["reasonpref"]).to be_empty
end
it "validates that no reason is given" do
record.reasonpref = 2
record.rp_medwel = 1
household_validator.validate_reasonable_preference(record)
expect(record.errors["reasonable_preference_reason"])
.to include(match I18n.t("validations.household.reasonable_preference_reason.reason_not_required"))
end
end
end
describe "reason for leaving last settled home validations" do
let(:field) { "validations.other_field_not_required" }
let(:main_field_label) { "reason" }
let(:other_field_label) { "reasonother" }
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when reason is other" do
let(:field) { "validations.other_field_missing" }
it "validates that a reason is provided" do
record.reason = 20
record.reasonother = nil
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reasonother"])
.to include(match(expected_error))
end
it "expects that a reason is provided" do
record.reason = 20
record.reasonother = "Some unusual reason"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reasonother"]).to be_empty
end
context "when form year is before 2024" do
let(:log_date) { Time.zone.local(2024, 1, 1) }
it "does not validate the content of reasonother for phrases indicating homelessness" do
record.reason = 20
record.reasonother = "Temp accommodation"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"]).to be_empty
end
end
context "when form year is >= 2024" do
let(:log_date) { Time.zone.local(2024, 4, 1) }
context "when checking the content of reasonother" do
it "validates that the reason doesn't match phrase indicating homelessness" do
record.reason = 20
record.reasonother = "Temp accommodation"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"]).to include(I18n.t("validations.household.reason.other_not_settled"))
end
it "allows reasons that don't exactly match a phrase indicating homelessness" do
record.reason = 20
record.reasonother = "Not quite homeless but some other reason"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"]).to be_empty
end
it "ignores surrounding non-alphabet characters and casing when determining a match" do
record.reason = 20
record.reasonother = " 0homelessness ! "
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"]).to include(I18n.t("validations.household.reason.other_not_settled"))
end
end
end
end
context "when reason is not other" do
it "validates that other reason is not provided" do
record.reason = 18
record.reasonother = "Some other reason"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reasonother"])
.to include(match(expected_error))
end
it "expects that other reason is not provided" do
record.reason = 18
record.reasonother = nil
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reasonother"]).to be_empty
end
end
context "when reason is don't know" do
let(:expected_error) { I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") }
it "validates that under occupation benefit cap is also not known" do
record.reason = 32
record.underoccupation_benefitcap = 1
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["underoccupation_benefitcap"])
.to include(match(expected_error))
expect(record.errors["reason"])
.to include(match(expected_error))
end
it "expects that under occupation benefit cap is also not known" do
record.reason = 32
record.underoccupation_benefitcap = 4
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["underoccupation_benefitcap"]).to be_empty
expect(record.errors["reason"]).to be_empty
end
end
context "when referral is not internal transfer" do
it "cannot be permanently decanted from another property owned by this landlord" do
record.reason = 1
record.referral = 2
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"])
.to include(match(I18n.t("validations.household.reason.not_internal_transfer")))
expect(record.errors["referral"])
.to include(match(I18n.t("validations.household.referral.reason_permanently_decanted")))
end
end
context "when referral is internal transfer" do
it "can be permanently decanted from another property owned by this landlord" do
record.reason = 1
record.referral = 1
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"])
.to be_empty
expect(record.errors["referral"])
.to be_empty
end
it "cannot have a PRP as landlord and Housing situation before this letting cannot be LA general needs" do
record.owning_organisation.provider_type = "PRP"
record.prevten = 30
record.referral = 1
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match(I18n.t("validations.household.referral.la_general_needs.internal_transfer")))
expect(record.errors["prevten"])
.to include(match(I18n.t("validations.household.prevten.la_general_needs.internal_transfer")))
record.prevten = 31
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match(I18n.t("validations.household.referral.la_general_needs.internal_transfer")))
expect(record.errors["prevten"])
.to include(match(I18n.t("validations.household.prevten.la_general_needs.internal_transfer")))
end
end
end
describe "armed forces validations" do
context "when the tenant or partner was and is not a member of the armed forces" do
it "validates that injured in the armed forces is not yes" do
record.armedforces = 2
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"])
.to include(match I18n.t("validations.household.reservist.injury_not_required"))
end
end
context "when the tenant prefers not to say if they were or are in the armed forces" do
it "validates that injured in the armed forces is not yes" do
record.armedforces = 3
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"])
.to include(match I18n.t("validations.household.reservist.injury_not_required"))
end
end
context "when the tenant was or is a regular member of the armed forces" do
it "expects that injured in the armed forces can be yes" do
record.armedforces = 0
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"]).to be_empty
end
end
context "when the tenant was or is a reserve member of the armed forces" do
it "expects that injured in the armed forces can be yes" do
record.armedforces = 1
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"]).to be_empty
end
end
3 years ago
context "when the tenant’s partner was or is a member of the armed forces" do
it "expects that injured in the armed forces can be yes" do
record.armedforces = 5
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"]).to be_empty
end
end
context "when the tenant or partner has left the armed forces" do
it "validates that they served in the armed forces" do
record.armedforces = 2
record.leftreg = 0
household_validator.validate_armed_forces(record)
expect(record.errors["leftreg"])
.to include(match I18n.t("validations.household.leftreg.question_not_required"))
end
it "expects that they served in the armed forces" do
record.armedforces = 1
record.leftreg = 0
household_validator.validate_armed_forces(record)
expect(record.errors["leftreg"]).to be_empty
end
it "expects that they served in the armed forces and may have been injured" do
record.armedforces = 1
record.leftreg = 0
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["leftreg"]).to be_empty
expect(record.errors["reservist"]).to be_empty
end
end
end
describe "#validate_numeric_min_max" do
it "validates that the number of household members cannot be less than 1" do
record.hhmemb = 0
household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"])
.to include(match I18n.t("validations.numeric.within_range", field: "Number of household members", min: 1, max: 8))
end
it "validates that the number of household members cannot be more than 8" do
record.hhmemb = 9
household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"])
.to include(match I18n.t("validations.numeric.within_range", field: "Number of household members", min: 1, max: 8))
end
it "expects that the number of other household members is between the min and max" do
record.hhmemb = 5
household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]).to be_empty
end
end
describe "#validate_partner_count" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
it "validates that only 1 partner exists" do
record.relat2 = "P"
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.one_partner"))
expect(record.errors["relat3"])
.to include(match I18n.t("validations.household.relat.one_partner"))
expect(record.errors["relat4"])
.not_to include(match I18n.t("validations.household.relat.one_partner"))
end
it "expects that a tenant can have a partner" do
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["base"]).to be_empty
end
end
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
it "validates that person must be a child of the tenant" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.child_under_16_lettings", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_under_16_relat_lettings", person_num: 2))
end
it "expects that person is a child of the tenant" do
record.age2 = 14
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
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 "does not add an error is person under 16 is a partner" do
record.age2 = 14
record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add an error if person over 19 is child" do
record.age2 = 20
record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record)
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end
end
describe "#validate_person_age_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 person under 16" do
it "validates that person's economic status must be Child" do
record.age2 = 14
record.ecstat2 = 1
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_under_16_ecstat", person_num: 2))
end
it "expects that person's economic status is Child" do
record.age2 = 14
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "validates that a person with economic status 'child' must be under 16" do
record.age2 = 21
record.relat2 = "C"
record.ecstat2 = 9
household_validator.validate_person_age_matches_economic_status(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.child_over_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_over_16", person_num: 2))
end
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 "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
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
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(match I18n.t("validations.household.ecstat.student_16_19.must_be_student", person_num: 2))
expect(record.errors["age2"])
.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"])
.to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student", person_num: 2))
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 aged 16-19 who is a student but not a child of the lead tenant" do
record.age2 = 18
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 "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 include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19"))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.student_16_19.must_be_16_19"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
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
context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "does not add an error" 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 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 "does not add 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["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add 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 be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
end
end
describe "condition effects validation" do
it "validates vision can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_1 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates hearing can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_2 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates mobility can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_3 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates dexterity can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_4 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates learning or understanding or concentrating can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_5 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates memory can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_6 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates mental health can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_7 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates stamina or breathing or fatigue can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_8 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates socially or behaviourally can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_9 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates other can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 2
record.illness_type_10 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "expects that an illness can be selected if answer to anyone in household with health condition is yes " do
record.illness = 1
record.illness_type_1 = 1
record.illness_type_2 = 1
record.illness_type_3 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"]).to be_empty
end
end
describe "referral validations" do
context "when homelessness is assessed" do
it "can be internal transfer" do
record.homeless = 11
record.referral = 1
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
it "can be non internal transfer" do
record.owning_organisation.provider_type = "PRP"
record.homeless = 0
record.referral = 3
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
end
context "when homelessness is other" do
it "cannot be internal transfer" do
record.referral = 1
record.homeless = 7
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
it "can be non internal transfer" do
record.owning_organisation.provider_type = "PRP"
record.referral = 3
record.homeless = 1
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
end
end
describe "la validations" do
context "when previous la is known" do
it "prevloc has to be provided" do
record.previous_la_known = 1
household_validator.validate_prevloc(record)
expect(record.errors["prevloc"])
.to include(match I18n.t("validations.household.previous_la_known"))
end
end
context "when validating layear" do
it "household cannot have just moved to area if renewal" do
record.layear = 1
record.renewal = 1
household_validator.validate_layear(record)
expect(record.errors["layear"])
.to include(match I18n.t("validations.household.renewal_just_moved_to_area.layear"))
expect(record.errors["renewal"])
.to include(match I18n.t("validations.household.renewal_just_moved_to_area.renewal"))
end
context "when validating layear and prevloc" do
it "household cannot have just moved to area if prevloc is the same as la" do
record.layear = 1
record.prevloc = "E07000084"
record.la = "E07000084"
record.startdate = Time.zone.now
household_validator.validate_layear_and_prevloc(record)
expect(record.errors["layear"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.layear"))
expect(record.errors["prevloc"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.previous_la"))
expect(record.errors["ppostcode_full"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.previous_la"))
expect(record.errors["la"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.current_la"))
expect(record.errors["postcode_full"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.current_la"))
expect(record.errors["uprn"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.current_la"))
end
end
end
end
3 years ago
describe "previous housing situation validations" do
context "when the property is being relet to a previously temporary tenant" do
it "validates that previous tenancy was temporary" do
record.rsnvac = 9
3 years ago
record.prevten = 4
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.non_temp_accommodation"))
end
end
context "when the lead tenant is over 25" do
it "cannot be children's home/foster care" do
record.prevten = 13
record.age1 = 26
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.over_25_foster_care"))
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.lead.over_25"))
end
end
context "when the lead tenant is male" do
it "cannot be refuge" do
record.prevten = 21
record.sex1 = "M"
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.male_refuge"))
expect(record.errors["sex1"])
.to include(match I18n.t("validations.household.gender.male_refuge"))
end
end
context "when the referral is internal transfer" do
it "prevten can be 9" do
record.referral = 1
record.prevten = 9
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to be_empty
expect(record.errors["referral"])
.to be_empty
end
[
{ code: 3, label: "Private sector tenancy" },
{ code: 4, label: "Tied housing or rented with job" },
{ code: 7, label: "Direct access hostel" },
{ code: 10, label: "Hospital" },
{ code: 13, label: "Children’s home or foster care" },
{ code: 14, label: "Bed and breakfast" },
{ code: 19, label: "Rough sleeping" },
{ code: 23, label: "Mobile home or caravan" },
{ code: 24, label: "Home Office Asylum Support" },
{ code: 25, label: "Any other accommodation" },
{ code: 26, label: "Owner occupation (private)" },
{ code: 28, label: "Living with friends or family" },
{ code: 29, label: "Prison or approved probation hostel" },
].each do |prevten|
it "prevten cannot be #{prevten[:code]}" do
record.referral = 1
record.prevten = prevten[:code]
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.internal_transfer", prevten: prevten[:label]))
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
end
end
end
3 years ago
end
describe "housing needs validations" do
context "with housingneeds == 1 (yes) && housingneeds_type == 3" do
before do
record.housingneeds = 1
record.housingneeds_type = 3
end
context "with housingneeds_other == 0 (no)" do
before do
record.housingneeds_other = 0
end
it "is invalid" do
household_validator.validate_combination_of_housing_needs_responses(record)
error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"]
expect(record.errors["housingneeds"]).to eq(error_message)
expect(record.errors["housingneeds_type"]).to eq(error_message)
expect(record.errors["housingneeds_other"]).to eq(error_message)
end
end
context "with housingneeds_other == 2 (don't know)" do
before do
record.housingneeds_other = 2
end
it "is invalid" do
household_validator.validate_combination_of_housing_needs_responses(record)
error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"]
expect(record.errors["housingneeds"]).to eq(error_message)
expect(record.errors["housingneeds_type"]).to eq(error_message)
expect(record.errors["housingneeds_other"]).to eq(error_message)
end
end
end
end
end