Skip to content

Commit

Permalink
Test collection caching with callable cache key.
Browse files Browse the repository at this point in the history
When people pass `cache: -> item { item.upcase }` they scope the collection
cache keys so the individual partial cache isn't reused.

Test that behavior.
  • Loading branch information
kaspth committed Feb 12, 2016
1 parent db9ef08 commit 48349f2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions actionpack/test/controller/caching_test.rb
Expand Up @@ -390,6 +390,11 @@ def index_with_comment
@customers = [Customer.new('david', 1)]
render partial: 'customers/commented_customer', collection: @customers, as: :customer
end

def index_with_callable_cache_key
@customers = [Customer.new('david', 1)]
render @customers, cache: -> customer { 'cached_david' }
end
end

class AutomaticCollectionCacheTest < ActionController::TestCase
Expand Down Expand Up @@ -430,6 +435,26 @@ def test_caching_works_with_beginning_comment
get :index_with_comment
assert_equal 1, @controller.partial_rendered_times
end

def test_caching_with_callable_cache_key
get :index_with_callable_cache_key
assert_equal 1, @controller.partial_rendered_times
assert_select ':root', 'david, 1'

get :index_with_callable_cache_key
assert_equal 1, @controller.partial_rendered_times
assert_select ':root', 'david, 1'
end

def test_caching_mixing_callable_cache_key_and_automatic_caching
get :index
assert_equal 1, @controller.partial_rendered_times
assert_select ':root', 'david, 1'

get :index_with_callable_cache_key
assert_equal 1, @controller.partial_rendered_times, 'individual cache not reused with collection'
assert_select ':root', 'david, 1'
end
end

class FragmentCacheKeyTestController < CachingController
Expand Down

0 comments on commit 48349f2

Please sign in to comment.