From 02aa97e79369917c5e89d9fbdb7ff69b7e4e293c Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Tue, 28 Mar 2023 10:41:12 +0100 Subject: [PATCH] if dont know joint tenancy dont validate hhmemb (#1477) --- app/models/validations/tenancy_validations.rb | 2 +- spec/models/validations/tenancy_validations_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index 5e1ec4a3c..14727d3b0 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -42,7 +42,7 @@ module Validations::TenancyValidations def validate_joint_tenancy(record) return unless record.collection_start_year && record.joint - if record.hhmemb == 1 && record.joint != 2 && record.collection_start_year >= 2022 + if record.hhmemb == 1 && record.joint == 1 && record.collection_start_year >= 2022 record.errors.add :joint, :not_joint_tenancy, message: I18n.t("validations.tenancy.not_joint") record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member") end diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index 9f3a2b873..e2dae02e2 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -311,6 +311,16 @@ RSpec.describe Validations::TenancyValidations do expect(record.errors["joint"]).to be_empty expect(record.errors["hhmemb"]).to be_empty end + + it "does not error when don't know answer to joint" do + record.hhmemb = 1 + record.joint = 3 + + tenancy_validator.validate_joint_tenancy(record) + + expect(record.errors["joint"]).to be_empty + expect(record.errors["hhmemb"]).to be_empty + end end end end