Browse files

Added more tests to validates_format_of (closes #3142) [jp.bougie@gma…

…il.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3951 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2de765e commit 7581193678f58d363d6d51600c83803e6709a7da @dhh dhh committed Mar 18, 2006
Showing with 28 additions and 0 deletions.
  1. +28 −0 activerecord/test/validations_test.rb
View
28 activerecord/test/validations_test.rb
@@ -320,6 +320,34 @@ def test_validate_format
assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) }
end
+
+ # testing ticket #3142
+ def test_validate_format_numeric
+ Topic.validates_format_of(:title, :content, :with => /^[1-9][0-9]*$/, :message => "is bad data")
+
+ t = Topic.create("title" => "72x", "content" => "6789")
+ assert !t.valid?, "Shouldn't be valid"
+ assert !t.save, "Shouldn't save because it's invalid"
+ assert_equal "is bad data", t.errors.on(:title)
+ assert_nil t.errors.on(:content)
+
+ t.title = "-11"
+ assert !t.valid?, "Shouldn't be valid"
+
+ t.title = "03"
+ assert !t.valid?, "Shouldn't be valid"
+
+ t.title = "z44"
+ assert !t.valid?, "Shouldn't be valid"
+
+ t.title = "5v7"
+ assert !t.valid?, "Shouldn't be valid"
+
+ t.title = "1"
+
+ assert t.save
+ assert_nil t.errors.on(:title)
+ end
def test_validates_inclusion_of
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ) )

0 comments on commit 7581193

Please sign in to comment.