Merge d3b9de0bab71ba1ca47d2dd57d0a9b05e01bcc8b into 7db80f673d037ed841bef8e8a93dcda21380e135
This commit is contained in:
commit
961a06c099
@ -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
|
||||
|
@ -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
7
spec/fixtures/debut.rb
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
Debut = Struct.new(:id, :location)
|
||||
|
||||
class DebutSerializer
|
||||
include JSONAPI::Serializer
|
||||
|
||||
attributes :location
|
||||
end
|
5
spec/fixtures/movie.rb
vendored
5
spec/fixtures/movie.rb
vendored
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user