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