Browse Source

Add reason and referral validations (#376)

* Add reason and referral validations

* extract method
pull/378/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
ac8d41b4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/case_log.rb
  2. 5
      app/models/validations/household_validations.rb
  3. 3
      config/locales/en.yml
  4. 24
      spec/models/validations/household_validations_spec.rb

4
app/models/case_log.rb

@ -227,6 +227,10 @@ class CaseLog < ApplicationRecord
prevten == 21
end
def is_reason_permanently_decanted?
reason == 1
end
private
PIO = Postcodes::IO.new

5
app/models/validations/household_validations.rb

@ -19,6 +19,11 @@ module Validations::HouseholdValidations
record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required")
end
validate_other_field(record, 31, :reason, :other_reason_for_leaving_last_settled_home)
if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer?
record.errors.add :referral, I18n.t("validations.household.referral.reason_permanently_decanted")
record.errors.add :reason, I18n.t("validations.household.reason.not_internal_transfer")
end
end
def validate_armed_forces(record)

3
config/locales/en.yml

@ -132,6 +132,7 @@ en:
assessed_homeless: "Answer cannot be internal transfer as you already told us the tenant was assessed as homeless"
other_homeless: "Answer cannot be internal transfer as you already told us the tenant was considered homeless by their landlord"
prevten_invalid: "Answer cannot be internal transfer as you already told us the source of referral for this letting was %{prevten}"
reason_permanently_decanted: "Answer must be internal transfer as you already told us the tenant was permanently decanted from another property owned by this landlord"
homeless:
assessed:
internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer"
@ -142,6 +143,8 @@ en:
previous_la_known: "Enter a local authority"
gender:
male_refuge: "Answer cannot be refuge as the lead tenant identifies as male"
reason:
not_internal_transfer: "Answer cannot be permanently decanted from another property owned by this landlord as you told us the source of referral for this tenancy was not an internal transfer"
tenancy:
length:

24
spec/models/validations/household_validations_spec.rb

@ -229,6 +229,30 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["reason"]).to be_empty
end
end
context "when referral is not internal transfer" do
it "cannot be permanently decanted from another property owned by this landlord" do
record.reason = 1
record.referral = 2
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"])
.to include(match(I18n.t("validations.household.reason.not_internal_transfer")))
expect(record.errors["referral"])
.to include(match(I18n.t("validations.household.referral.reason_permanently_decanted")))
end
end
context "when referral is internal transfer" do
it "can be permanently decanted from another property owned by this landlord" do
record.reason = 1
record.referral = 1
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"])
.to be_empty
expect(record.errors["referral"])
.to be_empty
end
end
end
describe "armed forces validations" do

Loading…
Cancel
Save