Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created December 19, 2009 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jnunemaker/259987 to your computer and use it in GitHub Desktop.
Save jnunemaker/259987 to your computer and use it in GitHub Desktop.
clearing collections in between tests with mongo
class ActiveSupport::TestCase
def setup
clear_all_collections
end
def clear_all_collections
Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path|
klass = File.basename(model_path, '.rb').classify.constantize
klass.collection.remove if klass.respond_to?(:collection)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment