re: RuboCop: Bulk minor style corrections

This commit is contained in:
Alexey Dubovskoy
2016-06-20 20:55:44 +01:00
parent 32a3b53892
commit f15f6850de
15 changed files with 41 additions and 143 deletions

View File

@@ -74,7 +74,7 @@ module ActionController
end
def update_and_render_object_with_cache_enabled
@post.updated_at = Time.now
@post.updated_at = Time.zone.now
generate_cached_serializer(@post)
render json: @post

View File

@@ -22,10 +22,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
assert_equal({
reviews: { data: [
{ type: 'comments', id: '1' },
{ type: 'comments', id: '2' }
] },
reviews: { data: [{ type: 'comments', id: '1' },
{ type: 'comments', id: '2' }] },
writer: { data: { type: 'authors', id: '1' } },
site: { data: { type: 'blogs', id: '1' } }
}, adapter.serializable_hash[:data][:relationships])

View File

@@ -47,7 +47,7 @@ module ActiveModel
assert_equal(expected_type, hash.fetch(:data).fetch(:type))
end
def with_jsonapi_resource_type inflection
def with_jsonapi_resource_type(inflection)
old_inflection = ActiveModelSerializers.config.jsonapi_resource_type
ActiveModelSerializers.config.jsonapi_resource_type = inflection
yield

View File

@@ -20,4 +20,3 @@ module ActiveModelSerializers
end
end
end

View File

@@ -101,7 +101,7 @@ module ActiveModelSerializers
uncached_author_serializer = AuthorSerializer.new(uncached_author)
render_object_with_cache(uncached_author)
key = "#{uncached_author_serializer.class._cache_key}/#{uncached_author_serializer.object.id}-#{uncached_author_serializer.object.updated_at.strftime("%Y%m%d%H%M%S%9N")}"
key = "#{uncached_author_serializer.class._cache_key}/#{uncached_author_serializer.object.id}-#{uncached_author_serializer.object.updated_at.strftime('%Y%m%d%H%M%S%9N')}"
key = "#{key}/#{adapter.cache_key}"
assert_equal(uncached_author_serializer.attributes.to_json, cache_store.fetch(key).to_json)
end

View File

@@ -8,7 +8,7 @@ class Model < ActiveModelSerializers::Model
# Convenience when not adding @attributes readers and writers
def method_missing(meth, *args)
if meth.to_s =~ /^(.*)=$/
attributes[$1.to_sym] = args[0]
attributes[Regexp.last_match(1).to_sym] = args[0]
elsif attributes.key?(meth)
attributes[meth]
else
@@ -64,7 +64,7 @@ VirtualValue = Class.new(Model)
Comment = Class.new(Model) do
# Uses a custom non-time-based cache key
def cache_key
"#{self.class.name.downcase}/#{self.id}"
"#{self.class.name.downcase}/#{id}"
end
end

View File

@@ -39,12 +39,12 @@ class ActiveModelSerializers::GrapeTest < ActiveSupport::TestCase
begin
Kaminari.paginate_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')
]
).page(1).per(collection_per)
end
end

View File

@@ -30,7 +30,7 @@ module ActiveModel
def errors
end
def self.human_attribute_name(attr, options = {})
def self.human_attribute_name(_, _ = {})
end
def self.lookup_ancestors

View File

@@ -41,7 +41,9 @@ module ActiveModel
end
class CustomProfile
def serializer_class; ProfileSerializer; end
def serializer_class
ProfileSerializer
end
end
Tweet = Class.new(::Model)