@@ -31,13 +31,13 @@ def test_has_many_and_has_one
3131
3232 case key
3333 when :posts
34- assert_equal ( { include_data : true } , options )
34+ assert_equal true , options . fetch ( :include_data )
3535 assert_kind_of ( ActiveModelSerializers . config . collection_serializer , serializer )
3636 when :bio
37- assert_equal ( { include_data : true } , options )
37+ assert_equal true , options . fetch ( :include_data )
3838 assert_nil serializer
3939 when :roles
40- assert_equal ( { include_data : true } , options )
40+ assert_equal true , options . fetch ( :include_data )
4141 assert_kind_of ( ActiveModelSerializers . config . collection_serializer , serializer )
4242 else
4343 flunk "Unknown association: #{ key } "
@@ -79,7 +79,7 @@ def test_belongs_to
7979 flunk "Unknown association: #{ key } "
8080 end
8181
82- assert_equal ( { include_data : true } , association . options )
82+ assert_equal true , association . options . fetch ( :include_data )
8383 end
8484 end
8585
@@ -291,11 +291,23 @@ def test_illegal_conditional_associations
291291 end
292292
293293 class InheritedSerializerTest < ActiveSupport ::TestCase
294+ class PostSerializer < ActiveModel ::Serializer
295+ belongs_to :author
296+ has_many :comments
297+ belongs_to :blog
298+ end
299+
294300 class InheritedPostSerializer < PostSerializer
295301 belongs_to :author , polymorphic : true
296302 has_many :comments , key : :reviews
297303 end
298304
305+ class AuthorSerializer < ActiveModel ::Serializer
306+ has_many :posts
307+ has_many :roles
308+ has_one :bio
309+ end
310+
299311 class InheritedAuthorSerializer < AuthorSerializer
300312 has_many :roles , polymorphic : true
301313 has_one :bio , polymorphic : true
@@ -333,9 +345,18 @@ def setup
333345 end
334346
335347 test 'a serializer inheriting from another serializer can redefine belongs_to associations' do
336- expected = [ :author , :comments , :blog ] . sort
337- result = ( @inherited_post_associations - @post_associations ) . map ( &:name ) . sort
338- assert_equal ( result , expected )
348+ assert_equal [ :author , :comments , :blog ] , @post_associations . map ( &:name )
349+ assert_equal [ :author , :comments , :blog , :comments ] , @inherited_post_associations . map ( &:name )
350+
351+ refute @post_associations . detect { |assoc | assoc . name == :author } . options . key? ( :polymorphic )
352+ assert_equal true , @inherited_post_associations . detect { |assoc | assoc . name == :author } . options . fetch ( :polymorphic )
353+
354+ refute @post_associations . detect { |assoc | assoc . name == :comments } . options . key? ( :key )
355+ original_comment_assoc , new_comments_assoc = @inherited_post_associations . select { |assoc | assoc . name == :comments }
356+ refute original_comment_assoc . options . key? ( :key )
357+ assert_equal :reviews , new_comments_assoc . options . fetch ( :key )
358+
359+ assert_equal @post_associations . detect { |assoc | assoc . name == :blog } , @inherited_post_associations . detect { |assoc | assoc . name == :blog }
339360 end
340361
341362 test 'a serializer inheriting from another serializer can have an additional association with the same name but with different key' do
0 commit comments