Browse Source

Armed forces injured validations

pull/303/head
baarkerlounger 3 years ago
parent
commit
39ec422920
  1. 2
      app/models/validations/household_validations.rb
  2. 11
      spec/models/case_log_spec.rb
  3. 49
      spec/models/validations/household_validations_spec.rb

2
app/models/validations/household_validations.rb

@ -24,7 +24,7 @@ module Validations::HouseholdValidations
end end
def validate_armed_forces_injured(record) 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") record.errors.add :reservist, I18n.t("validations.household.reservist.injury_not_required")
end end
end end

11
spec/models/case_log_spec.rb

@ -44,17 +44,6 @@ RSpec.describe CaseLog do
end end
# TODO: replace these with validator specs and checks for method call here # 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 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 it "cannot have a previously let as type, if it hasn't been let before" do
expect { expect {

49
spec/models/validations/household_validations_spec.rb

@ -230,4 +230,53 @@ RSpec.describe Validations::HouseholdValidations do
end end
end 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 end

Loading…
Cancel
Save