mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Rubocop: Consistent spacing
This commit is contained in:
@@ -103,7 +103,7 @@ module ActionController
|
||||
{ 'title' => 'New Post',
|
||||
'body' => 'Body',
|
||||
'id' => assigns(:post).id,
|
||||
'comments' => [{'id' => 1}, {'id' => 2}],
|
||||
'comments' => [{ 'id' => 1 }, { 'id' => 2 }],
|
||||
'author' => { 'id' => assigns(:author).id }
|
||||
}
|
||||
]
|
||||
|
||||
@@ -75,7 +75,7 @@ module ActionController
|
||||
|
||||
def render_collection_with_include
|
||||
setup_post
|
||||
render json: [@post], include: ['author', 'comments'], adapter: :json_api
|
||||
render json: [@post], include: %w(author comments), adapter: :json_api
|
||||
end
|
||||
end
|
||||
|
||||
@@ -107,7 +107,7 @@ module ActionController
|
||||
},
|
||||
'relationships' => {
|
||||
'posts' => { 'data' => [] },
|
||||
'roles' => { 'data' => [{ 'type' =>'roles', 'id' => '1' }, { 'type' =>'roles', 'id' => '2' }] },
|
||||
'roles' => { 'data' => [{ 'type' => 'roles', 'id' => '1' }, { 'type' => 'roles', 'id' => '2' }] },
|
||||
'bio' => { 'data' => nil }
|
||||
}
|
||||
}, {
|
||||
@@ -119,7 +119,7 @@ module ActionController
|
||||
'slug' => 'admin-1'
|
||||
},
|
||||
'relationships' => {
|
||||
'author' => { 'data' => { 'type' =>'authors', 'id' => '1' } }
|
||||
'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
|
||||
}
|
||||
}, {
|
||||
'id' => '2',
|
||||
@@ -130,7 +130,7 @@ module ActionController
|
||||
'slug' => 'colab-2'
|
||||
},
|
||||
'relationships' => {
|
||||
'author' => { 'data' => { 'type' =>'authors', 'id' => '1' } }
|
||||
'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -172,7 +172,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def has_type?(collection, value)
|
||||
collection.detect { |i| i['type'] == value}
|
||||
collection.detect { |i| i['type'] == value }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,11 +47,11 @@ module ActionController
|
||||
tests PaginationTestController
|
||||
|
||||
def test_render_pagination_links_with_will_paginate
|
||||
expected_links = { 'self'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1"}
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||
|
||||
get :render_pagination_using_will_paginate, page: { number: 2, size: 1 }
|
||||
response = JSON.parse(@response.body)
|
||||
@@ -59,47 +59,47 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_only_last_and_next_pagination_links
|
||||
expected_links = { 'self'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||
'next'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
||||
'last'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2"}
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2" }
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_pagination_links_with_kaminari
|
||||
expected_links = { 'self'=>"#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1"}
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||
get :render_pagination_using_kaminari, page: { number: 2, size: 1 }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_prev_and_first_pagination_links
|
||||
expected_links = { 'self'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'first'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev'=>"#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1"}
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1" }
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_last_and_next_pagination_links_with_additional_params
|
||||
expected_links = { 'self'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||
'next'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
||||
'last'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional"}
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional" }
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }, teste: 'additional'
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_prev_and_first_pagination_links_with_additional_params
|
||||
expected_links = { 'self'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
||||
'first'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
||||
'prev'=>"#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional"}
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional" }
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }, teste: 'additional'
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
|
||||
@@ -48,7 +48,6 @@ module ActionController
|
||||
|
||||
def render_array_using_implicit_serializer_and_meta
|
||||
with_adapter ActiveModel::Serializer::Adapter::JsonApi do
|
||||
|
||||
@profiles = [
|
||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
]
|
||||
@@ -69,11 +68,11 @@ module ActionController
|
||||
end
|
||||
|
||||
def render_json_object_without_serializer
|
||||
render json: {error: 'Result is Invalid'}
|
||||
render json: { error: 'Result is Invalid' }
|
||||
end
|
||||
|
||||
def render_json_array_object_without_serializer
|
||||
render json: [{error: 'Result is Invalid'}]
|
||||
render json: [{ error: 'Result is Invalid' }]
|
||||
end
|
||||
|
||||
def update_and_render_object_with_cache_enabled
|
||||
@@ -138,6 +137,7 @@ module ActionController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_cached_serializer(obj)
|
||||
ActiveModel::SerializableResource.new(obj).to_json
|
||||
end
|
||||
@@ -188,7 +188,7 @@ module ActionController
|
||||
def test_render_array_using_custom_root
|
||||
get :render_array_using_custom_root
|
||||
|
||||
expected = {custom_roots: [{name: 'Name 1', description: 'Description 1'}]}
|
||||
expected = { custom_roots: [{ name: 'Name 1', description: 'Description 1' }] }
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@@ -196,7 +196,7 @@ module ActionController
|
||||
def test_render_array_that_is_empty_using_custom_root
|
||||
get :render_array_that_is_empty_using_custom_root
|
||||
|
||||
expected = {custom_roots: []}
|
||||
expected = { custom_roots: [] }
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@@ -204,7 +204,7 @@ module ActionController
|
||||
def test_render_object_using_custom_root
|
||||
get :render_object_using_custom_root
|
||||
|
||||
expected = {custom_root: {name: 'Name 1', description: 'Description 1'}}
|
||||
expected = { custom_root: { name: 'Name 1', description: 'Description 1' } }
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@@ -213,7 +213,7 @@ module ActionController
|
||||
get :render_json_object_without_serializer
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
expected_body = {error: 'Result is Invalid'}
|
||||
expected_body = { error: 'Result is Invalid' }
|
||||
assert_equal expected_body.to_json, @response.body
|
||||
end
|
||||
|
||||
@@ -221,7 +221,7 @@ module ActionController
|
||||
get :render_json_array_object_without_serializer
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
expected_body = [{error: 'Result is Invalid'}]
|
||||
expected_body = [{ error: 'Result is Invalid' }]
|
||||
assert_equal expected_body.to_json, @response.body
|
||||
end
|
||||
|
||||
@@ -357,11 +357,11 @@ module ActionController
|
||||
response = JSON.parse(@response.body)
|
||||
|
||||
expected_return = {
|
||||
'id'=>1,
|
||||
'time'=>Time.now.to_s,
|
||||
'id' => 1,
|
||||
'time' => Time.now.to_s,
|
||||
'likeable' => {
|
||||
'id'=>1,
|
||||
'body'=>'ZOMG A COMMENT'
|
||||
'id' => 1,
|
||||
'body' => 'ZOMG A COMMENT'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ module ActionController
|
||||
body: 'ZOMG A COMMENT' }
|
||||
],
|
||||
blog: {
|
||||
id:999,
|
||||
id: 999,
|
||||
name: 'Custom blog'
|
||||
},
|
||||
author: {
|
||||
|
||||
Reference in New Issue
Block a user