Browse Source

Add validation for referrals and vacancy reasons

pull/242/head
Kat 3 years ago
parent
commit
506131a15f
  1. 7
      app/models/constants/case_log.rb
  2. 7
      app/models/validations/local_authority_validations.rb
  3. 14
      app/models/validations/property_validations.rb
  4. 5
      config/locales/en.yml
  5. 18
      spec/models/case_log_spec.rb

7
app/models/constants/case_log.rb

@ -1112,6 +1112,13 @@ module Constants::CaseLog
"Other" => 16,
}.freeze
REFERRAL_INVALID_TMP = ["Re-located through official housing mobility scheme",
"Other social landlord",
"Police, probation or prison",
"Youth offending team",
"Community mental health team",
"Health service"].freeze
NON_TEMP_ACCOMMODATION = ["Tied housing or rented with job",
"Supported housing",
"Sheltered accomodation",

7
app/models/validations/local_authority_validations.rb

@ -1,4 +1,5 @@
module Validations::LocalAuthorityValidations
include Constants::CaseLog
POSTCODE_REGEXP = Validations::PropertyValidations::POSTCODE_REGEXP
def validate_previous_accommodation_postcode(record)
@ -8,4 +9,10 @@ module Validations::LocalAuthorityValidations
record.errors.add :previous_postcode, error_message
end
end
def validate_referral(record)
if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral)
record.errors.add :referral, I18n.t("validations.local_authority.referral.rsnvac_non_temp")
end
end
end

14
app/models/validations/property_validations.rb

@ -40,6 +40,14 @@ module Validations::PropertyValidations
if record.first_time_property_let_as_social_housing? && record.rsnvac.present? && !FIRST_LET_VACANCY_REASONS.include?(record.rsnvac)
record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.first_let_social")
end
if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && NON_TEMP_ACCOMMODATION.include?(record.prevten)
record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.non_temp_accommodation")
end
if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral)
record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.referral_invalid")
end
end
def validate_unitletas(record)
@ -55,10 +63,4 @@ module Validations::PropertyValidations
record.errors.add :property_postcode, error_message
end
end
def validate_property_vacancy_reason_not_first_let(record)
if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && NON_TEMP_ACCOMMODATION.include?(record.prevten)
record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.non_temp_accommodation")
end
end
end

5
config/locales/en.yml

@ -56,6 +56,7 @@ en:
first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing"
previous_let_social: "Property cannot have a previous let type if it is being let as social housing for the first time"
non_temp_accommodation: "Vacancy reason cannot be \"Relet to tenant who occupied same property as temporary accommodation\" if previous tenancy is a non temporary accommodation"
referral_invalid: "Vacancy reason cannot be \"Relet to tenant who occupied same property as temporary accommodation\" if source of referral for letting is ..."
financial:
tshortfall:
@ -110,6 +111,10 @@ en:
shorthold: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years"
secure: "Secure (including flexible) should be between 2 and 99 years or not specified"
local_authority:
referral:
rsnvac_non_temp: "Source of referral for letting cannot be ... if the vacancy reason is \"Relet to tenant who occupied same property as temporary accommodation\""
soft_validations:
net_income:
hint_text: "This is based on the tenant’s work situation: %{ecstat1}"

18
spec/models/case_log_spec.rb

@ -918,6 +918,15 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
def check_rsnvac_referral_validation(referral)
expect {
CaseLog.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation",
referral: referral,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "cannot be temp accomodation if previous tenancy was non temp" do
check_rsnvac_validation("Tied housing or rented with job")
check_rsnvac_validation("Supported housing")
@ -925,6 +934,15 @@ RSpec.describe Form, type: :model do
check_rsnvac_validation("Home Office Asylum Support")
check_rsnvac_validation("Other")
end
it "cannot be temp accomodation if source of letting referral " do
check_rsnvac_referral_validation("Re-located through official housing mobility scheme")
check_rsnvac_referral_validation("Other social landlord")
check_rsnvac_referral_validation("Police, probation or prison")
check_rsnvac_referral_validation("Youth offending team")
check_rsnvac_referral_validation("Community mental health team")
check_rsnvac_referral_validation("Health service")
end
end
end

Loading…
Cancel
Save