diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-20 05:23:34 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-20 05:23:34 +0000 |
commit | 70577d0dcab2f1756e05c98565acf525e55dc51f (patch) | |
tree | 96dfe26e412aa81563ef56d3ac07e509488bae05 /activerecord/test/associations_join_model_test.rb | |
parent | e96c58224c31c63b023b7f71e8f3ada440eb2fa8 (diff) | |
download | rails-70577d0dcab2f1756e05c98565acf525e55dc51f.tar.gz rails-70577d0dcab2f1756e05c98565acf525e55dc51f.tar.bz2 rails-70577d0dcab2f1756e05c98565acf525e55dc51f.zip |
Pushing a record onto a has_many :through sets the association's foreign key to the associate's primary key and adds it to the correct association. Closes #5829.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4792 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_join_model_test.rb')
-rw-r--r-- | activerecord/test/associations_join_model_test.rb | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb index 1a0882fcfb..77908d4540 100644 --- a/activerecord/test/associations_join_model_test.rb +++ b/activerecord/test/associations_join_model_test.rb @@ -372,17 +372,30 @@ class AssociationsJoinModelTest < Test::Unit::TestCase def test_create_associate_when_adding_to_has_many_through count = posts(:thinking).tags.count push = Tag.create!(:name => 'pushme') - assert_nothing_raised { posts(:thinking).tags << push } - assert_equal(count + 1, posts(:thinking).tags.size) - assert_equal(count + 1, posts(:thinking).tags(true).size) - - assert_nothing_raised { posts(:thinking).tags.create!(:name => 'foo') } - assert_equal(count + 2, posts(:thinking).tags.size) - assert_equal(count + 2, posts(:thinking).tags(true).size) - - assert_nothing_raised { posts(:thinking).tags.concat(Tag.create!(:name => 'abc'), Tag.create!(:name => 'def')) } - assert_equal(count + 4, posts(:thinking).tags.size) - assert_equal(count + 4, posts(:thinking).tags(true).size) + post_thinking = posts(:thinking) + assert_nothing_raised { post_thinking.tags << push } + assert_nil( wrong = post_thinking.tags.detect { |t| t.class != Tag }, + message = "Expected a Tag in tags collection, got #{wrong.class}.") + assert_nil( wrong = post_thinking.taggings.detect { |t| t.class != Tagging }, + message = "Expected a Tagging in taggings collection, got #{wrong.class}.") + assert_equal(count + 1, post_thinking.tags.size) + assert_equal(count + 1, post_thinking.tags(true).size) + + assert_nothing_raised { post_thinking.tags.create!(:name => 'foo') } + assert_nil( wrong = post_thinking.tags.detect { |t| t.class != Tag }, + message = "Expected a Tag in tags collection, got #{wrong.class}.") + assert_nil( wrong = post_thinking.taggings.detect { |t| t.class != Tagging }, + message = "Expected a Tagging in taggings collection, got #{wrong.class}.") + assert_equal(count + 2, post_thinking.tags.size) + assert_equal(count + 2, post_thinking.tags(true).size) + + assert_nothing_raised { post_thinking.tags.concat(Tag.create!(:name => 'abc'), Tag.create!(:name => 'def')) } + assert_nil( wrong = post_thinking.tags.detect { |t| t.class != Tag }, + message = "Expected a Tag in tags collection, got #{wrong.class}.") + assert_nil( wrong = post_thinking.taggings.detect { |t| t.class != Tagging }, + message = "Expected a Tagging in taggings collection, got #{wrong.class}.") + assert_equal(count + 4, post_thinking.tags.size) + assert_equal(count + 4, post_thinking.tags(true).size) end def test_adding_junk_to_has_many_through_should_raise_type_mismatch |