diff --git a/README.markdown b/README.markdown index 6e37fb2..29188f6 100644 --- a/README.markdown +++ b/README.markdown @@ -7,7 +7,7 @@ Each strategy is a small amount of code but is code that is usually needed in an ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported. -[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner) +[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner) [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner) Here is an overview of the strategies supported for each library: diff --git a/lib/database_cleaner/mongo/truncation.rb b/lib/database_cleaner/mongo/truncation.rb index e5938dc..a09d1ff 100644 --- a/lib/database_cleaner/mongo/truncation.rb +++ b/lib/database_cleaner/mongo/truncation.rb @@ -20,10 +20,7 @@ module DatabaseCleaner def mongoid_collection_names @@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names| ObjectSpace.each_object(Class) do |klass| - next unless klass.ancestors.map(&:to_s).include?('Mongoid::Document') - next if klass.embedded - next if klass.collection_name.empty? - names[klass.db.name] << klass.collection_name + (names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass) end end end @@ -52,6 +49,14 @@ module DatabaseCleaner db_collections end + + private + + def valid_collection_name?(klass) + klass.ancestors.map(&:to_s).include?('Mongoid::Document') && + !klass.embedded && + !klass.collection_name.empty? + end end end end