diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-14 23:56:47 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-14 23:56:47 +0000 |
commit | b55f59e811564604a86dcaba23e3d27c32812f17 (patch) | |
tree | a9e7842b89f066ffdaa2829a4825000bc3994264 /activerecord/test/validations_test.rb | |
parent | bfa6bfc24a0034ae599861a6e8655df024973eed (diff) | |
download | rails-b55f59e811564604a86dcaba23e3d27c32812f17.tar.gz rails-b55f59e811564604a86dcaba23e3d27c32812f17.tar.bz2 rails-b55f59e811564604a86dcaba23e3d27c32812f17.zip |
Added optionally allow for nil or empty strings with validates_numericality_of #801 [Sebastian Kanthak] Fixed problem with using slashes in validates_format_of regular expressions #801 [Sebastian Kanthak]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@910 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/validations_test.rb')
-rwxr-xr-x | activerecord/test/validations_test.rb | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 913c72ea3c..30de66c94b 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -606,40 +606,40 @@ class ValidationsTest < Test::Unit::TestCase end def test_validates_numericality_of_with_string - Topic.validates_numericality_of( :replies_count ) + Topic.validates_numericality_of( :approved ) ["not a number","42 not a number","0xdeadbeef","00-1","-+019.0","12.12.13.12",nil].each do |v| - t = Topic.create("title" => "numeric test", "content" => "whatever", "replies_count" => "not a number") + t = Topic.create("title" => "numeric test", "content" => "whatever", "approved" => "not a number") assert !t.valid?, "#{v} not rejected as a number" - assert t.errors.on(:replies_count) + assert t.errors.on(:approved) end end def test_validates_numericality_of - Topic.validates_numericality_of( :replies_count ) - ["10", "10.0", "10.5", "-10.5", "-0.0001","0090","-090","-090.1"].each do |v| - t = Topic.create("title" => "numeric test", "content" => "whatever", "replies_count" => v) + Topic.validates_numericality_of( :approved, :allow_nil => true ) + ["10", "10.0", "10.5", "-10.5", "-0.0001","0090","-090","-090.1",nil,""].each do |v| + t = Topic.create("title" => "numeric test", "content" => "whatever", "approved" => v) assert t.valid?, "#{v} not recognized as a number" - # we cannot check this as replies_count is actually an integer field - #assert_in_delta v.to_f, t.replies_count, 0.0000001 + # we cannot check this as approved is actually an integer field + #assert_in_delta v.to_f, t.approved, 0.0000001 end end def test_validates_numericality_of_int_with_string - Topic.validates_numericality_of( :replies_count, :only_integer => true ) + Topic.validates_numericality_of( :approved, :only_integer => true ) ["not a number","42 not a number","0xdeadbeef","0-1","--3","+-3","+3-1",nil].each do |v| - t = Topic.create("title" => "numeric test", "content" => "whatever", "replies_count" => v) + t = Topic.create("title" => "numeric test", "content" => "whatever", "approved" => v) assert !t.valid?, "#{v} not rejected as integer" - assert t.errors.on(:replies_count) + assert t.errors.on(:approved) end end def test_validates_numericality_of_int - Topic.validates_numericality_of( :replies_count, :only_integer => true ) - ["42", "+42", "-42", "042", "0042", "-042", 42].each do |v| - t = Topic.create("title" => "numeric test", "content" => "whatever", "replies_count" => v) + Topic.validates_numericality_of( :approved, :only_integer => true, :allow_nil => true ) + ["42", "+42", "-42", "042", "0042", "-042", 42, nil,""].each do |v| + t = Topic.create("title" => "numeric test", "content" => "whatever", "approved" => v) assert t.valid?, "#{v} not recognized as integer" - assert_equal v.to_i, t.replies_count + assert_equal((v.nil? or v == "")? nil : v.to_i, t.approved) end end - + end |