Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/jbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ def target!
@attributes.to_json
end

private

alias_method :method_missing, :set!
private :method_missing

private

def _extract(object, attributes)
if ::Hash === object
Expand Down
5 changes: 3 additions & 2 deletions lib/jbuilder/jbuilder_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ def set!(name, object = BLANK, *args)
end
end

private

alias_method :method_missing, :set!
private :method_missing

private

def _render_partial_with_options(options)
options[:locals] ||= options.except(:partial, :as, :collection, :cached)
Expand Down
5 changes: 5 additions & 0 deletions test/jbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
assert_equal "hello", result["content"]
end

test "method_missing can be used as a key" do
result = render('json.method_missing "hello"')
assert_equal({ "method_missing" => "hello" }, result)
end

test "partial by name with top-level locals" do
result = render('json.partial! "partial", content: "hello"')
assert_equal "hello", result["content"]
Expand Down
8 changes: 8 additions & 0 deletions test/jbuilder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class JbuilderTest < ActiveSupport::TestCase
assert_equal 'hello', result['content']
end

test 'method_missing key' do
result = jbuild do |json|
json.method_missing 'hello'
end

assert_equal 'hello', result['method_missing']
end

test 'single key with false value' do
result = jbuild do |json|
json.content false
Expand Down
Loading