Browse Source

Add prevten validations (#374)

* Add prevten validations

* Fix indentation and extract a case_log method

* extract refuge method
pull/376/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
1cb5fd43b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/models/case_log.rb
  2. 16
      app/models/validations/household_validations.rb
  3. 8
      config/locales/en.yml
  4. 46
      spec/models/validations/household_validations_spec.rb

7
app/models/case_log.rb

@ -219,6 +219,13 @@ class CaseLog < ApplicationRecord
rent_type == 2 || rent_type == 4
end
def previous_tenancy_was_foster_care?
prevten == 13
end
def previous_tenancy_was_refuge?
prevten == 21
end
private
PIO = Postcodes::IO.new

16
app/models/validations/household_validations.rb

@ -64,6 +64,22 @@ module Validations::HouseholdValidations
if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary?
record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation")
end
if record.age1.present? && record.age1 > 19 && record.previous_tenancy_was_foster_care?
record.errors.add :prevten, I18n.t("validations.household.prevten.over_20_foster_care")
record.errors.add :age1, I18n.t("validations.household.age.lead.over_20")
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
if record.is_internal_transfer? && [3, 4, 10, 13, 19, 23, 24, 25, 26, 28, 29].include?(record.prevten)
label = record.form.get_question("prevten").present? ? record.form.get_question("prevten").label_from_value(record.prevten) : ""
record.errors.add :prevten, I18n.t("validations.household.prevten.internal_transfer", prevten: label)
record.errors.add :referral, I18n.t("validations.household.referral.prevten_invalid", prevten: label)
end
end
def validate_referral(record)

8
config/locales/en.yml

@ -109,6 +109,8 @@ en:
age:
retired_male: "Male tenant who is retired must be 65 or over"
retired_female: "Female tenant who is retired must be 60 or over"
lead:
over_20: "Lead tenant must be under 20 as you told us that their housing situation immediately before this letting was a children's home or foster care"
ecstat:
retired_over_70: "Tenant %{person_num} must be retired if over 70"
child_under_16: "Tenant %{person_num} economic status must be Child under 16 if their age is under 16"
@ -120,12 +122,16 @@ en:
one_or_two_choices: "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities"
prevten:
non_temp_accommodation: "Answer cannot be non-temporary accommodation as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
over_20_foster_care: "Answer cannot be children's home or foster care as the lead tenant is 20 or older"
male_refuge: "Answer cannot be refuge as the lead tenant identifies as male"
internal_transfer: "Answer cannot be %{prevten} as you already told us this tenancy is an internal transfer"
referral:
secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy"
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us 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 you already told us this is not an internal transfer"
assessed_homeless: "Answer cannot be internal transfer as you already told us the tenant was assessed as homeless"
other_homeless: "Answer cannot be internal transfer as you already told us the tenant was considered homeless by their landlord"
prevten_invalid: "Answer cannot be internal transfer as you already told us the source of referral for this letting was %{prevten}"
homeless:
assessed:
internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer"
@ -134,6 +140,8 @@ en:
reasonpref:
not_homeless: "Answer cannot be ‘no’ as you already told us the tenant was homeless or about to lose their home"
previous_la_known: "Enter a local authority"
gender:
male_refuge: "Answer cannot be refuge as the lead tenant identifies as male"
tenancy:
length:

46
spec/models/validations/household_validations_spec.rb

@ -561,5 +561,51 @@ RSpec.describe Validations::HouseholdValidations do
.to include(match I18n.t("validations.household.prevten.non_temp_accommodation"))
end
end
context "when the lead tenant is over 20" do
it "cannot be children's home/foster care" do
record.prevten = 13
record.age1 = 21
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.over_20_foster_care"))
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.lead.over_20"))
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 "cannot be 3" do
record.referral = 1
record.prevten = 3
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.internal_transfer", prevten: ""))
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
end
it "cannot be 4, 10, 13, 19, 23, 24, 25, 26, 28, 29" do
record.referral = 1
record.prevten = 4
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.internal_transfer", prevten: ""))
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
end
end
end
end

Loading…
Cancel
Save