Merge d3b9de0bab71ba1ca47d2dd57d0a9b05e01bcc8b into 7db80f673d037ed841bef8e8a93dcda21380e135

This commit is contained in:
Grant Paulson 2022-04-29 21:09:22 +09:00 committed by GitHub
commit 961a06c099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 3 deletions

View File

@ -107,7 +107,7 @@ module FastJsonapi
return unless associated_object = fetch_associated_object(record, params)
if associated_object.respond_to? :map
if associated_object.respond_to? :to_ary
return associated_object.map do |object|
id_hash_from_record object, params
end

View File

@ -173,7 +173,7 @@ module FastJsonapi
next unless relationship_item&.include_relationship?(record, params)
included_objects = Array(relationship_item.fetch_associated_object(record, params))
included_objects = Array.wrap(relationship_item.fetch_associated_object(record, params))
next if included_objects.empty?
static_serializer = relationship_item.static_serializer

7
spec/fixtures/debut.rb vendored Normal file
View File

@ -0,0 +1,7 @@
Debut = Struct.new(:id, :location)
class DebutSerializer
include JSONAPI::Serializer
attributes :location
end

View File

@ -8,7 +8,8 @@ class Movie
:actor_ids,
:polymorphics,
:owner,
:owner_id
:owner_id,
:debut
)
def self.fake(id = nil)
@ -104,6 +105,8 @@ class MovieSerializer
) do |obj|
obj.polymorphics
end
has_one(:debut) { |obj| obj.debut }
end
module Cached

View File

@ -9,6 +9,7 @@ RSpec.describe JSONAPI::Serializer do
poly_act.movies = [Movie.fake]
mov.polymorphics = [User.fake, poly_act]
mov.actor_or_user = Actor.fake
mov.debut = Debut.new(SecureRandom.uuid, 'Los Angeles')
mov
end
let(:params) { {} }
@ -141,6 +142,16 @@ RSpec.describe JSONAPI::Serializer do
)
end
end
context 'with enumerable data types' do
let(:params) do
{ include: [:debut] }
end
it do
expect(serialized['included']).to include(have_type('debut').and(have_id(movie.debut.id)))
end
end
end
end
end