From 39ec422920026ca9b39acfa8c12adf67fb9a99f7 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 14 Feb 2022 13:07:57 +0000 Subject: [PATCH] Armed forces injured validations --- .../validations/household_validations.rb | 2 +- spec/models/case_log_spec.rb | 11 ----- .../validations/household_validations_spec.rb | 49 +++++++++++++++++++ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index f70e1e60d..a9cdeca22 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -24,7 +24,7 @@ module Validations::HouseholdValidations end def validate_armed_forces_injured(record) - if (record.armedforces == "No" || record.armedforces == "Prefer not to say") && record.reservist.present? + if (record.armedforces == "No" || record.armedforces == "Tenant prefers not to say") && record.reservist.present? record.errors.add :reservist, I18n.t("validations.household.reservist.injury_not_required") end end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 715dd752c..ecf6c709a 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -44,17 +44,6 @@ RSpec.describe CaseLog do end # TODO: replace these with validator specs and checks for method call here - context "with armed forces injured validation" do - it "must not be answered if tenant was not a regular or reserve in armed forces" do - expect { - described_class.create!(armedforces: "No", - reservist: "Yes", - owning_organisation:, - managing_organisation:) - }.to raise_error(ActiveRecord::RecordInvalid) - end - end - context "when validating property vacancy and let as" do it "cannot have a previously let as type, if it hasn't been let before" do expect { diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 8031a9ade..adcc1a838 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -230,4 +230,53 @@ RSpec.describe Validations::HouseholdValidations do end end end + + describe "armed forces validations" do + context "when the tenant or partner was and is not a member of the armed forces" do + it "validates that injured in the armed forces is not yes" do + record.armedforces = "No" + record.reservist = "Yes" + household_validator.validate_armed_forces_injured(record) + expect(record.errors["reservist"]) + .to include(match I18n.t("validations.household.reservist.injury_not_required")) + end + end + + context "when the tenant prefers not to say if they were or are in the armed forces" do + it "validates that injured in the armed forces is not yes" do + record.armedforces = "Tenant prefers not to say" + record.reservist = "Yes" + household_validator.validate_armed_forces_injured(record) + expect(record.errors["reservist"]) + .to include(match I18n.t("validations.household.reservist.injury_not_required")) + end + end + + context "when the tenant was or is a regular member of the armed forces" do + it "expects that injured in the armed forces can be yes" do + record.armedforces = "A current or former regular in the UK Armed Forces (excluding National Service)" + record.reservist = "Yes" + household_validator.validate_armed_forces_injured(record) + expect(record.errors["reservist"]).to be_empty + end + end + + context "when the tenant was or is a reserve member of the armed forces" do + it "expects that injured in the armed forces can be yes" do + record.armedforces = "A current or former reserve in the UK Armed Forces (excluding National Service)" + record.reservist = "Yes" + household_validator.validate_armed_forces_injured(record) + expect(record.errors["reservist"]).to be_empty + end + end + + context "when the tenant's partner was or is a member of the armed forces" do + it "expects that injured in the armed forces can be yes" do + record.armedforces = "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years" + record.reservist = "Yes" + household_validator.validate_armed_forces_injured(record) + expect(record.errors["reservist"]).to be_empty + end + end + end end