diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 07:03:31 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 07:03:31 -0300 |
commit | 6099b643e6388c23fab40f645544ed4dc478e763 (patch) | |
tree | ce046526f9e718f0f5c66f180d545361227a284b /activemodel/test | |
parent | d625af297a9d2256cdaf5bce15b1e6c757c9d177 (diff) | |
parent | 64a05a928c50a770c6562ac1840772c5d6ad6f53 (diff) | |
download | rails-6099b643e6388c23fab40f645544ed4dc478e763.tar.gz rails-6099b643e6388c23fab40f645544ed4dc478e763.tar.bz2 rails-6099b643e6388c23fab40f645544ed4dc478e763.zip |
Merge pull request #15834 from rmehner/allow_proc_and_symbol_for_only_integer
Allow proc and symbol as values for `only_integer` of `NumericalityValidator`
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations/numericality_validation_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb index e1657407cf..3834d327ea 100644 --- a/activemodel/test/cases/validations/numericality_validation_test.rb +++ b/activemodel/test/cases/validations/numericality_validation_test.rb @@ -50,6 +50,21 @@ class NumericalityValidationTest < ActiveModel::TestCase valid!(NIL + INTEGERS) end + def test_validates_numericality_of_with_integer_only_and_symbol_as_value + Topic.validates_numericality_of :approved, only_integer: :condition_is_true_but_its_not + + invalid!(NIL + BLANK + JUNK) + valid!(FLOATS + INTEGERS + BIGDECIMAL + INFINITY) + end + + def test_validates_numericality_of_with_integer_only_and_proc_as_value + Topic.send(:define_method, :allow_only_integers?, lambda { false }) + Topic.validates_numericality_of :approved, only_integer: Proc.new {|topic| topic.allow_only_integers? } + + invalid!(NIL + BLANK + JUNK) + valid!(FLOATS + INTEGERS + BIGDECIMAL + INFINITY) + end + def test_validates_numericality_with_greater_than Topic.validates_numericality_of :approved, greater_than: 10 |