diff --git a/test/serializers/inline_serializers_test.rb b/test/serializers/inline_serializers_test.rb new file mode 100644 index 000000000..74be69185 --- /dev/null +++ b/test/serializers/inline_serializers_test.rb @@ -0,0 +1,25 @@ +module ActiveModel + class Serializer + class InlineSerializersTest < Minitest::Test + class PostSerializer < ActiveModel::Serializer + attributes :title, :body + belongs_to :author + has_many :comments do + attributes :body + belongs_to :author + end + end + + def test_inline_serializer_defined_if_block_given + refute_nil("#{self.class}::PostSerializer::CommentSerializer".safe_constantize) + assert_equal(ActiveModel::Serializer, PostSerializer::CommentSerializer.superclass) + assert_equal([:author], PostSerializer::CommentSerializer._reflections.map(&:name)) + assert_equal([:body], PostSerializer::CommentSerializer._attributes) + end + + def test_inline_serializer_not_defined_unless_block_given + assert_nil("#{self.class}::PostSerializer::AuthorSerializer".safe_constantize) + end + end + end +end