mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #1214 from NullVoxPopuli/issue/1211-failing-test
Fix #1211, include_tree is null when using the key: options
This commit is contained in:
commit
34d65716cb
@ -20,6 +20,7 @@ Features:
|
||||
- [#1050](https://github.com/rails-api/active_model_serializers/pull/1050) Add support for toplevel jsonapi member (@beauby, @bf4)
|
||||
|
||||
Fixes:
|
||||
- [#1214](https://github.com/rails-api/active_model_serializers/pull/1214) retrieve the key from the reflection options when building associations (@NullVoxPopuli, @hut8)
|
||||
|
||||
Misc:
|
||||
- [#1178](https://github.com/rails-api/active_model_serializers/pull/1178) env CAPTURE_STDERR=false lets devs see hard failures (@bf4)
|
||||
|
||||
@ -92,7 +92,8 @@ module ActiveModel
|
||||
|
||||
Enumerator.new do |y|
|
||||
self.class._reflections.each do |reflection|
|
||||
next unless include_tree.key?(reflection.name)
|
||||
key = reflection.options.fetch(:key, reflection.name)
|
||||
next unless include_tree.key?(key)
|
||||
y.yield reflection.build_association(self, instance_options)
|
||||
end
|
||||
end
|
||||
|
||||
@ -46,6 +46,11 @@ module ActionController
|
||||
render json: @post, include: [:author], adapter: :json_api
|
||||
end
|
||||
|
||||
def render_resource_with_include_of_custom_key_by_original
|
||||
setup_post
|
||||
render json: @post, include: [:reviews], adapter: :json_api, serializer: PostWithCustomKeysSerializer
|
||||
end
|
||||
|
||||
def render_resource_with_nested_include
|
||||
setup_post
|
||||
render json: @post, include: [comments: [:author]], adapter: :json_api
|
||||
@ -137,6 +142,18 @@ module ActionController
|
||||
assert_equal expected_linked, response['included']
|
||||
end
|
||||
|
||||
def test_render_resource_with_include_of_custom_key_by_original
|
||||
get :render_resource_with_include_of_custom_key_by_original
|
||||
response = JSON.parse(@response.body)
|
||||
assert response.key? 'included'
|
||||
|
||||
relationships = response['data']['relationships']
|
||||
|
||||
assert_includes relationships, 'reviews'
|
||||
assert_includes relationships, 'writer'
|
||||
assert_includes relationships, 'site'
|
||||
end
|
||||
|
||||
def test_render_resource_with_nested_include
|
||||
get :render_resource_with_nested_include
|
||||
response = JSON.parse(@response.body)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user