mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Rubocop: Consistent spacing
This commit is contained in:
@@ -6,7 +6,7 @@ module ActiveModel
|
||||
def setup
|
||||
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
||||
@author = Author.new(name: 'Joao M. D. Moura')
|
||||
@role = Role.new(name: 'Great Author', description:nil)
|
||||
@role = Role.new(name: 'Great Author', description: nil)
|
||||
@role.author = [@author]
|
||||
@role_serializer = RoleSerializer.new(@role)
|
||||
@spam_serializer = Spam::UnrelatedLinkSerializer.new(@spam)
|
||||
|
||||
@@ -24,21 +24,21 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_includes_post
|
||||
assert_equal({id: 42, title: 'New Post', body: 'Body'}, @adapter.serializable_hash[:comment][:post])
|
||||
assert_equal({ id: 42, title: 'New Post', body: 'Body' }, @adapter.serializable_hash[:comment][:post])
|
||||
end
|
||||
|
||||
def test_include_nil_author
|
||||
serializer = PostSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({post: {title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], blog: {id: 999, name: 'Custom blog'}, author: nil}}, adapter.serializable_hash)
|
||||
assert_equal({ post: { title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], blog: { id: 999, name: 'Custom blog' }, author: nil } }, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_include_nil_author_with_specified_serializer
|
||||
serializer = PostPreviewSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({post: {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
|
||||
|
||||
@@ -26,11 +26,11 @@ module ActiveModel
|
||||
serializer = ArraySerializer.new([@blog], serializer: CustomBlogSerializer)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
expected = {blogs:[{
|
||||
expected = { blogs: [{
|
||||
id: 1,
|
||||
special_attribute: 'Special',
|
||||
articles: [{id: 1,title: 'Hello!!', body: 'Hello, world!!'}, {id: 2, title: 'New Post', body: 'Body'}]
|
||||
}]}
|
||||
articles: [{ id: 1, title: 'Hello!!', body: 'Hello, world!!' }, { id: 2, title: 'New Post', body: 'Body' }]
|
||||
}] }
|
||||
assert_equal expected, adapter.serializable_hash
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ module ActiveModel
|
||||
id: 999,
|
||||
name: 'Custom blog'
|
||||
}
|
||||
}]}
|
||||
}] }
|
||||
assert_equal expected, adapter.serializable_hash
|
||||
end
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ module ActiveModel
|
||||
serializer = PostSerializer.new(@post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
assert_equal([
|
||||
{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
], adapter.serializable_hash[:post][:comments])
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ module ActiveModel
|
||||
assert_equal({
|
||||
id: 42,
|
||||
tags: [
|
||||
{'attributes'=>{'id'=>1, 'name'=>'#hash_tag'}}
|
||||
{ 'attributes' => { 'id' => 1, 'name' => '#hash_tag' } }
|
||||
]
|
||||
}.to_json, adapter.serializable_hash[:post].to_json)
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ module ActiveModel
|
||||
body: 'Body',
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@@ -56,7 +56,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_limiting_linked_post_fields
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'post', fields: {post: [:title]})
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'post', fields: { post: [:title] })
|
||||
expected = [{
|
||||
id: '42',
|
||||
type: 'posts',
|
||||
@@ -64,7 +64,7 @@ module ActiveModel
|
||||
title: 'New Post'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@@ -76,7 +76,7 @@ module ActiveModel
|
||||
serializer = PostSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal({comments: { data: [] }, blog: { data: { type: 'blogs', id: '999' } }, author: { data: nil }}, adapter.serializable_hash[:data][:relationships])
|
||||
assert_equal({ comments: { data: [] }, blog: { data: { type: 'blogs', id: '999' } }, author: { data: nil } }, adapter.serializable_hash[:data][:relationships])
|
||||
end
|
||||
|
||||
def test_include_type_for_association_when_different_than_name
|
||||
@@ -108,7 +108,7 @@ module ActiveModel
|
||||
|
||||
def test_include_linked_resources_with_type_name
|
||||
serializer = BlogSerializer.new(@blog)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer, include: ['writer', 'articles'])
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer, include: %w(writer articles))
|
||||
linked = adapter.serializable_hash[:included]
|
||||
expected = [
|
||||
{
|
||||
@@ -122,7 +122,7 @@ module ActiveModel
|
||||
roles: { data: [] },
|
||||
bio: { data: nil }
|
||||
}
|
||||
},{
|
||||
}, {
|
||||
id: '42',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
@@ -130,7 +130,7 @@ module ActiveModel
|
||||
body: 'Body'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ module ActiveModel
|
||||
]
|
||||
assert_equal(expected, @adapter.serializable_hash[:data])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,8 +27,8 @@ module ActiveModel
|
||||
def test_includes_comment_ids
|
||||
expected = {
|
||||
data: [
|
||||
{ type: 'posts', id: '1'},
|
||||
{ type: 'posts', id: '2'}
|
||||
{ type: 'posts', id: '1' },
|
||||
{ type: 'posts', id: '2' }
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ module ActiveModel
|
||||
@serializer = PostPreviewSerializer.new(@post)
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
||||
@serializer,
|
||||
include: ['comments', 'author']
|
||||
include: %w(comments author)
|
||||
)
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ module ActiveModel
|
||||
id: @author.id.to_s,
|
||||
type: 'authors',
|
||||
relationships: {
|
||||
posts: { data: [ {type: 'posts', id: @post.id.to_s } ] }
|
||||
posts: { data: [{ type: 'posts', id: @post.id.to_s }] }
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -36,7 +36,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_includes_comment_ids
|
||||
expected = { data: [ { type: 'comments', id: '1' }, { type: 'comments', id: '2' } ] }
|
||||
expected = { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] }
|
||||
|
||||
assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:comments])
|
||||
end
|
||||
@@ -68,7 +68,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_limit_fields_of_linked_comments
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments', fields: {comment: [:id]})
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments', fields: { comment: [:id] })
|
||||
expected = [{
|
||||
id: '1',
|
||||
type: 'comments',
|
||||
@@ -117,7 +117,7 @@ module ActiveModel
|
||||
id: '1',
|
||||
type: 'posts',
|
||||
relationships: {
|
||||
tags: { data: [@tag.as_json]}
|
||||
tags: { data: [@tag.as_json] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
@@ -132,8 +132,8 @@ module ActiveModel
|
||||
id: '1',
|
||||
type: 'virtual_values',
|
||||
relationships: {
|
||||
maker: {data: {id: 1}},
|
||||
reviews: {data: [{id: 1}, {id: 2}]}
|
||||
maker: { data: { id: 1 } },
|
||||
reviews: { data: [{ id: 1 }, { id: 2 }] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
|
||||
@@ -45,7 +45,7 @@ module ActiveModel
|
||||
id: '43',
|
||||
type: 'bios',
|
||||
attributes: {
|
||||
content:'AMS Contributor',
|
||||
content: 'AMS Contributor',
|
||||
rating: nil
|
||||
},
|
||||
relationships: {
|
||||
@@ -66,8 +66,8 @@ module ActiveModel
|
||||
id: '1',
|
||||
type: 'virtual_values',
|
||||
relationships: {
|
||||
maker: {data: {id: 1}},
|
||||
reviews: {data: [{id: 1}, {id: 2}]}
|
||||
maker: { data: { id: 1 } },
|
||||
reviews: { data: [{ id: 1 }, { id: 2 }] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ module ActiveModel
|
||||
@post.author = @author
|
||||
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
||||
@post.blog = @blog
|
||||
|
||||
end
|
||||
|
||||
def test_custom_keys
|
||||
@@ -25,11 +24,11 @@ module ActiveModel
|
||||
|
||||
assert_equal({
|
||||
reviews: { data: [
|
||||
{type: 'comments', id: '1'},
|
||||
{type: 'comments', id: '2'}
|
||||
]},
|
||||
writer: { data: {type: 'authors', id: '1'} },
|
||||
site: { data: {type: 'blogs', id: '1' } }
|
||||
{ type: 'comments', id: '1' },
|
||||
{ type: 'comments', id: '2' }
|
||||
] },
|
||||
writer: { data: { type: 'authors', id: '1' } },
|
||||
site: { data: { type: 'blogs', id: '1' } }
|
||||
}, adapter.serializable_hash[:data][:relationships])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ module ActiveModel
|
||||
body: 'Hello, world!!'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' }, { type: 'comments', id: '2' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@@ -107,7 +107,7 @@ module ActiveModel
|
||||
name: 'Steve K.'
|
||||
},
|
||||
relationships: {
|
||||
posts: { data: [ { type: 'posts', id: '10' }, { type: 'posts', id: '30' } ] },
|
||||
posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
|
||||
roles: { data: [] },
|
||||
bio: { data: { type: 'bios', id: '1' } }
|
||||
}
|
||||
@@ -128,7 +128,7 @@ module ActiveModel
|
||||
name: 'Tenderlove'
|
||||
},
|
||||
relationships: {
|
||||
posts: { data: [ { type: 'posts', id:'20' } ] },
|
||||
posts: { data: [{ type: 'posts', id: '20' }] },
|
||||
roles: { data: [] },
|
||||
bio: { data: { type: 'bios', id: '2' } }
|
||||
}
|
||||
@@ -168,9 +168,9 @@ module ActiveModel
|
||||
name: 'Steve K.'
|
||||
},
|
||||
relationships: {
|
||||
posts: { data: [ { type: 'posts', id: '10'}, { type: 'posts', id: '30' }] },
|
||||
posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
|
||||
roles: { data: [] },
|
||||
bio: { data: { type: 'bios', id: '1' }}
|
||||
bio: { data: { type: 'bios', id: '1' } }
|
||||
}
|
||||
}, {
|
||||
id: '10',
|
||||
@@ -180,7 +180,7 @@ module ActiveModel
|
||||
body: 'Hello, world!!'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1'}, { type: 'comments', id: '2' }] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@@ -237,13 +237,13 @@ module ActiveModel
|
||||
},
|
||||
relationships: {
|
||||
comments: {
|
||||
data: [{type: 'comments', id: '1'}, {type: 'comments', id: '2'}]
|
||||
data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }]
|
||||
},
|
||||
blog: {
|
||||
data: {type: 'blogs', id: '999'}
|
||||
data: { type: 'blogs', id: '999' }
|
||||
},
|
||||
author: {
|
||||
data: {type: 'authors', id: '1'}
|
||||
data: { type: 'authors', id: '1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ module ActiveModel
|
||||
body: 'Hello, world!!'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' }, { type: 'comments', id: '2' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
||||
author: { data: nil }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ module ActiveModel
|
||||
]
|
||||
end
|
||||
|
||||
def mock_request(query_parameters={}, original_url=URI)
|
||||
def mock_request(query_parameters = {}, original_url = URI)
|
||||
context = Minitest::Mock.new
|
||||
context.expect(:original_url, original_url )
|
||||
context.expect(:original_url, original_url)
|
||||
context.expect(:query_parameters, query_parameters)
|
||||
@options = {}
|
||||
@options[:context] = context
|
||||
@@ -42,17 +42,17 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def data
|
||||
{ data:[
|
||||
{ id:'1', type:'profiles', attributes:{name:'Name 1', description:'Description 1' } },
|
||||
{ id:'2', type:'profiles', attributes:{name:'Name 2', description:'Description 2' } },
|
||||
{ id:'3', type:'profiles', attributes:{name:'Name 3', description:'Description 3' } }
|
||||
{ data: [
|
||||
{ id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } },
|
||||
{ id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } },
|
||||
{ id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } }
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def links
|
||||
{
|
||||
links:{
|
||||
links: {
|
||||
self: "#{URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
prev: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
@@ -74,7 +74,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def expected_response_with_pagination_links_and_additional_params
|
||||
new_links = links[:links].each_with_object({}) {|(key, value), hash| hash[key] = "#{value}&test=test" }
|
||||
new_links = links[:links].each_with_object({}) { |(key, value), hash| hash[key] = "#{value}&test=test" }
|
||||
{}.tap do |hash|
|
||||
hash[:data] = [data.values.flatten.second]
|
||||
hash.merge! links: new_links
|
||||
|
||||
@@ -23,8 +23,8 @@ module ActiveModel
|
||||
|
||||
def test_has_many
|
||||
assert_equal([
|
||||
{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
], @adapter.serializable_hash[:post][:comments])
|
||||
end
|
||||
|
||||
@@ -34,11 +34,11 @@ module ActiveModel
|
||||
|
||||
assert_equal({
|
||||
id: 1,
|
||||
reviews: [{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
reviews: [{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
],
|
||||
writer: {id: 1, name: 'Steve K.'},
|
||||
site: {id: 1, name: 'My Blog!!'}
|
||||
writer: { id: 1, name: 'Steve K.' },
|
||||
site: { id: 1, name: 'My Blog!!' }
|
||||
}, adapter.serializable_hash[:post])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user