Browse Source

Add specific error for non-digit error

CLDC-858-update-sales-property-information
Mo Seedat 2 years ago
parent
commit
6834e0f037
  1. 1
      app/models/lettings_log.rb
  2. 4
      config/locales/en.yml
  3. 2
      spec/models/sales_log_spec.rb

1
app/models/lettings_log.rb

@ -8,7 +8,6 @@ class LettingsLogValidator < ActiveModel::Validator
include Validations::TenancyValidations include Validations::TenancyValidations
include Validations::DateValidations include Validations::DateValidations
include Validations::LocalAuthorityValidations include Validations::LocalAuthorityValidations
def validate(record) def validate(record)
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
validation_methods.each { |meth| public_send(meth, record) } validation_methods.each { |meth| public_send(meth, record) }

4
config/locales/en.yml

@ -92,9 +92,9 @@ en:
sales_log: sales_log:
attributes: attributes:
beds: 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" 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" 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" greater_than: "Number of bedrooms must be between 1 and 9"
less_than: "Number of bedrooms must be between 1 and 9" less_than: "Number of bedrooms must be between 1 and 9"

2
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 it "fails with appropriate error message", aggregate_failures: true do
invalid_beds_values = { 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 => ["Number of bedrooms must be between 1 and 9"],
2.5 => ["Number of bedrooms must be a whole number between 1 and 9"] 2.5 => ["Number of bedrooms must be a whole number between 1 and 9"]
} }

Loading…
Cancel
Save