Browse Source

Add referral validations

pull/427/head
Kat 3 years ago
parent
commit
f201929ad7
  1. 4
      app/models/case_log.rb
  2. 5
      app/models/validations/household_validations.rb
  3. 4
      config/locales/en.yml
  4. 18
      spec/models/validations/household_validations_spec.rb

4
app/models/case_log.rb

@ -277,6 +277,10 @@ class CaseLog < ApplicationRecord
landlord == 2
end
def is_prevten_la_general_needs?
[30, 31].any?(prevten)
end
private
PIO = Postcodes::IO.new

5
app/models/validations/household_validations.rb

@ -104,6 +104,11 @@ module Validations::HouseholdValidations
record.errors.add :referral, I18n.t("validations.household.referral.other_homeless")
record.errors.add :homeless, I18n.t("validations.household.homeless.other.internal_transfer")
end
if record.is_internal_transfer? && record.this_landlord? && record.is_prevten_la_general_needs?
record.errors.add :referral, I18n.t("validations.household.referral.la_general_needs.internal_transfer")
record.errors.add :prevten, I18n.t("validations.household.prevten.la_general_needs.internal_transfer")
end
end
def validate_prevloc(record)

4
config/locales/en.yml

@ -177,6 +177,8 @@ en:
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"
la_general_needs:
internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as you already told us it's the same landlord on the tenancy agreement and it 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"
@ -185,6 +187,8 @@ en:
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 household situation immediately before this letting was %{prevten}"
reason_permanently_decanted: "Answer must be internal transfer as you already told us the tenant was permanently decanted from another property owned by this landlord"
la_general_needs:
internal_transfer: "Answer cannot be internal transfer as you already told us 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 you already told us this tenancy is an internal transfer"

18
spec/models/validations/household_validations_spec.rb

@ -196,6 +196,24 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["referral"])
.to be_empty
end
it "cannot have `this landlord` as landlord and Housing situation before this letting cannot be LA general needs" do
record.landlord = 1
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

Loading…
Cancel
Save