diff --git a/test/adapter/polymorphic_test.rb b/test/adapter/polymorphic_test.rb index 87d5ff51..61bad810 100644 --- a/test/adapter/polymorphic_test.rb +++ b/test/adapter/polymorphic_test.rb @@ -165,6 +165,53 @@ module ActiveModel assert_equal(expected, serialization(@picture, :json_api)) end + + def test_json_api_serialization_with_polymorphic_belongs_to + expected = { + data: { + id: '1', + type: 'poly-tags', + attributes: { phrase: 'foo' }, + relationships: { + :"object-tags" => { + data: [ + { id: '1', type: 'object-tags' }, + { id: '5', type: 'object-tags' } + ] + } + } + }, + included: [ + { + id: '1', + type: 'object-tags', + relationships: { + taggable: { + data: { id: '42', type: 'employees' } + } + } + }, + { + id: '42', + type: 'employees' + }, + { + id: '5', + type: 'object-tags', + relationships: { + taggable: { + data: { id: '1', type: 'pictures' } + } + } + }, + { + id: '1', + type: 'pictures' + } + ] + } + assert_equal(expected, tag_serialization(:json_api)) + end end end end diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index 9dc3830d..9a0567c2 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -89,7 +89,7 @@ class ObjectTag < ActiveRecord::Base end class PolymorphicObjectTagSerializer < ActiveModel::Serializer attributes :id - has_many :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true + belongs_to :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true end class PolyTag < ActiveRecord::Base @@ -109,5 +109,5 @@ class PolymorphicHasManySerializer < ActiveModel::Serializer end class PolymorphicBelongsToSerializer < ActiveModel::Serializer attributes :id, :title - has_one :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true + belongs_to :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true end