Browse Source

First let vacancy reason validations

pull/304/head
baarkerlounger 4 years ago
parent
commit
f12bc583ac
  1. 88
      spec/models/case_log_spec.rb
  2. 89
      spec/models/validations/property_validations_spec.rb

88
spec/models/case_log_spec.rb

@ -44,86 +44,6 @@ RSpec.describe CaseLog do
end end
# TODO: replace these with validator specs and checks for method call here # 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 "when saving income ranges" do
context "with an income in upper soft range" do context "with an income in upper soft range" do
let(:case_log) do let(:case_log) do
@ -323,6 +243,14 @@ RSpec.describe CaseLog do
it "validates housing benefit rent shortfall" do it "validates housing benefit rent shortfall" do
expect(validator).to receive(:validate_tshortfall) expect(validator).to receive(:validate_tshortfall)
end 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 end
describe "status" do describe "status" do

89
spec/models/validations/property_validations_spec.rb

@ -145,4 +145,93 @@ RSpec.describe Validations::PropertyValidations do
end end
end 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 end

Loading…
Cancel
Save