diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index c88a679..55f2d5f 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -159,7 +159,7 @@ def _render_partial_with_options(options) results = CollectionRenderer .new(@context.lookup_context, options) { |&block| _scope(&block) } .render_collection_with_partial(collection, partial, @context, nil) - + array! if results.respond_to?(:body) && results.body.nil? else array! @@ -284,7 +284,7 @@ class JbuilderHandler def self.call(template, source = nil) source ||= template.source # this juggling is required to keep line numbers right in the error - %{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{source} + %{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{source}; json.target! unless (__already_defined && __already_defined != "method")} end end diff --git a/test/jbuilder_template_test.rb b/test/jbuilder_template_test.rb index 6b8ac82..54addb2 100644 --- a/test/jbuilder_template_test.rb +++ b/test/jbuilder_template_test.rb @@ -49,6 +49,17 @@ class JbuilderTemplateTest < ActiveSupport::TestCase assert_equal "hello", result["content"] end + test "partial by name with hash value omission (punning) as last statement [3.1+]" do + major, minor, _ = RUBY_VERSION.split(".").map(&:to_i) + return unless (major == 3 && minor >= 1) || major > 3 + + result = render(<<-JBUILDER) + content = "hello" + json.partial! "partial", content: + JBUILDER + assert_equal "hello", result["content"] + end + test "partial by options containing nested locals" do result = render('json.partial! partial: "partial", locals: { content: "hello" }') assert_equal "hello", result["content"]