Sha256: bb68a450e975ebbbe8e005b28f909c8b7a7b42ffcec15685f3f2b1223d1432ac

Contents?: true

Size: 646 Bytes

Versions: 2

Compression:

Stored size: 646 Bytes

Contents

module DatabaseCleaner
  module Mongoid
    module Mongoid4Mixin
      def clean
        collections_to_delete.each(&:remove_all)
        wait_for_removals_to_finish
      end

      private

      def database
        ::Mongoid.default_session
      end

      def collections
        if db != :default
          database.use(db)
        end

        database.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
          collection['name']
        end
      end

      def wait_for_removals_to_finish
        database.command(getlasterror: 1)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
database_cleaner-mongoid-2.0.1 lib/database_cleaner/mongoid/mongoid4_mixin.rb
database_cleaner-mongoid-2.0.0.beta lib/database_cleaner/mongoid/mongoid4_mixin.rb