Skip to content

Commit 94db09b

Browse files
noahsilasNullVoxPopuli
authored andcommitted
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
1 parent 8a3196d commit 94db09b

File tree

14 files changed

+147
-133
lines changed

14 files changed

+147
-133
lines changed

lib/active_model/serializer/include_tree.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ def key?(key)
9595

9696
def [](key)
9797
# TODO(beauby): Adopt a lazy caching strategy for generating subtrees.
98-
case
99-
when @hash.key?(key)
98+
if @hash.key?(key)
10099
self.class.new(@hash[key])
101-
when @hash.key?(:*)
100+
elsif @hash.key?(:*)
102101
self.class.new(@hash[:*])
103-
when @hash.key?(:**)
102+
elsif @hash.key?(:**)
104103
self.class.new(:** => {})
105104
else
106105
nil

lib/active_model_serializers/deprecate.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def deprecate(name, replacement)
3636
target = is_a?(Module) ? "#{self}." : "#{self.class}#"
3737
msg = ["NOTE: #{target}#{name} is deprecated",
3838
replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
39-
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"
40-
]
39+
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"]
4140
warn "#{msg.join}."
4241
send old, *args, &block
4342
end

test/action_controller/explicit_serializer_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def test_render_array_using_explicit_serializer_and_custom_serializers
100100
get :render_array_using_explicit_serializer_and_custom_serializers
101101

102102
expected = [
103-
{ 'title' => 'New Post',
103+
{
104+
'title' => 'New Post',
104105
'body' => 'Body',
105106
'id' => assigns(:post).id,
106107
'comments' => [{ 'id' => 1 }, { 'id' => 2 }],

test/action_controller/json_api/errors_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class ErrorsTest < ActionController::TestCase
77
def test_active_model_with_multiple_errors
88
get :render_resource_with_errors
99

10-
expected_errors_object =
11-
{ :errors =>
10+
expected_errors_object = {
11+
:errors =>
1212
[
1313
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
1414
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },

test/action_controller/serialization_test.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ def test_render_with_cache_enable
294294
comments: [
295295
{
296296
id: 1,
297-
body: 'ZOMG A COMMENT' }
297+
body: 'ZOMG A COMMENT'
298+
}
298299
],
299300
blog: {
300301
id: 999,
@@ -333,7 +334,8 @@ def test_render_with_cache_enable_and_expired
333334
comments: [
334335
{
335336
id: 1,
336-
body: 'ZOMG A COMMENT' }
337+
body: 'ZOMG A COMMENT'
338+
}
337339
],
338340
blog: {
339341
id: 999,
@@ -407,7 +409,8 @@ def test_cache_expiration_on_update
407409
comments: [
408410
{
409411
id: 1,
410-
body: 'ZOMG A COMMENT' }
412+
body: 'ZOMG A COMMENT'
413+
}
411414
],
412415
blog: {
413416
id: 999,

test/adapter/json_api/collection_test.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def test_include_multiple_posts
5858

5959
def test_limiting_fields
6060
actual = ActiveModelSerializers::SerializableResource.new(
61-
[@first_post, @second_post], adapter: :json_api,
62-
fields: { posts: %w(title comments blog author) })
63-
.serializable_hash
61+
[@first_post, @second_post],
62+
adapter: :json_api,
63+
fields: { posts: %w(title comments blog author) }
64+
).serializable_hash
6465
expected = [
6566
{
6667
id: '1',

test/adapter/json_api/errors_test.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ def test_active_model_with_error
2222
assert_equal serializable_resource.serializer_instance.attributes, {}
2323
assert_equal serializable_resource.serializer_instance.object, @resource
2424

25-
expected_errors_object =
26-
{ :errors =>
27-
[
28-
{
29-
source: { pointer: '/data/attributes/name' },
30-
detail: 'cannot be nil'
31-
}
32-
]
25+
expected_errors_object = {
26+
:errors => [
27+
{
28+
source: { pointer: '/data/attributes/name' },
29+
detail: 'cannot be nil'
30+
}
31+
]
3332
}
3433
assert_equal serializable_resource.as_json, expected_errors_object
3534
end
@@ -48,13 +47,12 @@ def test_active_model_with_multiple_errors
4847
assert_equal serializable_resource.serializer_instance.attributes, {}
4948
assert_equal serializable_resource.serializer_instance.object, @resource
5049

51-
expected_errors_object =
52-
{ :errors =>
53-
[
54-
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
55-
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
56-
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
57-
]
50+
expected_errors_object = {
51+
:errors => [
52+
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
53+
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
54+
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
55+
]
5856
}
5957
assert_equal serializable_resource.as_json, expected_errors_object
6058
end

test/adapter/json_api/linked_test.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ def test_no_duplicates
341341

342342
def test_no_duplicates_collection
343343
hash = ActiveModelSerializers::SerializableResource.new(
344-
[@post1, @post2], adapter: :json_api,
345-
include: '*.*')
346-
.serializable_hash
344+
[@post1, @post2],
345+
adapter: :json_api,
346+
include: '*.*'
347+
).serializable_hash
347348
expected = [
348349
{
349350
type: 'authors', id: '1',
@@ -364,7 +365,8 @@ def test_no_duplicates_global
364365
hash = ActiveModelSerializers::SerializableResource.new(
365366
@nestedpost1,
366367
adapter: :json_api,
367-
include: '*').serializable_hash
368+
include: '*'
369+
).serializable_hash
368370
expected = [
369371
type: 'nested-posts', id: '2',
370372
relationships: {
@@ -383,7 +385,8 @@ def test_no_duplicates_collection_global
383385
hash = ActiveModelSerializers::SerializableResource.new(
384386
[@nestedpost1, @nestedpost2],
385387
adapter: :json_api,
386-
include: '*').serializable_hash
388+
include: '*'
389+
).serializable_hash
387390
assert_nil(hash[:included])
388391
end
389392
end

test/adapter/json_api/links_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def test_toplevel_links
4040
stuff: 'value'
4141
}
4242
}
43-
}).serializable_hash
43+
}
44+
).serializable_hash
4445
expected = {
4546
self: {
4647
href: 'http://example.com/posts',

test/adapter/json_api/pagination_links_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def using_will_paginate(page = 2)
4343
end
4444

4545
def data
46-
{ data: [
46+
{
47+
data: [
4748
{ id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } },
4849
{ id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } },
4950
{ id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } },

0 commit comments

Comments
 (0)