Skip to content

Commit

Permalink
Style/StringLiterals single quote all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Sep 4, 2015
1 parent 09c97de commit bdfe13c
Show file tree
Hide file tree
Showing 36 changed files with 347 additions and 347 deletions.
2 changes: 1 addition & 1 deletion lib/action_controller/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def serialization_scope

def get_serializer(resource, options = {})
if ! use_adapter?
warn "ActionController::Serialization#use_adapter? has been removed. "\
warn 'ActionController::Serialization#use_adapter? has been removed. '\
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource#serialize"
options[:adapter] = false
end
Expand Down
8 changes: 4 additions & 4 deletions lib/active_model/serializer/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.create(resource, options = {})
end

def self.adapter_class(adapter)
adapter_name = adapter.to_s.classify.sub("API", "Api")
adapter_name = adapter.to_s.classify.sub('API', 'Api')
"ActiveModel::Serializer::Adapter::#{adapter_name}".safe_constantize
end

Expand Down Expand Up @@ -68,12 +68,12 @@ def cache_key
parts = []
parts << object_cache_key
parts << @klass._cache_digest unless @klass._cache_options && @klass._cache_options[:skip_digest]
parts.join("/")
parts.join('/')
end

def object_cache_key
object_time_safe = @cached_serializer.object.updated_at
object_time_safe = object_time_safe.strftime("%Y%m%d%H%M%S%9N") if object_time_safe.respond_to?(:strftime)
object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
(@klass._cache_key) ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key
end

Expand All @@ -82,7 +82,7 @@ def meta
end

def meta_key
serializer.meta_key || "meta"
serializer.meta_key || 'meta'
end

def root
Expand Down
4 changes: 2 additions & 2 deletions lib/active_model/serializer/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Tests
# <tt>serializable_hash</tt> returns a hash representation of a object's attributes.
# Typically, it is implemented by including ActiveModel::Serialization.
def test_serializable_hash
assert_respond_to resource, :serializable_hash, "The resource should respond to serializable_hash"
assert_respond_to resource, :serializable_hash, 'The resource should respond to serializable_hash'
resource.serializable_hash
resource.serializable_hash(nil)
end
Expand All @@ -35,7 +35,7 @@ def test_serializable_hash
# <tt>read_attribute_for_serialization</tt> gets the attribute value for serialization
# Typically, it is implemented by including ActiveModel::Serialization.
def test_read_attribute_for_serialization
assert_respond_to resource, :read_attribute_for_serialization, "The resource should respond to read_attribute_for_serialization"
assert_respond_to resource, :read_attribute_for_serialization, 'The resource should respond to read_attribute_for_serialization'
actual_arity = resource.method(:read_attribute_for_serialization).arity
if defined?(::Rubinius)
# 1 for def read_attribute_for_serialization(name); end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveModel
class Serializer
VERSION = "0.10.0.rc2"
VERSION = '0.10.0.rc2'
end
end
12 changes: 6 additions & 6 deletions lib/generators/serializer/serializer_generator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Rails
module Generators
class SerializerGenerator < NamedBase
source_root File.expand_path("../templates", __FILE__)
check_class_collision :suffix => "Serializer"
source_root File.expand_path('../templates', __FILE__)
check_class_collision :suffix => 'Serializer'

argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'

class_option :parent, :type => :string, :desc => "The parent class for the generated serializer"
class_option :parent, :type => :string, :desc => 'The parent class for the generated serializer'

def create_serializer_file
template 'serializer.rb.erb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
Expand All @@ -26,9 +26,9 @@ def parent_class_name
if options[:parent]
options[:parent]
elsif defined?(::ApplicationSerializer)
"ApplicationSerializer"
'ApplicationSerializer'
else
"ActiveModel::Serializer"
'ActiveModel::Serializer'
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/action_controller/adapter_selector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def test_render_using_adapter_override
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',
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions test/action_controller/explicit_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def test_render_array_using_explicit_serializer_and_custom_serializers
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 }
}
]

Expand All @@ -116,13 +116,13 @@ def test_render_using_explicit_each_serializer

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
}
]
}
Expand Down
52 changes: 26 additions & 26 deletions test/action_controller/json_api/linked_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def setup_post
@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
Expand Down Expand Up @@ -100,37 +100,37 @@ def test_render_resource_with_nested_has_many_include
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' } }
}
}
]
Expand Down
48 changes: 24 additions & 24 deletions test/action_controller/json_api/pagination_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,60 +47,60 @@ def render_array_without_pagination_links
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)
assert_equal expected_links, response['links']
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
Expand Down
Loading

0 comments on commit bdfe13c

Please sign in to comment.