added support for mongoid 5.0

This commit is contained in:
Jon Principe 2015-06-05 15:33:59 -04:00
parent 19773bbd1c
commit f080668b98

View file

@ -20,7 +20,7 @@ module DatabaseCleaner
::Mongoid.database
end
else
elsif ::Mongoid::VERSION < '5'
include ::DatabaseCleaner::Moped::TruncationBase
@ -37,6 +37,38 @@ module DatabaseCleaner
::Mongoid.database
end
end
else
def clean
if @only
collections.each { |c| database[c].find.delete_many if @only.include?(c) }
else
collections.each { |c| database[c].find.delete_many unless @tables_to_exclude.include?(c) }
end
true
end
private
def collections
if db != :default
database.use(db)
end
database['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
_, name = collection['name'].split('.', 2)
name
end
end
def database
if not(@db.nil? or @db == :default)
::Mongoid::Clients.with_name(@db)
else
::Mongoid::Clients.default
end
end
end
end
end