Browse Source

Validate internal referrals and secure tenancy

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

6
app/models/validations/household_validations.rb

@ -73,6 +73,12 @@ module Validations::HouseholdValidations
end end
end end
def validate_referral(record)
if record.tenancy == "Secure (including flexible)" && record.referral == "Internal transfer"
record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy")
end
end
private private
def women_of_child_bearing_age_in_household(record) def women_of_child_bearing_age_in_household(record)

6
app/models/validations/tenancy_validations.rb

@ -25,4 +25,10 @@ module Validations::TenancyValidations
def validate_other_tenancy_type(record) def validate_other_tenancy_type(record)
validate_other_field(record, :tenancy, :tenancyother) validate_other_field(record, :tenancy, :tenancyother)
end end
def validate_tenancy(record)
if record.tenancy == "Secure (including flexible)" && record.referral == "Internal transfer"
record.errors.add :tenancy, I18n.t("validations.tenancy.internal_referral")
end
end
end end

3
config/locales/en.yml

@ -110,12 +110,15 @@ en:
one_or_two_choices: "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities" one_or_two_choices: "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities"
prevten: prevten:
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" 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"
tenancy: tenancy:
length: length:
fixed_term_not_required: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term" fixed_term_not_required: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term"
shorthold: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years" shorthold: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years"
secure: "Secure (including flexible) should be between 2 and 99 years or not specified" 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: local_authority:
referral: referral:

12
spec/models/validations/household_validations_spec.rb

@ -477,4 +477,16 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["accessibility_requirements"]).to be_empty expect(record.errors["accessibility_requirements"]).to be_empty
end end
end end
describe "referral validations" do
context "when type of tenancy is secure" do
it "must be internal transfer" do
record.tenancy = "Secure (including flexible)"
record.referral = "Internal transfer"
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.secure_tenancy"))
end
end
end
end end

10
spec/models/validations/tenancy_validations_spec.rb

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

Loading…
Cancel
Save