From 26c0107779f9be91f4fce9fb595373030b9dd332 Mon Sep 17 00:00:00 2001 From: Dushan <47317567+dushan-madetech@users.noreply.github.com> Date: Mon, 9 May 2022 14:54:15 +0100 Subject: [PATCH] add check to prevent error on hhmemb if joint is nil (#560) * add failing spec * add check to prevent error on hhmemb if joint is nil --- app/models/validations/tenancy_validations.rb | 2 +- spec/models/validations/tenancy_validations_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index b24933a56..008843053 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -34,7 +34,7 @@ module Validations::TenancyValidations end def validate_joint_tenancy(record) - return unless record.collection_start_year + return unless record.collection_start_year && record.joint if record.hhmemb == 1 && record.joint != 2 && record.collection_start_year >= 2022 record.errors.add :joint, I18n.t("validations.tenancy.not_joint") diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index db6c999f4..09b3c5314 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -168,6 +168,14 @@ RSpec.describe Validations::TenancyValidations do expect(record.errors["joint"]).to be_empty expect(record.errors["hhmemb"]).to be_empty end + + it "does not display an error if the data inputter has given the household members but not input if it is a joint tenancy" do + record.hhmemb = 1 + record.joint = nil + tenancy_validator.validate_joint_tenancy(record) + expect(record.errors["joint"]).to be_empty + expect(record.errors["hhmemb"]).to be_empty + end end end end