From 2eee8af4d058b60323b60dd1a56c247e485c0835 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 14 Oct 2014 16:39:57 -0700 Subject: make sure cache is not used for collection assocations too follow up for #17052 --- activerecord/test/cases/scoping/relation_scoping_test.rb | 13 ++++++++++++- activerecord/test/models/author.rb | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/scoping/relation_scoping_test.rb b/activerecord/test/cases/scoping/relation_scoping_test.rb index c63fea15f2..29b32576b8 100644 --- a/activerecord/test/cases/scoping/relation_scoping_test.rb +++ b/activerecord/test/cases/scoping/relation_scoping_test.rb @@ -7,6 +7,7 @@ require 'models/comment' require 'models/category' require 'models/person' require 'models/reference' +require 'models/reference' class RelationScopingTest < ActiveRecord::TestCase fixtures :authors, :developers, :projects, :comments, :posts, :developers_projects @@ -19,12 +20,22 @@ class RelationScopingTest < ActiveRecord::TestCase author = authors :mary assert_nil author.first_post post = FirstPost.unscoped do - author = authors :mary author.reload.first_post end assert post end + def test_scope_breaks_caching_on_collections + author = authors :david + ids = author.reload.special_posts_with_default_scope.map(&:id) + assert_equal [1,5,6], ids.sort + scoped_posts = SpecialPostWithDefaultScope.unscoped do + author = authors :david + author.reload.special_posts_with_default_scope.to_a + end + assert_equal author.posts.map(&:id).sort, scoped_posts.map(&:id).sort + end + def test_reverse_order assert_equal Developer.order("id DESC").to_a.reverse, Developer.order("id DESC").reverse_order end diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 8949cf5826..3f34d09a04 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -44,6 +44,7 @@ class Author < ActiveRecord::Base has_many :special_posts has_many :special_post_comments, :through => :special_posts, :source => :comments + has_many :special_posts_with_default_scope, :class_name => 'SpecialPostWithDefaultScope' has_many :sti_posts, :class_name => 'StiPost' has_many :sti_post_comments, :through => :sti_posts, :source => :comments -- cgit v1.2.3