Skip to content

Commit

Permalink
Pass options when calling cache_fragment_name
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicpacquing committed Feb 17, 2014
1 parent 8c1a8e9 commit 07c2cc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/jbuilder/jbuilder_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def array!(collection = [], *attributes, &block)
# end
def cache!(key=nil, options={}, &block)
if @context.controller.perform_caching
value = ::Rails.cache.fetch(_cache_key(key), options) do
value = ::Rails.cache.fetch(_cache_key(key, options), options) do
_scope { yield self }
end

Expand Down Expand Up @@ -83,11 +83,11 @@ def _render_partial(options)
@context.render options
end

def _cache_key(key)
def _cache_key(key, options)
if @context.respond_to?(:cache_fragment_name)
# Current compatibility, fragment_name_with_digest is private again and cache_fragment_name
# should be used instead.
@context.cache_fragment_name(key)
@context.cache_fragment_name(key, options)
elsif @context.respond_to?(:fragment_name_with_digest)
# Backwards compatibility for period of time when fragment_name_with_digest was made public.
@context.fragment_name_with_digest(key)
Expand Down
12 changes: 12 additions & 0 deletions test/jbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ def assert_collection_rendered(json, context = nil)
JBUILDER
end

test 'current cache digest option accepts options' do
undef_context_methods :fragment_name_with_digest

@context.expects(:cache_fragment_name).with('cachekey', skip_digest: true)

render_jbuilder <<-JBUILDER
json.cache! 'cachekey', skip_digest: true do
json.name 'Cache'
end
JBUILDER
end

test 'does not perform caching when controller.perform_caching is false' do
controller.perform_caching = false
render_jbuilder <<-JBUILDER
Expand Down

0 comments on commit 07c2cc7

Please sign in to comment.