From 143558f2b8d05ce1093a6840c9a435a1ecf07d28 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 14 Feb 2022 12:30:16 +0000 Subject: [PATCH] Additional tests --- .../validations/household_validations.rb | 1 + .../validations/household_validations_spec.rb | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index e253ee34b..f70e1e60d 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -18,6 +18,7 @@ module Validations::HouseholdValidations def validate_reason_for_leaving_last_settled_home(record) if record.reason == "Don’t know" && record.underoccupation_benefitcap != "Don’t know" record.errors.add :underoccupation_benefitcap, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") + record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") end validate_other_field(record, :reason, :other_reason_for_leaving_last_settled_home) end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index c55679f37..70f31d018 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -181,6 +181,13 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["other_reason_for_leaving_last_settled_home"]) .to include(match(expected_error)) end + + it "expects that a reason is provided" do + record.reason = "Other" + record.other_reason_for_leaving_last_settled_home = "Some unusual reason" + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty + end end context "when reason is not other" do @@ -191,6 +198,13 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["other_reason_for_leaving_last_settled_home"]) .to include(match(expected_error)) end + + it "expects that other reason is not provided" do + record.reason = "Repossession" + record.other_reason_for_leaving_last_settled_home = nil + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty + end end context "when reason is not other" do @@ -201,6 +215,13 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["other_reason_for_leaving_last_settled_home"]) .to include(match(expected_error)) end + + it "expects that other reason is not provided" do + record.reason = "Repossession" + record.other_reason_for_leaving_last_settled_home = nil + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty + end end context "when reason is don't know" do @@ -211,6 +232,16 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_reason_for_leaving_last_settled_home(record) expect(record.errors["underoccupation_benefitcap"]) .to include(match(expected_error)) + expect(record.errors["reason"]) + .to include(match(expected_error)) + end + + it "expects that under occupation benefit cap is also not known" do + record.reason = "Don’t know" + record.underoccupation_benefitcap = "Don’t know" + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["underoccupation_benefitcap"]).to be_empty + expect(record.errors["reason"]).to be_empty end end end