mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
added support for mongoid 5.0
This commit is contained in:
parent
19773bbd1c
commit
f080668b98
1 changed files with 33 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue