aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2008-12-02 14:12:09 -0300
committerJeremy Kemper <jeremy@bitsweat.net>2008-12-10 10:59:52 -0800
commit05f2183747c8e75c9e8bbaadb9573b4bdf41ecfc (patch)
tree6286202b3884a8b20be2f027ce76a49642143cc9 /activerecord/test/cases/associations/has_many_through_associations_test.rb
parent355f41d8aafd75d76db25cdda4736e0052b0605c (diff)
downloadrails-05f2183747c8e75c9e8bbaadb9573b4bdf41ecfc.tar.gz
rails-05f2183747c8e75c9e8bbaadb9573b4bdf41ecfc.tar.bz2
rails-05f2183747c8e75c9e8bbaadb9573b4bdf41ecfc.zip
Fix: counter_cache should decrement on deleting associated records.
[#1195 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb14
1 files changed, 14 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 a07f4bcbdd..ba3428a508 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -3,6 +3,9 @@ require 'models/post'
require 'models/person'
require 'models/reader'
require 'models/comment'
+require 'models/tag'
+require 'models/tagging'
+require 'models/author'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors
@@ -84,6 +87,17 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert posts(:welcome).reload.people(true).empty?
end
+ def test_deleting_updates_counter_cache
+ taggable = Tagging.first.taggable
+ taggable.taggings.push(Tagging.new)
+ taggable.reload
+ assert_equal 1, taggable.taggings_count
+
+ taggable.taggings.delete(taggable.taggings.first)
+ taggable.reload
+ assert_equal 0, taggable.taggings_count
+ end
+
def test_replace_association
assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)}