test/jbuilder_template_test.rb in jbuilder-2.5.0 vs test/jbuilder_template_test.rb in jbuilder-2.6.0

- old
+ new

@@ -330,17 +330,58 @@ json.name "Cache" end JBUILDER end + test "fragment caching uses fragment_cache_key" do + undef_context_methods :fragment_name_with_digest, :cache_fragment_name + + @context.expects(:fragment_cache_key).with("cachekey") + + jbuild <<-JBUILDER + json.cache! "cachekey" do + json.name "Cache" + end + JBUILDER + end + + test "fragment caching instrumentation" do + undef_context_methods :fragment_name_with_digest, :cache_fragment_name + + payloads = {} + ActiveSupport::Notifications.subscribe("read_fragment.action_controller") { |*args| payloads[:read_fragment] = args.last } + ActiveSupport::Notifications.subscribe("write_fragment.action_controller") { |*args| payloads[:write_fragment] = args.last } + + jbuild <<-JBUILDER + json.cache! "cachekey" do + json.name "Cache" + end + JBUILDER + + assert_equal "jbuilder/cachekey", payloads[:read_fragment][:key] + assert_equal "jbuilder/cachekey", payloads[:write_fragment][:key] + 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) ActiveSupport::Cache.expects :expand_cache_key jbuild <<-JBUILDER json.cache! "cachekey", skip_digest: true do + json.name "Cache" + end + JBUILDER + end + + test "fragment caching accepts expires_in option" do + undef_context_methods :fragment_name_with_digest + + @context.expects(:cache_fragment_name).with("cachekey", {}) + + jbuild <<-JBUILDER + json.cache! "cachekey", expires_in: 1.minute do json.name "Cache" end JBUILDER end