From 413068592bb738e1f0af625c6d6e86464b43ddbf Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Mon, 12 Feb 2024 10:33:27 +0000 Subject: [PATCH] CLDC-3227: Add unit tests --- .../validations/household_validations_spec.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 98da214f1..5b87bd45e 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -53,6 +53,35 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_reason_for_leaving_last_settled_home(record) expect(record.errors["reasonother"]).to be_empty end + + context "when form year is >= 2024" do + before do + record.startdate = Time.zone.local(2024, 4, 1) + end + + context "when checking the content of reasonother" do + it "validates that the reason doesn't match phrase indicating homelessness" do + record.reason = 20 + record.reasonother = "Temp accommodation" + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["reason"]).to include(I18n.t("validations.household.reason.other_not_settled")) + end + + it "allows reasons that don't exactly match a phrase indicating homelessness" do + record.reason = 20 + record.reasonother = "Not quite homeless but some other reason" + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["reason"]).to be_empty + end + + it "ignores surrounding non-alphabet characters and casing when determining a match" do + record.reason = 20 + record.reasonother = " 0homelessness!" + household_validator.validate_reason_for_leaving_last_settled_home(record) + expect(record.errors["reason"]).to include(I18n.t("validations.household.reason.other_not_settled")) + end + end + end end context "when reason is not other" do