From 8ed83b9b1efbe94728f9b504ff58f06cc41f9fed Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 20 Nov 2007 22:01:04 +0000 Subject: 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 --- activerecord/test/validations_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'activerecord/test/validations_test.rb') 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 -- cgit v1.2.3