Closed paulogrupp closed 1 year ago
I am not sure Ruby can handle a ,
as a delimiter in a Float itself. I think it can only handle it on the output via the i18n gem.
I would be happy to accept a PR that makes it work consistently for all locales.
got this issue a few days ago
class Product < ApplicationRecord
monetize :price_cents, numericality: { greater_than_or_equal_to: 0, less_than: 5000 }
end
I18n.locale = :id
product = Product.create!(name: 'test', price: '4999,99') #=> saved without error
product.reload.valid? #=> false
product.update!(price: '1000') #=> saved without error
product.reload.valid? #=> false
product.errors.details #=> {:price=>[{:error=>:less_than, :value=>10000, :count=>5000}]}
my solution is to override MoneyValidator#normalize to do nothing when details.raw_value already Numeric :
module MoneyRails
module ActiveModel
class MoneyValidator < ::ActiveModel::Validations::NumericalityValidator
private
def normalize(details)
return details.raw_value if details.raw_value.is_a?(Numeric)
super
end
end
end
end
should we make this a change?
Hi, I'm having a problem where using '.' as a delimiter fails the "less_than" validation when doing the following in the tests at spec/active_record/monetizable_spec.rb:286:
I noticed that using an empty string as a delimiter makes the test pass. Removing the delimiter key from spec/dummy/config/locales/it.yml keeps the test failing Is this the expected behavior?
I created this PR with the failing test using the behvior I mentioned: https://github.com/RubyMoney/money-rails/pull/633