Browse Source

Fix referral validations and move referral validation from local_authority to household

pull/312/head
Kat 3 years ago
parent
commit
18d893544d
  1. 5
      app/models/validations/household_validations.rb
  2. 6
      app/models/validations/local_authority_validations.rb
  3. 2
      app/models/validations/tenancy_validations.rb
  4. 5
      config/locales/en.yml
  5. 13
      spec/models/validations/household_validations_spec.rb
  6. 13
      spec/models/validations/tenancy_validations_spec.rb

5
app/models/validations/household_validations.rb

@ -74,7 +74,10 @@ module Validations::HouseholdValidations
end
def validate_referral(record)
if record.tenancy == "Secure (including flexible)" && record.referral == "Internal transfer"
if record.rsnvac == "Re-let to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral)
record.errors.add :referral, I18n.t("validations.household.referral.rsnvac_non_temp")
end
if record.tenancy == "Secure (including flexible)" && record.referral.present? && record.referral != "Internal transfer"
record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy")
end
end

6
app/models/validations/local_authority_validations.rb

@ -9,10 +9,4 @@ module Validations::LocalAuthorityValidations
record.errors.add :previous_postcode, error_message
end
end
def validate_referral(record)
if record.rsnvac == "Re-let to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral)
record.errors.add :referral, I18n.t("validations.local_authority.referral.rsnvac_non_temp")
end
end
end

2
app/models/validations/tenancy_validations.rb

@ -27,7 +27,7 @@ module Validations::TenancyValidations
end
def validate_tenancy(record)
if record.tenancy == "Secure (including flexible)" && record.referral == "Internal transfer"
if record.tenancy.present? && record.tenancy != "Secure (including flexible)" && record.referral == "Internal transfer"
record.errors.add :tenancy, I18n.t("validations.tenancy.internal_referral")
end
end

5
config/locales/en.yml

@ -112,6 +112,7 @@ en:
non_temp_accommodation: "Answer cannot be non-temporary accommodation as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
referral:
secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy"
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
tenancy:
length:
@ -120,10 +121,6 @@ en:
secure: "Secure (including flexible) should be between 2 and 99 years or not specified"
internal_referral: "Answer must be secure tenancy as you already told us this tenancy is an internal transfer"
local_authority:
referral:
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
declaration:
missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log."

13
spec/models/validations/household_validations_spec.rb

@ -479,14 +479,21 @@ RSpec.describe Validations::HouseholdValidations do
end
describe "referral validations" do
context "when type of tenancy is secure" do
it "must be internal transfer" do
context "when type of tenancy is not secure" do
it "cannot be not internal transfer" do
record.tenancy = "Secure (including flexible)"
record.referral = "Internal transfer"
record.referral = "Other social landlord"
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.secure_tenancy"))
end
it "can be internal transfer" do
record.tenancy = "Secure (including flexible)"
record.referral = "Internal transfer"
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
end
end
end
end

13
spec/models/validations/tenancy_validations_spec.rb

@ -107,15 +107,24 @@ RSpec.describe Validations::TenancyValidations do
end
end
context "when referral is internal transfer" do
context "when referral is not internal transfer" do
it "adds an error" do
record.tenancy = "Secure (including flexible)"
record.tenancy = "Assured"
record.referral = "Internal transfer"
tenancy_validator.validate_tenancy(record)
expect(record.errors["tenancy"])
.to include(match I18n.t("validations.tenancy.internal_referral"))
end
end
context "when referral is internal transfer" do
it "does not add an error" do
record.tenancy = "Secure (including flexible)"
record.referral = "Internal transfer"
tenancy_validator.validate_tenancy(record)
expect(record.errors["tenancy"]).to be_empty
end
end
end
end
end

Loading…
Cancel
Save