diff options
author | Roque Pinel <repinel@gmail.com> | 2015-06-12 15:30:04 -0400 |
---|---|---|
committer | Roque Pinel <repinel@gmail.com> | 2015-06-28 20:41:59 -0500 |
commit | da1674576d01f8fe3ad3b448a4c3fa636bcce106 (patch) | |
tree | 5de420942c36f327b435761fba41a0f37ac80995 /actionview/test/template | |
parent | aba43b7da1f45465fc3753225e5c73046342d4ec (diff) | |
download | rails-da1674576d01f8fe3ad3b448a4c3fa636bcce106.tar.gz rails-da1674576d01f8fe3ad3b448a4c3fa636bcce106.tar.bz2 rails-da1674576d01f8fe3ad3b448a4c3fa636bcce106.zip |
Fix cache issue when different partials use the same collection
Adds the `virtual_path` option to `cache_fragment_name` so it can
be provided when needed.
That allows `cache_collection_render` to get the appropriate cache
key with the digest generated based on the template and prevent
collision with other templates that cache the same collection.
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/render_test.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 27bbb9b6c1..9c2c9507b7 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -7,7 +7,10 @@ end module RenderTestCases def setup_view(paths) @assigns = { :secret => 'in the sauce' } - @view = ActionView::Base.new(paths, @assigns) + @view = Class.new(ActionView::Base) do + def view_cache_dependencies; end + end.new(paths, @assigns) + @controller_view = TestController.new.view_context # Reload and register danish language for testing @@ -616,7 +619,7 @@ class CachedCollectionViewRenderTest < CachedViewRenderTest test "with custom key" do customer = Customer.new("david") - key = ActionController::Base.new.fragment_cache_key([customer, 'key']) + key = cache_key([customer, 'key'], "test/_customer") ActionView::PartialRenderer.collection_cache.write(key, 'Hello') @@ -626,7 +629,7 @@ class CachedCollectionViewRenderTest < CachedViewRenderTest test "automatic caching with inferred cache name" do customer = CachedCustomer.new("david") - key = ActionController::Base.new.fragment_cache_key(customer) + key = cache_key(customer, "test/_cached_customer") ActionView::PartialRenderer.collection_cache.write(key, 'Cached') @@ -636,11 +639,17 @@ class CachedCollectionViewRenderTest < CachedViewRenderTest test "automatic caching with as name" do customer = CachedCustomer.new("david") - key = ActionController::Base.new.fragment_cache_key(customer) + key = cache_key(customer, "test/_cached_customer_as") ActionView::PartialRenderer.collection_cache.write(key, 'Cached') assert_equal "Cached", @view.render(partial: "test/cached_customer_as", collection: [customer], as: :buyer) end + + private + def cache_key(names, virtual_path) + digest = ActionView::Digestor.digest name: virtual_path, finder: @view.lookup_context, dependencies: [] + @view.fragment_cache_key([ *Array(names), digest ]) + end end |