mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
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:
committed by
L. Preston Sego III
parent
8a3196d920
commit
94db09b3f6
@@ -58,9 +58,10 @@ module ActiveModelSerializers
|
||||
|
||||
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',
|
||||
|
||||
@@ -22,14 +22,13 @@ module ActiveModelSerializers
|
||||
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
|
||||
@@ -48,13 +47,12 @@ module ActiveModelSerializers
|
||||
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
|
||||
|
||||
@@ -341,9 +341,10 @@ module ActiveModelSerializers
|
||||
|
||||
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',
|
||||
@@ -364,7 +365,8 @@ module ActiveModelSerializers
|
||||
hash = ActiveModelSerializers::SerializableResource.new(
|
||||
@nestedpost1,
|
||||
adapter: :json_api,
|
||||
include: '*').serializable_hash
|
||||
include: '*'
|
||||
).serializable_hash
|
||||
expected = [
|
||||
type: 'nested-posts', id: '2',
|
||||
relationships: {
|
||||
@@ -383,7 +385,8 @@ module ActiveModelSerializers
|
||||
hash = ActiveModelSerializers::SerializableResource.new(
|
||||
[@nestedpost1, @nestedpost2],
|
||||
adapter: :json_api,
|
||||
include: '*').serializable_hash
|
||||
include: '*'
|
||||
).serializable_hash
|
||||
assert_nil(hash[:included])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,8 @@ module ActiveModelSerializers
|
||||
stuff: 'value'
|
||||
}
|
||||
}
|
||||
}).serializable_hash
|
||||
}
|
||||
).serializable_hash
|
||||
expected = {
|
||||
self: {
|
||||
href: 'http://example.com/posts',
|
||||
|
||||
@@ -43,7 +43,8 @@ module ActiveModelSerializers
|
||||
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' } },
|
||||
|
||||
@@ -86,7 +86,8 @@ module ActiveModelSerializers
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
@@ -122,7 +123,8 @@ module ActiveModelSerializers
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
@@ -158,7 +160,8 @@ module ActiveModelSerializers
|
||||
Data: [
|
||||
{ Id: '7', Type: 'Comments' },
|
||||
{ Id: '12', Type: 'Comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
Links: {
|
||||
Self: 'http://example.com/posts/1337',
|
||||
@@ -192,7 +195,8 @@ module ActiveModelSerializers
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
@@ -226,7 +230,8 @@ module ActiveModelSerializers
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
@@ -270,7 +275,8 @@ module ActiveModelSerializers
|
||||
Data: [
|
||||
{ Id: '7', Type: 'Comments' },
|
||||
{ Id: '12', Type: 'Comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
Links: {
|
||||
Self: 'http://example.com/posts/1337',
|
||||
@@ -304,7 +310,8 @@ module ActiveModelSerializers
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
] }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
@@ -324,18 +331,18 @@ module ActiveModelSerializers
|
||||
serializer = ActiveModel::Serializer::ErrorSerializer.new(resource)
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
expected_errors_object =
|
||||
{ :errors =>
|
||||
[
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/published-at' },
|
||||
:detail => 'must be in the future' },
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/title' },
|
||||
:detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
expected_errors_object = {
|
||||
:errors => [
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/published-at' },
|
||||
:detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/title' },
|
||||
:detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
|
||||
@@ -349,19 +356,18 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
adapter.serializable_hash
|
||||
end
|
||||
expected_errors_object =
|
||||
{ :Errors =>
|
||||
[
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
||||
:Detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/Title' },
|
||||
:Detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
expected_errors_object = {
|
||||
:Errors => [
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
||||
:Detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/Title' },
|
||||
:Detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
|
||||
@@ -375,19 +381,18 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
adapter.serializable_hash
|
||||
end
|
||||
expected_errors_object =
|
||||
{ :Errors =>
|
||||
[
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
||||
:Detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/Title' },
|
||||
:Detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
expected_errors_object = {
|
||||
:Errors => [
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
||||
:Detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:Source => { :Pointer => '/data/attributes/Title' },
|
||||
:Detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
|
||||
@@ -402,18 +407,17 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
|
||||
expected_errors_object =
|
||||
{ :errors =>
|
||||
[
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/published-at' },
|
||||
:detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/title' },
|
||||
:detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
expected_errors_object = {
|
||||
:errors => [
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/published-at' },
|
||||
:detail => 'must be in the future'
|
||||
},
|
||||
{
|
||||
:source => { :pointer => '/data/attributes/title' },
|
||||
:detail => 'must be longer'
|
||||
}
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
@@ -429,12 +433,11 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
|
||||
expected_errors_object =
|
||||
{ :errors =>
|
||||
[
|
||||
{ :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
|
||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
||||
]
|
||||
expected_errors_object = {
|
||||
:errors => [
|
||||
{ :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
|
||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
@@ -466,12 +469,11 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
|
||||
expected_errors_object =
|
||||
{ :Errors =>
|
||||
[
|
||||
{ :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
|
||||
{ :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
|
||||
]
|
||||
expected_errors_object = {
|
||||
:Errors => [
|
||||
{ :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
|
||||
{ :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
@@ -487,12 +489,11 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
|
||||
expected_errors_object =
|
||||
{ :errors =>
|
||||
[
|
||||
{ :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
|
||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
||||
]
|
||||
expected_errors_object = {
|
||||
:errors => [
|
||||
{ :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
|
||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
||||
]
|
||||
}
|
||||
assert_equal expected_errors_object, result
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user