mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Add :tokenizer option to validates_length_of. [#507 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
committed by
Pratik Naik
parent
570f5aad66
commit
87fbcaa622
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user