@@ -285,6 +285,56 @@ def test_associations_namespaced_resources
285
285
end
286
286
end
287
287
288
+ class AssociationsNamespacedSerializersTest < ActiveSupport ::TestCase
289
+ class Post < ::Model
290
+ associations :comments , :author , :description
291
+
292
+ def latest_comments
293
+ comments [ 0 ..3 ]
294
+ end
295
+ end
296
+ class Comment < ::Model ; end
297
+ class Author < ::Model ; end
298
+ class Description < ::Model ; end
299
+
300
+ class ResourceNamespace
301
+ class PostSerializer < ActiveModel ::Serializer
302
+ has_many :comments , namespace : ResourceNamespace
303
+ has_many :latest_comments , namespace : ResourceNamespace
304
+ belongs_to :author , namespace : ResourceNamespace
305
+ has_one :description , namespace : ResourceNamespace
306
+ end
307
+ class CommentSerializer < ActiveModel ::Serializer ; end
308
+ class AuthorSerializer < ActiveModel ::Serializer ; end
309
+ class DescriptionSerializer < ActiveModel ::Serializer ; end
310
+ end
311
+
312
+ def setup
313
+ @comment = Comment . new
314
+ @author = Author . new
315
+ @description = Description . new
316
+ @post = Post . new ( comments : [ @comment ] ,
317
+ author : @author ,
318
+ description : @description )
319
+ @post_serializer = ResourceNamespace ::PostSerializer . new ( @post )
320
+ end
321
+
322
+ def test_associations_namespaced_serializers
323
+ @post_serializer . associations . each do |association |
324
+ case association . key
325
+ when :comments , :latest_comments
326
+ assert_instance_of ( ResourceNamespace ::CommentSerializer , association . lazy_association . serializer . first )
327
+ when :author
328
+ assert_instance_of ( ResourceNamespace ::AuthorSerializer , association . lazy_association . serializer )
329
+ when :description
330
+ assert_instance_of ( ResourceNamespace ::DescriptionSerializer , association . lazy_association . serializer )
331
+ else
332
+ flunk "Unknown association: #{ key } "
333
+ end
334
+ end
335
+ end
336
+ end
337
+
288
338
class NestedSerializersTest < ActiveSupport ::TestCase
289
339
class Post < ::Model
290
340
associations :comments , :author , :description
0 commit comments