Created
May 16, 2013 20:28
-
-
Save carllerche/5594832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SpecHelper | |
module Helpers | |
def default_serializer_options | |
{} | |
end | |
def serialization_scope | |
nil | |
end | |
alias _serialization_scope serialization_scope | |
def serialized(obj, opts = {}) | |
opts = opts.merge(controller: self) | |
if obj.respond_to?(:active_model_serializer) | |
serializer = obj.active_model_serializer | |
end | |
if opts[:serializer] | |
serializer = opts[:serializer] | |
end | |
if serializer | |
unless opts.key?(:root) | |
if el = (obj.respond_to?(:to_ary) && obj.first) | |
opts[:root] ||= el.class.to_s.underscore.pluralize | |
end | |
end | |
obj = ActiveModel::Serializer.build_json(self, obj, opts) | |
obj = obj.as_json | |
end | |
obj | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment