mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Style/StringLiterals single quote all the things
This commit is contained in:
@@ -33,10 +33,10 @@ module ActionController
|
||||
expected = {
|
||||
data: {
|
||||
id: assigns(:profile).id.to_s,
|
||||
type: "profiles",
|
||||
type: 'profiles',
|
||||
attributes: {
|
||||
name: "Name 1",
|
||||
description: "Description 1",
|
||||
name: 'Name 1',
|
||||
description: 'Description 1',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,11 +100,11 @@ module ActionController
|
||||
get :render_array_using_explicit_serializer_and_custom_serializers
|
||||
|
||||
expected = [
|
||||
{ "title" => "New Post",
|
||||
"body" => "Body",
|
||||
"id" => assigns(:post).id,
|
||||
"comments" => [{"id" => 1}, {"id" => 2}],
|
||||
"author" => { "id" => assigns(:author).id }
|
||||
{ 'title' => 'New Post',
|
||||
'body' => 'Body',
|
||||
'id' => assigns(:post).id,
|
||||
'comments' => [{'id' => 1}, {'id' => 2}],
|
||||
'author' => { 'id' => assigns(:author).id }
|
||||
}
|
||||
]
|
||||
|
||||
@@ -116,13 +116,13 @@ module ActionController
|
||||
|
||||
expected = {
|
||||
id: 1337,
|
||||
name: "Amazing Place",
|
||||
name: 'Amazing Place',
|
||||
locations: [
|
||||
{
|
||||
id: 42,
|
||||
lat: "-23.550520",
|
||||
lng: "-46.633309",
|
||||
place: "Nowhere" # is a virtual attribute on LocationSerializer
|
||||
lat: '-23.550520',
|
||||
lng: '-46.633309',
|
||||
place: 'Nowhere' # is a virtual attribute on LocationSerializer
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ module ActionController
|
||||
@first_comment.author = @author2
|
||||
@second_comment.post = @post
|
||||
@second_comment.author = nil
|
||||
@post2 = Post.new(id: 2, title: "Another Post", body: "Body")
|
||||
@post2 = Post.new(id: 2, title: 'Another Post', body: 'Body')
|
||||
@post2.author = @author
|
||||
@post2.comments = []
|
||||
@blog = Blog.new(id: 1, name: "My Blog!!")
|
||||
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
||||
@post.blog = @blog
|
||||
@post2.blog = @blog
|
||||
end
|
||||
@@ -100,37 +100,37 @@ module ActionController
|
||||
response = JSON.parse(@response.body)
|
||||
expected_linked = [
|
||||
{
|
||||
"id" => "1",
|
||||
"type" => "authors",
|
||||
"attributes" => {
|
||||
"name" => "Steve K."
|
||||
'id' => '1',
|
||||
'type' => 'authors',
|
||||
'attributes' => {
|
||||
'name' => 'Steve K.'
|
||||
},
|
||||
"relationships" => {
|
||||
"posts" => { "data" => [] },
|
||||
"roles" => { "data" => [{ "type" =>"roles", "id" => "1" }, { "type" =>"roles", "id" => "2" }] },
|
||||
"bio" => { "data" => nil }
|
||||
'relationships' => {
|
||||
'posts' => { 'data' => [] },
|
||||
'roles' => { 'data' => [{ 'type' =>'roles', 'id' => '1' }, { 'type' =>'roles', 'id' => '2' }] },
|
||||
'bio' => { 'data' => nil }
|
||||
}
|
||||
}, {
|
||||
"id" => "1",
|
||||
"type" => "roles",
|
||||
"attributes" => {
|
||||
"name" => "admin",
|
||||
"description" => nil,
|
||||
"slug" => "admin-1"
|
||||
'id' => '1',
|
||||
'type' => 'roles',
|
||||
'attributes' => {
|
||||
'name' => 'admin',
|
||||
'description' => nil,
|
||||
'slug' => 'admin-1'
|
||||
},
|
||||
"relationships" => {
|
||||
"author" => { "data" => { "type" =>"authors", "id" => "1" } }
|
||||
'relationships' => {
|
||||
'author' => { 'data' => { 'type' =>'authors', 'id' => '1' } }
|
||||
}
|
||||
}, {
|
||||
"id" => "2",
|
||||
"type" => "roles",
|
||||
"attributes" => {
|
||||
"name" => "colab",
|
||||
"description" => nil,
|
||||
"slug" => "colab-2"
|
||||
'id' => '2',
|
||||
'type' => 'roles',
|
||||
'attributes' => {
|
||||
'name' => 'colab',
|
||||
'description' => nil,
|
||||
'slug' => 'colab-2'
|
||||
},
|
||||
"relationships" => {
|
||||
"author" => { "data" => { "type" =>"authors", "id" => "1" } }
|
||||
'relationships' => {
|
||||
'author' => { 'data' => { 'type' =>'authors', 'id' => '1' } }
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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,48 +59,48 @@ 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"}
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 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"}
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 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']
|
||||
end
|
||||
|
||||
@@ -21,20 +21,20 @@ module ActionController
|
||||
def render_array_using_custom_root
|
||||
with_adapter ActiveModel::Serializer::Adapter::Json do
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: [@profile], root: "custom_root"
|
||||
render json: [@profile], root: 'custom_root'
|
||||
end
|
||||
end
|
||||
|
||||
def render_array_that_is_empty_using_custom_root
|
||||
with_adapter ActiveModel::Serializer::Adapter::Json do
|
||||
render json: [], root: "custom_root"
|
||||
render json: [], root: 'custom_root'
|
||||
end
|
||||
end
|
||||
|
||||
def render_object_using_custom_root
|
||||
with_adapter ActiveModel::Serializer::Adapter::Json do
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: @profile, root: "custom_root"
|
||||
render json: @profile, root: 'custom_root'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -159,8 +159,8 @@ module ActionController
|
||||
get :render_using_implicit_serializer
|
||||
|
||||
expected = {
|
||||
name: "Name 1",
|
||||
description: "Description 1"
|
||||
name: 'Name 1',
|
||||
description: 'Description 1'
|
||||
}
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
@@ -173,10 +173,10 @@ module ActionController
|
||||
expected = {
|
||||
data: {
|
||||
id: assigns(:profile).id.to_s,
|
||||
type: "profiles",
|
||||
type: 'profiles',
|
||||
attributes: {
|
||||
name: "Name 1",
|
||||
description: "Description 1"
|
||||
name: 'Name 1',
|
||||
description: 'Description 1'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -250,10 +250,10 @@ module ActionController
|
||||
data: [
|
||||
{
|
||||
id: assigns(:profiles).first.id.to_s,
|
||||
type: "profiles",
|
||||
type: 'profiles',
|
||||
attributes: {
|
||||
name: "Name 1",
|
||||
description: "Description 1"
|
||||
name: 'Name 1',
|
||||
description: 'Description 1'
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -335,8 +335,8 @@ module ActionController
|
||||
response = JSON.parse(@response.body)
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal 'ZOMG A ROLE', response["name"]
|
||||
assert_equal 'HUEHUEBRBR', response["description"]
|
||||
assert_equal 'ZOMG A ROLE', response['name']
|
||||
assert_equal 'HUEHUEBRBR', response['description']
|
||||
end
|
||||
|
||||
def test_render_with_fragment_except_cache_enable
|
||||
@@ -345,8 +345,8 @@ module ActionController
|
||||
response = JSON.parse(@response.body)
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal 5, response["rating"]
|
||||
assert_equal 'lol', response["content"]
|
||||
assert_equal 5, response['rating']
|
||||
assert_equal 'lol', response['content']
|
||||
end
|
||||
|
||||
def test_render_fragment_changed_object_with_relationship
|
||||
@@ -357,11 +357,11 @@ module ActionController
|
||||
response = JSON.parse(@response.body)
|
||||
|
||||
expected_return = {
|
||||
"id"=>1,
|
||||
"time"=>Time.now.to_s,
|
||||
"likeable" => {
|
||||
"id"=>1,
|
||||
"body"=>"ZOMG A COMMENT"
|
||||
'id'=>1,
|
||||
'time'=>Time.now.to_s,
|
||||
'likeable' => {
|
||||
'id'=>1,
|
||||
'body'=>'ZOMG A COMMENT'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ module ActionController
|
||||
],
|
||||
blog: {
|
||||
id:999,
|
||||
name: "Custom blog"
|
||||
name: 'Custom blog'
|
||||
},
|
||||
author: {
|
||||
id: 1,
|
||||
@@ -416,7 +416,7 @@ module ActionController
|
||||
true
|
||||
end
|
||||
}.new
|
||||
assert_equal "", (capture(:stderr) {
|
||||
assert_equal '', (capture(:stderr) {
|
||||
controller.get_serializer(Profile.new)
|
||||
})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user