diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-11-03 13:12:04 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-11-03 13:13:13 +0000 |
commit | 19b2a5f2bdd5bf6404bfc3e574b7477038e9b2bf (patch) | |
tree | e56662ad1827608c92a2e0088c8bca3cfab2ff38 /activerecord/test | |
parent | 71bc921ec8ac89840077bb54752282a3d89429f6 (diff) | |
download | rails-19b2a5f2bdd5bf6404bfc3e574b7477038e9b2bf.tar.gz rails-19b2a5f2bdd5bf6404bfc3e574b7477038e9b2bf.tar.bz2 rails-19b2a5f2bdd5bf6404bfc3e574b7477038e9b2bf.zip |
Remove all revelant through records.
If a record is removed from a has_many :through, all of the join records
relating to that record should also be removed from the through
association's target.
(Previously the records were removed in the database, but only one was
removed from the in-memory target array.)
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 115e06144e..7a6aba6a6b 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -77,6 +77,21 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end end + def test_add_two_instance_and_then_deleting + post = posts(:thinking) + person = people(:david) + + post.people << person + post.people << person + + counts = ['post.people.count', 'post.people.to_a.count', 'post.readers.count', 'post.readers.to_a.count'] + assert_difference counts, -2 do + post.people.delete(person) + end + + assert !post.people.reload.include?(person) + end + def test_associating_new assert_queries(1) { posts(:thinking) } new_person = nil # so block binding catches it |