diff options
author | David Lowenfels <david@internautdesign.com> | 2008-06-28 17:41:12 -0700 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-04 01:31:39 +0100 |
commit | 87fbcaa6229e9073095fb8d77c7a536c9466fbce (patch) | |
tree | 93ad434fdfc2be549da65ad4d167b5d9c4859802 /activerecord/test | |
parent | 570f5aad663fa3113772cf56306862829babc739 (diff) | |
download | rails-87fbcaa6229e9073095fb8d77c7a536c9466fbce.tar.gz rails-87fbcaa6229e9073095fb8d77c7a536c9466fbce.tar.bz2 rails-87fbcaa6229e9073095fb8d77c7a536c9466fbce.zip |
Add :tokenizer option to validates_length_of. [#507 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/cases/validations_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 7b71647d25..60566cd064 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -1059,6 +1059,18 @@ class ValidationsTest < ActiveRecord::TestCase end end + def test_validates_length_of_with_block + Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least %d words.", + :tokenizer => lambda {|str| str.scan(/\w+/) } + t = Topic.create!(:content => "this content should be long enough") + assert t.valid? + + t.content = "not long enough" + assert !t.valid? + assert t.errors.on(:content) + assert_equal "Your essay must be at least 5 words.", t.errors[:content] + end + def test_validates_size_of_association_utf8 with_kcode('UTF8') do assert_nothing_raised { Topic.validates_size_of :replies, :minimum => 1 } |