mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Exercise tests on decimal attribute values
And avoid the magic `to_d(4)`.
This commit is contained in:
parent
63835772bb
commit
291a3d2ef2
2 changed files with 12 additions and 8 deletions
|
@ -109,13 +109,17 @@ class NumericalityValidationTest < ActiveRecord::TestCase
|
|||
:virtual_decimal_number, less_than_or_equal_to: 99.99
|
||||
)
|
||||
|
||||
subject = model_class.new(virtual_decimal_number: 99.994)
|
||||
assert_equal 99.99.to_d(4), subject.virtual_decimal_number
|
||||
assert_predicate subject, :valid?
|
||||
["99.994", 99.994, BigDecimal("99.994")].each do |raw_value|
|
||||
subject = model_class.new(virtual_decimal_number: raw_value)
|
||||
assert_equal BigDecimal("99.99"), subject.virtual_decimal_number
|
||||
assert_predicate subject, :valid?
|
||||
end
|
||||
|
||||
subject = model_class.new(virtual_decimal_number: 99.999)
|
||||
assert_equal 100.00.to_d(4), subject.virtual_decimal_number
|
||||
assert_not_predicate subject, :valid?
|
||||
["99.999", 99.999, BigDecimal("99.999")].each do |raw_value|
|
||||
subject = model_class.new(virtual_decimal_number: raw_value)
|
||||
assert_equal BigDecimal("100.00"), subject.virtual_decimal_number
|
||||
assert_not_predicate subject, :valid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_aliased_attribute
|
||||
|
|
|
@ -189,13 +189,13 @@ class ValidationsTest < ActiveRecord::TestCase
|
|||
|
||||
["97.179", 97.179, BigDecimal("97.179")].each do |raw_value|
|
||||
subject = klass.new(wibble: raw_value)
|
||||
assert_equal 97.18.to_d(4), subject.wibble
|
||||
assert_equal BigDecimal("97.18"), subject.wibble
|
||||
assert_predicate subject, :valid?
|
||||
end
|
||||
|
||||
["97.174", 97.174, BigDecimal("97.174")].each do |raw_value|
|
||||
subject = klass.new(wibble: raw_value)
|
||||
assert_equal 97.17.to_d(4), subject.wibble
|
||||
assert_equal BigDecimal("97.17"), subject.wibble
|
||||
assert_not_predicate subject, :valid?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue