Merge pull request #37666

Closes #37666
上级 d2f53ac5
......@@ -12,7 +12,7 @@ module CollectionCaching # :nodoc:
private
def cache_collection_render(instrumentation_payload, view, template)
return yield unless @options[:cached]
return yield unless @options[:cached] && view.controller.respond_to?(:perform_caching) && view.controller.perform_caching
# Result is a hash with the key represents the
# key used for cache lookup and the value is the item
......
......@@ -22,6 +22,10 @@ def combined_fragment_cache_key(key)
[ :views, key ]
end
end.with_view_paths(view_paths, {})
controller = ActionController::Base.new
controller.perform_caching = true
@view.controller = controller
end
def test_only_preloading_for_records_that_miss_the_cache
......
......@@ -194,6 +194,8 @@ def test_render_partial_with_cache_hitted_and_missed
def test_render_collection_template
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
set_cache_controller
@view.render(partial: "test/customer", collection: [ Customer.new("david"), Customer.new("mary") ])
wait
......@@ -204,6 +206,8 @@ def test_render_collection_template
def test_render_collection_with_implicit_path
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
set_cache_controller
@view.render([ Customer.new("david"), Customer.new("mary") ], greeting: "hi")
wait
......@@ -214,6 +218,8 @@ def test_render_collection_with_implicit_path
def test_render_collection_template_without_path
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
set_cache_controller
@view.render([ GoodCustomer.new("david"), Customer.new("mary") ], greeting: "hi")
wait
......@@ -225,6 +231,7 @@ def test_render_collection_template_without_path
def test_render_collection_with_cached_set
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
set_view_cache_dependencies
set_cache_controller
@view.render(partial: "customers/customer", collection: [ Customer.new("david"), Customer.new("mary") ], cached: true,
locals: { greeting: "hi" })
......
......@@ -19,6 +19,8 @@ def combined_fragment_cache_key(key)
end.with_view_paths(paths, @assigns)
controller = TestController.new
controller.perform_caching = true
@view.controller = controller
@controller_view = controller.view_context_class.with_empty_template_cache.new(
controller.lookup_context,
......@@ -785,6 +787,30 @@ def teardown
@view.render(partial: "test/customer", collection: [customer])
end
test "collection caching does not cache if controller doesn't respond to perform_caching" do
@view.controller = nil
customer = Customer.new("david", 1)
key = cache_key(customer, "test/_customer")
ActionView::PartialRenderer.collection_cache.write(key, "Cached")
assert_not_equal "Cached",
@view.render(partial: "test/customer", collection: [customer], cached: true)
end
test "collection caching does not cache if perform_caching is disabled" do
@view.controller.perform_caching = false
customer = Customer.new("david", 1)
key = cache_key(customer, "test/_customer")
ActionView::PartialRenderer.collection_cache.write(key, "Cached")
assert_not_equal "Cached",
@view.render(partial: "test/customer", collection: [customer], cached: true)
end
test "collection caching with partial that doesn't use fragment caching" do
customer = Customer.new("david", 1)
key = cache_key(customer, "test/_customer")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册