Create DefaultSerializer so that as_json uses same interface.

This is to ensure that PORO's as_json is called if no serializer
is specified.

Original behaviour was that serializable_hash was being called,
overriding the as_json method.
This commit is contained in:
Adam Stanton
2013-02-10 09:06:24 -08:00
parent 3e9b366a45
commit 8f6218c587
4 changed files with 13 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ class ArraySerializerTest < ActiveModel::TestCase
serializer = array.active_model_serializer.new(array, :scope => {:scope => true})
assert_equal([
{ :model => "Model" },
{ :last_name => "Valim", :ok => true, :first_name => "Jose", :scope => true },
{ :first_name => "Jose", :last_name => "Valim", :ok => true, :scope => true },
{ :title => "Comment1" }
], serializer.as_json)
end
@@ -51,5 +51,4 @@ class ArraySerializerTest < ActiveModel::TestCase
{ :title => "Post2" }
], serializer.as_json)
end
end

View File

@@ -68,7 +68,7 @@ class MyUserSerializer < ActiveModel::Serializer
end
end
class CommentSerializer
class CommentSerializer < ActiveModel::Serializer
def initialize(comment, options={})
@object = comment
end