Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some more collection-partials examples and tests

  • Loading branch information...
commit 79316ca26c98047ad323d66675080deefbccd769 1 parent aae2703
@rwz rwz authored
Showing with 14 additions and 1 deletion.
  1. +4 −0 README.md
  2. +10 −1 test/jbuilder_template_test.rb
View
4 README.md
@@ -154,6 +154,10 @@ json.partial! 'posts/post', collection: @posts, as: :post
# or
json.partial! partial: 'posts/post', collection: @posts, as: :post
+
+# or
+
+json.comments @post.comments, partial: 'comment/comment', as: :comment
```
You can explicitly make Jbuilder object return null if you want:
View
11 test/jbuilder_template_test.rb
@@ -52,8 +52,9 @@ def undef_context_methods(*names)
end
end
- def assert_collection_rendered(json)
+ def assert_collection_rendered(json, context = nil)
result = MultiJson.load(json)
+ result = result.fetch(context) if context
assert_equal 10, result.length
assert_equal Array, result.class
@@ -125,6 +126,14 @@ def assert_collection_rendered(json)
assert_collection_rendered json
end
+ test 'render array if partials as a value' do
+ json = render_jbuilder <<-JBUILDER
+ json.posts BLOG_POST_COLLECTION, :partial => 'blog_post', :as => :blog_post
+ JBUILDER
+
+ assert_collection_rendered json, 'posts'
+ end
+
test 'fragment caching a JSON object' do
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
Please sign in to comment.
Something went wrong with that request. Please try again.