mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Fix polymorphic belongs_to tests; passes on v0.10.5
This commit is contained in:
parent
5e1e138d47
commit
0fcb8a6cce
@ -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
|
||||
|
||||
4
test/fixtures/active_record.rb
vendored
4
test/fixtures/active_record.rb
vendored
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user