Browse Source

CLDC-3689: Extract lettings household validations (#2741)

* Extract household validations

* Use question ids a primary key

* Fix lint

* Refactor, remove one level of keys

* Fix merge
pull/2771/head
Manny Dinssa 2 months ago committed by GitHub
parent
commit
0b4ff65429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 89
      app/models/validations/household_validations.rb
  2. 50
      config/locales/en.yml
  3. 93
      config/locales/validations/lettings/household.en.yml
  4. 106
      spec/models/validations/household_validations_spec.rb

89
app/models/validations/household_validations.rb

@ -5,7 +5,7 @@ module Validations::HouseholdValidations
# or 'validate_' to run on submit as well
def validate_reasonable_preference(record)
if !record.given_reasonable_preference? && [record.rp_homeless, record.rp_insan_unsat, record.rp_medwel, record.rp_hardship, record.rp_dontknow].any? { |a| a == 1 }
record.errors.add :reasonable_preference_reason, I18n.t("validations.household.reasonable_preference_reason.reason_not_required")
record.errors.add :reasonable_preference_reason, I18n.t("validations.lettings.household.reasonable_preference_reason.reason_not_required")
end
end
@ -25,29 +25,29 @@ module Validations::HouseholdValidations
def validate_reason_for_leaving_last_settled_home(record)
if record.reason == 32 && record.underoccupation_benefitcap != 4
record.errors.add :underoccupation_benefitcap, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required")
record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required")
record.errors.add :underoccupation_benefitcap, I18n.t("validations.lettings.household.underoccupation_benefitcap.leaving_last_settled_home.dont_know_required")
record.errors.add :reason, I18n.t("validations.lettings.household.reason.leaving_last_settled_home.dont_know_required")
end
validate_other_field(record, 20, :reason, :reasonother)
if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer?
record.errors.add :referral, I18n.t("validations.household.referral.reason_permanently_decanted")
record.errors.add :reason, I18n.t("validations.household.reason.not_internal_transfer")
record.errors.add :referral, I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted")
record.errors.add :reason, I18n.t("validations.lettings.household.reason.leaving_last_settled_home.not_internal_transfer")
end
return unless record.form.start_year_2024_or_later?
if record.reason == 20 && PHRASES_INDICATING_HOMELESSNESS_REGEX.match?(record.reasonother)
record.errors.add :reason, I18n.t("validations.household.reason.other_not_settled")
record.errors.add :reason, I18n.t("validations.lettings.household.reason.leaving_last_settled_home.other_not_settled")
end
end
def validate_armed_forces(record)
if (record.armed_forces_no? || record.armed_forces_refused?) && record.reservist.present?
record.errors.add :reservist, I18n.t("validations.household.reservist.injury_not_required")
record.errors.add :reservist, I18n.t("validations.lettings.household.reservist.injury_not_required")
end
if !record.armed_forces_regular? && record.leftreg.present?
record.errors.add :leftreg, I18n.t("validations.household.leftreg.question_not_required")
record.errors.add :leftreg, I18n.t("validations.lettings.household.leftreg.question_not_required")
end
end
@ -66,12 +66,12 @@ module Validations::HouseholdValidations
return unless record.age1 && record.ecstat1 && !record.form.start_year_2024_or_later?
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)
record.errors.add "age1", I18n.t("validations.household.age.child_under_16_ecstat", person_num: 1)
record.errors.add "ecstat1", I18n.t("validations.lettings.household.ecstat.child_under_16", person_num: 1)
record.errors.add "age1", I18n.t("validations.lettings.household.age.child_under_16_ecstat", person_num: 1)
end
if tenant_is_economic_child?(record.ecstat1) && record.age1 > 16
record.errors.add "ecstat1", I18n.t("validations.household.ecstat.child_over_16", person_num: 1)
record.errors.add "age1", I18n.t("validations.household.age.child_over_16", person_num: 1)
record.errors.add "ecstat1", I18n.t("validations.lettings.household.ecstat.child_over_16", person_num: 1)
record.errors.add "age1", I18n.t("validations.lettings.household.age.child_over_16", person_num: 1)
end
end
@ -82,12 +82,13 @@ module Validations::HouseholdValidations
next unless age && economic_status
if age < 16 && !economic_status_is_child_other_or_refused?(economic_status) && !record.form.start_year_2024_or_later?
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_ecstat", person_num:)
record.errors.add "ecstat#{person_num}", I18n.t("validations.lettings.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.lettings.household.age.child_under_16_ecstat", person_num:)
end
if tenant_is_economic_child?(economic_status) && age > 16
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_16", person_num:)
record.errors.add "ecstat#{person_num}", I18n.t("validations.lettings.household.ecstat.child_over_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.lettings.household.age.child_over_16", person_num:)
end
end
end
@ -101,8 +102,8 @@ module Validations::HouseholdValidations
next unless age && relationship
if age < 16 && !relationship_is_child_other_or_refused?(relationship)
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 "relat#{person_num}", I18n.t("validations.lettings.household.relat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.lettings.household.age.child_under_16_relat", person_num:)
end
end
end
@ -122,34 +123,34 @@ module Validations::HouseholdValidations
child = tenant_is_child?(relationship)
if age_between_16_19 && !(student || economic_status_refused) && child
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_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 "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student")
record.errors.add "ecstat#{person_num}", I18n.t("validations.lettings.household.ecstat.student_16_19.must_be_student")
record.errors.add "age#{person_num}", I18n.t("validations.lettings.household.age.student_16_19.cannot_be_16_19.child_not_student")
record.errors.add "relat#{person_num}", I18n.t("validations.lettings.household.relat.student_16_19.cannot_be_child.16_19_not_student")
end
next unless !age_between_16_19 && student && child
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_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 "age#{person_num}", I18n.t("validations.lettings.household.age.student_16_19.must_be_16_19")
record.errors.add "ecstat#{person_num}", I18n.t("validations.lettings.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")
record.errors.add "relat#{person_num}", I18n.t("validations.lettings.household.relat.student_16_19.cannot_be_child.student_not_16_19")
end
end
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]
if all_options.count(1) >= 1 && household_no_illness?(record)
record.errors.add :condition_effects, I18n.t("validations.household.condition_effects.no_choices")
record.errors.add :condition_effects, I18n.t("validations.lettings.household.condition_effects.no_choices")
end
end
def validate_previous_housing_situation(record)
if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary?
record.errors.add :prevten, :non_temp_accommodation, message: I18n.t("validations.household.prevten.non_temp_accommodation")
record.errors.add :prevten, :non_temp_accommodation, message: I18n.t("validations.lettings.household.prevten.non_temp_accommodation")
end
if record.age1.present? && record.age1 > 25 && record.previous_tenancy_was_foster_care?
record.errors.add :prevten, :over_25_foster_care, message: I18n.t("validations.household.prevten.over_25_foster_care")
record.errors.add :age1, I18n.t("validations.household.age.lead.over_25")
record.errors.add :prevten, :over_25_foster_care, message: I18n.t("validations.lettings.household.prevten.over_25_foster_care")
record.errors.add :age1, I18n.t("validations.lettings.household.age.lead.over_25")
end
# 3 Private Sector Tenancy
@ -168,8 +169,8 @@ module Validations::HouseholdValidations
# 29 Prison / Approved Probation Hostel
if record.is_internal_transfer? && [3, 4, 7, 10, 13, 14, 19, 23, 24, 25, 26, 27, 28, 29].include?(record.prevten)
label = record.form.get_question("prevten", record).present? ? record.form.get_question("prevten", record).label_from_value(record.prevten) : ""
record.errors.add :prevten, :internal_transfer_non_social_housing, message: I18n.t("validations.household.prevten.internal_transfer", prevten: label)
record.errors.add :referral, :internal_transfer_non_social_housing, message: I18n.t("validations.household.referral.prevten_invalid", prevten: label)
record.errors.add :prevten, :internal_transfer_non_social_housing, message: I18n.t("validations.lettings.household.prevten.internal_transfer", prevten: label)
record.errors.add :referral, :internal_transfer_non_social_housing, message: I18n.t("validations.lettings.household.referral.prevten_invalid", prevten: label)
end
end
@ -177,14 +178,14 @@ module Validations::HouseholdValidations
return unless record.owning_organisation
if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs?
record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.prevten.la_general_needs.internal_transfer")
record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.referral.la_general_needs.internal_transfer")
record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer")
record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer")
end
end
def validate_prevloc(record)
if record.previous_la_known? && record.prevloc.blank?
record.errors.add :prevloc, I18n.t("validations.household.previous_la_known")
record.errors.add :prevloc, I18n.t("validations.lettings.household.prevloc.previous_la_known")
end
end
@ -192,8 +193,8 @@ module Validations::HouseholdValidations
return unless record.layear && record.renewal
if record.is_renewal? && record.layear == 1
record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.household.renewal_just_moved_to_area.layear")
record.errors.add :renewal, I18n.t("validations.household.renewal_just_moved_to_area.renewal")
record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.lettings.household.layear.renewal_just_moved_to_area")
record.errors.add :renewal, I18n.t("validations.lettings.household.renewal.renewal_just_moved_to_area")
end
end
@ -201,20 +202,20 @@ module Validations::HouseholdValidations
return unless record.layear && record.la && record.prevloc && record.collection_start_year
if record.la == record.prevloc && record.layear == 1 && record.collection_start_year >= 2023
record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.household.same_la_just_moved_to_area.layear")
record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.household.same_la_just_moved_to_area.current_la")
record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.household.same_la_just_moved_to_area.current_la")
record.errors.add :uprn, :renewal_just_moved, message: I18n.t("validations.household.same_la_just_moved_to_area.current_la")
record.errors.add :ppostcode_full, :renewal_just_moved, message: I18n.t("validations.household.same_la_just_moved_to_area.previous_la")
record.errors.add :prevloc, :renewal_just_moved, message: I18n.t("validations.household.same_la_just_moved_to_area.previous_la")
record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area")
record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.lettings.household.la.same_la_just_moved_to_area")
record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area")
record.errors.add :uprn, :renewal_just_moved, message: I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area")
record.errors.add :ppostcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area")
record.errors.add :prevloc, :renewal_just_moved, message: I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area")
end
end
def validate_combination_of_housing_needs_responses(record)
if record.has_housingneeds? && record.housingneeds_type_not_listed? && record.no_or_unknown_other_housing_needs?
record.errors.add :housingneeds, I18n.t("validations.household.housingneeds.invalid")
record.errors.add :housingneeds_type, I18n.t("validations.household.housingneeds.invalid")
record.errors.add :housingneeds_other, I18n.t("validations.household.housingneeds.invalid")
record.errors.add :housingneeds, I18n.t("validations.lettings.household.housingneeds.invalid")
record.errors.add :housingneeds_type, I18n.t("validations.lettings.household.housingneeds_type.invalid")
record.errors.add :housingneeds_other, I18n.t("validations.lettings.household.housingneeds_other.invalid")
end
end

50
config/locales/en.yml

@ -294,74 +294,35 @@ en:
shared_ownership_deposit: "The %{mortgage_deposit_and_discount_error_fields} added together is %{mortgage_deposit_and_discount_total}. The value times the equity percentage is %{value_times_equity}. These figures should be the same."
household:
reasonable_preference_reason:
reason_required: "Enter a reason if you've answered 'yes' to reasonable preference."
reason_not_required: "Do not enter a reason if you've answered 'no' to reasonable preference."
underoccupation_benefitcap:
dont_know_required: "Answer must be ‘don’t know’ as you told us you don’t know the tenant’s main reason for leaving."
reservist:
injury_required: "Tell us whether the person was seriously injured or ill as a result of serving in the UK armed forces."
injury_not_required: "You cannot answer this question as you told us the person has not served in the UK armed forces or prefers not to say."
leftreg:
question_required: "Tell us 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."
age:
retired_male: "A male tenant who is retired must be 65 or over."
retired_female: "A female tenant who is retired must be 60 or over."
retired_over_70: "Answer cannot be over 70 as person %{person_num} has economic status that is not ‘retired’."
child_under_16_relat_lettings: "Answer cannot be under 16 as person %{person_num}'s relationship to the lead tenant is ‘partner’."
child_under_16_ecstat: "Answer cannot be under 16 as person %{person_num}’s working situation is not ‘child under 16’, ‘other’ or ‘prefers not to say’."
child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘."
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:
cannot_be_16_19:
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’."
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."
student_not_child:
cannot_be_16_19: "Person cannot be aged 16-19 if they are a student but not a child."
ecstat:
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_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16."
not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19."
student_16_19:
cannot_be_student:
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’."
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."
not_child_16_19:
cannot_be_student: "Person cannot be a student if they are aged 16-19 but are not a child."
relat:
child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16."
not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student."
student_16_19:
cannot_be_child:
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."
child_over_19: "Answer cannot be child as you told us person %{person_num} is over 19."
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’."
housingneeds:
invalid: "If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs."
prevten:
non_temp_accommodation: "Answer cannot be non-temporary accommodation as this is a re-let to a tenant who occupied the same property as temporary accommodation."
over_25_foster_care: "Answer cannot be a children’s home or foster care as the lead tenant is 26 or older."
internal_transfer: "Answer cannot be %{prevten} as this tenancy is an internal transfer."
la_general_needs:
internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as it’s an internal transfer and a private registered provider is on the tenancy agreement."
referral:
secure_tenancy: "Answer must be internal transfer as this is a secure tenancy."
rsnvac_non_temp: "Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation."
cannot_be_secure_tenancy: "Answer cannot be secure tenancy as this is not an internal transfer."
assessed_homeless: "Answer cannot be internal transfer as the tenant was assessed as homeless."
other_homeless: "Answer cannot be internal transfer as the tenant was considered homeless by their landlord."
prevten_invalid: "Answer cannot be internal transfer as the household situation immediately before this letting was %{prevten}."
reason_permanently_decanted: "Answer must be internal transfer as the tenant was permanently decanted from another property owned by this landlord."
la_general_needs:
internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting."
homeless:
assessed:
internal_transfer: "Answer cannot be 'assessed as homeless' as this tenancy is an internal transfer."
@ -369,20 +330,9 @@ en:
internal_transfer: "Answer cannot be 'other homelessness' as this tenancy was an internal transfer."
reasonpref:
not_homeless: "Answer cannot be ‘no’ as the tenant was homeless or about to lose their home."
previous_la_known: "Enter name of local authority."
renewal_just_moved_to_area:
layear: 'The household cannot have just moved to the local authority area if this letting is a renewal'
renewal: 'This letting cannot be a renewal if the household has just moved to the local authority area'
same_la_just_moved_to_area:
layear: 'You told us this tenant previously lived in this local authority. Check your answers are correct.'
current_la: 'You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct'
previous_la: 'The local authority of the previous property should not be the same as the current local authority, as you told us they had just moved to the local authority area. Check your answers are correct.'
gender:
retired_male: "Answer cannot be ‘male’ as tenant is under 65 and retired."
retired_female: "Answer cannot be ‘female’ as tenant is under 60 and retired."
reason:
not_internal_transfer: "Answer cannot be ‘permanently decanted from another property owned by this landlord’ as you told us the source of referral for this tenancy was not an internal transfer."
other_not_settled: "Please give the reason for the tenant leaving their last settled home. This is where they were living before they became homeless, were living in temporary accommodation or sleeping rough."
condition_effects:
no_choices: "You cannot answer this question as you told us nobody in the household has a physical or mental health condition (or other illness) expected to last 12 months or more."
postcode:

93
config/locales/validations/lettings/household.en.yml

@ -2,6 +2,99 @@ en:
validations:
lettings:
household:
reasonable_preference_reason:
reason_not_required: "Do not enter a reason if you've answered 'no' to reasonable preference."
underoccupation_benefitcap:
leaving_last_settled_home:
dont_know_required: "Answer must be ‘don’t know’ as you told us you don’t know the tenant’s main reason for leaving."
reservist:
injury_not_required: "You cannot answer this question as you told us the person has not served in the UK armed forces or prefers not to say."
leftreg:
question_required: "Tell us 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."
housingneeds:
invalid: "If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs."
housingneeds_other:
invalid: "If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs."
housingneeds_type:
invalid: "If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs."
reason:
leaving_last_settled_home:
dont_know_required: "Answer must be ‘don’t know’ as you told us you don’t know the tenant’s main reason for leaving."
not_internal_transfer: "Answer cannot be ‘permanently decanted from another property owned by this landlord’ as you told us the source of referral for this tenancy was not an internal transfer."
other_not_settled: "Please give the reason for the tenant leaving their last settled home. This is where they were living before they became homeless, were living in temporary accommodation or sleeping rough."
condition_effects:
no_choices: "You cannot answer this question as you told us nobody in the household has a physical or mental health condition (or other illness) expected to last 12 months or more."
prevloc:
previous_la_known: "Enter name of local authority."
same_la_just_moved_to_area: "The local authority of the previous property should not be the same as the current local authority, as you told us they had just moved to the local authority area. Check your answers are correct."
renewal:
renewal_just_moved_to_area: "This letting cannot be a renewal if the household has just moved to the local authority area"
layear:
renewal_just_moved_to_area: "The household cannot have just moved to the local authority area if this letting is a renewal"
same_la_just_moved_to_area: "You told us this tenant previously lived in this local authority. Check your answers are correct."
la:
same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct"
postcode_full:
same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct"
ppostcode_full:
same_la_just_moved_to_area: "The local authority of the previous property should not be the same as the current local authority, as you told us they had just moved to the local authority area. Check your answers are correct."
uprn:
same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct"
age:
child_under_16_relat: "Answer cannot be under 16 as person %{person_num}'s relationship to the lead tenant is ‘partner’."
child_under_16_ecstat: "Answer cannot be under 16 as person %{person_num}’s working situation is not ‘child under 16’, ‘other’ or ‘prefers not to say’."
child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘."
student_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."
must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’."
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."
ecstat:
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_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16."
student_16_19:
cannot_be_student:
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’."
relat:
one_partner: "Number of partners cannot be greater than 1."
child_under_16: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16."
student_16_19:
cannot_be_child:
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."
prevten:
non_temp_accommodation: "Answer cannot be non-temporary accommodation as this is a re-let to a tenant who occupied the same property as temporary accommodation."
over_25_foster_care: "Answer cannot be a children’s home or foster care as the lead tenant is 26 or older."
internal_transfer: "Answer cannot be %{prevten} as this tenancy is an internal transfer."
la_general_needs:
internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as it’s an internal transfer and a private registered provider is on the tenancy agreement."
referral:
prevten_invalid: "Answer cannot be internal transfer as the household situation immediately before this letting was %{prevten}."
leaving_last_settled_home:
reason_permanently_decanted: "Answer must be internal transfer as the tenant was permanently decanted from another property owned by this landlord."
la_general_needs:
internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting."

106
spec/models/validations/household_validations_spec.rb

@ -21,7 +21,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.household.reasonable_preference_reason.reason_not_required"))
end
end
end
@ -69,7 +69,7 @@ RSpec.describe Validations::HouseholdValidations 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"))
expect(record.errors["reason"]).to include(I18n.t("validations.lettings.household.reason.leaving_last_settled_home.other_not_settled"))
end
it "allows reasons that don't exactly match a phrase indicating homelessness" do
@ -83,7 +83,7 @@ RSpec.describe Validations::HouseholdValidations 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"))
expect(record.errors["reason"]).to include(I18n.t("validations.lettings.household.reason.leaving_last_settled_home.other_not_settled"))
end
end
end
@ -107,16 +107,14 @@ RSpec.describe Validations::HouseholdValidations do
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))
.to include(match(I18n.t("validations.lettings.household.underoccupation_benefitcap.leaving_last_settled_home.dont_know_required")))
expect(record.errors["reason"])
.to include(match(expected_error))
.to include(match(I18n.t("validations.lettings.household.reason.leaving_last_settled_home.dont_know_required")))
end
it "expects that under occupation benefit cap is also not known" do
@ -134,9 +132,9 @@ RSpec.describe Validations::HouseholdValidations do
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")))
.to include(match(I18n.t("validations.lettings.household.reason.leaving_last_settled_home.not_internal_transfer")))
expect(record.errors["referral"])
.to include(match(I18n.t("validations.household.referral.reason_permanently_decanted")))
.to include(match(I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted")))
end
end
@ -157,16 +155,16 @@ RSpec.describe Validations::HouseholdValidations do
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")))
.to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer")))
expect(record.errors["prevten"])
.to include(match(I18n.t("validations.household.prevten.la_general_needs.internal_transfer")))
.to include(match(I18n.t("validations.lettings.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")))
.to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer")))
expect(record.errors["prevten"])
.to include(match(I18n.t("validations.household.prevten.la_general_needs.internal_transfer")))
.to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer")))
end
end
end
@ -178,7 +176,7 @@ RSpec.describe Validations::HouseholdValidations do
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"])
.to include(match I18n.t("validations.household.reservist.injury_not_required"))
.to include(match I18n.t("validations.lettings.household.reservist.injury_not_required"))
end
end
@ -188,7 +186,7 @@ RSpec.describe Validations::HouseholdValidations do
record.reservist = 1
household_validator.validate_armed_forces(record)
expect(record.errors["reservist"])
.to include(match I18n.t("validations.household.reservist.injury_not_required"))
.to include(match I18n.t("validations.lettings.household.reservist.injury_not_required"))
end
end
@ -225,7 +223,7 @@ RSpec.describe Validations::HouseholdValidations do
record.leftreg = 0
household_validator.validate_armed_forces(record)
expect(record.errors["leftreg"])
.to include(match I18n.t("validations.household.leftreg.question_not_required"))
.to include(match I18n.t("validations.lettings.household.leftreg.question_not_required"))
end
it "expects that they served in the armed forces" do
@ -300,9 +298,9 @@ RSpec.describe Validations::HouseholdValidations do
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))
.to include(match I18n.t("validations.lettings.household.relat.child_under_16", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.child_under_16_relat_lettings", person_num: 2))
.to include(match I18n.t("validations.lettings.household.age.child_under_16_relat", person_num: 2))
end
it "expects that person is a child of the tenant" do
@ -346,9 +344,9 @@ RSpec.describe Validations::HouseholdValidations do
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))
.to include(match I18n.t("validations.lettings.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))
.to include(match I18n.t("validations.lettings.household.age.child_under_16_ecstat", person_num: 2))
end
it "expects that person's economic status is Child" do
@ -365,9 +363,9 @@ RSpec.describe Validations::HouseholdValidations do
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))
.to include(match I18n.t("validations.lettings.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))
.to include(match I18n.t("validations.lettings.household.age.child_over_16", person_num: 2))
end
end
end
@ -380,9 +378,9 @@ RSpec.describe Validations::HouseholdValidations do
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))
.not_to include(match I18n.t("validations.lettings.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))
.not_to include(match I18n.t("validations.lettings.household.age.child_under_16_ecstat", person_num: 2))
end
end
end
@ -398,11 +396,11 @@ RSpec.describe Validations::HouseholdValidations do
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))
.to include(match I18n.t("validations.lettings.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))
.to include(match I18n.t("validations.lettings.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))
.to include(match I18n.t("validations.lettings.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
@ -452,11 +450,11 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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"))
.to include(match I18n.t("validations.lettings.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"))
.to include(match I18n.t("validations.lettings.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
end
end
@ -516,7 +514,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -524,7 +522,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -532,7 +530,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -540,7 +538,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -548,7 +546,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -556,7 +554,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -564,7 +562,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -572,7 +570,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -580,7 +578,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -588,7 +586,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.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
@ -647,7 +645,7 @@ RSpec.describe Validations::HouseholdValidations 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"))
.to include(match I18n.t("validations.lettings.household.prevloc.previous_la_known"))
end
end
@ -657,9 +655,9 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.household.layear.renewal_just_moved_to_area"))
expect(record.errors["renewal"])
.to include(match I18n.t("validations.household.renewal_just_moved_to_area.renewal"))
.to include(match I18n.t("validations.lettings.household.renewal.renewal_just_moved_to_area"))
end
context "when validating layear and prevloc" do
@ -670,17 +668,17 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area"))
expect(record.errors["prevloc"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.previous_la"))
.to include(match I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area"))
expect(record.errors["ppostcode_full"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.previous_la"))
.to include(match I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area"))
expect(record.errors["la"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.current_la"))
.to include(match I18n.t("validations.lettings.household.la.same_la_just_moved_to_area"))
expect(record.errors["postcode_full"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.current_la"))
.to include(match I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area"))
expect(record.errors["uprn"])
.to include(match I18n.t("validations.household.same_la_just_moved_to_area.current_la"))
.to include(match I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area"))
end
end
end
@ -693,7 +691,7 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.household.prevten.non_temp_accommodation"))
end
end
@ -703,9 +701,9 @@ RSpec.describe Validations::HouseholdValidations do
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"))
.to include(match I18n.t("validations.lettings.household.prevten.over_25_foster_care"))
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.lead.over_25"))
.to include(match I18n.t("validations.lettings.household.age.lead.over_25"))
end
end
@ -740,9 +738,9 @@ RSpec.describe Validations::HouseholdValidations do
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]))
.to include(match I18n.t("validations.lettings.household.prevten.internal_transfer", prevten: prevten[:label]))
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
.to include(match I18n.t("validations.lettings.household.referral.prevten_invalid", prevten: ""))
end
end
end

Loading…
Cancel
Save