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