From 2b8be761e476c103e94f8567c3880ea7363dfec0 Mon Sep 17 00:00:00 2001 From: miloops Date: Tue, 16 Sep 2008 11:14:23 -0300 Subject: validate_length_of should use custom message if given when using in or within. Signed-off-by: Michael Koziarski [#1057 state:committed] --- activerecord/test/cases/validations_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 380d8ac260..cbb184131f 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -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") -- cgit v1.2.3