Fix RuboCop 0.40 linter errors (#1722)

These errors are breaking the build, which seems to use RuboCop 0.40 [1]
despite the Gemfile.lock pinning rubocop to 0.38.

New lints that I am updating the code style to reflect:

- Style/EmptyCaseCondition: Do not use empty case condition, instead use
  an if expression.

- Style/MultilineArrayBraceLayout: Closing array brace must be on the
  same line as the last array element when opening brace is on the same
  line as the first array element.

- Style/MultilineHashBraceLayout: Closing hash brace must be on the same
  line as the last hash element when opening brace is on the same line
  as the first hash element.

- Style/MultilineMethodCallBraceLayout: Closing method call brace must
  be on the line after the last argument when opening brace is on a
  separate line from the first argument.

[1] https://github.com/bbatsov/rubocop/releases/tag/v0.40.0
This commit is contained in:
Noah Silas 2016-05-26 09:58:05 -07:00 committed by L. Preston Sego III
parent 8a3196d920
commit 94db09b3f6
14 changed files with 147 additions and 133 deletions

View File

@ -95,12 +95,11 @@ module ActiveModel
def [](key) def [](key)
# TODO(beauby): Adopt a lazy caching strategy for generating subtrees. # TODO(beauby): Adopt a lazy caching strategy for generating subtrees.
case if @hash.key?(key)
when @hash.key?(key)
self.class.new(@hash[key]) self.class.new(@hash[key])
when @hash.key?(:*) elsif @hash.key?(:*)
self.class.new(@hash[:*]) self.class.new(@hash[:*])
when @hash.key?(:**) elsif @hash.key?(:**)
self.class.new(:** => {}) self.class.new(:** => {})
else else
nil nil

View File

@ -36,8 +36,7 @@ module ActiveModelSerializers
target = is_a?(Module) ? "#{self}." : "#{self.class}#" target = is_a?(Module) ? "#{self}." : "#{self.class}#"
msg = ["NOTE: #{target}#{name} is deprecated", msg = ["NOTE: #{target}#{name} is deprecated",
replacement == :none ? ' with no replacement' : "; use #{replacement} instead", replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}" "\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"]
]
warn "#{msg.join}." warn "#{msg.join}."
send old, *args, &block send old, *args, &block
end end

View File

@ -100,7 +100,8 @@ module ActionController
get :render_array_using_explicit_serializer_and_custom_serializers get :render_array_using_explicit_serializer_and_custom_serializers
expected = [ expected = [
{ 'title' => 'New Post', {
'title' => 'New Post',
'body' => 'Body', 'body' => 'Body',
'id' => assigns(:post).id, 'id' => assigns(:post).id,
'comments' => [{ 'id' => 1 }, { 'id' => 2 }], 'comments' => [{ 'id' => 1 }, { 'id' => 2 }],

View File

@ -7,8 +7,8 @@ module ActionController
def test_active_model_with_multiple_errors def test_active_model_with_multiple_errors
get :render_resource_with_errors get :render_resource_with_errors
expected_errors_object = expected_errors_object = {
{ :errors => :errors =>
[ [
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' }, { :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' }, { :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },

View File

@ -294,7 +294,8 @@ module ActionController
comments: [ comments: [
{ {
id: 1, id: 1,
body: 'ZOMG A COMMENT' } body: 'ZOMG A COMMENT'
}
], ],
blog: { blog: {
id: 999, id: 999,
@ -333,7 +334,8 @@ module ActionController
comments: [ comments: [
{ {
id: 1, id: 1,
body: 'ZOMG A COMMENT' } body: 'ZOMG A COMMENT'
}
], ],
blog: { blog: {
id: 999, id: 999,
@ -407,7 +409,8 @@ module ActionController
comments: [ comments: [
{ {
id: 1, id: 1,
body: 'ZOMG A COMMENT' } body: 'ZOMG A COMMENT'
}
], ],
blog: { blog: {
id: 999, id: 999,

View File

@ -58,9 +58,10 @@ module ActiveModelSerializers
def test_limiting_fields def test_limiting_fields
actual = ActiveModelSerializers::SerializableResource.new( actual = ActiveModelSerializers::SerializableResource.new(
[@first_post, @second_post], adapter: :json_api, [@first_post, @second_post],
fields: { posts: %w(title comments blog author) }) adapter: :json_api,
.serializable_hash fields: { posts: %w(title comments blog author) }
).serializable_hash
expected = [ expected = [
{ {
id: '1', id: '1',

View File

@ -22,9 +22,8 @@ module ActiveModelSerializers
assert_equal serializable_resource.serializer_instance.attributes, {} assert_equal serializable_resource.serializer_instance.attributes, {}
assert_equal serializable_resource.serializer_instance.object, @resource assert_equal serializable_resource.serializer_instance.object, @resource
expected_errors_object = expected_errors_object = {
{ :errors => :errors => [
[
{ {
source: { pointer: '/data/attributes/name' }, source: { pointer: '/data/attributes/name' },
detail: 'cannot be nil' detail: 'cannot be nil'
@ -48,9 +47,8 @@ module ActiveModelSerializers
assert_equal serializable_resource.serializer_instance.attributes, {} assert_equal serializable_resource.serializer_instance.attributes, {}
assert_equal serializable_resource.serializer_instance.object, @resource assert_equal serializable_resource.serializer_instance.object, @resource
expected_errors_object = expected_errors_object = {
{ :errors => :errors => [
[
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' }, { :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' }, { :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' } { :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }

View File

@ -341,9 +341,10 @@ module ActiveModelSerializers
def test_no_duplicates_collection def test_no_duplicates_collection
hash = ActiveModelSerializers::SerializableResource.new( hash = ActiveModelSerializers::SerializableResource.new(
[@post1, @post2], adapter: :json_api, [@post1, @post2],
include: '*.*') adapter: :json_api,
.serializable_hash include: '*.*'
).serializable_hash
expected = [ expected = [
{ {
type: 'authors', id: '1', type: 'authors', id: '1',
@ -364,7 +365,8 @@ module ActiveModelSerializers
hash = ActiveModelSerializers::SerializableResource.new( hash = ActiveModelSerializers::SerializableResource.new(
@nestedpost1, @nestedpost1,
adapter: :json_api, adapter: :json_api,
include: '*').serializable_hash include: '*'
).serializable_hash
expected = [ expected = [
type: 'nested-posts', id: '2', type: 'nested-posts', id: '2',
relationships: { relationships: {
@ -383,7 +385,8 @@ module ActiveModelSerializers
hash = ActiveModelSerializers::SerializableResource.new( hash = ActiveModelSerializers::SerializableResource.new(
[@nestedpost1, @nestedpost2], [@nestedpost1, @nestedpost2],
adapter: :json_api, adapter: :json_api,
include: '*').serializable_hash include: '*'
).serializable_hash
assert_nil(hash[:included]) assert_nil(hash[:included])
end end
end end

View File

@ -40,7 +40,8 @@ module ActiveModelSerializers
stuff: 'value' stuff: 'value'
} }
} }
}).serializable_hash }
).serializable_hash
expected = { expected = {
self: { self: {
href: 'http://example.com/posts', href: 'http://example.com/posts',

View File

@ -43,7 +43,8 @@ module ActiveModelSerializers
end end
def data def data
{ data: [ {
data: [
{ id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } }, { id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } },
{ id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } }, { id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } },
{ id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } }, { id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } },

View File

@ -86,7 +86,8 @@ module ActiveModelSerializers
data: [ data: [
{ id: '7', type: 'comments' }, { id: '7', type: 'comments' },
{ id: '12', type: 'comments' } { id: '12', type: 'comments' }
] } ]
}
}, },
links: { links: {
self: 'http://example.com/posts/1337', self: 'http://example.com/posts/1337',
@ -122,7 +123,8 @@ module ActiveModelSerializers
data: [ data: [
{ id: '7', type: 'comments' }, { id: '7', type: 'comments' },
{ id: '12', type: 'comments' } { id: '12', type: 'comments' }
] } ]
}
}, },
links: { links: {
self: 'http://example.com/posts/1337', self: 'http://example.com/posts/1337',
@ -158,7 +160,8 @@ module ActiveModelSerializers
Data: [ Data: [
{ Id: '7', Type: 'Comments' }, { Id: '7', Type: 'Comments' },
{ Id: '12', Type: 'Comments' } { Id: '12', Type: 'Comments' }
] } ]
}
}, },
Links: { Links: {
Self: 'http://example.com/posts/1337', Self: 'http://example.com/posts/1337',
@ -192,7 +195,8 @@ module ActiveModelSerializers
data: [ data: [
{ id: '7', type: 'comments' }, { id: '7', type: 'comments' },
{ id: '12', type: 'comments' } { id: '12', type: 'comments' }
] } ]
}
}, },
links: { links: {
self: 'http://example.com/posts/1337', self: 'http://example.com/posts/1337',
@ -226,7 +230,8 @@ module ActiveModelSerializers
data: [ data: [
{ id: '7', type: 'comments' }, { id: '7', type: 'comments' },
{ id: '12', type: 'comments' } { id: '12', type: 'comments' }
] } ]
}
}, },
links: { links: {
self: 'http://example.com/posts/1337', self: 'http://example.com/posts/1337',
@ -270,7 +275,8 @@ module ActiveModelSerializers
Data: [ Data: [
{ Id: '7', Type: 'Comments' }, { Id: '7', Type: 'Comments' },
{ Id: '12', Type: 'Comments' } { Id: '12', Type: 'Comments' }
] } ]
}
}, },
Links: { Links: {
Self: 'http://example.com/posts/1337', Self: 'http://example.com/posts/1337',
@ -304,7 +310,8 @@ module ActiveModelSerializers
data: [ data: [
{ id: '7', type: 'comments' }, { id: '7', type: 'comments' },
{ id: '12', type: 'comments' } { id: '12', type: 'comments' }
] } ]
}
}, },
links: { links: {
self: 'http://example.com/posts/1337', self: 'http://example.com/posts/1337',
@ -324,12 +331,12 @@ module ActiveModelSerializers
serializer = ActiveModel::Serializer::ErrorSerializer.new(resource) serializer = ActiveModel::Serializer::ErrorSerializer.new(resource)
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
result = adapter.serializable_hash result = adapter.serializable_hash
expected_errors_object = expected_errors_object = {
{ :errors => :errors => [
[
{ {
:source => { :pointer => '/data/attributes/published-at' }, :source => { :pointer => '/data/attributes/published-at' },
:detail => 'must be in the future' }, :detail => 'must be in the future'
},
{ {
:source => { :pointer => '/data/attributes/title' }, :source => { :pointer => '/data/attributes/title' },
:detail => 'must be longer' :detail => 'must be longer'
@ -349,9 +356,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
adapter.serializable_hash adapter.serializable_hash
end end
expected_errors_object = expected_errors_object = {
{ :Errors => :Errors => [
[
{ {
:Source => { :Pointer => '/data/attributes/PublishedAt' }, :Source => { :Pointer => '/data/attributes/PublishedAt' },
:Detail => 'must be in the future' :Detail => 'must be in the future'
@ -375,9 +381,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
adapter.serializable_hash adapter.serializable_hash
end end
expected_errors_object = expected_errors_object = {
{ :Errors => :Errors => [
[
{ {
:Source => { :Pointer => '/data/attributes/PublishedAt' }, :Source => { :Pointer => '/data/attributes/PublishedAt' },
:Detail => 'must be in the future' :Detail => 'must be in the future'
@ -402,9 +407,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
result = adapter.serializable_hash result = adapter.serializable_hash
expected_errors_object = expected_errors_object = {
{ :errors => :errors => [
[
{ {
:source => { :pointer => '/data/attributes/published-at' }, :source => { :pointer => '/data/attributes/published-at' },
:detail => 'must be in the future' :detail => 'must be in the future'
@ -429,9 +433,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
result = adapter.serializable_hash result = adapter.serializable_hash
expected_errors_object = expected_errors_object = {
{ :errors => :errors => [
[
{ :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' }, { :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' } { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
] ]
@ -466,9 +469,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
result = adapter.serializable_hash result = adapter.serializable_hash
expected_errors_object = expected_errors_object = {
{ :Errors => :Errors => [
[
{ :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' }, { :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
{ :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' } { :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
] ]
@ -487,9 +489,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
result = adapter.serializable_hash result = adapter.serializable_hash
expected_errors_object = expected_errors_object = {
{ :errors => :errors => [
[
{ :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' }, { :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' } { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
] ]

View File

@ -33,7 +33,8 @@ module ActiveModelSerializers
assert_equal({ assert_equal({
id: 1, id: 1,
reviews: [{ id: 1, body: 'ZOMG A COMMENT' }, reviews: [
{ id: 1, body: 'ZOMG A COMMENT' },
{ id: 2, body: 'ZOMG ANOTHER COMMENT' } { id: 2, body: 'ZOMG ANOTHER COMMENT' }
], ],
writer: { id: 1, name: 'Steve K.' }, writer: { id: 1, name: 'Steve K.' },

View File

@ -48,10 +48,10 @@ module ActiveModelSerializers
resource, { resource, {
serializer: ActiveModel::Serializer::ErrorSerializer, serializer: ActiveModel::Serializer::ErrorSerializer,
adapter: :json_api adapter: :json_api
}) }
expected_response_document = )
{ :errors => expected_response_document = {
[ :errors => [
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' } { :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' }
] ]
} }
@ -69,10 +69,10 @@ module ActiveModelSerializers
serializer: ActiveModel::Serializer::ErrorsSerializer, serializer: ActiveModel::Serializer::ErrorsSerializer,
each_serializer: ActiveModel::Serializer::ErrorSerializer, each_serializer: ActiveModel::Serializer::ErrorSerializer,
adapter: :json_api adapter: :json_api
}) }
expected_response_document = )
{ :errors => expected_response_document = {
[ :errors => [
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be amazing' } { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be amazing' }
] ]
} }

View File

@ -15,7 +15,8 @@ module ActiveModel
@blog, @blog,
adapter: :json, adapter: :json,
serializer: AlternateBlogSerializer, serializer: AlternateBlogSerializer,
meta: { total: 10 }).as_json meta: { total: 10 }
).as_json
expected = { expected = {
blog: { blog: {
id: 1, id: 1,
@ -65,7 +66,8 @@ module ActiveModel
@blog, @blog,
adapter: :attributes, adapter: :attributes,
serializer: AlternateBlogSerializer, serializer: AlternateBlogSerializer,
meta: { total: 10 }).as_json meta: { total: 10 }
).as_json
expected = { expected = {
id: 1, id: 1,
title: 'AMS Hints' title: 'AMS Hints'
@ -79,7 +81,8 @@ module ActiveModel
adapter: :json, adapter: :json,
serializer: AlternateBlogSerializer, serializer: AlternateBlogSerializer,
meta: { total: 10 }, meta: { total: 10 },
meta_key: 'haha_meta').as_json meta_key: 'haha_meta'
).as_json
expected = { expected = {
blog: { blog: {
id: 1, id: 1,
@ -98,7 +101,8 @@ module ActiveModel
adapter: :json_api, adapter: :json_api,
serializer: AlternateBlogSerializer, serializer: AlternateBlogSerializer,
meta: { total: 10 }, meta: { total: 10 },
meta_key: 'haha_meta').as_json meta_key: 'haha_meta'
).as_json
expected = { expected = {
data: { data: {
id: '1', id: '1',
@ -148,7 +152,8 @@ module ActiveModel
actual = ActiveModelSerializers::SerializableResource.new( actual = ActiveModelSerializers::SerializableResource.new(
[@blog], [@blog],
adapter: :attributes, adapter: :attributes,
meta: { total: 10 }).as_json meta: { total: 10 }
).as_json
expected = [{ expected = [{
id: 1, id: 1,
name: 'AMS Hints', name: 'AMS Hints',
@ -170,7 +175,8 @@ module ActiveModel
[@blog], [@blog],
adapter: :json, adapter: :json,
meta: { total: 10 }, meta: { total: 10 },
meta_key: 'haha_meta').as_json meta_key: 'haha_meta'
).as_json
expected = { expected = {
blogs: [{ blogs: [{
id: 1, id: 1,