Module: Validations::HouseholdValidations
- Includes:
- SharedValidations
- Defined in:
- household_validations.rb
Constant Summary collapse
- PHRASES_INDICATING_HOMELESSNESS =
[ "Homeless", "Homelessness", "Temporary accommodation", "Temp accommodation", "TA", "Sleeping rough", "Rough sleeping", ].freeze
- PHRASES_INDICATING_HOMELESSNESS_REGEX =
Regexp.union( PHRASES_INDICATING_HOMELESSNESS.map { |phrase| Regexp.new("\\A[^[:alpha:]]*#{phrase}[^[:alpha:]]*\\Z", Regexp::IGNORECASE) }, )
Instance Method Summary collapse
- #validate_armed_forces(record) ⇒ Object
- #validate_combination_of_housing_needs_responses(record) ⇒ Object
- #validate_condition_effects(record) ⇒ Object
- #validate_layear(record) ⇒ Object
- #validate_layear_and_prevloc(record) ⇒ Object
- #validate_partner_count(record) ⇒ Object
- #validate_person_1_economic(record) ⇒ Object
- #validate_person_age_and_relationship_matches_economic_status(record) ⇒ Object
- #validate_person_age_matches_economic_status(record) ⇒ Object
- #validate_person_age_matches_relationship(record) ⇒ Object
- #validate_previous_housing_situation(record) ⇒ Object
- #validate_prevloc(record) ⇒ Object
-
#validate_reason_for_leaving_last_settled_home(record) ⇒ Object
describe everything this does here.
-
#validate_reasonable_preference(record) ⇒ Object
Validations methods need to be called ‘validate_<page_name>’ to run on model save or ‘validate_’ to run on submit as well.
- #validate_referral(record) ⇒ Object
Instance Method Details
#validate_armed_forces(record) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'household_validations.rb', line 46 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") end if !record.armed_forces_regular? && record.leftreg.present? record.errors.add :leftreg, I18n.t("validations.household.leftreg.question_not_required") end end |
#validate_combination_of_housing_needs_responses(record) ⇒ Object
212 213 214 215 216 217 218 |
# File 'household_validations.rb', line 212 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") end end |
#validate_condition_effects(record) ⇒ Object
132 133 134 135 136 137 |
# File 'household_validations.rb', line 132 def validate_condition_effects(record) = [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 .count(1) >= 1 && household_no_illness?(record) record.errors.add :condition_effects, I18n.t("validations.household.condition_effects.no_choices") end end |
#validate_layear(record) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'household_validations.rb', line 190 def validate_layear(record) 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") end end |
#validate_layear_and_prevloc(record) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'household_validations.rb', line 199 def validate_layear_and_prevloc(record) 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") end end |
#validate_partner_count(record) ⇒ Object
55 56 57 |
# File 'household_validations.rb', line 55 def validate_partner_count(record) shared_validate_partner_count(record, 8) end |
#validate_person_1_economic(record) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'household_validations.rb', line 59 def validate_person_1_economic(record) 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) record.errors.add "age1", I18n.t("validations.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) end end |
#validate_person_age_and_relationship_matches_economic_status(record) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'household_validations.rb', line 104 def validate_person_age_and_relationship_matches_economic_status(record) return unless record.startdate && !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}") relationship = record.public_send("relat#{person_num}") next unless age && economic_status && relationship age_between_16_19 = age.between?(16, 19) student = tenant_is_fulltime_student?(economic_status) economic_status_refused = tenant_economic_status_refused?(economic_status) 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") 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") end end |
#validate_person_age_matches_economic_status(record) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'household_validations.rb', line 72 def validate_person_age_matches_economic_status(record) (2..8).each do |person_num| age = record.public_send("age#{person_num}") economic_status = record.public_send("ecstat#{person_num}") next unless age && economic_status if age < 16 && !economic_status_is_child_other_or_refused?(economic_status) && !record.form.start_year_after_2024? 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:) 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:) end end end |
#validate_person_age_matches_relationship(record) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'household_validations.rb', line 89 def validate_person_age_matches_relationship(record) return unless record.startdate && !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 && 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:) end end end |
#validate_previous_housing_situation(record) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'household_validations.rb', line 139 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") 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") end if record.sex1 == "M" && record.previous_tenancy_was_refuge? record.errors.add :prevten, I18n.t("validations.household.prevten.male_refuge") record.errors.add :sex1, I18n.t("validations.household.gender.male_refuge") end # 3 Private Sector Tenancy # 4 Tied housing or rented with job # 7 Direct access hostel # 10 Hospital # 13 Children's home / Foster Care # 14 Bed and breakfast # 19 Rough Sleeping # 23 Mobile home / Caravan # 24 Home Office Asylum Support # 25 Other # 26 Owner Occupation # 27 Owner occupation (low-cost home ownership) # 28 Living with Friends or Family # 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) end end |
#validate_prevloc(record) ⇒ Object
184 185 186 187 188 |
# File 'household_validations.rb', line 184 def validate_prevloc(record) if record.previous_la_known? && record.prevloc.blank? record.errors.add :prevloc, I18n.t("validations.household.previous_la_known") end end |
#validate_reason_for_leaving_last_settled_home(record) ⇒ Object
describe everything this does here
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'household_validations.rb', line 27 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") 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") end return unless record.form.start_year_after_2024? if record.reason == 20 && PHRASES_INDICATING_HOMELESSNESS_REGEX.match?(record.reasonother) record.errors.add :reason, I18n.t("validations.household.reason.other_not_settled") end end |
#validate_reasonable_preference(record) ⇒ Object
Validations methods need to be called ‘validate_<page_name>’ to run on model save or ‘validate_’ to run on submit as well
6 7 8 9 10 |
# File 'household_validations.rb', line 6 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") end end |
#validate_referral(record) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'household_validations.rb', line 175 def validate_referral(record) 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") end end |