aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorTomohito Ozaki <ozaki@yuroyoro.com>2015-03-06 11:55:22 +0900
committerTomohito Ozaki <ozaki@yuroyoro.com>2015-04-17 11:20:46 +0900
commit842f5c2dad8ed021274c16f2dc231c15ddefba18 (patch)
tree6af333d0b761ba5e512bcbbd24b0e4eadf6f5c25 /activerecord/test
parenta1d042bea1d3b6d2e41356b3240e3e146823c19b (diff)
downloadrails-842f5c2dad8ed021274c16f2dc231c15ddefba18.tar.gz
rails-842f5c2dad8ed021274c16f2dc231c15ddefba18.tar.bz2
rails-842f5c2dad8ed021274c16f2dc231c15ddefba18.zip
Read already loaded association records from association.target
For performance, Avoid instantiate CollectionProxy. Fixes #12537
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 7d8b933992..2c6f199cf1 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1349,4 +1349,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
post = Post.eager_load(:tags).where('tags.name = ?', 'General').first
assert_equal posts(:welcome), post
end
+
+ # CollectionProxy#reader is expensive, so the preloader avoids calling it.
+ test "preloading has_many_through association avoids calling association.reader" do
+ ActiveRecord::Associations::HasManyAssociation.any_instance.expects(:reader).never
+ Author.preload(:readonly_comments).first!
+ end
end