-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply records_for_RELATIONSHIP method on polymorphic to many linkage
Currently we can use `records_for_RELATIONSHIP` to control the included records. But that change doesn't apply to the linkage data. So we'll get a consistent result between included records and linkage data. This commit fixes the issue. Closes gh-1239
- Loading branch information
Showing
2 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,73 @@ def test_sti_polymorphic_to_many_serialization | |
) | ||
end | ||
|
||
def test_sti_polymorphic_to_many_serialization_with_custom_polymorphic_records | ||
person_resource = PersonResource.new(@person, nil) | ||
serializer = JSONAPI::ResourceSerializer.new( | ||
PersonResource, | ||
include: %w(vehicles) | ||
) | ||
|
||
def person_resource.records_for_vehicles(opts = {}) | ||
@model.vehicles.none | ||
end | ||
|
||
serialized_data = serializer.serialize_to_hash(person_resource) | ||
|
||
assert_hash_equals( | ||
{ | ||
data: { | ||
id: '1', | ||
type: 'people', | ||
links: { | ||
self: '/people/1' | ||
}, | ||
attributes: { | ||
name: 'Joe Author', | ||
email: '[email protected]', | ||
dateJoined: '2013-08-07 16:25:00 -0400' | ||
}, | ||
relationships: { | ||
comments: { | ||
links: { | ||
self: '/people/1/relationships/comments', | ||
related: '/people/1/comments' | ||
} | ||
}, | ||
posts: { | ||
links: { | ||
self: '/people/1/relationships/posts', | ||
related: '/people/1/posts' | ||
} | ||
}, | ||
vehicles: { | ||
links: { | ||
self: '/people/1/relationships/vehicles', | ||
related: '/people/1/vehicles' | ||
}, | ||
:data => [] | ||
}, | ||
preferences: { | ||
links: { | ||
self: '/people/1/relationships/preferences', | ||
related: '/people/1/preferences' | ||
} | ||
}, | ||
hairCut: { | ||
links: { | ||
self: '/people/1/relationships/hairCut', | ||
related: '/people/1/hairCut' | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
serialized_data | ||
) | ||
end | ||
|
||
|
||
|
||
def test_polymorphic_belongs_to_serialization | ||
serialized_data = JSONAPI::ResourceSerializer.new( | ||
PictureResource, | ||
|