diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-07-16 17:45:28 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-07-16 17:45:28 -0500 |
commit | 73ade4fe100ae7f48c5f95dcdf7067f6a0cd51fa (patch) | |
tree | 2f1601292978a844226e16f3cef428ed760b9eb5 /activerecord/test/cases/validations_test.rb | |
parent | 8fe01de2e8753d045408ecde3178ab4e9192bf9a (diff) | |
parent | 90c930f45c5c6766306929241462ffff8f67b86e (diff) | |
download | rails-73ade4fe100ae7f48c5f95dcdf7067f6a0cd51fa.tar.gz rails-73ade4fe100ae7f48c5f95dcdf7067f6a0cd51fa.tar.bz2 rails-73ade4fe100ae7f48c5f95dcdf7067f6a0cd51fa.zip |
Resolved conflict
Diffstat (limited to 'activerecord/test/cases/validations_test.rb')
-rwxr-xr-x | activerecord/test/cases/validations_test.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 7b71647d25..0742e2c632 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -1059,6 +1059,18 @@ class ValidationsTest < ActiveRecord::TestCase end end + def test_validates_length_of_with_block + Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least %d words.", + :tokenizer => lambda {|str| str.scan(/\w+/) } + t = Topic.create!(:content => "this content should be long enough") + assert t.valid? + + t.content = "not long enough" + assert !t.valid? + assert t.errors.on(:content) + assert_equal "Your essay must be at least 5 words.", t.errors[:content] + end + def test_validates_size_of_association_utf8 with_kcode('UTF8') do assert_nothing_raised { Topic.validates_size_of :replies, :minimum => 1 } @@ -1379,6 +1391,7 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase INTEGERS = [0, 10, -10] + INTEGER_STRINGS BIGDECIMAL = BIGDECIMAL_STRINGS.collect! { |bd| BigDecimal.new(bd) } JUNK = ["not a number", "42 not a number", "0xdeadbeef", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"] + INFINITY = [1.0/0.0] def setup Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new) @@ -1390,27 +1403,27 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase Topic.validates_numericality_of :approved invalid!(NIL + BLANK + JUNK) - valid!(FLOATS + INTEGERS + BIGDECIMAL) + valid!(FLOATS + INTEGERS + BIGDECIMAL + INFINITY) end def test_validates_numericality_of_with_nil_allowed Topic.validates_numericality_of :approved, :allow_nil => true invalid!(BLANK + JUNK) - valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL) + valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY) end def test_validates_numericality_of_with_integer_only Topic.validates_numericality_of :approved, :only_integer => true - invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL) + invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY) valid!(INTEGERS) end def test_validates_numericality_of_with_integer_only_and_nil_allowed Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true - invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL) + invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY) valid!(NIL + INTEGERS) end @@ -1431,7 +1444,7 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase def test_validates_numericality_with_equal_to Topic.validates_numericality_of :approved, :equal_to => 10 - invalid!([-10, 11], 'must be equal to 10') + invalid!([-10, 11] + INFINITY, 'must be equal to 10') valid!([10]) end |