From 5abf662959aa2be98f4b5ce07c4051f530125e19 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sat, 19 Nov 2016 20:57:58 -0500 Subject: 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. --- activemodel/test/cases/validations/numericality_validation_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activemodel/test') 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 -- cgit v1.2.3