Browse Source

Refactor reason for leaving last settled home validations

pull/303/head
baarkerlounger 3 years ago
parent
commit
249a75ba82
  1. 26
      spec/models/case_log_spec.rb
  2. 43
      spec/models/validations/household_validations_spec.rb

26
spec/models/case_log_spec.rb

@ -44,28 +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 a reason for leaving last settled home validation" do
it "checks the reason for leaving must be don’t know if reason for leaving settled home (Q9a) is don’t know." do
expect {
described_class.create!(reason: "Don’t know",
underoccupation_benefitcap: "Yes - benefit cap",
owning_organisation:,
managing_organisation:)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "with reason for leaving last settled home validation set to other" do
it "must not be provided if the main reason for leaving settled home is not other" do
expect {
described_class.create!(reason: "Repossession",
other_reason_for_leaving_last_settled_home: "the other reason provided",
owning_organisation:,
managing_organisation:)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "with armed forces injured validation" do context "with armed forces injured validation" do
it "must not be answered if tenant was not a regular or reserve in armed forces" do it "must not be answered if tenant was not a regular or reserve in armed forces" do
expect { expect {
@ -690,6 +668,10 @@ RSpec.describe CaseLog do
it "validates reasonable preference" do it "validates reasonable preference" do
expect(validator).to receive(:validate_reasonable_preference) expect(validator).to receive(:validate_reasonable_preference)
end end
it "validates reason for leaving last settled home" do
expect(validator).to receive(:validate_reason_for_leaving_last_settled_home)
end
end end
describe "status" do describe "status" do

43
spec/models/validations/household_validations_spec.rb

@ -167,17 +167,50 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "reason for leaving last settled home validations" do describe "reason for leaving last settled home validations" do
let(:field) { "validations.other_field_not_required" }
let(:main_field_label) { "reason" }
let(:other_field_label) { "other reason for leaving last settled home" }
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when reason is other" do context "when reason is other" do
let(:field) { "validations.other_field_missing" }
it "validates that a reason is provided" do it "validates that a reason is provided" do
record.reason = "Other" record.reason = "Other"
record.other_reason_for_leaving_last_settled_home = nil record.other_reason_for_leaving_last_settled_home = nil
household_validator.validate_reason_for_leaving_last_settled_home(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"]) expect(record.errors["other_reason_for_leaving_last_settled_home"])
.to include(match I18n.t( .to include(match(expected_error))
"validations.other_field_missing", end
main_field_label: "reason", end
other_field_label: "other reason for leaving last settled home",
)) context "when reason is not other" do
it "validates that other reason is not provided" do
record.reason = "Repossession"
record.other_reason_for_leaving_last_settled_home = "Some other reason"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"])
.to include(match(expected_error))
end
end
context "when reason is not other" do
it "validates that other reason is not provided" do
record.reason = "Repossession"
record.other_reason_for_leaving_last_settled_home = "Some other reason"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"])
.to include(match(expected_error))
end
end
context "when reason is don't know" do
let(:expected_error) { I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") }
it "validates that under occupation benefit cap is also not known" do
record.reason = "Don’t know"
record.underoccupation_benefitcap = "Yes - benefit cap"
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["underoccupation_benefitcap"])
.to include(match(expected_error))
end end
end end
end end

Loading…
Cancel
Save