Skip to content

Commit f39e8b8

Browse files
committed
Add tests for fragment_cache_key and instrumentation
1 parent ddb2985 commit f39e8b8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/jbuilder_template_test.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,35 @@ def assert_collection_rendered(result, context = nil)
332332
JBUILDER
333333
end
334334

335+
test "fragment caching uses fragment_cache_key" do
336+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
337+
338+
@context.expects(:fragment_cache_key).with("cachekey")
339+
340+
jbuild <<-JBUILDER
341+
json.cache! "cachekey" do
342+
json.name "Cache"
343+
end
344+
JBUILDER
345+
end
346+
347+
test "fragment caching instrumentation" do
348+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
349+
350+
payloads = {}
351+
ActiveSupport::Notifications.subscribe("read_fragment.action_controller") { |*args| payloads[:read_fragment] = args.last }
352+
ActiveSupport::Notifications.subscribe("write_fragment.action_controller") { |*args| payloads[:write_fragment] = args.last }
353+
354+
jbuild <<-JBUILDER
355+
json.cache! "cachekey" do
356+
json.name "Cache"
357+
end
358+
JBUILDER
359+
360+
assert_equal "jbuilder/cachekey", payloads[:read_fragment][:key]
361+
assert_equal "jbuilder/cachekey", payloads[:write_fragment][:key]
362+
end
363+
335364
test "current cache digest option accepts options" do
336365
undef_context_methods :fragment_name_with_digest
337366

0 commit comments

Comments
 (0)