active_model_serializers/test/serializers/association_macros_test.rb
Avon 3ad2457aaf Bugfix/redefine associations on inherited serializers (#1848)
* replace reflection collection type with hash to prevent duplicated associations in some cases

* include tests

* Fix robucup offenses

* Improve test

* Remove usless requirement

* improve tests

* remove custom_options option from Post and InheritedPost serializer

* Improve tests

* update changelog

* update changelog
2016-07-17 16:25:43 -04:00

37 lines
1.0 KiB
Ruby

require 'test_helper'
module ActiveModel
class Serializer
class AssociationMacrosTest < ActiveSupport::TestCase
AuthorSummarySerializer = Class.new
class AssociationsTestSerializer < Serializer
belongs_to :author, serializer: AuthorSummarySerializer
has_many :comments
has_one :category
end
def before_setup
@reflections = AssociationsTestSerializer._reflections.values
end
def test_has_one_defines_reflection
has_one_reflection = HasOneReflection.new(:category, {})
assert_includes(@reflections, has_one_reflection)
end
def test_has_many_defines_reflection
has_many_reflection = HasManyReflection.new(:comments, {})
assert_includes(@reflections, has_many_reflection)
end
def test_belongs_to_defines_reflection
belongs_to_reflection = BelongsToReflection.new(:author, serializer: AuthorSummarySerializer)
assert_includes(@reflections, belongs_to_reflection)
end
end
end
end