diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-20 22:01:04 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-20 22:01:04 +0000 |
commit | 8ed83b9b1efbe94728f9b504ff58f06cc41f9fed (patch) | |
tree | 07ff26010cf3a2d4617065e592e72c42307424cb /activerecord/test | |
parent | 609a03fd2ad434ea4e5e5418336b3e50dcce3557 (diff) | |
download | rails-8ed83b9b1efbe94728f9b504ff58f06cc41f9fed.tar.gz rails-8ed83b9b1efbe94728f9b504ff58f06cc41f9fed.tar.bz2 rails-8ed83b9b1efbe94728f9b504ff58f06cc41f9fed.zip |
validates_inclusion_of and validates_exclusion_of allow formatted :message strings. Closes #8132 [devrieda, Mike Naberezny]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8172 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/validations_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 2f67e9a36d..03d5da4990 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -547,6 +547,17 @@ class ValidationsTest < Test::Unit::TestCase assert Topic.create("title" => "abcde").valid? end + def test_validates_inclusion_of_with_formatted_message + Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => "option %s is not in the list" ) + + assert Topic.create("title" => "a", "content" => "abc").valid? + + t = Topic.create("title" => "uhoh", "content" => "abc") + assert !t.valid? + assert t.errors.on(:title) + assert_equal "option uhoh is not in the list", t.errors["title"] + end + def test_numericality_with_allow_nil_and_getter_method Developer.validates_numericality_of( :salary, :allow_nil => true) developer = Developer.new("name" => "michael", "salary" => nil) @@ -561,6 +572,17 @@ class ValidationsTest < Test::Unit::TestCase assert !Topic.create("title" => "monkey", "content" => "abc").valid? end + def test_validates_exclusion_of_with_formatted_message + Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => "option %s is restricted" ) + + assert Topic.create("title" => "something", "content" => "abc") + + t = Topic.create("title" => "monkey") + assert !t.valid? + assert t.errors.on(:title) + assert_equal "option monkey is restricted", t.errors["title"] + end + def test_validates_length_of_using_minimum Topic.validates_length_of :title, :minimum => 5 |