Skip to content

Commit

Permalink
Fix RuboCop 0.40 linter errors (#1722)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
noahsilas authored and NullVoxPopuli committed May 26, 2016
1 parent 8a3196d commit 94db09b
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 133 deletions.
7 changes: 3 additions & 4 deletions lib/active_model/serializer/include_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ def key?(key)

def [](key)
# TODO(beauby): Adopt a lazy caching strategy for generating subtrees.
case
when @hash.key?(key)
if @hash.key?(key)
self.class.new(@hash[key])
when @hash.key?(:*)
elsif @hash.key?(:*)
self.class.new(@hash[:*])
when @hash.key?(:**)
elsif @hash.key?(:**)
self.class.new(:** => {})
else
nil
Expand Down
3 changes: 1 addition & 2 deletions lib/active_model_serializers/deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def deprecate(name, replacement)
target = is_a?(Module) ? "#{self}." : "#{self.class}#"
msg = ["NOTE: #{target}#{name} is deprecated",
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}."
send old, *args, &block
end
Expand Down
3 changes: 2 additions & 1 deletion test/action_controller/explicit_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def test_render_array_using_explicit_serializer_and_custom_serializers
get :render_array_using_explicit_serializer_and_custom_serializers

expected = [
{ 'title' => 'New Post',
{
'title' => 'New Post',
'body' => 'Body',
'id' => assigns(:post).id,
'comments' => [{ 'id' => 1 }, { 'id' => 2 }],
Expand Down
4 changes: 2 additions & 2 deletions test/action_controller/json_api/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class ErrorsTest < ActionController::TestCase
def test_active_model_with_multiple_errors
get :render_resource_with_errors

expected_errors_object =
{ :errors =>
expected_errors_object = {
:errors =>
[
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
Expand Down
9 changes: 6 additions & 3 deletions test/action_controller/serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def test_render_with_cache_enable
comments: [
{
id: 1,
body: 'ZOMG A COMMENT' }
body: 'ZOMG A COMMENT'
}
],
blog: {
id: 999,
Expand Down Expand Up @@ -333,7 +334,8 @@ def test_render_with_cache_enable_and_expired
comments: [
{
id: 1,
body: 'ZOMG A COMMENT' }
body: 'ZOMG A COMMENT'
}
],
blog: {
id: 999,
Expand Down Expand Up @@ -407,7 +409,8 @@ def test_cache_expiration_on_update
comments: [
{
id: 1,
body: 'ZOMG A COMMENT' }
body: 'ZOMG A COMMENT'
}
],
blog: {
id: 999,
Expand Down
7 changes: 4 additions & 3 deletions test/adapter/json_api/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def test_include_multiple_posts

def test_limiting_fields
actual = ActiveModelSerializers::SerializableResource.new(
[@first_post, @second_post], adapter: :json_api,
fields: { posts: %w(title comments blog author) })
.serializable_hash
[@first_post, @second_post],
adapter: :json_api,
fields: { posts: %w(title comments blog author) }
).serializable_hash
expected = [
{
id: '1',
Expand Down
28 changes: 13 additions & 15 deletions test/adapter/json_api/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ def test_active_model_with_error
assert_equal serializable_resource.serializer_instance.attributes, {}
assert_equal serializable_resource.serializer_instance.object, @resource

expected_errors_object =
{ :errors =>
[
{
source: { pointer: '/data/attributes/name' },
detail: 'cannot be nil'
}
]
expected_errors_object = {
:errors => [
{
source: { pointer: '/data/attributes/name' },
detail: 'cannot be nil'
}
]
}
assert_equal serializable_resource.as_json, expected_errors_object
end
Expand All @@ -48,13 +47,12 @@ def test_active_model_with_multiple_errors
assert_equal serializable_resource.serializer_instance.attributes, {}
assert_equal serializable_resource.serializer_instance.object, @resource

expected_errors_object =
{ :errors =>
[
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
]
expected_errors_object = {
:errors => [
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
]
}
assert_equal serializable_resource.as_json, expected_errors_object
end
Expand Down
13 changes: 8 additions & 5 deletions test/adapter/json_api/linked_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ def test_no_duplicates

def test_no_duplicates_collection
hash = ActiveModelSerializers::SerializableResource.new(
[@post1, @post2], adapter: :json_api,
include: '*.*')
.serializable_hash
[@post1, @post2],
adapter: :json_api,
include: '*.*'
).serializable_hash
expected = [
{
type: 'authors', id: '1',
Expand All @@ -364,7 +365,8 @@ def test_no_duplicates_global
hash = ActiveModelSerializers::SerializableResource.new(
@nestedpost1,
adapter: :json_api,
include: '*').serializable_hash
include: '*'
).serializable_hash
expected = [
type: 'nested-posts', id: '2',
relationships: {
Expand All @@ -383,7 +385,8 @@ def test_no_duplicates_collection_global
hash = ActiveModelSerializers::SerializableResource.new(
[@nestedpost1, @nestedpost2],
adapter: :json_api,
include: '*').serializable_hash
include: '*'
).serializable_hash
assert_nil(hash[:included])
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/adapter/json_api/links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def test_toplevel_links
stuff: 'value'
}
}
}).serializable_hash
}
).serializable_hash
expected = {
self: {
href: 'http://example.com/posts',
Expand Down
3 changes: 2 additions & 1 deletion test/adapter/json_api/pagination_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def using_will_paginate(page = 2)
end

def data
{ 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' } },
Expand Down
Loading

0 comments on commit 94db09b

Please sign in to comment.