aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-22 13:54:26 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-22 13:54:26 +0000
commitdfd43d577eaaf4b9c157f6379045d1e2fb68d1ee (patch)
tree76078e64131c52bb7b87975da973f689daa8b06b /activerecord/test
parent148f6d8fb6ea028b2738a0553f058e903268a0b8 (diff)
downloadrails-dfd43d577eaaf4b9c157f6379045d1e2fb68d1ee.tar.gz
rails-dfd43d577eaaf4b9c157f6379045d1e2fb68d1ee.tar.bz2
rails-dfd43d577eaaf4b9c157f6379045d1e2fb68d1ee.zip
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
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/validations_test.rb82
1 files changed, 82 insertions, 0 deletions
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