Browse Source

Remove redundant validations (can't trigger them because on inferrance)

pull/2742/head
Kat 1 year ago
parent
commit
37df8c2995
  1. 19
      app/models/validations/property_validations.rb
  2. 6
      config/locales/validations/lettings/property_information.en.yml
  3. 12
      spec/models/lettings_log_spec.rb
  4. 94
      spec/models/validations/property_validations_spec.rb

19
app/models/validations/property_validations.rb

@ -4,14 +4,6 @@ module Validations::PropertyValidations
REFERRAL_INVALID_TMP = [8, 10, 12, 13, 14, 15].freeze REFERRAL_INVALID_TMP = [8, 10, 12, 13, 14, 15].freeze
def validate_rsnvac(record) def validate_rsnvac(record)
if !record.first_time_property_let_as_social_housing? && record.has_first_let_vacancy_reason?
record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.first_let_not_social")
end
if record.first_time_property_let_as_social_housing? && record.rsnvac.present? && !record.has_first_let_vacancy_reason?
record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.first_let_social")
end
if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary? if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary?
record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.non_temp_accommodation") record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.non_temp_accommodation")
end end
@ -26,20 +18,9 @@ module Validations::PropertyValidations
end end
end end
def validate_unitletas(record)
if record.first_time_property_let_as_social_housing? && record.unitletas.present?
record.errors.add :unitletas, I18n.t("validations.lettings.property.unitletas.previous_let_social")
end
end
def validate_shared_housing_rooms(record) def validate_shared_housing_rooms(record)
return unless record.unittype_gn return unless record.unittype_gn
if record.is_bedsit? && record.beds != 1 && record.beds.present? && !record.form.start_year_2024_or_later?
record.errors.add :unittype_gn, I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit")
record.errors.add :beds, I18n.t("validations.lettings.property.beds.one_bedroom_bedsit")
end
if record.hhmemb == 1 && record.is_shared_housing? && if record.hhmemb == 1 && record.is_shared_housing? &&
!record.beds.to_i.between?(1, 3) && record.beds.present? !record.beds.to_i.between?(1, 3) && record.beds.present?
record.errors.add :unittype_gn, I18n.t("validations.lettings.property.unittype_gn.one_three_bedroom_single_tenant_shared") record.errors.add :unittype_gn, I18n.t("validations.lettings.property.unittype_gn.one_three_bedroom_single_tenant_shared")

6
config/locales/validations/lettings/property_information.en.yml

@ -5,21 +5,15 @@ en:
postcode_full: postcode_full:
invalid: "Enter a postcode in the correct format, for example AA1 1AA." invalid: "Enter a postcode in the correct format, for example AA1 1AA."
rsnvac: rsnvac:
first_let_not_social: "Enter a reason for vacancy that is not '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."
non_temp_accommodation: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as this accommodation is not temporary." non_temp_accommodation: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as this accommodation is not temporary."
referral_invalid: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as a different source of referral for this letting." referral_invalid: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as a different source of referral for this letting."
not_a_renewal: "Reason for vacancy cannot be 'Renewal of fixed-term tenancy' if letting is not a renewal." not_a_renewal: "Reason for vacancy cannot be 'Renewal of fixed-term tenancy' if letting is not a renewal."
referral: referral:
rsnvac_non_temp: "Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation." rsnvac_non_temp: "Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation."
unitletas:
previous_let_social: "Property cannot have a previous let type if being let as social housing for the first time."
unittype_gn: unittype_gn:
one_bedroom_bedsit: "A bedsit can only have one bedroom."
one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms." one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms."
one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms." one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms."
beds: beds:
one_bedroom_bedsit: "A bedsit can only have one bedroom."
one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms." one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms."
one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms." one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms."
uprn: uprn:

12
spec/models/lettings_log_spec.rb

@ -194,10 +194,6 @@ RSpec.describe LettingsLog 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 it "validates reason for vacancy" do
expect(validator).to receive(:validate_rsnvac) expect(validator).to receive(:validate_rsnvac)
end end
@ -1010,8 +1006,8 @@ RSpec.describe LettingsLog do
end end
it "does not impact other validations" do it "does not impact other validations" do
expect { lettings_log.update!(startdate: Time.zone.yesterday, first_time_property_let_as_social_housing: 0, rsnvac: 16) } expect { lettings_log.update!(startdate: Time.zone.yesterday, referral: 8, rsnvac: 9) }
.to raise_error(ActiveRecord::RecordInvalid, /Enter a reason for vacancy that is not 'first let' if unit has been previously let as social housing/) .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.lettings.property.rsnvac.referral_invalid")}/)
end end
end end
@ -1046,8 +1042,8 @@ RSpec.describe LettingsLog do
end end
it "does not impact other validations" do it "does not impact other validations" do
expect { lettings_log.update!(location:, scheme:, first_time_property_let_as_social_housing: 0, rsnvac: 16) } expect { lettings_log.update!(startdate: Time.zone.yesterday, referral: 8, rsnvac: 9) }
.to raise_error(ActiveRecord::RecordInvalid, /Enter a reason for vacancy that is not 'first let' if unit has been previously let as social housing/) .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.lettings.property.rsnvac.referral_invalid")}/)
end end
end end
end end

94
spec/models/validations/property_validations_spec.rb

@ -47,43 +47,6 @@ RSpec.describe Validations::PropertyValidations do
expect(log.errors).to be_empty expect(log.errors).to be_empty
end end
end end
context "and the log is from before 24/25" do
it "adds an error" do
allow(log.form).to receive(:start_year_2024_or_later?).and_return false
property_validator.validate_shared_housing_rooms(log)
expect(log.errors["unittype_gn"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit"))
expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit"))
end
end
end
context "when a bedsit has less than 1 bedroom" do
before do
log.beds = 0
log.unittype_gn = 2
end
context "and the log is for 24/25 or later" do
it "does not add an error" do
property_validator.validate_shared_housing_rooms(log)
expect(log.errors).to be_empty
end
end
context "and the log is from before 24/25" do
it "adds an error" do
allow(log.form).to receive(:start_year_2024_or_later?).and_return false
property_validator.validate_shared_housing_rooms(log)
expect(log.errors["unittype_gn"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit"))
expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit"))
end
end
end end
context "when shared housing has more than 7 bedrooms" do context "when shared housing has more than 7 bedrooms" do
@ -126,49 +89,8 @@ RSpec.describe Validations::PropertyValidations do
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
log.first_time_property_let_as_social_housing = 1
log.unitletas = 0
property_validator.validate_unitletas(log)
expect(log.errors["unitletas"])
.to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social"))
log.unitletas = 1
property_validator.validate_unitletas(log)
expect(log.errors["unitletas"])
.to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social"))
log.unitletas = 2
property_validator.validate_unitletas(log)
expect(log.errors["unitletas"])
.to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social"))
log.unitletas = 3
property_validator.validate_unitletas(log)
expect(log.errors["unitletas"])
.to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social"))
end
end
context "when the property has been let previously" do
it "expects to have a previous let type" do
log.first_time_property_let_as_social_housing = 0
log.unitletas = 0
property_validator.validate_unitletas(log)
expect(log.errors["unitletas"]).to be_empty
end
end
end
describe "validate_rsnvac" do describe "validate_rsnvac" do
context "when the property has not been let before" do context "when the property has not been let before" do
it "validates that it has a first let reason for vacancy" do
log.first_time_property_let_as_social_housing = 1
log.rsnvac = 6
property_validator.validate_rsnvac(log)
expect(log.errors["rsnvac"])
.to include(match I18n.t("validations.lettings.property.rsnvac.first_let_social"))
end
it "expects to have a first let reason for vacancy" do it "expects to have a first let reason for vacancy" do
log.first_time_property_let_as_social_housing = 1 log.first_time_property_let_as_social_housing = 1
log.rsnvac = 15 log.rsnvac = 15
@ -184,22 +106,6 @@ RSpec.describe Validations::PropertyValidations do
end end
context "when the property has been let as social housing before" do 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
log.first_time_property_let_as_social_housing = 0
log.rsnvac = 15
property_validator.validate_rsnvac(log)
expect(log.errors["rsnvac"])
.to include(match I18n.t("validations.lettings.property.rsnvac.first_let_not_social"))
log.rsnvac = 16
property_validator.validate_rsnvac(log)
expect(log.errors["rsnvac"])
.to include(match I18n.t("validations.lettings.property.rsnvac.first_let_not_social"))
log.rsnvac = 17
property_validator.validate_rsnvac(log)
expect(log.errors["rsnvac"])
.to include(match I18n.t("validations.lettings.property.rsnvac.first_let_not_social"))
end
it "expects the reason for vacancy to be a first let as social housing reason" do it "expects the reason for vacancy to be a first let as social housing reason" do
log.first_time_property_let_as_social_housing = 1 log.first_time_property_let_as_social_housing = 1
log.rsnvac = 15 log.rsnvac = 15

Loading…
Cancel
Save