Browse Source

remove reference to currency in validation message that concerns step only and doesn't check whether firled is currency related

validations-copy
Arthur Campbell 2 years ago
parent
commit
b5b62fd616
  1. 2
      app/models/validations/shared_validations.rb
  2. 2
      config/locales/en.yml
  3. 2
      spec/models/validations/shared_validations_spec.rb

2
app/models/validations/shared_validations.rb

@ -44,7 +44,7 @@ module Validations::SharedValidations
incorrect_accuracy = (value.to_d * 100) % (question.step * 100) != 0 incorrect_accuracy = (value.to_d * 100) % (question.step * 100) != 0
if question.step < 1 && incorrect_accuracy if question.step < 1 && incorrect_accuracy
record.errors.add question.id.to_sym, I18n.t("validations.numeric.nearest_penny", field:) record.errors.add question.id.to_sym, I18n.t("validations.numeric.nearest_hundredth", field:)
elsif incorrect_accuracy || value.to_d != value.to_i # if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value elsif incorrect_accuracy || value.to_d != value.to_i # if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value
field = question.check_answer_label || question.id field = question.check_answer_label || question.id
case question.step case question.step

2
config/locales/en.yml

@ -141,7 +141,7 @@ en:
above_min: "%{field} must be at least %{min}" above_min: "%{field} must be at least %{min}"
whole_number: "%{field} must be a whole number" whole_number: "%{field} must be a whole number"
nearest_ten: "%{field} must be given to the nearest ten" nearest_ten: "%{field} must be given to the nearest ten"
nearest_penny: "%{field} must be given to the nearest penny" nearest_hundredth: "%{field} must be given to the nearest hundredth"
normal_format: "Enter a number" normal_format: "Enter a number"
date: date:

2
spec/models/validations/shared_validations_spec.rb

@ -159,7 +159,7 @@ RSpec.describe Validations::SharedValidations do
it "adds an error if input has more than 2 decimal places" do it "adds an error if input has more than 2 decimal places" do
sales_log.mscharge = 30.7418 sales_log.mscharge = 30.7418
shared_validator.validate_numeric_step(sales_log) shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors[:mscharge]).to include I18n.t("validations.numeric.nearest_penny", field: "Monthly leasehold charges") expect(sales_log.errors[:mscharge]).to include I18n.t("validations.numeric.nearest_hundredth", field: "Monthly leasehold charges")
end end
it "does not add an error if the user attempts to input a number in exponent format" do it "does not add an error if the user attempts to input a number in exponent format" do

Loading…
Cancel
Save