Browse Source

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
pull/619/head
Dushan 3 years ago committed by baarkerlounger
parent
commit
26c0107779
  1. 2
      app/models/validations/tenancy_validations.rb
  2. 8
      spec/models/validations/tenancy_validations_spec.rb

2
app/models/validations/tenancy_validations.rb

@ -34,7 +34,7 @@ module Validations::TenancyValidations
end end
def validate_joint_tenancy(record) 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 if record.hhmemb == 1 && record.joint != 2 && record.collection_start_year >= 2022
record.errors.add :joint, I18n.t("validations.tenancy.not_joint") record.errors.add :joint, I18n.t("validations.tenancy.not_joint")

8
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["joint"]).to be_empty
expect(record.errors["hhmemb"]).to be_empty expect(record.errors["hhmemb"]).to be_empty
end 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 end
end end

Loading…
Cancel
Save