@@ -125,6 +125,88 @@ def test_associations_custom_keys
125125 assert expected_association_keys . include? :writer
126126 assert expected_association_keys . include? :site
127127 end
128+
129+ class NamespacedResourcesTest < Minitest ::Test
130+ class ResourceNamespace
131+ Post = Class . new ( ::Model )
132+ Comment = Class . new ( ::Model )
133+ Author = Class . new ( ::Model )
134+ Description = Class . new ( ::Model )
135+ class PostSerializer < ActiveModel ::Serializer
136+ has_many :comments
137+ belongs_to :author
138+ has_one :description
139+ end
140+ CommentSerializer = Class . new ( ActiveModel ::Serializer )
141+ AuthorSerializer = Class . new ( ActiveModel ::Serializer )
142+ DescriptionSerializer = Class . new ( ActiveModel ::Serializer )
143+ end
144+
145+ def setup
146+ @comment = ResourceNamespace ::Comment . new
147+ @author = ResourceNamespace ::Author . new
148+ @description = ResourceNamespace ::Description . new
149+ @post = ResourceNamespace ::Post . new ( comments : [ @comment ] ,
150+ author : @author ,
151+ description : @description )
152+ @post_serializer = ResourceNamespace ::PostSerializer . new ( @post )
153+ end
154+
155+ def test_associations_namespaced_resources
156+ @post_serializer . associations . each do |association |
157+ case association . key
158+ when :comments
159+ assert_instance_of ( ResourceNamespace ::CommentSerializer , association . serializer . first )
160+ when :author
161+ assert_instance_of ( ResourceNamespace ::AuthorSerializer , association . serializer )
162+ when :description
163+ assert_instance_of ( ResourceNamespace ::DescriptionSerializer , association . serializer )
164+ else
165+ flunk "Unknown association: #{ key } "
166+ end
167+ end
168+ end
169+ end
170+
171+ class NestedSerializersTest < Minitest ::Test
172+ Post = Class . new ( ::Model )
173+ Comment = Class . new ( ::Model )
174+ Author = Class . new ( ::Model )
175+ Description = Class . new ( ::Model )
176+ class PostSerializer < ActiveModel ::Serializer
177+ has_many :comments
178+ CommentSerializer = Class . new ( ActiveModel ::Serializer )
179+ belongs_to :author
180+ AuthorSerializer = Class . new ( ActiveModel ::Serializer )
181+ has_one :description
182+ DescriptionSerializer = Class . new ( ActiveModel ::Serializer )
183+ end
184+
185+ def setup
186+ @comment = Comment . new
187+ @author = Author . new
188+ @description = Description . new
189+ @post = Post . new ( comments : [ @comment ] ,
190+ author : @author ,
191+ description : @description )
192+ @post_serializer = PostSerializer . new ( @post )
193+ end
194+
195+ def test_associations_namespaced_resources
196+ @post_serializer . associations . each do |association |
197+ case association . key
198+ when :comments
199+ assert_instance_of ( PostSerializer ::CommentSerializer , association . serializer . first )
200+ when :author
201+ assert_instance_of ( PostSerializer ::AuthorSerializer , association . serializer )
202+ when :description
203+ assert_instance_of ( PostSerializer ::DescriptionSerializer , association . serializer )
204+ else
205+ flunk "Unknown association: #{ key } "
206+ end
207+ end
208+ end
209+ end
128210 end
129211 end
130212end
0 commit comments