aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2016-11-19 20:57:58 -0500
committerKir Shatrov <shatrov@me.com>2016-11-19 21:02:29 -0500
commit5abf662959aa2be98f4b5ce07c4051f530125e19 (patch)
tree375bbd6e54c4dce6033ca4a5187f51961d381c21 /activemodel/test
parent3a558aa2bc8ce3834ee79ff3346bcf5d7debbbd0 (diff)
downloadrails-5abf662959aa2be98f4b5ce07c4051f530125e19.tar.gz
rails-5abf662959aa2be98f4b5ce07c4051f530125e19.tar.bz2
rails-5abf662959aa2be98f4b5ce07c4051f530125e19.zip
Do not rely on Ruby implementation in AM test
Now a few tests in ActiveModel rely on Ruby implementation and the fact that in MRI `97.18` as a float is greater than `97.18` as a BigDecimal. This is only relevant for MRI. On JRuby, comparing float to BigDecimal would be conversion of them to the same type and they will be equal. I'd like the ActiveModel test suite to be Ruby implementation-agnostic. Here we test ActiveModel, not the Ruby internals. This PR fixes a couple more JRuby tests.
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/validations/numericality_validation_test.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb
index 36efa6caf5..a1be2de578 100644
--- a/activemodel/test/cases/validations/numericality_validation_test.rb
+++ b/activemodel/test/cases/validations/numericality_validation_test.rb
@@ -82,7 +82,7 @@ class NumericalityValidationTest < ActiveModel::TestCase
Topic.validates_numericality_of :approved, greater_than: BigDecimal.new("97.18")
invalid!([-97.18, BigDecimal.new("97.18"), BigDecimal("-97.18")], "must be greater than 97.18")
- valid!([97.18, 98, BigDecimal.new("98")]) # Notice the 97.18 as a float is greater than 97.18 as a BigDecimal due to floating point precision
+ valid!([97.19, 98, BigDecimal.new("98"), BigDecimal.new("97.19")])
end
def test_validates_numericality_with_greater_than_using_string_value
@@ -123,7 +123,7 @@ class NumericalityValidationTest < ActiveModel::TestCase
def test_validates_numericality_with_equal_to_using_differing_numeric_types
Topic.validates_numericality_of :approved, equal_to: BigDecimal.new("97.18")
- invalid!([-97.18, 97.18], "must be equal to 97.18")
+ invalid!([-97.18], "must be equal to 97.18")
valid!([BigDecimal.new("97.18")])
end
@@ -165,7 +165,7 @@ class NumericalityValidationTest < ActiveModel::TestCase
def test_validates_numericality_with_less_than_or_equal_to_using_differing_numeric_types
Topic.validates_numericality_of :approved, less_than_or_equal_to: BigDecimal.new("97.18")
- invalid!([97.18, 98], "must be less than or equal to 97.18")
+ invalid!([97.19, 98], "must be less than or equal to 97.18")
valid!([-97.18, BigDecimal.new("-97.18"), BigDecimal.new("97.18")])
end