Browse Source

Add more error messages

pull/312/head
Kat 3 years ago
parent
commit
3be30306c3
  1. 2
      app/models/constants/case_log.rb
  2. 5
      app/models/validations/household_validations.rb
  3. 5
      app/models/validations/tenancy_validations.rb
  4. 4
      config/locales/en.yml
  5. 2
      spec/models/validations/tenancy_validations_spec.rb

2
app/models/constants/case_log.rb

@ -164,7 +164,7 @@ module Constants::CaseLog
}.freeze
RSNVAC = {
"Internal transfer (excluding renewals of a fixed-term tenancy)" => 13,
"Internal transfer" => 13,
"Previous tenant died with no succession" => 5,
"Re-let to tenant who occupied same property as temporary accommodation" => 9,
"Renewal of fixed-term tenancy" => 14,

5
app/models/validations/household_validations.rb

@ -74,8 +74,9 @@ module Validations::HouseholdValidations
end
def validate_referral(record)
if record.tenancy == "Secure (including flexible)" && record.referral.present? && record.referral != "Internal transfer"
record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy")
if record.referral.present? && record.tenancy.present? && record.referral != "Internal transfer" && record.tenancy == "Secure (including flexible)"
record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy")
record.errors.add :tenancy, I18n.t("validations.tenancy.cannot_be_internal_transfer")
end
end

5
app/models/validations/tenancy_validations.rb

@ -26,9 +26,10 @@ module Validations::TenancyValidations
validate_other_field(record, :tenancy, :tenancyother)
end
def validate_tenancy(record)
def validate_tenancy_type(record)
if record.tenancy.present? && record.tenancy != "Secure (including flexible)" && record.referral == "Internal transfer"
record.errors.add :tenancy, I18n.t("validations.tenancy.internal_referral")
record.errors.add :tenancy, I18n.t("validations.tenancy.internal_transfer")
record.errors.add :referral, I18n.t("validations.household.referral.cannot_be_secure_tenancy")
end
end
end

4
config/locales/en.yml

@ -113,13 +113,15 @@ en:
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"
cannot_be_secure_tenancy: "Answer cannot be secure tenancy as you already told us this is not an internal transfer"
tenancy:
length:
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"
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"
internal_transfer: "Answer must be secure tenancy as you already told us this tenancy is an internal transfer"
cannot_be_internal_transfer: "Answer cannot be internal transfer as you already told us this is not a secure tenancy"
declaration:
missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log."

2
spec/models/validations/tenancy_validations_spec.rb

@ -113,7 +113,7 @@ RSpec.describe Validations::TenancyValidations do
record.referral = "Internal transfer"
tenancy_validator.validate_tenancy(record)
expect(record.errors["tenancy"])
.to include(match I18n.t("validations.tenancy.internal_referral"))
.to include(match I18n.t("validations.tenancy.internal_transfer"))
end
end

Loading…
Cancel
Save