Browse Source

Vacancy reason validations

pull/307/head
baarkerlounger 3 years ago
parent
commit
3eb1dc7330
  1. 37
      spec/models/case_log_spec.rb
  2. 56
      spec/models/validations/property_validations_spec.rb

37
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

56
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

Loading…
Cancel
Save