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
4 changes: 2 additions & 2 deletions lib/jbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def method_missing(method, *args)

# json.age 32
# { "age": 32 }
when args.one?
when args.length == 1
set! method, args.first

# json.comments { |json| ... }
Expand Down Expand Up @@ -182,4 +182,4 @@ def _inline_extract(container, record, attributes)
end
end

require "jbuilder_template" if defined?(ActionView::Template)
require "jbuilder_template" if defined?(ActionView::Template)
19 changes: 18 additions & 1 deletion test/jbuilder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ class JbuilderTest < ActiveSupport::TestCase
assert_equal "hello", JSON.parse(json)["content"]
end

test "single key with false value" do
json = Jbuilder.encode do |json|
json.content false
end

assert_equal false, JSON.parse(json)["content"]
end

test "single key with nil value" do
json = Jbuilder.encode do |json|
json.content nil
end

assert JSON.parse(json).has_key?("content")
assert_equal nil, JSON.parse(json)["content"]
end

test "multiple keys" do
json = Jbuilder.encode do |json|
json.title "hello"
Expand Down Expand Up @@ -225,4 +242,4 @@ def initialize(name, age)

assert_equal "stuff", JSON.parse(json)["each"]
end
end
end