Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rubocop, reduce logging level with Mongoid 6 in specs. #189

Merged
merged 2 commits into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 47 additions & 38 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,101 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-09-17 17:43:47 -0400 using RuboCop version 0.34.1.
# on 2017-04-09 18:25:15 -0400 using RuboCop version 0.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
Exclude:
- 'Gemfile'

# Offense count: 3
Lint/HandleExceptions:
Exclude:
- 'spec/unit/trackable_spec.rb'

Metrics/ClassLength:
Max: 103
# Offense count: 2
Lint/ParenthesesAsGroupedExpression:
Exclude:
- 'spec/integration/integration_spec.rb'

# Offense count: 12
# Offense count: 21
Metrics/AbcSize:
Max: 60
Max: 50

# Offense count: 100
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 801

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 124

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 199
# Configuration parameters: AllowURI, URISchemes.
# Offense count: 435
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 688

# Offense count: 7
# Offense count: 13
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 33
Max: 23

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 223
Max: 176

# Offense count: 4
Metrics/PerceivedComplexity:
Max: 12

# Offense count: 44
# Offense count: 12
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/mongoid/history.rb'
- 'lib/mongoid/history/options.rb'
- 'lib/mongoid/history/trackable.rb'
- 'lib/mongoid/history/tracker.rb'
- 'lib/mongoid/history/version.rb'
- 'lib/mongoid/history/attributes/base.rb'
- 'lib/mongoid/history/attributes/create.rb'
- 'lib/mongoid/history/attributes/destroy.rb'
- 'lib/mongoid/history/attributes/update.rb'
- 'spec/integration/embedded_in_polymorphic_spec.rb'
- 'spec/integration/integration_spec.rb'
- 'spec/integration/multi_relation_spec.rb'
- 'spec/integration/nested_embedded_documents_spec.rb'
- 'spec/integration/nested_embedded_polymorphic_documents_spec.rb'
- 'spec/integration/subclasses_spec.rb'
- 'spec/support/mongoid_history.rb'
- 'spec/unit/options_spec.rb'
- 'spec/unit/singleton_methods_spec.rb'
- 'spec/unit/trackable_spec.rb'
- 'spec/unit/tracker_spec.rb'
- 'spec/unit/attributes/base_spec.rb'
- 'spec/unit/attributes/create_spec.rb'
- 'spec/unit/attributes/destroy_spec.rb'
- 'spec/unit/attributes/update_spec.rb'
- 'lib/mongoid/history/options.rb'
- 'lib/mongoid/history/trackable.rb'
- 'lib/mongoid/history/tracker.rb'

# Offense count: 6
# Offense count: 3
# Cop supports --auto-correct.
Style/EachWithObject:
Exclude:
- 'lib/mongoid/history/trackable.rb'
- 'lib/mongoid/history/tracker.rb'

# Offense count: 1
# Configuration parameters: Exclude.
# Offense count: 2
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Style/FileName:
Exclude:
- 'Dangerfile'
- 'lib/mongoid-history.rb'

# Offense count: 3
Style/MultilineBlockChain:
# Offense count: 1
Style/IfInsideElse:
Exclude:
- 'lib/mongoid/history/trackable.rb'
- 'lib/mongoid/history/tracker.rb'

Style/ClassLength:
# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/mongoid/history/options.rb'
- 'lib/mongoid/history/tracker.rb'
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ else
end

group :development, :test do
gem 'rake', '< 11.0'
gem 'bundler'
gem 'rake', '< 11.0'
end

group :test do
gem 'coveralls'
gem 'gem-release'
gem 'mongoid-danger', '~> 0.1.0', require: false
gem 'request_store'
gem 'rspec', '~> 3.1'
gem 'rubocop', '0.34.1'
gem 'rubocop', '0.48.1'
gem 'yard'
gem 'gem-release'
gem 'coveralls'
gem 'request_store'
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)

task default: [:rubocop, :spec]
task default: %i[rubocop spec]

require 'yard'
YARD::Rake::YardocTask.new
2 changes: 1 addition & 1 deletion lib/mongoid/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

module Mongoid
module History
GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'
GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'.freeze

class << self
attr_accessor :tracker_class_name
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/history/attributes/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def insert_embeds_many_changes
rel = aliased_fields.key(rel) || rel
@attributes[rel] = [nil,
trackable.send(rel)
.reject { |obj| obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present? }
.map { |obj| format_embeds_many_relation(rel, obj.attributes) }]
.reject { |obj| obj.respond_to?(paranoia_field) && obj.public_send(paranoia_field).present? }
.map { |obj| format_embeds_many_relation(rel, obj.attributes) }]
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/mongoid/history/attributes/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def attributes

def insert_embeds_one_changes
trackable_class.tracked_embeds_one
.map { |rel| aliased_fields.key(rel) || rel }
.each do |rel|
obj = trackable.send(rel)
@attributes[rel] = [format_embeds_one_relation(rel, obj.attributes), nil] if obj
end
.map { |rel| aliased_fields.key(rel) || rel }
.each do |rel|
obj = trackable.send(rel)
@attributes[rel] = [format_embeds_one_relation(rel, obj.attributes), nil] if obj
end
end

def insert_embeds_many_changes
trackable_class.tracked_embeds_many
.map { |rel| aliased_fields.key(rel) || rel }
.each do |rel|
@attributes[rel] = [trackable.send(rel).map { |obj| format_embeds_many_relation(rel, obj.attributes) }, nil]
end
.map { |rel| aliased_fields.key(rel) || rel }
.each do |rel|
@attributes[rel] = [trackable.send(rel).map { |obj| format_embeds_many_relation(rel, obj.attributes) }, nil]
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/history/attributes/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def insert_embeds_many_changes(relation, value)
paranoia_field = Mongoid::History.trackable_class_settings(relation_class)[:paranoia_field]
@attributes[relation] = []
@attributes[relation][0] = value[0].reject { |rel| rel[paranoia_field].present? }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
@attributes[relation][1] = value[1].reject { |rel| rel[paranoia_field].present? }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/mongoid/history/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parse(options = {})
def default_options
@default_options ||=
{ on: :all,
except: [:created_at, :updated_at],
except: %i[created_at updated_at],
tracker_class_name: nil,
modifier_field: :modifier,
version_field: :version,
Expand Down Expand Up @@ -83,7 +83,7 @@ def parse_tracked_fields_and_relations
Going forward, :all will track all the fields and relations for the class"
end

@options[:on] = options[:on].map { |opt| (opt == :all) ? :fields : opt }
@options[:on] = options[:on].map { |opt| opt == :all ? :fields : opt }

if options[:on].include?(:fields)
@options[:on] = options[:on].reject { |opt| opt == :fields }
Expand Down Expand Up @@ -163,7 +163,7 @@ def track_embeds_one(field, field_options)
@options[:relations][:embeds_one][field] = if field_options.blank?
relation_class.fields.keys
else
%w(_id) | field_options.map { |opt| relation_class.database_field_name(opt) }
%w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) }
end
end

Expand All @@ -172,7 +172,7 @@ def track_embeds_many(field, field_options)
@options[:relations][:embeds_many][field] = if field_options.blank?
relation_class.fields.keys
else
%w(_id) | field_options.map { |opt| relation_class.database_field_name(opt) }
%w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) }
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/mongoid/history/trackable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_versions_criteria(options_or_version)
elsif options[:last]
versions = history_tracks.limit(options[:last])
else
fail 'Invalid options, please specify (:from / :to) keys or :last key.'
raise 'Invalid options, please specify (:from / :to) keys or :last key.'
end
else
options_or_version = options_or_version.to_a if options_or_version.is_a?(Range)
Expand Down Expand Up @@ -178,7 +178,7 @@ def association_hash(node = self)
relation.class_name == node.metadata.class_name.to_s && relation.name == node.metadata.name
else
relation.class_name == node.relation_metadata.class_name.to_s &&
relation.name == node.relation_metadata.name
relation.name == node.relation_metadata.name
end
end
end
Expand Down Expand Up @@ -445,8 +445,8 @@ def tracked_embeds_one?(relation)
def tracked_embeds_one
@tracked_embeds_one ||= begin
reflect_on_all_associations(:embeds_one)
.map(&:key)
.select { |rel| history_trackable_options[:relations][:embeds_one].include? rel }
.map(&:key)
.select { |rel| history_trackable_options[:relations][:embeds_one].include? rel }
end
end

Expand All @@ -469,8 +469,8 @@ def tracked_embeds_many?(relation)
def tracked_embeds_many
@tracked_embeds_many ||= begin
reflect_on_all_associations(:embeds_many)
.map(&:key)
.select { |rel| history_trackable_options[:relations][:embeds_many].include? rel }
.map(&:key)
.select { |rel| history_trackable_options[:relations][:embeds_many].include? rel }
end
end

Expand Down
12 changes: 7 additions & 5 deletions lib/mongoid/history/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def create_on_parent
elsif trackable_parent.class.embeds_many?(name)
trackable_parent.get_embedded(name).create!(localize_keys(original))
else
fail 'This should never happen. Please report bug!'
raise 'This should never happen. Please report bug!'
end
end

Expand All @@ -205,7 +205,7 @@ def traverse_association_chain
elsif doc.class.embeds_many?(name)
doc.get_embedded(name).unscoped.where(_id: node['id']).first
else
fail 'This should never happen. Please report bug.'
raise 'This should never happen. Please report bug.'
end
documents << doc
break if chain.empty?
Expand All @@ -215,9 +215,11 @@ def traverse_association_chain

def localize_keys(hash)
klass = association_chain.first['name'].constantize
klass.localized_fields.keys.each do |name|
hash["#{name}_translations"] = hash.delete(name) if hash[name].present?
end if klass.respond_to?(:localized_fields)
if klass.respond_to?(:localized_fields)
klass.localized_fields.keys.each do |name|
hash["#{name}_translations"] = hash.delete(name) if hash[name].present?
end
end
hash
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/history/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Mongoid
module History
VERSION = '0.6.2'
VERSION = '0.6.2'.freeze
end
end
2 changes: 1 addition & 1 deletion spec/integration/embedded_in_polymorphic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Contact
track_create: true, # track document creation, default is false
track_update: true, # track document updates, default is true
track_destroy: false, # track document destruction, default is false
scope: [:real_state, :company]
scope: %i[real_state company]
end

class User
Expand Down
Loading