mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Support for setting root element
This commit is contained in:
@@ -318,6 +318,16 @@ class SerializerTest < ActiveModel::TestCase
|
||||
assert_equal({ :author => nil }, serializer.new(blog, :scope => user).as_json)
|
||||
end
|
||||
|
||||
def test_true_root
|
||||
blog = Blog.new
|
||||
|
||||
assert_equal({
|
||||
:blog_with_root => {
|
||||
:author => nil,
|
||||
}
|
||||
}, BlogWithRootSerializer.new(blog).as_json)
|
||||
end
|
||||
|
||||
def test_root_false_on_load_active_model_serializers
|
||||
begin
|
||||
ActiveSupport.on_load(:active_model_serializers) do
|
||||
|
||||
@@ -146,6 +146,10 @@ class BlogSerializer < ActiveModel::Serializer
|
||||
has_one :author, :serializer => AuthorSerializer
|
||||
end
|
||||
|
||||
class BlogWithRootSerializer < BlogSerializer
|
||||
root true
|
||||
end
|
||||
|
||||
class CustomPostSerializer < ActiveModel::Serializer
|
||||
attributes :title
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user