Skip to content

Commit c0dc25c

Browse files
committed
Add tests.
1 parent 9f0938c commit c0dc25c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module ActiveModel
2+
class Serializer
3+
class InlineSerializersTest < Minitest::Test
4+
class PostSerializer < ActiveModel::Serializer
5+
attributes :title, :body
6+
belongs_to :author
7+
has_many :comments do
8+
attributes :body
9+
belongs_to :author
10+
end
11+
end
12+
13+
def test_inline_serializer_defined_if_block_given
14+
refute_nil("#{self.class}::PostSerializer::CommentSerializer".safe_constantize)
15+
assert_equal(ActiveModel::Serializer, PostSerializer::CommentSerializer.superclass)
16+
assert_equal([:author], PostSerializer::CommentSerializer._reflections.map(&:name))
17+
assert_equal([:body], PostSerializer::CommentSerializer._attributes)
18+
end
19+
20+
def test_inline_serializer_not_defined_unless_block_given
21+
assert_nil("#{self.class}::PostSerializer::AuthorSerializer".safe_constantize)
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)