extracts Mongo::Truncation module

This commit is contained in:
Ben Mabey 2011-01-25 21:09:29 -07:00
parent 2794ba9e8b
commit 7dbd5c5616
3 changed files with 30 additions and 32 deletions

View 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

View file

@ -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

View file

@ -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