aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-12-17 20:54:50 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-20 13:56:04 -0800
commit834e5336a5d8a8250251e756385e39ebfb4917c3 (patch)
tree76adf636cd2fe00e272ab77d98fca75f814d0174 /activerecord/test/cases/associations
parent57b90098930a52fa160f9b1aed2dcea0f557d670 (diff)
downloadrails-834e5336a5d8a8250251e756385e39ebfb4917c3.tar.gz
rails-834e5336a5d8a8250251e756385e39ebfb4917c3.tar.bz2
rails-834e5336a5d8a8250251e756385e39ebfb4917c3.zip
has_many associations with :dependent => :delete_all should update the counter cache when deleting records
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index fb772bb8e6..2b7ad3642a 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -616,6 +616,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_deleting_updates_counter_cache_with_dependent_delete_all
+ post = posts(:welcome)
+
+ # Manually update the count as the tagging will have been added to the taggings association,
+ # rather than to the taggings_with_delete_all one (which is just a 'shadow' of the former)
+ post.update_attribute(:taggings_with_delete_all_count, post.taggings_with_delete_all.to_a.count)
+
+ assert_difference "post.reload.taggings_with_delete_all_count", -1 do
+ post.taggings_with_delete_all.delete(post.taggings_with_delete_all.first)
+ end
+ end
+
def test_deleting_a_collection
force_signal37_to_load_all_clients_of_firm
companies(:first_firm).clients_of_firm.create("name" => "Another Client")