From 3eb1dc7330cf955d7dbde5835995b336f206fb36 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 15 Feb 2022 12:32:38 +0000 Subject: [PATCH] Vacancy reason validations --- spec/models/case_log_spec.rb | 37 ------------ .../validations/property_validations_spec.rb | 56 +++++++++++++++++++ 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 3d55b93d2..fff57abf5 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -130,43 +130,6 @@ RSpec.describe CaseLog do }.to raise_error(ActiveRecord::RecordInvalid) end end - - context "when validating reason for vacancy" do - def check_rsnvac_validation(prevten) - expect { - described_class.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", - prevten:, - owning_organisation:, - managing_organisation:) - }.to raise_error(ActiveRecord::RecordInvalid) - end - - def check_rsnvac_referral_validation(referral) - expect { - described_class.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", - referral:, - owning_organisation:, - managing_organisation:) - }.to raise_error(ActiveRecord::RecordInvalid) - end - - it "cannot be temp accommodation 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 accommodation") - check_rsnvac_validation("Home Office Asylum Support") - check_rsnvac_validation("Any other accommodation") - end - - it "cannot be temp accommodation 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 TODO end diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index fa328dc35..7cbd6164c 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -233,5 +233,61 @@ RSpec.describe Validations::PropertyValidations do expect(record.errors["rsnvac"]).to be_empty end end + + context "when the property has been let before" do + let(:non_temporary_previous_tenancies) do + [ + "Tied housing or rented with job", "Supported housing", "Sheltered accommodation", + "Home Office Asylum Support", "Any other accommodation" + ] + end + + context "when the previous tenancy was not temporary" do + it "validates that the property is not being relet to tenant who occupied as temporary" do + non_temporary_previous_tenancies.each do |rsn| + record.rsnvac = "Relet to tenant who occupied same property as temporary accommodation" + record.prevten = rsn + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.non_temp_accommodation")) + end + end + + let(:referral_sources) do + [ + "Re-located through official housing mobility scheme", + "Other social landlord", "Police, probation or prison", + "Youth offending team", "Community mental health team", + "Health service" + ] + end + + it "validates that the letting source is not a referral" do + referral_sources.each do |src| + record.rsnvac = "Relet to tenant who occupied same property as temporary accommodation" + record.referral = src + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.referral_invalid")) + end + end + end + + context "when the previous tenancy was temporary" do + it "expects that the property can be relet to a tenant who previously occupied it as temporary" do + record.prevten = "Fixed-term local authority general needs tenancy" + record.rsnvac = "Relet to tenant who occupied same property as temporary accommodation" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + end + + it "expects that the letting source can be a referral" do + record.prevten = "Fixed-term local authority general needs tenancy" + record.referral = "Re-located through official housing mobility scheme" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + end + end + end end end