I like to do the setup before each unit test runs and clear my mongo db, how to do it with mongoid?
I found some links about this during the search, but nothing worked.
rake -T output
rake -T
rake db:drop # Drops all the collections for the database for the current Rails.env .. rake db:mongoid:drop # Drops the database for the current Rails.env rake db:mongoid:purge # Drop all collections except the system collections .. rake db:purge # Drop all collections except the system collections
Maybe you should take a look at the database_cleaner gem, which abstracts the database cleanup in the specs
This discussion (Delete all collections in Mongoid 3) in the mongoid group seems relevant. There are two methods of purge! and truncate! . Cleaning discards collections, which means indexes. Truncate only deletes documents in each collection, which means you keep indexes, but slower than cleanup.
purge!
truncate!
If you use Rails, you can run rake db:mongoid:purge to remove all collections except system collections.
rake db:mongoid:purge
Or run rake db:mongoid:drop to remove the database from the current Rails.env.
rake db:mongoid:drop
Source: https://habr.com/ru/post/1443917/More articles:Android Video Editor API - androidHow to enable Loggin content delivery service - tridionAntBuilder runs in Groovy console, but not in Eclipse - eclipsehow can I do javascript to print a json object (sent from ruby) without interpreting it as html? - jsonGet binary data using XMLHttpRequest in Firefox extension - javascriptHow to implement Cocoa copyWithZone on a derived object in MonoMac C #? - c #Checking dates using Calendar Extender and Javascript ASP.NET - javascriptJava grammar on weird ActionListener - javaHow can I customize a custom array in CakePHP - cakephpHow to transfer a project to a server - phpAll Articles