Skip to content

Commit

Permalink
Add a test for render collection:, cached: true
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
byroot committed Aug 14, 2023
1 parent 5ee23ca commit 5a483e6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/jbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
assert_equal "Pavel", result[5]["author"]["first_name"]
end

test "partial collection by name with caching" do
result = render('json.partial! "post", collection: @posts, cached: true, as: :post', posts: POSTS)
assert_equal 10, result.count
assert_equal "Post #5", result[4]["body"]
assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
assert_equal "Pavel", result[5]["author"]["first_name"]
end

test "partial collection by name with string local" do
result = render('json.partial! "post", collection: @posts, as: "post"', posts: POSTS)
assert_equal 10, result.count
Expand Down

0 comments on commit 5a483e6

Please sign in to comment.