Merge pull request #37666

Closes #37666
This commit is contained in:
Kasper Timm Hansen 2019-12-05 21:51:16 +01:00
commit 6f45307960
No known key found for this signature in database
GPG Key ID: 191153215EDA53D8
4 changed files with 38 additions and 1 deletions

View File

@ -12,7 +12,7 @@ module ActionView
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

View File

@ -22,6 +22,10 @@ class MultifetchCacheTest < ActiveRecordTestCase
[ :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

View File

@ -198,6 +198,8 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
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
@ -208,6 +210,8 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
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
@ -218,6 +222,8 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
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
@ -229,6 +235,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
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" })

View File

@ -21,6 +21,8 @@ module RenderTestCases
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,
@ -788,6 +790,30 @@ class CachedCollectionViewRenderTest < ActiveSupport::TestCase
@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")