diff options
author | Prem Sichanugrist <s@sikachu.com> | 2011-04-10 15:39:01 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-10 18:49:28 +0800 |
commit | f6540211b5b9133c9f93c11655a04d613c237e67 (patch) | |
tree | fda530dfc1f19d834bd1a638f55366be267b76da /activemodel/test | |
parent | 58594be680e8712c9e7352f184e15972d02cd4af (diff) | |
download | rails-f6540211b5b9133c9f93c11655a04d613c237e67.tar.gz rails-f6540211b5b9133c9f93c11655a04d613c237e67.tar.bz2 rails-f6540211b5b9133c9f93c11655a04d613c237e67.zip |
Add :use_include option to allow user to explicitly use `Range#include?` method in Ruby 1.9
In Ruby 1.9 we're currently use `Range#cover?` to fix the performance problem. However, there might be the case that you want to use `Range#include?` instead. This patch will give you that option.
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations/exclusion_validation_test.rb | 10 | ||||
-rw-r--r-- | activemodel/test/cases/validations/inclusion_validation_test.rb | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/exclusion_validation_test.rb b/activemodel/test/cases/validations/exclusion_validation_test.rb index fe0d13ec33..e1807a3f34 100644 --- a/activemodel/test/cases/validations/exclusion_validation_test.rb +++ b/activemodel/test/cases/validations/exclusion_validation_test.rb @@ -63,4 +63,14 @@ class ExclusionValidationTest < ActiveModel::TestCase p.author_name = "sikachu" assert_raise(ArgumentError){ p.valid? } end + + def test_validates_inclusion_with_explicit_include + range = (1..100) + Topic.validates_exclusion_of :title, :in => range, :use_include => true + range.expects(:include?).returns(false) + + t = Topic.new + t.title = 102 + assert t.valid? + end end diff --git a/activemodel/test/cases/validations/inclusion_validation_test.rb b/activemodel/test/cases/validations/inclusion_validation_test.rb index e6adb6d187..d183b42c2b 100644 --- a/activemodel/test/cases/validations/inclusion_validation_test.rb +++ b/activemodel/test/cases/validations/inclusion_validation_test.rb @@ -95,4 +95,13 @@ class InclusionValidationTest < ActiveModel::TestCase p.author_name = "sikachu" assert_raise(ArgumentError){ p.valid? } end + + def test_validates_inclusion_with_explicit_include + range = (1..100) + Topic.validates_inclusion_of :title, :in => range, :use_include => true + + t = Topic.new + t.title = 42 + assert t.valid? + end end |