Skip to content

Commit 77fb050

Browse files
committed
Merge pull request #821 from wjordan/patch-1
Fix explicit serializer for associations
2 parents 3505bc6 + f4eb33d commit 77fb050

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def each_association(&block)
176176

177177
def serializer_from_options(options)
178178
opts = {}
179-
serializer = options.fetch(:options, {}).fetch(:serializer, nil)
179+
serializer = options.fetch(:association_options, {}).fetch(:serializer, nil)
180180
opts[:serializer] = serializer if serializer
181181
opts
182182
end

test/adapter/json_api/has_many_explicit_serializer_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ def test_includes_comment_ids
3434
end
3535

3636
def test_includes_linked_comments
37-
assert_equal([{ id: '1', body: "ZOMG A COMMENT", links: { post: @post.id.to_s, author: nil }},
38-
{ id: '2', body: "ZOMG ANOTHER COMMENT", links: { post: @post.id.to_s, author: nil }}],
37+
# If CommentPreviewSerializer is applied correctly the body text will not be present in the output
38+
assert_equal([{ id: '1', links: { post: @post.id.to_s}},
39+
{ id: '2', links: { post: @post.id.to_s}}],
3940
@adapter.serializable_hash[:linked][:comments])
4041
end
4142

0 commit comments

Comments
 (0)