Browse Source

Refactor tests to use validation messages present in language file (#219)

pull/223/head
Stéphane Meny 3 years ago committed by GitHub
parent
commit
b5a436af45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      spec/models/case_log_spec.rb
  2. 4
      spec/models/validations/local_authority_validations_spec.rb

8
spec/models/case_log_spec.rb

@ -668,7 +668,7 @@ RSpec.describe Form, type: :model do
it "updates soft errors" do
expect(case_log.has_no_unresolved_soft_errors?).to be false
expect(case_log.soft_errors["override_net_income_validation"].message)
.to match(/Net income is higher than expected/)
.to match(I18n.t("soft_validations.net_income.in_soft_max_range.message"))
end
end
@ -683,7 +683,7 @@ RSpec.describe Form, type: :model do
it "updates soft errors" do
expect(case_log.has_no_unresolved_soft_errors?).to be false
expect(case_log.soft_errors["override_net_income_validation"].message)
.to match(/Net income is lower than expected/)
.to match(I18n.t("soft_validations.net_income.in_soft_min_range.message"))
end
end
end
@ -1090,12 +1090,12 @@ RSpec.describe Form, type: :model do
it "errors if the property postcode is emptied" do
expect { address_case_log.update!({ property_postcode: "" }) }
.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "errors if the property postcode is not valid" do
expect { address_case_log.update!({ property_postcode: "invalid_postcode" }) }
.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "correctly resets all fields if property postcode not known" do

4
spec/models/validations/local_authority_validations_spec.rb

@ -17,7 +17,7 @@ RSpec.describe CaseLog do
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
}.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
end
end
@ -50,7 +50,7 @@ RSpec.describe Validations::LocalAuthorityValidations do
record.previous_postcode = "invalid"
subject.validate_previous_accommodation_postcode(record)
expect(record.errors).to_not be_empty
expect(record.errors["previous_postcode"]).to include(match /Enter a postcode in the correct format/)
expect(record.errors["previous_postcode"]).to include(match I18n.t("validations.postcode"))
end
end
end

Loading…
Cancel
Save