Merge pull request #998 from joaomdmoura/changing_root_to_model_class_name

Changing root to model class name
This commit is contained in:
João Moura 2015-07-23 02:18:47 -04:00
commit e1c25e86e3
7 changed files with 8 additions and 9 deletions

View File

@ -169,7 +169,7 @@ module ActiveModel
end
def json_key
@root || self.class.root_name
@root || object.class.model_name.to_s.downcase
end
def id

View File

@ -39,7 +39,7 @@ module ActiveModel
serializer = PostPreviewSerializer.new(@anonymous_post)
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
assert_equal({posts: {title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], author: nil}}, adapter.serializable_hash)
assert_equal({post: {title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], author: nil}}, adapter.serializable_hash)
end
end
end

View File

@ -28,7 +28,7 @@ module ActiveModel
@serializer = ArraySerializer.new([@blog], serializer: CustomBlogSerializer)
@adapter = ActiveModel::Serializer::Adapter::Json.new(@serializer)
expected = {custom_blogs:[{
expected = {blogs:[{
id: 1,
special_attribute: "Special",
articles: [{id: 1,title: "Hello!!", body: "Hello, world!!"}, {id: 2, title: "New Post", body: "Body"}]

View File

@ -38,7 +38,7 @@ module ActiveModel
tags: [
{"attributes"=>{"id"=>1, "name"=>"#hash_tag"}}
]
}.to_json, adapter.serializable_hash[:post_with_tags].to_json)
}.to_json, adapter.serializable_hash[:post].to_json)
end
end
end

View File

@ -39,10 +39,9 @@ module ActiveModel
],
writer: {id: 1, name: "Steve K."},
site: {id: 1, name: "My Blog!!"}
}, adapter.serializable_hash[:post_with_custom_keys])
}, adapter.serializable_hash[:post])
end
end
end
end
end

View File

@ -15,7 +15,7 @@ module ActiveModel
def test_json_serializable_hash
adapter = ActiveModel::Serializer::Adapter::Json.new(@blog_serializer)
assert_equal({alternate_blog: { id:1, title:"AMS Hints"}}, adapter.serializable_hash)
assert_equal({blog: { id:1, title:"AMS Hints"}}, adapter.serializable_hash)
end
def test_attribute_inheritance_with_key

View File

@ -15,7 +15,7 @@ module ActiveModel
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10})
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
expected = {
alternate_blog: {
blog: {
id: 1,
title: "AMS Hints"
},
@ -40,7 +40,7 @@ module ActiveModel
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}, meta_key: "haha_meta")
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
expected = {
alternate_blog: {
blog: {
id: 1,
title: "AMS Hints"
},