rails-api/active_model_serializers — pull request #390 by plexus (2013-09-25 10:32:26+00:00)
Title: Use the DefaultSerializer for embedded objects when no serializer is specified

When using `embed :ids, include: true`, and the model class being embedded does
not implement `active_model_serializer`, then a default serialization should
happen.

The else branch in `ActiveModel::Serializer::Association#find_serializable` did
not yet have a test case, and would cause the following error :

NoMethodError: undefined method `object' for #
active_model_serializers/lib/active_model/serializer.rb:411:in `block in merge_association'

This is because `merge_association` calls `find_serializable`, and expects an
object that responds to `#object` and `#serializable_hash`, which is not the
case for the model instance itself. This commit wraps the object in a
DefaultSerializer so it satisfies the interface the caller expects.