aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-11-26 07:16:17 -0800
committerYves Senn <yves.senn@gmail.com>2013-11-26 07:16:17 -0800
commitd35678242cbb45f19039e3da6ba13911951b1f9b (patch)
tree0e8a9680d7783324ba2e4020edfa943c921c48e9 /activerecord/test
parent3669704050edfeb125d79a838d18584ec4a51a1a (diff)
parent45d4d141f971e50e2df40bbf3559ee254ebc81b9 (diff)
downloadrails-d35678242cbb45f19039e3da6ba13911951b1f9b.tar.gz
rails-d35678242cbb45f19039e3da6ba13911951b1f9b.tar.bz2
rails-d35678242cbb45f19039e3da6ba13911951b1f9b.zip
Merge pull request #13018 from heruku/scoping_fix
changed update counter to act on unscoped model
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
-rw-r--r--activerecord/test/models/topic.rb4
2 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 45bc974025..bfb80afa61 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1781,4 +1781,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [original_child], car.reload.failed_bulbs
end
+
+ test 'updates counter cache when default scope is given' do
+ topic = DefaultRejectedTopic.create approved: true
+
+ assert_difference "topic.reload.replies_count", 1 do
+ topic.approved_replies.create!
+ end
+ end
end
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 40c8e97fc2..f81ffe1d90 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -106,6 +106,10 @@ class ImportantTopic < Topic
serialize :important, Hash
end
+class DefaultRejectedTopic < Topic
+ default_scope -> { where(approved: false) }
+end
+
class BlankTopic < Topic
# declared here to make sure that dynamic finder with a bang can find a model that responds to `blank?`
def blank?