Browse Source

Use question ids a primary key

pull/2741/head
Manny Dinssa 8 months ago
parent
commit
cd809fa80e
  1. 36
      app/models/validations/household_validations.rb
  2. 41
      config/locales/validations/lettings/household.en.yml
  3. 36
      spec/models/validations/household_validations_spec.rb

36
app/models/validations/household_validations.rb

@ -25,20 +25,20 @@ 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.lettings.household.underoccupation_benefitcap.dont_know_required")
record.errors.add :reason, I18n.t("validations.lettings.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.lettings.household.referral.reason_permanently_decanted")
record.errors.add :reason, I18n.t("validations.lettings.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_after_2024?
if record.reason == 20 && PHRASES_INDICATING_HOMELESSNESS_REGEX.match?(record.reasonother)
record.errors.add :reason, I18n.t("validations.lettings.household.reason.other_not_settled")
record.errors.add :reason, I18n.t("validations.lettings.household.reason.leaving_last_settled_home.other_not_settled")
end
end
@ -94,8 +94,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.lettings.household.relat.child_under_16_lettings", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.lettings.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
@ -177,7 +177,7 @@ module Validations::HouseholdValidations
def validate_prevloc(record)
if record.previous_la_known? && record.prevloc.blank?
record.errors.add :prevloc, I18n.t("validations.lettings.household.previous_la_known")
record.errors.add :prevloc, I18n.t("validations.lettings.household.prevloc.previous_la_known")
end
end
@ -185,8 +185,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.lettings.household.renewal_just_moved_to_area.layear")
record.errors.add :renewal, I18n.t("validations.lettings.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
@ -194,20 +194,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.lettings.household.same_la_just_moved_to_area.layear")
record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.lettings.household.same_la_just_moved_to_area.current_la")
record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.same_la_just_moved_to_area.current_la")
record.errors.add :uprn, :renewal_just_moved, message: I18n.t("validations.lettings.household.same_la_just_moved_to_area.current_la")
record.errors.add :ppostcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.same_la_just_moved_to_area.previous_la")
record.errors.add :prevloc, :renewal_just_moved, message: I18n.t("validations.lettings.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.current_la")
record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.lettings.household.la.same_la_just_moved_to_area.current_la")
record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area.current_la")
record.errors.add :uprn, :renewal_just_moved, message: I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area.current_la")
record.errors.add :ppostcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area.previous_la")
record.errors.add :prevloc, :renewal_just_moved, message: I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area.previous_la")
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.lettings.household.housingneeds.invalid")
record.errors.add :housingneeds_type, I18n.t("validations.lettings.household.housingneeds.invalid")
record.errors.add :housingneeds_other, 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

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

@ -6,6 +6,7 @@ en:
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:
@ -18,26 +19,53 @@ en:
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:
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.'
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:
current_la: 'You told us this tenant previously lived in this local authority. Check your answers are correct.'
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'
la:
same_la_just_moved_to_area:
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'
postcode_full:
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.'
ppostcode_full:
same_la_just_moved_to_area:
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.'
uprn:
same_la_just_moved_to_area:
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'
age:
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_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:
@ -56,7 +84,7 @@ en:
must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’."
relat:
child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16."
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."
@ -71,6 +99,7 @@ en:
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."

36
spec/models/validations/household_validations_spec.rb

@ -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.lettings.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.lettings.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.lettings.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.lettings.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.lettings.household.referral.reason_permanently_decanted")))
.to include(match(I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted")))
end
end
@ -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.lettings.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.lettings.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
@ -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.lettings.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.lettings.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.lettings.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.lettings.household.same_la_just_moved_to_area.layear"))
.to include(match I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area.current_la"))
expect(record.errors["prevloc"])
.to include(match I18n.t("validations.lettings.household.same_la_just_moved_to_area.previous_la"))
.to include(match I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area.previous_la"))
expect(record.errors["ppostcode_full"])
.to include(match I18n.t("validations.lettings.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.previous_la"))
expect(record.errors["la"])
.to include(match I18n.t("validations.lettings.household.same_la_just_moved_to_area.current_la"))
.to include(match I18n.t("validations.lettings.household.la.same_la_just_moved_to_area.current_la"))
expect(record.errors["postcode_full"])
.to include(match I18n.t("validations.lettings.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.current_la"))
expect(record.errors["uprn"])
.to include(match I18n.t("validations.lettings.household.same_la_just_moved_to_area.current_la"))
.to include(match I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area.current_la"))
end
end
end

Loading…
Cancel
Save