Browse Source

Add a non temp accommocation validation for vacancy reason

pull/242/head
Kat 3 years ago
parent
commit
e276f4facb
  1. 4
      app/models/constants/case_log.rb
  2. 12
      app/models/validations/household_validations.rb
  3. 2
      config/forms/2021_2022.json
  4. 1
      config/locales/en.yml
  5. 19
      spec/models/case_log_spec.rb

4
app/models/constants/case_log.rb

@ -103,11 +103,11 @@ module Constants::CaseLog
}.freeze }.freeze
PREVIOUS_TENANCY = { PREVIOUS_TENANCY = {
"Owner occupation (private) " => 26, "Owner occupation (private)" => 26,
"Owner occupation (low cost home ownership)" => 27, "Owner occupation (low cost home ownership)" => 27,
"Private sector tenancy" => 3, "Private sector tenancy" => 3,
"Tied housing or rented with job" => 4, "Tied housing or rented with job" => 4,
"Supported housing" => 5, "Supported housing" => 6,
"Sheltered accomodation" => 8, "Sheltered accomodation" => 8,
"Residential care home" => 9, "Residential care home" => 9,
"Living with friends or family" => 28, "Living with friends or family" => 28,

12
app/models/validations/household_validations.rb

@ -84,6 +84,18 @@ module Validations::HouseholdValidations
end end
end end
NON_TEMP_ACCOMMODATION = ["Tied housing or rented with job",
"Supported housing",
"Sheltered accomodation",
"Home Office Asylum Support",
"Other"].freeze
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
private private
def women_of_child_bearing_age_in_household(record) def women_of_child_bearing_age_in_household(record)

2
config/forms/2021_2022.json

@ -790,7 +790,7 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Owner occupation (private) ", "0": "Owner occupation (private)",
"1": "Owner occupation (low cost home ownership)", "1": "Owner occupation (low cost home ownership)",
"2": "Private sector tenancy", "2": "Private sector tenancy",
"3": "Tied housing or rented with job", "3": "Tied housing or rented with job",

1
config/locales/en.yml

@ -55,6 +55,7 @@ en:
first_let_not_social: "Reason for vacancy cannot be first let if unit has been previously let as social housing" first_let_not_social: "Reason for vacancy cannot be first let if unit has been previously let as social housing"
first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing" 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" 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"
financial: financial:
tshortfall: tshortfall:

19
spec/models/case_log_spec.rb

@ -907,6 +907,25 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
end end
end end
context "Validate reason for vacancy" do
def check_rsnvac_validation(prevten)
expect {
CaseLog.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation",
prevten: prevten,
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")
check_rsnvac_validation("Sheltered accomodation")
check_rsnvac_validation("Home Office Asylum Support")
check_rsnvac_validation("Other")
end
end
end end
describe "status" do describe "status" do

Loading…
Cancel
Save