Do not convert root and meta_key to Strings

This commit is contained in:
Santiago Pastorino
2013-09-15 23:43:41 -03:00
parent 75e9a2599d
commit daa9304398
5 changed files with 30 additions and 30 deletions

View File

@@ -8,29 +8,29 @@ module ActiveModel
end
def test_meta
profile_serializer = ProfileSerializer.new(@profile, root: 'profile', meta: { 'total' => 10 })
profile_serializer = ProfileSerializer.new(@profile, root: 'profile', meta: { total: 10 })
assert_equal({
'profile' => {
name: 'Name 1',
description: 'Description 1'
},
'meta' => {
'total' => 10
meta: {
total: 10
}
}, profile_serializer.as_json)
end
def test_meta_using_meta_key
profile_serializer = ProfileSerializer.new(@profile, root: 'profile', meta_key: :my_meta, my_meta: { 'total' => 10 })
profile_serializer = ProfileSerializer.new(@profile, root: 'profile', meta_key: :my_meta, my_meta: { total: 10 })
assert_equal({
'profile' => {
name: 'Name 1',
description: 'Description 1'
},
'my_meta' => {
'total' => 10
my_meta: {
total: 10
}
}, profile_serializer.as_json)
end

View File

@@ -6,7 +6,7 @@ module ActiveModel
def setup
@old_root = ProfileSerializer._root
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
@serializer = ProfileSerializer.new(@profile, root: 'initialize')
@serializer = ProfileSerializer.new(@profile, root: :initialize)
ProfileSerializer._root = true
end
@@ -22,7 +22,7 @@ module ActiveModel
def test_root_using_as_json
assert_equal({
'initialize' => {
initialize: {
name: 'Name 1', description: 'Description 1'
}
}, @serializer.as_json)
@@ -40,10 +40,10 @@ module ActiveModel
def test_root_as_argument_takes_precedence
assert_equal({
'argument' => {
argument: {
name: 'Name 1', description: 'Description 1'
}
}, @serializer.as_json(root: 'argument'))
}, @serializer.as_json(root: :argument))
end
def test_using_false_root_in_initializer_takes_precedence
@@ -59,7 +59,7 @@ module ActiveModel
class RootInSerializerTest < ActiveModel::TestCase
def setup
@old_root = ProfileSerializer._root
ProfileSerializer._root = 'in_serializer'
ProfileSerializer._root = :in_serializer
profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
@serializer = ProfileSerializer.new(profile)
@rooted_serializer = ProfileSerializer.new(profile, root: :initialize)
@@ -77,7 +77,7 @@ module ActiveModel
def test_root_using_as_json
assert_equal({
'in_serializer' => {
in_serializer: {
name: 'Name 1', description: 'Description 1'
}
}, @serializer.as_json)
@@ -85,7 +85,7 @@ module ActiveModel
def test_root_in_initializer_takes_precedence
assert_equal({
'initialize' => {
initialize: {
name: 'Name 1', description: 'Description 1'
}
}, @rooted_serializer.as_json)
@@ -93,7 +93,7 @@ module ActiveModel
def test_root_as_argument_takes_precedence
assert_equal({
'argument' => {
argument: {
name: 'Name 1', description: 'Description 1'
}
}, @rooted_serializer.as_json(root: :argument))