validate_length_of should use custom message if given when using in or within.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1057 state:committed]
This commit is contained in:
miloops
2008-09-16 11:14:23 -03:00
committed by Michael Koziarski
parent 80747e9db1
commit 2b8be761e4
2 changed files with 17 additions and 5 deletions

View File

@@ -958,6 +958,19 @@ class ValidationsTest < ActiveRecord::TestCase
assert_equal "boo 5", t.errors["title"]
end
def test_validates_length_of_custom_errors_for_in
Topic.validates_length_of(:title, :in => 10..20, :message => "hoo {{count}}")
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid?
assert t.errors.on(:title)
assert_equal "hoo 10", t.errors["title"]
t = Topic.create("title" => "uhohuhohuhohuhohuhohuhohuhohuhoh", "content" => "whatever")
assert !t.valid?
assert t.errors.on(:title)
assert_equal "hoo 20", t.errors["title"]
end
def test_validates_length_of_custom_errors_for_maximum_with_too_long
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")