Validations are skipped if attribute is a Money object #79

Closed
deepak opened this Issue Feb 4, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@deepak
Contributor

deepak commented Feb 4, 2013

Validations are skipped if attribute is a Money object
validations only work on primitives ie. Integer and String

https://github.com/RubyMoney/money-rails/blob/master/lib/money-rails/active_model/validator.rb#L17

Is the attribute converted from a human readable string to Money Object here ?

Right now am writing a custom validation that the object has to be a money object
and that the subunit is non-negative ?

@alup

This comment has been minimized.

Show comment Hide comment
@alup

alup Feb 26, 2013

Owner

The current approach denotes that if the raw value is already a Money object it should pass the validation. That's why we issue a return for this case. If the raw value is a number or string, normalize it and pass it to numericality validator.

Conversion of String to Money object should not be done here. Here, we just check the validity of the parts needed to construct a new money object.

Moreover, why should the subunit be a non-negative? Negative money values must be supported, too.

Owner

alup commented Feb 26, 2013

The current approach denotes that if the raw value is already a Money object it should pass the validation. That's why we issue a return for this case. If the raw value is a number or string, normalize it and pass it to numericality validator.

Conversion of String to Money object should not be done here. Here, we just check the validity of the parts needed to construct a new money object.

Moreover, why should the subunit be a non-negative? Negative money values must be supported, too.

@deepak

This comment has been minimized.

Show comment Hide comment
@deepak

deepak Feb 27, 2013

Contributor

I do not know what i was thinking at that time. my bad
your explanation makes perfect sense :-)

Moreover, why should the subunit be a non-negative? Negative money values must be supported, too.
for my app, i have a non-negative constraint. sorry. unrelated to this bug

Contributor

deepak commented Feb 27, 2013

I do not know what i was thinking at that time. my bad
your explanation makes perfect sense :-)

Moreover, why should the subunit be a non-negative? Negative money values must be supported, too.
for my app, i have a non-negative constraint. sorry. unrelated to this bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment