aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
authorLachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au>2017-11-21 15:38:21 +1100
committerLachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au>2018-03-06 14:10:45 +1100
commitd04a32fe67d1d3d5735f9c4f4004c17631e83cc1 (patch)
treed99a42a32e3b41de6ccacede109f1a2c0bfe55ae /actionview/test
parenta3b7aa66bc81da96ea91019540e8874a76216cd8 (diff)
downloadrails-d04a32fe67d1d3d5735f9c4f4004c17631e83cc1.tar.gz
rails-d04a32fe67d1d3d5735f9c4f4004c17631e83cc1.tar.bz2
rails-d04a32fe67d1d3d5735f9c4f4004c17631e83cc1.zip
Only preload misses on multifetch cache
Diffstat (limited to 'actionview/test')
-rw-r--r--actionview/test/activerecord/multifetch_cache_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/actionview/test/activerecord/multifetch_cache_test.rb b/actionview/test/activerecord/multifetch_cache_test.rb
new file mode 100644
index 0000000000..12be069e69
--- /dev/null
+++ b/actionview/test/activerecord/multifetch_cache_test.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require "active_record_unit"
+require "active_record/railties/collection_cache_association_loading"
+
+ActionView::PartialRenderer.prepend(ActiveRecord::Railties::CollectionCacheAssociationLoading)
+
+class MultifetchCacheTest < ActiveRecordTestCase
+ fixtures :topics, :replies
+
+ def setup
+ view_paths = ActionController::Base.view_paths
+
+ @view = Class.new(ActionView::Base) do
+ def view_cache_dependencies
+ []
+ end
+
+ def combined_fragment_cache_key(key)
+ [ :views, key ]
+ end
+ end.new(view_paths, {})
+ end
+
+ def test_only_preloading_for_records_that_miss_the_cache
+ @view.render partial: "test/partial", collection: [topics(:rails)], cached: true
+
+ @topics = Topic.preload(:replies)
+
+ @view.render partial: "test/partial", collection: @topics, cached: true
+
+ assert_not @topics.detect { |topic| topic.id == topics(:rails).id }.replies.loaded?
+ assert @topics.detect { |topic| topic.id != topics(:rails).id }.replies.loaded?
+ end
+end