mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
re: RuboCop - get rid of redundant curly braces around a hash parameter
This commit is contained in:
parent
024b2d51d3
commit
13015680a7
@ -19,23 +19,6 @@ Style/AlignHash:
|
||||
Exclude:
|
||||
- 'test/action_controller/json_api/pagination_test.rb'
|
||||
|
||||
# Offense count: 27
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: braces, no_braces, context_dependent
|
||||
Style/BracesAroundHashParameters:
|
||||
Exclude:
|
||||
- 'test/action_controller/adapter_selector_test.rb'
|
||||
- 'test/action_controller/json_api/pagination_test.rb'
|
||||
- 'test/adapter/json_api/linked_test.rb'
|
||||
- 'test/adapter/json_api/pagination_links_test.rb'
|
||||
- 'test/adapter/null_test.rb'
|
||||
- 'test/adapter_test.rb'
|
||||
- 'test/collection_serializer_test.rb'
|
||||
- 'test/serializable_resource_test.rb'
|
||||
- 'test/serializers/associations_test.rb'
|
||||
- 'test/serializers/attributes_test.rb'
|
||||
- 'test/serializers/root_test.rb'
|
||||
|
||||
# Offense count: 271
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
|
||||
@ -5,17 +5,17 @@ module ActionController
|
||||
class AdapterSelectorTest < ActionController::TestCase
|
||||
class AdapterSelectorTestController < ActionController::Base
|
||||
def render_using_default_adapter
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||
render json: @profile
|
||||
end
|
||||
|
||||
def render_using_adapter_override
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||
render json: @profile, adapter: :json_api
|
||||
end
|
||||
|
||||
def render_skipping_adapter
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||
render json: @profile, adapter: false
|
||||
end
|
||||
end
|
||||
|
||||
@ -14,9 +14,9 @@ module ActionController
|
||||
class PaginationTestController < ActionController::Base
|
||||
def setup
|
||||
@array = [
|
||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
||||
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' }),
|
||||
Profile.new({ name: 'Name 3', description: 'Description 3', comments: 'Comments 3' })
|
||||
Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
|
||||
Profile.new(name: 'Name 2', description: 'Description 2', comments: 'Comments 2'),
|
||||
Profile.new(name: 'Name 3', description: 'Description 3', comments: 'Comments 3')
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ module ActiveModelSerializers
|
||||
@first_post = Post.new(id: 10, title: 'Hello!!', body: 'Hello, world!!')
|
||||
@second_post = Post.new(id: 20, title: 'New Post', body: 'Body')
|
||||
@third_post = Post.new(id: 30, title: 'Yet Another Post', body: 'Body')
|
||||
@blog = Blog.new({ name: 'AMS Blog' })
|
||||
@blog = Blog.new(name: 'AMS Blog')
|
||||
@first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
||||
@second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
|
||||
@first_post.blog = @blog
|
||||
|
||||
@ -13,11 +13,11 @@ module ActiveModelSerializers
|
||||
def setup
|
||||
ActionController::Base.cache_store.clear
|
||||
@array = [
|
||||
Profile.new({ id: 1, name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
||||
Profile.new({ id: 2, name: 'Name 2', description: 'Description 2', comments: 'Comments 2' }),
|
||||
Profile.new({ id: 3, name: 'Name 3', description: 'Description 3', comments: 'Comments 3' }),
|
||||
Profile.new({ id: 4, name: 'Name 4', description: 'Description 4', comments: 'Comments 4' }),
|
||||
Profile.new({ id: 5, name: 'Name 5', description: 'Description 5', comments: 'Comments 5' })
|
||||
Profile.new(id: 1, name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
|
||||
Profile.new(id: 2, name: 'Name 2', description: 'Description 2', comments: 'Comments 2'),
|
||||
Profile.new(id: 3, name: 'Name 3', description: 'Description 3', comments: 'Comments 3'),
|
||||
Profile.new(id: 4, name: 'Name 4', description: 'Description 4', comments: 'Comments 4'),
|
||||
Profile.new(id: 5, name: 'Name 5', description: 'Description 5', comments: 'Comments 5')
|
||||
]
|
||||
end
|
||||
|
||||
@ -122,7 +122,7 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
def test_pagination_links_with_additional_params
|
||||
adapter = load_adapter(using_will_paginate, mock_request({ test: 'test' }))
|
||||
adapter = load_adapter(using_will_paginate, mock_request(test: 'test'))
|
||||
|
||||
assert_equal expected_response_with_pagination_links_and_additional_params,
|
||||
adapter.serializable_hash
|
||||
|
||||
@ -4,7 +4,7 @@ module ActiveModelSerializers
|
||||
module Adapter
|
||||
class NullTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||
serializer = ProfileSerializer.new(profile)
|
||||
|
||||
@adapter = Null.new(serializer)
|
||||
|
||||
@ -51,7 +51,7 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
def test_create_adapter_with_override
|
||||
adapter = ActiveModelSerializers::Adapter.create(@serializer, { adapter: :json_api })
|
||||
adapter = ActiveModelSerializers::Adapter.create(@serializer, adapter: :json_api)
|
||||
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter.class
|
||||
end
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ module ActiveModel
|
||||
@comment = Comment.new
|
||||
@post = Post.new
|
||||
@resource = build_named_collection @comment, @post
|
||||
@serializer = collection_serializer.new(@resource, { some: :options })
|
||||
@serializer = collection_serializer.new(@resource, some: :options)
|
||||
end
|
||||
|
||||
def collection_serializer
|
||||
@ -44,7 +44,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_serializer_option_not_passed_to_each_serializer
|
||||
serializers = collection_serializer.new([@post], { serializer: PostSerializer }).to_a
|
||||
serializers = collection_serializer.new([@post], serializer: PostSerializer).to_a
|
||||
|
||||
refute serializers.first.custom_options.key?(:serializer)
|
||||
end
|
||||
|
||||
@ -3,7 +3,7 @@ require 'test_helper'
|
||||
module ActiveModelSerializers
|
||||
class SerializableResourceTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@resource = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@resource = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||
@serializer = ProfileSerializer.new(@resource)
|
||||
@adapter = ActiveModelSerializers::Adapter.create(@serializer)
|
||||
@serializable_resource = SerializableResource.new(@resource)
|
||||
@ -32,11 +32,11 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
def test_use_adapter_with_adapter_option
|
||||
assert SerializableResource.new(@resource, { adapter: 'json' }).use_adapter?
|
||||
assert SerializableResource.new(@resource, adapter: 'json').use_adapter?
|
||||
end
|
||||
|
||||
def test_use_adapter_with_adapter_option_as_false
|
||||
refute SerializableResource.new(@resource, { adapter: false }).use_adapter?
|
||||
refute SerializableResource.new(@resource, adapter: false).use_adapter?
|
||||
end
|
||||
|
||||
class SerializableResourceErrorsTest < Minitest::Test
|
||||
@ -45,10 +45,8 @@ module ActiveModelSerializers
|
||||
resource = ModelWithErrors.new
|
||||
resource.errors.add(:name, 'must be awesome')
|
||||
serializable_resource = ActiveModelSerializers::SerializableResource.new(
|
||||
resource, {
|
||||
serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
}
|
||||
resource, serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
)
|
||||
expected_response_document = {
|
||||
errors: [
|
||||
@ -65,11 +63,9 @@ module ActiveModelSerializers
|
||||
resource.errors.add(:title, 'must be amazing')
|
||||
resources << ModelWithErrors.new
|
||||
serializable_resource = SerializableResource.new(
|
||||
resources, {
|
||||
serializer: ActiveModel::Serializer::ErrorsSerializer,
|
||||
each_serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
}
|
||||
resources, serializer: ActiveModel::Serializer::ErrorsSerializer,
|
||||
each_serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
)
|
||||
expected_response_document = {
|
||||
errors: [
|
||||
|
||||
@ -7,10 +7,10 @@ module ActiveModel
|
||||
@author = Author.new(name: 'Steve K.')
|
||||
@author.bio = nil
|
||||
@author.roles = []
|
||||
@blog = Blog.new({ name: 'AMS Blog' })
|
||||
@post = Post.new({ title: 'New Post', body: 'Body' })
|
||||
@tag = Tag.new({ name: '#hashtagged' })
|
||||
@comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
|
||||
@blog = Blog.new(name: 'AMS Blog')
|
||||
@post = Post.new(title: 'New Post', body: 'Body')
|
||||
@tag = Tag.new(name: '#hashtagged')
|
||||
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
||||
@post.comments = [@comment]
|
||||
@post.tags = [@tag]
|
||||
@post.blog = @blog
|
||||
@ -19,7 +19,7 @@ module ActiveModel
|
||||
@post.author = @author
|
||||
@author.posts = [@post]
|
||||
|
||||
@post_serializer = PostSerializer.new(@post, { custom_options: true })
|
||||
@post_serializer = PostSerializer.new(@post, custom_options: true)
|
||||
@author_serializer = AuthorSerializer.new(@author)
|
||||
@comment_serializer = CommentSerializer.new(@comment)
|
||||
end
|
||||
|
||||
@ -4,7 +4,7 @@ module ActiveModel
|
||||
class Serializer
|
||||
class AttributesTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||
@profile_serializer = ProfileSerializer.new(@profile)
|
||||
@comment = Comment.new(id: 1, body: 'ZOMG!!', date: '2015')
|
||||
@serializer_klass = Class.new(CommentSerializer)
|
||||
|
||||
@ -8,7 +8,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_overwrite_root
|
||||
serializer = VirtualValueSerializer.new(@virtual_value, { root: 'smth' })
|
||||
serializer = VirtualValueSerializer.new(@virtual_value, root: 'smth')
|
||||
assert_equal('smth', serializer.json_key)
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user