Skip to content

Commit

Permalink
Merge pull request #125 from dblock/fix-rbx
Browse files Browse the repository at this point in the history
Fix RBX, update RuboCop & RSpec.
  • Loading branch information
dblock committed Dec 9, 2014
2 parents 9ddddf8 + 604b13e commit 0c6aa47
Show file tree
Hide file tree
Showing 18 changed files with 556 additions and 562 deletions.
72 changes: 1 addition & 71 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,4 @@ AllCops:
- vendor/**/*
- bin/**/*

LineLength:
Enabled: false

MethodLength:
Enabled: false

ClassLength:
Enabled: false

Documentation:
# don't require classes to be documented
Enabled: false

CollectionMethods:
# don't prefer map to collect, recuce to inject
Enabled: false

Encoding:
# no need to always specify encoding
Enabled: false

StringLiterals:
# use single or double-quoted strings, as you please
Enabled: false

Void:
# == operator used in void context in specs
Enabled: false

SignalException:
# prefer raise to fail
EnforcedStyle: only_raise

RaiseArgs:
# don't care for what kind of raise
Enabled: false

PerlBackrefs:
# TODO: regular expression matching with $1, $2, etc.
Enabled: false

BlockNesting:
# TODO: fix too much nesting
Max: 4

Lambda:
# TODO: replace all lambda with -> or Proc
Enabled: false

Blocks:
# allow multi-line blocks like expect { }
Enabled: false

WordArray:
# %w vs. [ '', ... ]
Enabled: false

CyclomaticComplexity:
Enabled: false

HandleExceptions:
Enabled: false

MultilineBlockChain:
Enabled: false

FileName:
Enabled: false

RegexpLiteral:
Enabled: false
inherit_from: .rubocop_todo.yml
61 changes: 61 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-12-09 07:20:55 -0500 using RuboCop version 0.27.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: 3
Lint/HandleExceptions:
Enabled: false

# Offense count: 27
Lint/Void:
Enabled: false

# Offense count: 12
Metrics/AbcSize:
Max: 51

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

# Offense count: 181
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 688

# Offense count: 7
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 32

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

# Offense count: 37
Style/Documentation:
Enabled: false

# Offense count: 6
Style/EachWithObject:
Enabled: false

# Offense count: 1
# Configuration parameters: Exclude.
Style/FileName:
Enabled: false

# Offense count: 1
Style/Lambda:
Enabled: false

# Offense count: 3
Style/MultilineBlockChain:
Enabled: false

# Offense count: 2
Style/RegexpLiteral:
MaxSlashes: 0
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
services: mongodb

sudo: false

language: ruby

cache: bundler
Expand All @@ -8,7 +10,7 @@ rvm:
- 2.1.1
- 2.0.0
- 1.9.3
- rbx-2
- rbx-2.2.10
- jruby-19mode

env:
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
$stderr.puts 'Run `bundle install` to install missing gems'
exit e.status_code
end

Expand All @@ -13,11 +13,11 @@ require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.rspec_opts = "--color --format progress"
spec.rspec_opts = '--color --format progress'
end

require 'rubocop/rake_task'
Rubocop::RakeTask.new(:rubocop)
RuboCop::RakeTask.new(:rubocop)

task default: [:rubocop, :spec]

Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid-history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
require 'mongoid/history/tracker'
require 'mongoid/history/trackable'

Mongoid::History.modifier_class_name = "User"
Mongoid::History.modifier_class_name = 'User'
Mongoid::History.trackable_class_options = {}
Mongoid::History.current_user_method ||= :current_user
2 changes: 1 addition & 1 deletion lib/mongoid/history.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Mongoid
module History
GLOBAL_TRACK_HISTORY_FLAG = "mongoid_history_trackable_enabled"
GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'

mattr_accessor :tracker_class_name
mattr_accessor :trackable_class_options
Expand Down
6 changes: 3 additions & 3 deletions lib/mongoid/history/trackable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def get_versions_criteria(options_or_version)
if options[:from] && options[:to]
lower = options[:from] >= options[:to] ? options[:to] : options[:from]
upper = options[:from] < options[:to] ? options[:to] : options[:from]
versions = history_tracks.where(:version.in => (lower .. upper).to_a)
versions = history_tracks.where(:version.in => (lower..upper).to_a)
elsif options[:last]
versions = history_tracks.limit(options[:last])
else
raise "Invalid options, please specify (:from / :to) keys or :last key."
fail '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 @@ -308,7 +308,7 @@ def tracked_fields
#
# @return [ Array < String > ] the list of reserved database field names
def reserved_tracked_fields
@reserved_tracked_fields ||= ["_id", history_trackable_options[:version_field].to_s, "#{history_trackable_options[:modifier_field]}_id"]
@reserved_tracked_fields ||= ['_id', history_trackable_options[:version_field].to_s, "#{history_trackable_options[:modifier_field]}_id"]
end

def history_trackable_options
Expand Down
16 changes: 8 additions & 8 deletions lib/mongoid/history/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ def tracked_edits
# { field_1: value, field_2: value }
def affected
target = action.to_sym == :destroy ? :from : :to
@affected ||= tracked_changes.inject(HashWithIndifferentAccess.new) { |h, (k, v)|
@affected ||= tracked_changes.inject(HashWithIndifferentAccess.new) do |h, (k, v)|
h[k] = v[target]
h
}
end
end

# Returns the class of the trackable, irrespective of whether the trackable object
# has been destroyed.
#
# @return [ Class ] the class of the trackable
def trackable_parent_class
association_chain.first["name"].constantize
association_chain.first['name'].constantize
end

private
Expand All @@ -166,18 +166,18 @@ def re_destroy

def create_standalone
restored = trackable_parent_class.new(localize_keys(original))
restored.id = original["_id"]
restored.id = original['_id']
restored.save!
end

def create_on_parent
name = association_chain.last["name"]
name = association_chain.last['name']
if trackable_parent.class.embeds_one?(name)
trackable_parent.create_embedded(name, localize_keys(original))
elsif trackable_parent.class.embeds_many?(name)
trackable_parent.get_embedded(name).create!(localize_keys(original))
else
raise "This should never happen. Please report bug!"
fail 'This should never happen. Please report bug!'
end
end

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

def localize_keys(hash)
klass = association_chain.first["name"].constantize
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)
Expand Down
4 changes: 2 additions & 2 deletions mongoid-history.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'activesupport'

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '>= 3.0'
s.add_development_dependency 'rspec', '~> 3.1'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rubocop', '0.21.0'
s.add_development_dependency 'rubocop', '0.27.1'
s.add_development_dependency 'yard'
s.add_development_dependency 'gem-release'
s.add_development_dependency 'coveralls'
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/embedded_in_polymorphic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ class User
end
end

it "tracks history for nested embedded documents with polymorphic relations" do
it 'tracks history for nested embedded documents with polymorphic relations' do
user = User.new
user.save!

real_state = user.real_states.build(name: 'rs_name')
real_state.save!
real_state.build_address(address: "Main Street #123", city: "Highland Park", state: 'IL').save!
real_state.build_address(address: 'Main Street #123', city: 'Highland Park', state: 'IL').save!
expect(real_state.history_tracks.count).to eq(2)
expect(real_state.address.history_tracks.count).to eq(1)

Expand All @@ -102,7 +102,7 @@ class User

company = user.companies.build(name: 'co_name')
company.save!
company.build_address(address: "Main Street #456", city: "Evanston", state: 'IL').save!
company.build_address(address: 'Main Street #456', city: 'Evanston', state: 'IL').save!
expect(company.history_tracks.count).to eq(2)
expect(company.address.history_tracks.count).to eq(1)

Expand All @@ -112,7 +112,7 @@ class User
expect(company.address.history_tracks.count).to eq(2)
expect(company.history_tracks.last.action).to eq('update')

company.build_second_address(address: "Main Street #789", city: "Highland Park", state: 'IL').save!
company.build_second_address(address: 'Main Street #789', city: 'Highland Park', state: 'IL').save!
expect(company.history_tracks.count).to eq(4)
expect(company.second_address.history_tracks.count).to eq(1)
expect(company.history_tracks.last.action).to eq('create')
Expand Down

0 comments on commit 0c6aa47

Please sign in to comment.