Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single nil object should be treated as nil #439

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/jbuilder/jbuilder_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _is_active_model?(object)

def _set_inline_partial(name, object, options)
value = if object.nil?
[]
nil
elsif _is_collection?(object)
_scope{ _render_partial_with_options options.merge(collection: object) }
else
Expand Down
8 changes: 0 additions & 8 deletions test/jbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,6 @@ def assert_collection_rendered(result, context = nil)
assert_collection_rendered result, "posts"
end

test "render as empty array if partials as a nil value" do
result = jbuild <<-JBUILDER
json.posts nil, partial: "blog_post", as: :blog_post
JBUILDER

assert_equal [], result["posts"]
end

test "cache an empty block" do
undef_context_methods :fragment_name_with_digest, :cache_fragment_name

Expand Down