From 6834e0f037c063f4ac5336e709889e9f21575a64 Mon Sep 17 00:00:00 2001 From: Mo Seedat Date: Sun, 16 Oct 2022 01:17:55 +0100 Subject: [PATCH] Add specific error for non-digit error --- app/models/lettings_log.rb | 1 - config/locales/en.yml | 4 ++-- spec/models/sales_log_spec.rb | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 371191ee6..9e38138eb 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -8,7 +8,6 @@ class LettingsLogValidator < ActiveModel::Validator include Validations::TenancyValidations include Validations::DateValidations include Validations::LocalAuthorityValidations - def validate(record) validation_methods = public_methods.select { |method| method.starts_with?("validate_") } validation_methods.each { |meth| public_send(meth, record) } diff --git a/config/locales/en.yml b/config/locales/en.yml index 5e2ca87b9..85a727d04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -92,9 +92,9 @@ en: sales_log: attributes: beds: - blank: "Enter the number of bedrooms" + blank: "Number of bedrooms must be between 1 and 9" invalid: "Number of bedrooms must be between 1 and 9" - not_a_number: "Number of bedrooms must be between 1 and 9" + not_a_number: "Number of bedrooms must be a digit between 1 and 9" not_an_integer: "Number of bedrooms must be a whole number between 1 and 9" greater_than: "Number of bedrooms must be between 1 and 9" less_than: "Number of bedrooms must be between 1 and 9" diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 4b2b9edfd..2f1d75e74 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -131,7 +131,7 @@ RSpec.describe SalesLog, type: :model do it "fails with appropriate error message", aggregate_failures: true do invalid_beds_values = { - "Four" => ["Number of bedrooms must be between 1 and 9", "Number of bedrooms must be between 1 and 9"], + "Four" => ["Number of bedrooms must be a digit between 1 and 9", "Number of bedrooms must be between 1 and 9"], -2 => ["Number of bedrooms must be between 1 and 9"], 2.5 => ["Number of bedrooms must be a whole number between 1 and 9"] }