mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
extracts Mongo::Truncation module
This commit is contained in:
parent
2794ba9e8b
commit
7dbd5c5616
3 changed files with 30 additions and 32 deletions
22
lib/database_cleaner/mongo/truncation.rb
Normal file
22
lib/database_cleaner/mongo/truncation.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
module DatabaseCleaner
|
||||
module Mongo
|
||||
module Truncation
|
||||
|
||||
def clean
|
||||
if @only
|
||||
collections.each { |c| c.remove if @only.include?(c.name) }
|
||||
else
|
||||
collections.each { |c| c.remove unless @tables_to_exclude.include?(c.name) }
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collections
|
||||
database.collections.select { |c| c.name !~ /^system/ }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,35 +1,18 @@
|
|||
require 'database_cleaner/mongo_mapper/base'
|
||||
require 'database_cleaner/generic/truncation'
|
||||
require 'database_cleaner/mongo/truncation'
|
||||
|
||||
module DatabaseCleaner
|
||||
module MongoMapper
|
||||
class Truncation
|
||||
include ::DatabaseCleaner::MongoMapper::Base
|
||||
include ::DatabaseCleaner::Generic::Truncation
|
||||
|
||||
def clean
|
||||
if @only
|
||||
collections.each { |c| c.remove if @only.include?(c.name) }
|
||||
elsif @tables_to_exclude
|
||||
collections.each { |c| c.remove unless @tables_to_exclude.include?(c.name) }
|
||||
else
|
||||
collections.each { |c| c.remove }
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
include ::DatabaseCleaner::Mongo::Truncation
|
||||
|
||||
private
|
||||
|
||||
def connection
|
||||
::MongoMapper.connection
|
||||
end
|
||||
|
||||
def collections
|
||||
connection.db(database).collections.select { |c| c.name !~ /^system/ }
|
||||
end
|
||||
|
||||
def database
|
||||
::MongoMapper.database.name
|
||||
::MongoMapper.database
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
require 'database_cleaner/mongoid/base'
|
||||
require 'database_cleaner/generic/truncation'
|
||||
require 'database_cleaner/mongo/truncation'
|
||||
|
||||
module DatabaseCleaner
|
||||
module Mongoid
|
||||
class Truncation
|
||||
include ::DatabaseCleaner::Mongoid::Base
|
||||
include ::DatabaseCleaner::Generic::Truncation
|
||||
|
||||
def clean
|
||||
if @only
|
||||
collections.each { |c| c.remove if @only.include?(c.name) }
|
||||
else
|
||||
collections.each { |c| c.remove unless @tables_to_exclude.include?(c.name) }
|
||||
end
|
||||
true
|
||||
end
|
||||
include ::DatabaseCleaner::Mongo::Truncation
|
||||
|
||||
private
|
||||
|
||||
def collections
|
||||
::Mongoid.database.collections.select { |c| c.name !~ /^system/ }
|
||||
def database
|
||||
::Mongoid.database
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue