Add :tokenizer option to validates_length_of. [#507 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
David Lowenfels
2008-06-28 17:41:12 -07:00
committed by Pratik Naik
parent 570f5aad66
commit 87fbcaa622
3 changed files with 27 additions and 6 deletions

View File

@@ -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 }