From a26d3e44255166104940c1afb2d212549574456d Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 4 Feb 2016 22:39:20 -0600 Subject: [PATCH] Rubocop autocorrect --- lib/active_model/serializable_resource.rb | 6 +++--- lib/active_model/serializer/caching.rb | 2 +- lib/active_model/serializer/version.rb | 2 +- lib/active_model_serializers/adapter.rb | 4 ++-- .../adapter/cached_serializer.rb | 2 +- lib/active_model_serializers/adapter/fragment_cache.rb | 2 +- .../adapter/json_api/deserialization.rb | 2 +- .../adapter/json_api/fragment_cache.rb | 2 +- lib/active_model_serializers/deprecate.rb | 2 +- test/action_controller/adapter_selector_test.rb | 2 +- test/action_controller/json_api/pagination_test.rb | 4 ++-- test/action_controller/serialization_test.rb | 2 +- test/adapter/json_api/belongs_to_test.rb | 2 +- test/adapter/json_api/collection_test.rb | 2 +- test/adapter/json_api/linked_test.rb | 8 ++++---- test/adapter/json_api/pagination_links_test.rb | 2 +- test/adapter/json_api/relationship_test.rb | 10 +++++----- test/grape_test.rb | 10 +++++----- test/serializers/associations_test.rb | 8 ++++---- test/support/rails5_shims.rb | 2 +- test/support/serialization_testing.rb | 2 +- 21 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/active_model/serializable_resource.rb b/lib/active_model/serializable_resource.rb index ec83fcfc..bf0e36f1 100644 --- a/lib/active_model/serializable_resource.rb +++ b/lib/active_model/serializable_resource.rb @@ -33,7 +33,7 @@ module ActiveModel def adapter @adapter ||= ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts) end - alias_method :adapter_instance, :adapter + alias adapter_instance adapter def serializer_instance @serializer_instance ||= serializer.new(resource, serializer_opts) @@ -54,7 +54,7 @@ module ActiveModel @serializer end end - alias_method :serializer_class, :serializer + alias serializer_class serializer # True when no explicit adapter given, or explicit appear is truthy (non-nil) # False when explicit adapter is falsy (nil or false) @@ -63,7 +63,7 @@ module ActiveModel end def serializer? - use_adapter? && !!(serializer) + use_adapter? && !!serializer end protected diff --git a/lib/active_model/serializer/caching.rb b/lib/active_model/serializer/caching.rb index e8db6f27..3ebb4bae 100644 --- a/lib/active_model/serializer/caching.rb +++ b/lib/active_model/serializer/caching.rb @@ -92,7 +92,7 @@ module ActiveModel self._cache_key = options.delete(:key) self._cache_only = options.delete(:only) self._cache_except = options.delete(:except) - self._cache_options = (options.empty?) ? nil : options + self._cache_options = options.empty? ? nil : options end end end diff --git a/lib/active_model/serializer/version.rb b/lib/active_model/serializer/version.rb index fc3ce89d..8a133f9c 100644 --- a/lib/active_model/serializer/version.rb +++ b/lib/active_model/serializer/version.rb @@ -1,5 +1,5 @@ module ActiveModel class Serializer - VERSION = '0.10.0.rc4' + VERSION = '0.10.0.rc4'.freeze end end diff --git a/lib/active_model_serializers/adapter.rb b/lib/active_model_serializers/adapter.rb index 679b862b..5a914b0c 100644 --- a/lib/active_model_serializers/adapter.rb +++ b/lib/active_model_serializers/adapter.rb @@ -1,7 +1,7 @@ module ActiveModelSerializers module Adapter UnknownAdapterError = Class.new(ArgumentError) - ADAPTER_MAP = {} + ADAPTER_MAP = {}.freeze private_constant :ADAPTER_MAP if defined?(private_constant) require 'active_model_serializers/adapter/fragment_cache' require 'active_model_serializers/adapter/cached_serializer' @@ -49,7 +49,7 @@ module ActiveModelSerializers # 'Json' will both register as 'json'. def register(name, klass = name) name = name.to_s.gsub(/\AActiveModelSerializers::Adapter::/, ''.freeze) - adapter_map.update(name.underscore => klass) + adapter_map[name.underscore] = klass self end diff --git a/lib/active_model_serializers/adapter/cached_serializer.rb b/lib/active_model_serializers/adapter/cached_serializer.rb index 45821668..6f0b0478 100644 --- a/lib/active_model_serializers/adapter/cached_serializer.rb +++ b/lib/active_model_serializers/adapter/cached_serializer.rb @@ -38,7 +38,7 @@ module ActiveModelSerializers def object_cache_key object_time_safe = @cached_serializer.object.updated_at object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime) - (@klass._cache_key) ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key + @klass._cache_key ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key end # find all cache_key for the collection_serializer diff --git a/lib/active_model_serializers/adapter/fragment_cache.rb b/lib/active_model_serializers/adapter/fragment_cache.rb index 7dbc2a87..7451bf38 100644 --- a/lib/active_model_serializers/adapter/fragment_cache.rb +++ b/lib/active_model_serializers/adapter/fragment_cache.rb @@ -46,7 +46,7 @@ module ActiveModelSerializers # 3. Add non-cached attributes to non-cached Serializer def cached_attributes(klass, serializers) attributes = serializer.class._attributes - cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) } + cached_attributes = klass._cache_only ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) } non_cached_attributes = attributes - cached_attributes cached_attributes.each do |attribute| diff --git a/lib/active_model_serializers/adapter/json_api/deserialization.rb b/lib/active_model_serializers/adapter/json_api/deserialization.rb index a50aa88f..f5244355 100644 --- a/lib/active_model_serializers/adapter/json_api/deserialization.rb +++ b/lib/active_model_serializers/adapter/json_api/deserialization.rb @@ -188,7 +188,7 @@ module ActiveModelSerializers end polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym) - hash.merge!("#{prefix_key}_type".to_sym => assoc_data['type']) if polymorphic + hash["#{prefix_key}_type".to_sym] = assoc_data['type'] if polymorphic hash end diff --git a/lib/active_model_serializers/adapter/json_api/fragment_cache.rb b/lib/active_model_serializers/adapter/json_api/fragment_cache.rb index 5ae0b08c..d2953440 100644 --- a/lib/active_model_serializers/adapter/json_api/fragment_cache.rb +++ b/lib/active_model_serializers/adapter/json_api/fragment_cache.rb @@ -8,7 +8,7 @@ module ActiveModelSerializers no_root_cache = cached_hash.delete_if { |key, _value| key == core_cached[0] } no_root_non_cache = non_cached_hash.delete_if { |key, _value| key == core_non_cached[0] } cached_resource = (core_cached[1]) ? core_cached[1].deep_merge(core_non_cached[1]) : core_non_cached[1] - hash = (root) ? { root => cached_resource } : cached_resource + hash = root ? { root => cached_resource } : cached_resource hash.deep_merge no_root_non_cache.deep_merge no_root_cache end diff --git a/lib/active_model_serializers/deprecate.rb b/lib/active_model_serializers/deprecate.rb index ba95c07f..64949699 100644 --- a/lib/active_model_serializers/deprecate.rb +++ b/lib/active_model_serializers/deprecate.rb @@ -33,7 +33,7 @@ module ActiveModelSerializers alias_method old, name class_eval do define_method(name) do |*args, &block| - target = self.is_a?(Module) ? "#{self}." : "#{self.class}#" + target = is_a?(Module) ? "#{self}." : "#{self.class}#" msg = ["NOTE: #{target}#{name} is deprecated", replacement == :none ? ' with no replacement' : "; use #{replacement} instead", "\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}" diff --git a/test/action_controller/adapter_selector_test.rb b/test/action_controller/adapter_selector_test.rb index 55cff11e..aa3539f7 100644 --- a/test/action_controller/adapter_selector_test.rb +++ b/test/action_controller/adapter_selector_test.rb @@ -36,7 +36,7 @@ module ActionController type: 'profiles', attributes: { name: 'Name 1', - description: 'Description 1', + description: 'Description 1' } } } diff --git a/test/action_controller/json_api/pagination_test.rb b/test/action_controller/json_api/pagination_test.rb index 7c8ebec2..183ec1c3 100644 --- a/test/action_controller/json_api/pagination_test.rb +++ b/test/action_controller/json_api/pagination_test.rb @@ -8,8 +8,8 @@ module ActionController module Serialization class JsonApi class PaginationTest < ActionController::TestCase - KAMINARI_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari' - WILL_PAGINATE_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate' + KAMINARI_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari'.freeze + WILL_PAGINATE_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate'.freeze class PaginationTestController < ActionController::Base def setup diff --git a/test/action_controller/serialization_test.rb b/test/action_controller/serialization_test.rb index e8e99dd5..3870c25a 100644 --- a/test/action_controller/serialization_test.rb +++ b/test/action_controller/serialization_test.rb @@ -91,7 +91,7 @@ module ActionController expires_in = [ PostSerializer._cache_options[:expires_in], - CommentSerializer._cache_options[:expires_in], + CommentSerializer._cache_options[:expires_in] ].max + 200 Timecop.travel(Time.zone.now + expires_in) do diff --git a/test/adapter/json_api/belongs_to_test.rb b/test/adapter/json_api/belongs_to_test.rb index c501b4d8..ded83ab5 100644 --- a/test/adapter/json_api/belongs_to_test.rb +++ b/test/adapter/json_api/belongs_to_test.rb @@ -43,7 +43,7 @@ module ActiveModelSerializers type: 'posts', attributes: { title: 'New Post', - body: 'Body', + body: 'Body' }, relationships: { comments: { data: [{ type: 'comments', id: '1' }] }, diff --git a/test/adapter/json_api/collection_test.rb b/test/adapter/json_api/collection_test.rb index b534108a..ef1a13d7 100644 --- a/test/adapter/json_api/collection_test.rb +++ b/test/adapter/json_api/collection_test.rb @@ -60,7 +60,7 @@ module ActiveModelSerializers actual = ActiveModel::SerializableResource.new( [@first_post, @second_post], adapter: :json_api, fields: { posts: %w(title comments blog author) }) - .serializable_hash + .serializable_hash expected = [ { id: '1', diff --git a/test/adapter/json_api/linked_test.rb b/test/adapter/json_api/linked_test.rb index bcf18123..e9132881 100644 --- a/test/adapter/json_api/linked_test.rb +++ b/test/adapter/json_api/linked_test.rb @@ -98,7 +98,7 @@ module ActiveModelSerializers id: '2', type: 'comments', attributes: { - body: 'ZOMG ANOTHER COMMENT', + body: 'ZOMG ANOTHER COMMENT' }, relationships: { post: { data: { type: 'posts', id: '10' } }, @@ -141,7 +141,7 @@ module ActiveModelSerializers type: 'bios', attributes: { rating: nil, - content: 'Rails Contributor', + content: 'Rails Contributor' }, relationships: { author: { data: { type: 'authors', id: '2' } } @@ -314,7 +314,7 @@ module ActiveModelSerializers def test_no_duplicates hash = ActiveModel::SerializableResource.new(@post1, adapter: :json_api, include: '*.*') - .serializable_hash + .serializable_hash expected = [ { type: 'authors', id: '1', @@ -343,7 +343,7 @@ module ActiveModelSerializers hash = ActiveModel::SerializableResource.new( [@post1, @post2], adapter: :json_api, include: '*.*') - .serializable_hash + .serializable_hash expected = [ { type: 'authors', id: '1', diff --git a/test/adapter/json_api/pagination_links_test.rb b/test/adapter/json_api/pagination_links_test.rb index 80046e10..d728f700 100644 --- a/test/adapter/json_api/pagination_links_test.rb +++ b/test/adapter/json_api/pagination_links_test.rb @@ -8,7 +8,7 @@ module ActiveModelSerializers module Adapter class JsonApi class PaginationLinksTest < ActiveSupport::TestCase - URI = 'http://example.com' + URI = 'http://example.com'.freeze def setup ActionController::Base.cache_store.clear diff --git a/test/adapter/json_api/relationship_test.rb b/test/adapter/json_api/relationship_test.rb index 64d8c549..bb3dbcb7 100644 --- a/test/adapter/json_api/relationship_test.rb +++ b/test/adapter/json_api/relationship_test.rb @@ -77,22 +77,22 @@ module ActiveModelSerializers end def test_relationship_block_link - links = { self: proc { "#{object.id}" } } - expected = { links: { self: "#{@blog.id}" } } + links = { self: proc { object.id.to_s } } + expected = { links: { self: @blog.id.to_s } } test_relationship(expected, links: links) end def test_relationship_block_link_with_meta links = { self: proc do - href "#{object.id}" + href object.id.to_s meta(id: object.id) end } expected = { links: { self: { - href: "#{@blog.id}", + href: @blog.id.to_s, meta: { id: @blog.id } } } @@ -122,7 +122,7 @@ module ActiveModelSerializers links = { self: 'a link', related: proc do - href "#{object.id}" + href object.id.to_s meta object.id end diff --git a/test/grape_test.rb b/test/grape_test.rb index c9e07b25..8ba8d6ab 100644 --- a/test/grape_test.rb +++ b/test/grape_test.rb @@ -15,11 +15,11 @@ class ActiveModelSerializers::GrapeTest < ActiveSupport::TestCase def self.all @all ||= - begin - model1.save! - model2.save! - ARModels::Post.all - end + begin + model1.save! + model2.save! + ARModels::Post.all + end end end diff --git a/test/serializers/associations_test.rb b/test/serializers/associations_test.rb index f62da8b8..ed5ce1e0 100644 --- a/test/serializers/associations_test.rb +++ b/test/serializers/associations_test.rb @@ -60,8 +60,8 @@ module ActiveModel def test_serializer_options_are_passed_into_associations_serializers association = @post_serializer - .associations - .detect { |assoc| assoc.key == :comments } + .associations + .detect { |assoc| assoc.key == :comments } assert association.serializer.first.custom_options[:custom_options] end @@ -143,11 +143,11 @@ module ActiveModel ) actual = serializable(post, adapter: :attributes, serializer: InlineAssociationTestPostSerializer).as_json expected = { - :comments => [ + :comments => [ { :id => 1, :contents => 'first comment' }, { :id => 2, :contents => 'last comment' } ], - :last_comments => [ + :last_comments => [ { :id => 2, :contents => 'last comment' } ] } diff --git a/test/support/rails5_shims.rb b/test/support/rails5_shims.rb index 5677d109..ad581c53 100644 --- a/test/support/rails5_shims.rb +++ b/test/support/rails5_shims.rb @@ -1,7 +1,7 @@ module Rails5Shims module ControllerTests # https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb - REQUEST_KWARGS = [:params, :session, :flash, :method, :body, :xhr] + REQUEST_KWARGS = [:params, :session, :flash, :method, :body, :xhr].freeze # Fold kwargs from test request into args # Band-aid for DEPRECATION WARNING diff --git a/test/support/serialization_testing.rb b/test/support/serialization_testing.rb index 1c59d7ed..1447d95d 100644 --- a/test/support/serialization_testing.rb +++ b/test/support/serialization_testing.rb @@ -21,7 +21,7 @@ module SerializationTesting ensure ActiveModelSerializers.config.adapter = old_adapter end - alias_method :with_configured_adapter, :with_adapter + alias with_configured_adapter with_adapter def with_config(hash) old_config = config.dup