Don't pluralize the CollectionSerializer#root for #json_key

One of three constituents is used to provide the
CollectionSerializer's #json_key:

1) the :root option - controlled by the caller
2) the #name of the first resource serializer - the root or
   underscored model name
3) the underscored #name of the resources object - generally
   equivalent to the underscored model name of #2

Of the three, only the latter 2 are out of the callers control, and
only the latter two are expected to be singular by default. Not
pluralizing the root gives the caller additional flexibility in
defining the desired root, whether conventionally plural,
unconventionally plural (e.g. objects_received:) or singular.
This commit is contained in:
Ben Woosley
2016-01-07 11:32:10 -08:00
parent 34e5faa1c4
commit 251e33a0a1
4 changed files with 22 additions and 10 deletions

View File

@@ -171,7 +171,7 @@ module ActionController
with_adapter :json do
get :render_array_using_custom_root
end
expected = { custom_roots: [{ name: 'Name 1', description: 'Description 1' }] }
expected = { custom_root: [{ name: 'Name 1', description: 'Description 1' }] }
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end
@@ -181,7 +181,7 @@ module ActionController
get :render_array_that_is_empty_using_custom_root
end
expected = { custom_roots: [] }
expected = { custom_root: [] }
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end