diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-15 17:52:08 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-15 17:52:08 +0000 |
commit | 51390b8524a644aa8655691fc7bf56e2a174d140 (patch) | |
tree | 5e982bec1cfe5b730930f0996a4330fbc652f0d9 /activerecord/test/validations_test.rb | |
parent | 823554eafef9e8ee8fe2788f6231a3e665c2cbbf (diff) | |
download | rails-51390b8524a644aa8655691fc7bf56e2a174d140.tar.gz rails-51390b8524a644aa8655691fc7bf56e2a174d140.tar.bz2 rails-51390b8524a644aa8655691fc7bf56e2a174d140.zip |
Added validates_associated that enables validation of objects in an unsaved association #398 [Tim Bates]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@418 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/validations_test.rb')
-rwxr-xr-x | activerecord/test/validations_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index ed9d76bd3e..052cf3d6ca 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -389,6 +389,27 @@ class ValidationsTest < Test::Unit::TestCase assert_equal "hoo 5", t.errors["title"] end + 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!")] + assert !t.valid? + assert t.errors.on(:replies) + r.content = "non-empty" + assert t.valid? + end + + def test_validates_associated_one + Reply.validates_associated( :topic ) + Topic.validates_presence_of( :content ) + r = Reply.create("title" => "A reply", "content" => "with content!") + r.topic = Topic.create("title" => "uhohuhoh") + assert !r.valid? + assert r.errors.on(:topic) + r.topic.content = "non-empty" + assert r.valid? + end + def test_throw_away_typing d = Developer.create "name" => "David", "salary" => "100,000" assert !d.valid? |