Browse Source

Additional tests

pull/303/head
baarkerlounger 3 years ago
parent
commit
143558f2b8
  1. 1
      app/models/validations/household_validations.rb
  2. 31
      spec/models/validations/household_validations_spec.rb

1
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

31
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

Loading…
Cancel
Save