Support passing a custom ArraySerializer for has_many associations

Thanks @phoet

Closes #316
This commit is contained in:
Santiago Pastorino
2013-10-29 00:26:42 -02:00
parent ebe3afe716
commit 49ab359a34
3 changed files with 21 additions and 4 deletions

View File

@@ -129,6 +129,21 @@ module ActiveModel
comments: [{ content: 'fake' }, { content: 'fake' }]
}, @post_serializer.as_json)
end
def test_associations_using_a_given_array_serializer
@association.embed = :ids
@association.embed_in_root = true
@association.serializer_class = Class.new(ActiveModel::ArraySerializer) do
def serializable_object
{ my_content: ['fake'] }
end
end
assert_equal({
'post' => { title: 'Title 1', body: 'Body 1', 'comment_ids' => @post.comments.map { |c| c.object_id } },
comments: { my_content: ['fake'] }
}, @post_serializer.as_json)
end
end
end
end