diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index a9cdeca22..6116cd6b2 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -23,13 +23,10 @@ module Validations::HouseholdValidations validate_other_field(record, :reason, :other_reason_for_leaving_last_settled_home) end - def validate_armed_forces_injured(record) + def validate_armed_forces(record) 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 - - def validate_armed_forces_active_response(record) if record.armedforces != "A current or former regular in the UK Armed Forces (excluding National Service)" && record.leftreg.present? record.errors.add :leftreg, I18n.t("validations.household.leftreg.question_not_required") end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index ecf6c709a..193bf2aea 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -171,28 +171,6 @@ RSpec.describe CaseLog do end end - context "when validating armed forces is active" do - it "must not be answered if not ever served as a regular" do - expect { - described_class.create!(armedforces: "No", - leftreg: "Yes", - owning_organisation:, - managing_organisation:) - }.to raise_error(ActiveRecord::RecordInvalid) - end - - # Crossover over tests here as injured must be answered as well for no error - it "must be answered if ever served in the forces as a regular" do - expect { - described_class.create!(armedforces: "A current or former regular in the UK Armed Forces (excluding National Service)", - leftreg: "Yes", - reservist: "Yes", - owning_organisation:, - managing_organisation:) - }.not_to raise_error - end - end - context "when validating household members" do it "validate that persons aged under 16 must have relationship Child" do expect { @@ -648,6 +626,10 @@ RSpec.describe CaseLog do it "validates reason for leaving last settled home" do expect(validator).to receive(:validate_reason_for_leaving_last_settled_home) end + + it "validates armed forces" do + expect(validator).to receive(:validate_armed_forces) + end end describe "status" do diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index adcc1a838..2b620b35e 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -236,7 +236,7 @@ RSpec.describe Validations::HouseholdValidations 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) + household_validator.validate_armed_forces(record) expect(record.errors["reservist"]) .to include(match I18n.t("validations.household.reservist.injury_not_required")) end @@ -246,7 +246,7 @@ RSpec.describe Validations::HouseholdValidations 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) + household_validator.validate_armed_forces(record) expect(record.errors["reservist"]) .to include(match I18n.t("validations.household.reservist.injury_not_required")) end @@ -256,7 +256,7 @@ RSpec.describe Validations::HouseholdValidations 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) + household_validator.validate_armed_forces(record) expect(record.errors["reservist"]).to be_empty end end @@ -265,7 +265,7 @@ RSpec.describe Validations::HouseholdValidations 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) + household_validator.validate_armed_forces(record) expect(record.errors["reservist"]).to be_empty end end @@ -274,7 +274,33 @@ RSpec.describe Validations::HouseholdValidations 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) + household_validator.validate_armed_forces(record) + expect(record.errors["reservist"]).to be_empty + end + end + + context "when the tenant or partner has left the armed forces" do + it "validates that they served in the armed forces" do + record.armedforces = "No" + record.leftreg = "Yes" + household_validator.validate_armed_forces(record) + expect(record.errors["leftreg"]) + .to include(match I18n.t("validations.household.leftreg.question_not_required")) + end + + it "expects that they served in the armed forces" do + record.armedforces = "A current or former regular in the UK Armed Forces (excluding National Service)" + record.leftreg = "Yes" + household_validator.validate_armed_forces(record) + expect(record.errors["leftreg"]).to be_empty + end + + it "expects that they served in the armed forces and may have been injured" do + record.armedforces = "A current or former regular in the UK Armed Forces (excluding National Service)" + record.leftreg = "Yes" + record.reservist = "Yes" + household_validator.validate_armed_forces(record) + expect(record.errors["leftreg"]).to be_empty expect(record.errors["reservist"]).to be_empty end end