From 13015680a7f3818de0914860e2b746e42fb596b3 Mon Sep 17 00:00:00 2001 From: Alexey Dubovskoy Date: Mon, 20 Jun 2016 21:00:06 +0100 Subject: [PATCH] re: RuboCop - get rid of redundant curly braces around a hash parameter --- .rubocop_todo.yml | 17 ---------------- .../adapter_selector_test.rb | 6 +++--- .../json_api/pagination_test.rb | 6 +++--- test/adapter/json_api/linked_test.rb | 2 +- .../adapter/json_api/pagination_links_test.rb | 12 +++++------ test/adapter/null_test.rb | 2 +- test/adapter_test.rb | 2 +- test/collection_serializer_test.rb | 4 ++-- test/serializable_resource_test.rb | 20 ++++++++----------- test/serializers/associations_test.rb | 10 +++++----- test/serializers/attributes_test.rb | 2 +- test/serializers/root_test.rb | 2 +- 12 files changed, 32 insertions(+), 53 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49185b4b..f6aa306d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/test/action_controller/adapter_selector_test.rb b/test/action_controller/adapter_selector_test.rb index f392b4a4..2746943f 100644 --- a/test/action_controller/adapter_selector_test.rb +++ b/test/action_controller/adapter_selector_test.rb @@ -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 diff --git a/test/action_controller/json_api/pagination_test.rb b/test/action_controller/json_api/pagination_test.rb index 183ec1c3..fc719c5a 100644 --- a/test/action_controller/json_api/pagination_test.rb +++ b/test/action_controller/json_api/pagination_test.rb @@ -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 diff --git a/test/adapter/json_api/linked_test.rb b/test/adapter/json_api/linked_test.rb index 159e2bec..876548e5 100644 --- a/test/adapter/json_api/linked_test.rb +++ b/test/adapter/json_api/linked_test.rb @@ -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 diff --git a/test/adapter/json_api/pagination_links_test.rb b/test/adapter/json_api/pagination_links_test.rb index 46c6b56a..f999ba7a 100644 --- a/test/adapter/json_api/pagination_links_test.rb +++ b/test/adapter/json_api/pagination_links_test.rb @@ -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 diff --git a/test/adapter/null_test.rb b/test/adapter/null_test.rb index 0234074d..4e701db1 100644 --- a/test/adapter/null_test.rb +++ b/test/adapter/null_test.rb @@ -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) diff --git a/test/adapter_test.rb b/test/adapter_test.rb index a9c8f183..c1b00d72 100644 --- a/test/adapter_test.rb +++ b/test/adapter_test.rb @@ -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 diff --git a/test/collection_serializer_test.rb b/test/collection_serializer_test.rb index 5e5267e4..db1cf1a7 100644 --- a/test/collection_serializer_test.rb +++ b/test/collection_serializer_test.rb @@ -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 diff --git a/test/serializable_resource_test.rb b/test/serializable_resource_test.rb index 3df71a17..ab12bc27 100644 --- a/test/serializable_resource_test.rb +++ b/test/serializable_resource_test.rb @@ -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: [ diff --git a/test/serializers/associations_test.rb b/test/serializers/associations_test.rb index 9032f31c..2e6c2299 100644 --- a/test/serializers/associations_test.rb +++ b/test/serializers/associations_test.rb @@ -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 diff --git a/test/serializers/attributes_test.rb b/test/serializers/attributes_test.rb index 8879e387..fb792b26 100644 --- a/test/serializers/attributes_test.rb +++ b/test/serializers/attributes_test.rb @@ -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) diff --git a/test/serializers/root_test.rb b/test/serializers/root_test.rb index ed54625b..5bd4cdc3 100644 --- a/test/serializers/root_test.rb +++ b/test/serializers/root_test.rb @@ -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