From f12bc583aca7afdefa13c809a5660bad3056bb61 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 14 Feb 2022 19:13:42 +0000 Subject: [PATCH] First let vacancy reason validations --- spec/models/case_log_spec.rb | 88 ++---------------- .../validations/property_validations_spec.rb | 89 +++++++++++++++++++ 2 files changed, 97 insertions(+), 80 deletions(-) diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 8cea4c1c6..3d55b93d2 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -44,86 +44,6 @@ RSpec.describe CaseLog do end # TODO: replace these with validator specs and checks for method call here - context "when validating property vacancy and let as" do - it "cannot have a previously let as type, if it hasn't been let before" do - expect { - described_class.create!( - first_time_property_let_as_social_housing: "No", - unitletas: "Social rent basis", - owning_organisation:, - managing_organisation:, - ) - }.not_to raise_error - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - unitletas: "Social rent basis", - owning_organisation:, - managing_organisation:, - ) - }.to raise_error(ActiveRecord::RecordInvalid) - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - unitletas: "Affordable rent basis", - owning_organisation:, - managing_organisation:, - ) - }.to raise_error(ActiveRecord::RecordInvalid) - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - unitletas: "Intermediate rent basis", - owning_organisation:, - managing_organisation:, - ) - }.to raise_error(ActiveRecord::RecordInvalid) - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - unitletas: "Don’t know", - owning_organisation:, - managing_organisation:, - ) - }.to raise_error(ActiveRecord::RecordInvalid) - end - - it "must have a first let reason for vacancy if it's being let as social housing for the first time" do - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - rsnvac: "First let of new-build property", - owning_organisation:, - managing_organisation:, - ) - }.not_to raise_error - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - rsnvac: "First let of conversion, rehabilitation or acquired property", - owning_organisation:, - managing_organisation:, - ) - }.not_to raise_error - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - rsnvac: "First let of leased property", - owning_organisation:, - managing_organisation:, - ) - }.not_to raise_error - expect { - described_class.create!( - first_time_property_let_as_social_housing: "Yes", - rsnvac: "Tenant moved to care home", - owning_organisation:, - managing_organisation:, - ) - }.to raise_error(ActiveRecord::RecordInvalid) - end - end - context "when saving income ranges" do context "with an income in upper soft range" do let(:case_log) do @@ -323,6 +243,14 @@ RSpec.describe CaseLog do it "validates housing benefit rent shortfall" do expect(validator).to receive(:validate_tshortfall) end + + it "validates let type" do + expect(validator).to receive(:validate_unitletas) + end + + it "validates reason for vacancy" do + expect(validator).to receive(:validate_rsnvac) + end end describe "status" do diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 6d1f987a5..fa328dc35 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -145,4 +145,93 @@ RSpec.describe Validations::PropertyValidations do end end end + + describe "#validate_unitletas" do + context "when the property has not been let before" do + it "validates that no previous let type is provided" do + record.first_time_property_let_as_social_housing = "Yes" + record.unitletas = "Social rent basis" + property_validator.validate_unitletas(record) + expect(record.errors["unitletas"]) + .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + record.unitletas = "Affordable rent basis" + property_validator.validate_unitletas(record) + expect(record.errors["unitletas"]) + .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + record.unitletas = "Intermediate rent basis" + property_validator.validate_unitletas(record) + expect(record.errors["unitletas"]) + .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + record.unitletas = "Don’t know" + property_validator.validate_unitletas(record) + expect(record.errors["unitletas"]) + .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + end + end + + context "when the property has been let previously" do + it "expects to have a previous let type" do + record.first_time_property_let_as_social_housing = "No" + record.unitletas = "Social rent basis" + property_validator.validate_unitletas(record) + expect(record.errors["unitletas"]).to be_empty + end + end + end + + describe "validate_rsnvac" do + context "when the property has not been let before" do + it "validates that it has a first let reason for vacancy" do + record.first_time_property_let_as_social_housing = "Yes" + record.rsnvac = "Tenant moved to care home" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.first_let_social")) + end + + it "expects to have a first let reason for vacancy" do + record.first_time_property_let_as_social_housing = "Yes" + record.rsnvac = "First let of new-build property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + record.rsnvac = "First let of conversion, rehabilitation or acquired property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + record.rsnvac = "First let of leased property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + end + end + + context "when the property has been let as social housing before" do + it "validates that the reason for vacancy is not a first let as social housing reason" do + record.first_time_property_let_as_social_housing = "No" + record.rsnvac = "First let of new-build property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) + record.rsnvac = "First let of conversion, rehabilitation or acquired property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) + record.rsnvac = "First let of leased property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) + end + + it "expects the reason for vacancy to be a first let as social housing reason" do + record.first_time_property_let_as_social_housing = "Yes" + record.rsnvac = "First let of new-build property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + record.rsnvac = "First let of conversion, rehabilitation or acquired property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + record.rsnvac = "First let of leased property" + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]).to be_empty + end + end + end end