mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Associations refactoring
* Move all associations related code from Serializer class to Associations module * Introduce Reflection class hierarchy * Introduce Association class * Rid off Serializer#each_association * Introduce Serializer#associations enumerator
This commit is contained in:
36
test/serializers/association_macros_test.rb
Normal file
36
test/serializers/association_macros_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class AssociationMacrosTest < Minitest::Test
|
||||
AuthorSummarySerializer = Class.new
|
||||
class AssociationsTestSerializer < Serializer
|
||||
belongs_to :author, serializer: AuthorSummarySerializer
|
||||
has_many :comments, embed: :ids
|
||||
has_one :category
|
||||
end
|
||||
|
||||
def before_setup
|
||||
@reflections = AssociationsTestSerializer._reflections
|
||||
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, embed: :ids)
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user