mirror of https://github.com/rails/rails
commit
6f45307960
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" })
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue