aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-18 21:44:08 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-18 21:44:08 +0000
commit7581193678f58d363d6d51600c83803e6709a7da (patch)
treeccb9f94e51db160fde9c28784d5137fcc619123d /activerecord
parent2de765e850eaa3f0f43a2c39cc64a4c180c55cfa (diff)
downloadrails-7581193678f58d363d6d51600c83803e6709a7da.tar.gz
rails-7581193678f58d363d6d51600c83803e6709a7da.tar.bz2
rails-7581193678f58d363d6d51600c83803e6709a7da.zip
Added more tests to validates_format_of (closes #3142) [jp.bougie@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3951 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/test/validations_test.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index 4356ea7428..2b913bda22 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -320,6 +320,34 @@ class ValidationsTest < Test::Unit::TestCase
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 ) )