Permalink
Browse files

Merge pull request #43 from johnnyshields/drop-mongoid-2

Drop support for Mongoid 2
  • Loading branch information...
2 parents 6b489d2 + 5b18f44 commit 87d1098dc1a2ab9102ebcbe4cb48ac25b985d3e5 @pyromaniac committed Nov 1, 2015
View
@@ -6,7 +6,6 @@ rvm:
# - rbx
env:
- - MONGOID_VERSION=2
- MONGOID_VERSION=3
- MONGOID_VERSION=4
- MONGOID_VERSION=5
View
@@ -10,9 +10,6 @@ when /^4/
gem 'mongoid', '~> 4.0'
when /^3/
gem 'mongoid', '~> 3.1'
-when /^2/
- gem 'mongoid', '~> 2.0'
- gem 'bson_ext', platforms: :ruby
else
gem 'mongoid', version
end
@@ -1,17 +1,15 @@
module Mongoid::Orderable
module Errors
class InvalidTargetPosition < Mongoid::Orderable::Errors::MongoidOrderableError
+
def initialize value
super _compose_message(value)
end
private
+
def _compose_message value
- if ::Mongoid::Compatibility::Version.mongoid2?
- translate 'invalid_target_position', { :value => value.inspect }
- else
- compose_message 'invalid_target_position', { :value => value.inspect }
- end
+ compose_message 'invalid_target_position', { :value => value.inspect }
end
end
end
@@ -1,14 +1,6 @@
module Mongoid::Orderable
module Errors
class MongoidOrderableError < ::Mongoid::Errors::MongoidError
-
- if ::Mongoid::Compatibility::Version.mongoid2?
- def translate key, options
- [:message, :summary, :resolution].map do |section|
- ::I18n.translate "#{BASE_KEY}.#{key}.#{section}", options
- end.join ' '
- end
- end
end
end
end
@@ -31,11 +31,7 @@ def add_db_field
def add_db_index
spec = [[configuration[:column], 1]]
spec.unshift([configuration[:scope], 1]) if configuration[:scope].is_a?(Symbol)
- if ::Mongoid::Compatibility::Version.mongoid2?
- klass.index(spec)
- else
- klass.index(Hash[spec])
- end
+ klass.index(Hash[spec])
end
def save_configuration
View
@@ -7,7 +7,7 @@
require 'mongoid/compatibility'
module MongoidOrderable
- if ::Mongoid::Compatibility::Version.mongoid2? || ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
def self.inc instance, attribute, value
instance.inc attribute, value
end
@@ -28,13 +28,7 @@ def self.metadata instance
require 'mongoid_orderable/version'
-if ::Mongoid::Compatibility::Version.mongoid2?
- require 'mongoid_orderable/mongoid/contexts/mongo'
- require 'mongoid_orderable/mongoid/contexts/enumerable'
- require 'mongoid_orderable/mongoid/criteria'
-else
- require 'mongoid_orderable/mongoid/contextual/memory'
-end
+require 'mongoid_orderable/mongoid/contextual/memory'
require 'mongoid/orderable'
require 'mongoid/orderable/errors'
@@ -1,15 +0,0 @@
-module MongoidOrderable #:nodoc:
- module Mongoid #:nodoc:
- module Contexts #:nodoc:
- module Enumerable #:nodoc:
- def inc attribute, value
- iterate do |doc|
- MongoidOrderable.inc doc, attribute, value
- end
- end
- end
- end
- end
-end
-
-Mongoid::Contexts::Enumerable.send :include, MongoidOrderable::Mongoid::Contexts::Enumerable
@@ -1,18 +0,0 @@
-module MongoidOrderable #:nodoc:
- module Mongoid #:nodoc:
- module Contexts #:nodoc:
- module Mongo #:nodoc:
- def inc attribute, value
- klass.collection.update(
- selector,
- { "$inc" => {attribute => value} },
- :multi => true,
- :safe => ::Mongoid.persist_in_safe_mode
- )
- end
- end
- end
- end
-end
-
-Mongoid::Contexts::Mongo.send :include, MongoidOrderable::Mongoid::Contexts::Mongo
@@ -1,4 +0,0 @@
-Mongoid::Criteria.delegate :inc, :to => :context
-Mongoid::Finders.send :define_method, :inc do |*args|
- criteria.send :inc, *args
-end
@@ -21,6 +21,6 @@ Gem::Specification.new do |s|
# specify any dependencies here; for example:
s.add_development_dependency "rake"
s.add_development_dependency "rspec"
- s.add_runtime_dependency "mongoid"
+ s.add_runtime_dependency "mongoid", ">= 3.0.0"
s.add_runtime_dependency "mongoid-compatibility"
end
@@ -137,9 +137,7 @@ def positions
end
it 'should have index on position column' do
- if ::Mongoid::Compatibility::Version.mongoid2?
- expect(SimpleOrderable.index_options[[[:position, 1]]]).not_to be_nil
- elsif ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
expect(SimpleOrderable.index_options[{:position => 1}]).not_to be_nil
else
expect(SimpleOrderable.index_specifications.detect { |spec| spec.key == {:position => 1} }).not_to be_nil
@@ -347,19 +345,15 @@ def positions
describe 'index' do
it 'is not on position alone' do
- if ::Mongoid::Compatibility::Version.mongoid2?
- expect(ScopedOrderable.index_options[[[:position, 1]]]).to be_nil
- elsif ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
expect(ScopedOrderable.index_options[{:position => 1}]).to be_nil
else
expect(ScopedOrderable.index_specifications.detect { |spec| spec.key == {:position => 1} }).to be_nil
end
end
it 'is on compound fields' do
- if ::Mongoid::Compatibility::Version.mongoid2?
- expect(ScopedOrderable.index_options[[[:group_id, 1], [:position, 1]]]).to_not be_nil
- elsif ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
expect(ScopedOrderable.index_options[{:group_id => 1, :position => 1}]).to_not be_nil
else
expect(ScopedOrderable.index_specifications.detect { |spec| spec.key == {:group_id => 1, :position => 1} }).to_not be_nil
@@ -540,7 +534,7 @@ def positions
describe NoIndexOrderable do
it 'should not have index on position column' do
- if ::Mongoid::Compatibility::Version.mongoid2? || ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
expect(NoIndexOrderable.index_options[[[:position, 1]]]).to be_nil
else
expect(NoIndexOrderable.index_specifications.detect { |spec| spec.key == :position }).to be_nil
@@ -901,9 +895,7 @@ class Apple
end
it 'should have index on serial_no column' do
- if ::Mongoid::Compatibility::Version.mongoid2?
- expect(MultipleColumnsOrderable.index_options[[[:serial_no, 1]]]).not_to be_nil
- elsif ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
expect(MultipleColumnsOrderable.index_options[{:serial_no => 1}]).not_to be_nil
else
expect(MultipleColumnsOrderable.index_specifications.detect { |spec| spec.key == {:serial_no => 1} }).not_to be_nil
@@ -1064,9 +1056,7 @@ class Apple
end
it 'should have index on position column' do
- if ::Mongoid::Compatibility::Version.mongoid2?
- expect(MultipleColumnsOrderable.index_options[[[:position, 1]]]).to be_nil
- elsif ::Mongoid::Compatibility::Version.mongoid3?
+ if ::Mongoid::Compatibility::Version.mongoid3?
expect(MultipleColumnsOrderable.index_options[{:position => 1}]).to be_nil
else
expect(MultipleColumnsOrderable.index_specifications.detect { |spec| spec.key == {:position => 1} }).to be_nil
View
@@ -1,27 +1,16 @@
require 'bundler'
Bundler.require
-if ::Mongoid::Compatibility::Version.mongoid2?
- Mongoid.configure do |config|
- config.master = Mongo::Connection.new.db 'mongoid_orderable_test'
- config.logger = nil
- end
-else
- Mongoid.configure do |config|
- config.connect_to 'mongoid_orderable_test'
- end
+Mongoid.configure do |config|
+ config.connect_to 'mongoid_orderable_test'
end
-unless Mongoid::Compatibility::Version.mongoid2?
- Mongoid.logger.level = Logger::INFO
- Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
-end
+Mongoid.logger.level = Logger::INFO
+Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
RSpec.configure do |config|
config.after(:all) do
- if Mongoid::Compatibility::Version.mongoid2?
- Mongoid.master.connection.drop_database(Mongoid.database.name)
- elsif Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
+ if Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
Mongoid.default_session.drop
else
Mongoid::Clients.default.database.drop

0 comments on commit 87d1098

Please sign in to comment.