Skip to content

Commit 5a483e6

Browse files
committed
Add a test for render collection:, cached: true
Ref: rails/rails#48936 `jbuilder` template bodies not being String tend to make Action View much more tricky than it need to be. I'm very unfamiliar with `jbuilder`, but it seems to me that in theory it could cache actual `json` fragments rather than complex ruby objects. That would be both faster and stop breaking assumptions in Action View.
1 parent 5ee23ca commit 5a483e6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test/jbuilder_template_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
7373
assert_equal "Pavel", result[5]["author"]["first_name"]
7474
end
7575

76+
test "partial collection by name with caching" do
77+
result = render('json.partial! "post", collection: @posts, cached: true, as: :post', posts: POSTS)
78+
assert_equal 10, result.count
79+
assert_equal "Post #5", result[4]["body"]
80+
assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
81+
assert_equal "Pavel", result[5]["author"]["first_name"]
82+
end
83+
7684
test "partial collection by name with string local" do
7785
result = render('json.partial! "post", collection: @posts, as: "post"', posts: POSTS)
7886
assert_equal 10, result.count

0 commit comments

Comments
 (0)