Skip to content

Commit d61e335

Browse files
tnprwz
authored andcommitted
fix #cache! with expires_in option (#325)
1 parent 83256f4 commit d61e335

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/jbuilder/jbuilder_template.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def _write_fragment_cache(key, options = nil)
122122
end
123123

124124
def _cache_key(key, options)
125-
key = _fragment_name_with_digest(key, options)
125+
name_options = options.slice(:skip_digest, :virtual_path)
126+
key = _fragment_name_with_digest(key, name_options)
126127

127128
if @context.respond_to?(:fragment_cache_key)
128129
key = @context.fragment_cache_key(key)

test/jbuilder_template_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ def assert_collection_rendered(result, context = nil)
374374
JBUILDER
375375
end
376376

377+
test "fragment caching accepts expires_in option" do
378+
undef_context_methods :fragment_name_with_digest
379+
380+
@context.expects(:cache_fragment_name).with("cachekey", {})
381+
382+
jbuild <<-JBUILDER
383+
json.cache! "cachekey", expires_in: 1.minute do
384+
json.name "Cache"
385+
end
386+
JBUILDER
387+
end
388+
377389
test "does not perform caching when controller.perform_caching is false" do
378390
controller.perform_caching = false
379391

0 commit comments

Comments
 (0)