From dfd43d577eaaf4b9c157f6379045d1e2fb68d1ee Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 22 Feb 2005 13:54:26 +0000 Subject: Fixed that when using validation macros with a custom message, if you happened to use single quotes in the message string you would get a parsing error #657 [tonka] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@740 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/validations_test.rb | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index f03c7dfcae..9d7b8b987a 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -522,4 +522,86 @@ class ValidationsTest < Test::Unit::TestCase assert_equal 100, d.salary assert_equal "100,000", d.salary_before_type_cast end + + def test_validates_acceptance_of_with_custom_error_using_quotes + Developer.validates_acceptance_of :salary, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.salary = "0" + assert !d.valid? + assert_equal d.errors.on(:salary).first, "This string contains 'single' and \"double\" quotes" + end + + def test_validates_confirmation_of_with_custom_error_using_quotes + Developer.validates_confirmation_of :name, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "John" + d.name_confirmation = "Johnny" + assert !d.valid? + assert_equal d.errors.on(:name), "This string contains 'single' and \"double\" quotes" + end + + def test_validates_format_of_with_custom_error_using_quotes + Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "John 32" + assert !d.valid? + assert_equal d.errors.on(:name), "This string contains 'single' and \"double\" quotes" + end + + def test_validates_inclusion_of_with_custom_error_using_quotes + Developer.validates_inclusion_of :salary, :in => 1000..80000, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.salary = "90,000" + assert !d.valid? + assert_equal d.errors.on(:salary).first, "This string contains 'single' and \"double\" quotes" + end + + def test_validates_length_of_with_custom_too_long_using_quotes + Developer.validates_length_of :name, :maximum => 4, :too_long=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "Jeffrey" + assert !d.valid? + assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes" + end + + def test_validates_length_of_with_custom_too_short_using_quotes + Developer.validates_length_of :name, :minimum => 4, :too_short=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "Joe" + assert !d.valid? + assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes" + end + + def test_validates_length_of_with_custom_message_using_quotes + Developer.validates_length_of :name, :minimum => 4, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "Joe" + assert !d.valid? + assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes" + end + + def test_validates_presence_of_with_custom_message_using_quotes + Developer.validates_presence_of :non_existent, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "Joe" + assert !d.valid? + assert_equal d.errors.on(:non_existent), "This string contains 'single' and \"double\" quotes" + end + + def test_validates_uniqueness_of_with_custom_message_using_quotes + Developer.validates_uniqueness_of :name, :message=> "This string contains 'single' and \"double\" quotes" + d = Developer.new + d.name = "David" + assert !d.valid? + assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes" + end + + def test_validates_associated_with_custom_message_using_quotes + Reply.validates_associated :topic, :message=> "This string contains 'single' and \"double\" quotes" + Topic.validates_presence_of :content + r = Reply.create("title" => "A reply", "content" => "with content!") + r.topic = Topic.create("title" => "uhohuhoh") + assert !r.valid? + assert_equal r.errors.on(:topic).first, "This string contains 'single' and \"double\" quotes" + end end -- cgit v1.2.3