Skip to content

Commit 363c3c8

Browse files
authored
Merge pull request #614 from alexceder/make-method-missing-private
2 parents 4869a93 + 26c236c commit 363c3c8

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/jbuilder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,10 @@ def target!
272272
@attributes.to_json
273273
end
274274

275-
private
276-
277275
alias_method :method_missing, :set!
276+
private :method_missing
277+
278+
private
278279

279280
def _extract(object, attributes)
280281
if ::Hash === object

lib/jbuilder/jbuilder_template.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ def set!(name, object = BLANK, *args)
141141
end
142142
end
143143

144-
private
145-
146144
alias_method :method_missing, :set!
145+
private :method_missing
146+
147+
private
147148

148149
def _render_partial_with_options(options)
149150
options[:locals] ||= options.except(:partial, :as, :collection, :cached)

test/jbuilder_template_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
3939
assert_equal "hello", result["content"]
4040
end
4141

42+
test "method_missing can be used as a key" do
43+
result = render('json.method_missing "hello"')
44+
assert_equal({ "method_missing" => "hello" }, result)
45+
end
46+
4247
test "partial by name with top-level locals" do
4348
result = render('json.partial! "partial", content: "hello"')
4449
assert_equal "hello", result["content"]

test/jbuilder_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class JbuilderTest < ActiveSupport::TestCase
6161
assert_equal 'hello', result['content']
6262
end
6363

64+
test 'method_missing key' do
65+
result = jbuild do |json|
66+
json.method_missing 'hello'
67+
end
68+
69+
assert_equal 'hello', result['method_missing']
70+
end
71+
6472
test 'single key with false value' do
6573
result = jbuild do |json|
6674
json.content false

0 commit comments

Comments
 (0)