Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing root to model class name #998

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def initialize(object, options = {})
end

def json_key
@root || self.class.root_name
@root || object.class.model_name.to_s.downcase
end

def id
Expand Down
2 changes: 1 addition & 1 deletion test/adapter/json/belongs_to_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_include_nil_author_with_specified_serializer
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
Expand Down
2 changes: 1 addition & 1 deletion test/adapter/json/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_with_serializer_option
@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"}]
Expand Down
2 changes: 1 addition & 1 deletion test/adapter/json/has_many_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_has_many_with_no_serializer
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
Expand Down
3 changes: 1 addition & 2 deletions test/adapter/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ def test_custom_keys
],
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

2 changes: 1 addition & 1 deletion test/serializers/attribute_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_attributes_definition

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
Expand Down
4 changes: 2 additions & 2 deletions test/serializers/meta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_meta_is_present_with_root
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10})
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
expected = {
alternate_blog: {
blog: {
id: 1,
title: "AMS Hints"
},
Expand All @@ -40,7 +40,7 @@ def test_meta_key_is_used
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"
},
Expand Down