aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/join_model_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-04-06 00:27:12 +0000
committerPratik Naik <pratiknaik@gmail.com>2008-04-06 00:27:12 +0000
commitf6b12c11cd3a6df8525dd16ec093ec473813489e (patch)
tree121421e0e9199655419cb2f4a29fa744c32bbb26 /activerecord/test/cases/associations/join_model_test.rb
parent15d88885eedbac1193361a9eea957a7f49e39c9e (diff)
downloadrails-f6b12c11cd3a6df8525dd16ec093ec473813489e.tar.gz
rails-f6b12c11cd3a6df8525dd16ec093ec473813489e.tar.bz2
rails-f6b12c11cd3a6df8525dd16ec093ec473813489e.zip
Refactor HasManyThroughAssociation to inherit from HasManyAssociation. Association callbacks and <association>_ids= now work with hm:t. Closes #11516 [rubyruy]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9230 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/cases/associations/join_model_test.rb')
-rw-r--r--activerecord/test/cases/associations/join_model_test.rb32
1 files changed, 27 insertions, 5 deletions
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb
index 2b929d4480..952ea63706 100644
--- a/activerecord/test/cases/associations/join_model_test.rb
+++ b/activerecord/test/cases/associations/join_model_test.rb
@@ -443,11 +443,33 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
assert_nil posts(:thinking).tags.find_by_name("General").attributes["tag_id"]
end
- def test_raise_error_when_adding_new_record_to_has_many_through
- assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags << tags(:general).clone }
- assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).clone.tags << tags(:general) }
- assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags.build }
- assert_raise(ActiveRecord::HasManyThroughCantAssociateNewRecords) { posts(:thinking).tags.new }
+ def test_associating_unsaved_records_with_has_many_through
+ saved_post = posts(:thinking)
+ new_tag = Tag.new(:name => "new")
+
+ saved_post.tags << new_tag
+ assert !new_tag.new_record? #consistent with habtm!
+ assert !saved_post.new_record?
+ assert saved_post.tags.include?(new_tag)
+
+ assert !new_tag.new_record?
+ assert saved_post.reload.tags(true).include?(new_tag)
+
+
+ new_post = Post.new(:title => "Association replacmenet works!", :body => "You best believe it.")
+ saved_tag = tags(:general)
+
+ new_post.tags << saved_tag
+ assert new_post.new_record?
+ assert !saved_tag.new_record?
+ assert new_post.tags.include?(saved_tag)
+
+ new_post.save!
+ assert !new_post.new_record?
+ assert new_post.reload.tags(true).include?(saved_tag)
+
+ assert posts(:thinking).tags.build.new_record?
+ assert posts(:thinking).tags.new.new_record?
end
def test_create_associate_when_adding_to_has_many_through