Browse Source

add joint tenancy validation

pull/549/head
Dushan Despotovic 3 years ago
parent
commit
8c6d13f0c7
  1. 6
      app/models/validations/tenancy_validations.rb
  2. 1
      config/locales/en.yml
  3. 20
      spec/models/validations/tenancy_validations_spec.rb

6
app/models/validations/tenancy_validations.rb

@ -32,4 +32,10 @@ module Validations::TenancyValidations
def validate_other_tenancy_type(record) def validate_other_tenancy_type(record)
validate_other_field(record, 3, :tenancy, :tenancyother) validate_other_field(record, 3, :tenancy, :tenancyother)
end end
def validate_joint_tenancy(record)
if record.hhmemb == 1 && record.joint != 2
record.errors.add :joint, I18n.t("validations.tenancy.not_joint")
end
end
end end

1
config/locales/en.yml

@ -221,6 +221,7 @@ en:
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_transfer: "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" cannot_be_internal_transfer: "Answer cannot be internal transfer as you already told us this is not a secure tenancy"
not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household"
declaration: declaration:
missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log." missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log."

20
spec/models/validations/tenancy_validations_spec.rb

@ -146,4 +146,24 @@ RSpec.describe Validations::TenancyValidations do
end end
end end
end end
describe "joint tenancy validation" do
context "when the data inputter has said that there is only one member in the household" do
let(:expected_error) { I18n.t("validations.tenancy.not_joint") }
it "displays an error if the data inputter says the letting is a joint tenancy" do
record.hhmemb = 1
record.joint = 1
tenancy_validator.validate_joint_tenancy(record)
expect(record.errors["joint"]).to include(match(expected_error))
end
it "does not display an error if the data inputter says the letting is not a joint tenancy" do
record.hhmemb = 1
record.joint = 2
tenancy_validator.validate_joint_tenancy(record)
expect(record.errors["joint"]).to be_empty
end
end
end
end end

Loading…
Cancel
Save