Fix polymorphic belongs_to tests; passes on v0.10.5

This commit is contained in:
Benjamin Fleischer 2017-10-29 19:26:14 -05:00
parent 5e1e138d47
commit 0fcb8a6cce
2 changed files with 49 additions and 2 deletions

View File

@ -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

View File

@ -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