Skip to content

Commit 0fcb8a6

Browse files
committed
Fix polymorphic belongs_to tests; passes on v0.10.5
1 parent 5e1e138 commit 0fcb8a6

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

test/adapter/polymorphic_test.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,53 @@ def test_json_api_serialization
165165

166166
assert_equal(expected, serialization(@picture, :json_api))
167167
end
168+
169+
def test_json_api_serialization_with_polymorphic_belongs_to
170+
expected = {
171+
data: {
172+
id: '1',
173+
type: 'poly-tags',
174+
attributes: { phrase: 'foo' },
175+
relationships: {
176+
:"object-tags" => {
177+
data: [
178+
{ id: '1', type: 'object-tags' },
179+
{ id: '5', type: 'object-tags' }
180+
]
181+
}
182+
}
183+
},
184+
included: [
185+
{
186+
id: '1',
187+
type: 'object-tags',
188+
relationships: {
189+
taggable: {
190+
data: { id: '42', type: 'employees' }
191+
}
192+
}
193+
},
194+
{
195+
id: '42',
196+
type: 'employees'
197+
},
198+
{
199+
id: '5',
200+
type: 'object-tags',
201+
relationships: {
202+
taggable: {
203+
data: { id: '1', type: 'pictures' }
204+
}
205+
}
206+
},
207+
{
208+
id: '1',
209+
type: 'pictures'
210+
}
211+
]
212+
}
213+
assert_equal(expected, tag_serialization(:json_api))
214+
end
168215
end
169216
end
170217
end

test/fixtures/active_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ObjectTag < ActiveRecord::Base
8989
end
9090
class PolymorphicObjectTagSerializer < ActiveModel::Serializer
9191
attributes :id
92-
has_many :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true
92+
belongs_to :taggable, serializer: PolymorphicSimpleSerializer, polymorphic: true
9393
end
9494

9595
class PolyTag < ActiveRecord::Base
@@ -109,5 +109,5 @@ class PolymorphicHasManySerializer < ActiveModel::Serializer
109109
end
110110
class PolymorphicBelongsToSerializer < ActiveModel::Serializer
111111
attributes :id, :title
112-
has_one :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true
112+
belongs_to :imageable, serializer: PolymorphicHasManySerializer, polymorphic: true
113113
end

0 commit comments

Comments
 (0)