From b5a436af4556bbc4709f803a9ea2d8a2e36ab06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Fri, 14 Jan 2022 12:12:50 +0000 Subject: [PATCH] Refactor tests to use validation messages present in language file (#219) --- spec/models/case_log_spec.rb | 8 ++++---- .../validations/local_authority_validations_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 1c77b47d6..e09c209e8 100644 --- a/spec/models/case_log_spec.rb +++ b/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 diff --git a/spec/models/validations/local_authority_validations_spec.rb b/spec/models/validations/local_authority_validations_spec.rb index c62607e2a..d6e6d0328 100644 --- a/spec/models/validations/local_authority_validations_spec.rb +++ b/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