diff options
author | Roque Pinel <repinel@gmail.com> | 2015-07-11 14:40:14 -0400 |
---|---|---|
committer | Roque Pinel <repinel@gmail.com> | 2015-07-11 14:40:14 -0400 |
commit | 7500daec69499e4f2da2fc06cd816c754cf59504 (patch) | |
tree | b4d0dcd9a5174c457994c5d69382ea0666731b47 /activerecord/test/models/auto_id.rb | |
parent | 14354f195540954a1dfc5c954d06389c9f71e986 (diff) | |
download | rails-7500daec69499e4f2da2fc06cd816c754cf59504.tar.gz rails-7500daec69499e4f2da2fc06cd816c754cf59504.tar.bz2 rails-7500daec69499e4f2da2fc06cd816c754cf59504.zip |
Conditionally convert the raw_value received by the numeric validator.
This fixes the issue where you may be comparing (using a numeric
validator such as `greater_than`) numbers of a specific Numeric type
such as `BigDecimal`.
Previous behavior took the numeric value to be validated and
unconditionally converted to Float. For example, due to floating point
precision, this can cause issues when comparing a Float to a BigDecimal.
Consider the following:
```
validates :sub_total, numericality: {
greater_than: BigDecimal('97.18')
}
```
If the `:sub_total` value BigDecimal.new('97.18') was validated against
the above, the following would be valid since `:sub_total` is converted
to a Float regardless of its original type. The result therefore becomes
Kernel.Float(97.18) > BigDecimal.new('97.18')
The above illustrated behavior is corrected with this patch by
conditionally converting the value to validate to float.
Use the post-type-cast version of the attribute to validate numericality
[Roque Pinel & Trevor Wistaff]
Diffstat (limited to 'activerecord/test/models/auto_id.rb')
0 files changed, 0 insertions, 0 deletions