diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-17 19:14:15 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-17 19:14:15 +0000 |
commit | 0e764a55991179dd371df8c0c5b5d5bd7fd2b793 (patch) | |
tree | ed2128ece13c71ec21514d7a3daba98330e6c68b /activerecord/test | |
parent | 8151c4e84d3ecad36357dc97a8d8e6b0399fa8d9 (diff) | |
download | rails-0e764a55991179dd371df8c0c5b5d5bd7fd2b793.tar.gz rails-0e764a55991179dd371df8c0c5b5d5bd7fd2b793.tar.bz2 rails-0e764a55991179dd371df8c0c5b5d5bd7fd2b793.zip |
Addded validation for validate all the associated objects before declaring failure with validates_associated #618 [Tim Bates]. Added that validates_* now accept blocks to perform validations #618 [Tim Bates]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@650 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/validations_test.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 052cf3d6ca..7ac93b43fb 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -392,10 +392,12 @@ class ValidationsTest < Test::Unit::TestCase def test_validates_associated_many Topic.validates_associated( :replies ) t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - t.replies << [r = Reply.create("title" => "A reply"), Reply.create("title" => "Another reply", "content" => "with content!")] + t.replies << [r = Reply.create("title" => "A reply"), r2 = Reply.create("title" => "Another reply")] assert !t.valid? assert t.errors.on(:replies) - r.content = "non-empty" + assert_equal 1, r.errors.count # make sure all associated objects have been validated + assert_equal 1, r2.errors.count + r.content = r2.content = "non-empty" assert t.valid? end @@ -410,6 +412,19 @@ class ValidationsTest < Test::Unit::TestCase assert r.valid? end + def test_validate_block + Topic.validate { |topic| topic.errors.add("title", "will never be valid") } + t = Topic.create("title" => "Title", "content" => "whatever") + assert !t.valid? + assert t.errors.on(:title) + assert_equal "will never be valid", t.errors["title"] + end + + def test_invalid_validator + Topic.validate 3 + assert_raise(ActiveRecord::ActiveRecordError) { t = Topic.create } + end + def test_throw_away_typing d = Developer.create "name" => "David", "salary" => "100,000" assert !d.valid? |