diff options
author | Robert Eshleman <c.robert.eshleman@gmail.com> | 2015-12-22 12:23:33 -0500 |
---|---|---|
committer | Robert Eshleman <c.robert.eshleman@gmail.com> | 2015-12-22 14:27:25 -0500 |
commit | b96fdd234de9484b6c0999d04193de31d925dc3a (patch) | |
tree | 6f88fe55b352ffafa829b31fd6aa282c395461b8 /activemodel | |
parent | 90815ce412b6341c7372e1e514d9078869b4b933 (diff) | |
download | rails-b96fdd234de9484b6c0999d04193de31d925dc3a.tar.gz rails-b96fdd234de9484b6c0999d04193de31d925dc3a.tar.bz2 rails-b96fdd234de9484b6c0999d04193de31d925dc3a.zip |
Failing Tests for Validating String Numbericality
Covers Regressions:
* <=
* <
* ==
* >
* >=
* other than
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/test/cases/validations/numericality_validation_test.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb index 04ec74bad3..74a048537d 100644 --- a/activemodel/test/cases/validations/numericality_validation_test.rb +++ b/activemodel/test/cases/validations/numericality_validation_test.rb @@ -79,6 +79,13 @@ class NumericalityValidationTest < ActiveModel::TestCase 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 end + def test_validates_numericality_with_greater_than_using_string_value + Topic.validates_numericality_of :approved, greater_than: 10 + + invalid!(['-10', '9', '9.9', '10'], 'must be greater than 10') + valid!(['10.1', '11']) + end + def test_validates_numericality_with_greater_than_or_equal Topic.validates_numericality_of :approved, greater_than_or_equal_to: 10 @@ -93,6 +100,13 @@ class NumericalityValidationTest < ActiveModel::TestCase valid!([97.18, 98, BigDecimal.new('97.19')]) end + def test_validates_numericality_with_greater_than_or_equal_using_string_value + Topic.validates_numericality_of :approved, greater_than_or_equal_to: 10 + + invalid!(['-10', '9', '9.9'], 'must be greater than or equal to 10') + valid!(['10', '10.1', '11']) + end + def test_validates_numericality_with_equal_to Topic.validates_numericality_of :approved, equal_to: 10 @@ -107,6 +121,13 @@ class NumericalityValidationTest < ActiveModel::TestCase valid!([BigDecimal.new('97.18')]) end + def test_validates_numericality_with_equal_to_using_string_value + Topic.validates_numericality_of :approved, equal_to: 10 + + invalid!(['-10', '9', '9.9', '10.1', '11'], 'must be equal to 10') + valid!(['10']) + end + def test_validates_numericality_with_less_than Topic.validates_numericality_of :approved, less_than: 10 @@ -121,6 +142,13 @@ class NumericalityValidationTest < ActiveModel::TestCase valid!([-97.0, 97.0, -97, 97, BigDecimal.new('-97'), BigDecimal.new('97')]) end + def test_validates_numericality_with_less_than_using_string_value + Topic.validates_numericality_of :approved, less_than: 10 + + invalid!(['10', '10.1', '11'], 'must be less than 10') + valid!(['-10', '9', '9.9']) + end + def test_validates_numericality_with_less_than_or_equal_to Topic.validates_numericality_of :approved, less_than_or_equal_to: 10 @@ -135,6 +163,13 @@ class NumericalityValidationTest < ActiveModel::TestCase valid!([-97.18, BigDecimal.new('-97.18'), BigDecimal.new('97.18')]) end + def test_validates_numericality_with_less_than_or_equal_using_string_value + Topic.validates_numericality_of :approved, less_than_or_equal_to: 10 + + invalid!(['10.1', '11'], 'must be less than or equal to 10') + valid!(['-10', '9', '9.9', '10']) + end + def test_validates_numericality_with_odd Topic.validates_numericality_of :approved, odd: true @@ -163,6 +198,13 @@ class NumericalityValidationTest < ActiveModel::TestCase valid!([-1, 42]) end + def test_validates_numericality_with_other_than_using_string_value + Topic.validates_numericality_of :approved, other_than: 0 + + invalid!(['0', '0.0']) + valid!(['-1', '1.1', '42']) + end + def test_validates_numericality_with_proc Topic.send(:define_method, :min_approved, lambda { 5 }) Topic.validates_numericality_of :approved, greater_than_or_equal_to: Proc.new(&:min_approved) |