我喜欢在每次运行单元测试并清除我的mongo db之前执行一次设置,我该如何在mongoid中做到这一点?
我在谷歌搜索的时候发现了一些关于它的链接,但似乎什么都不起作用。
发布于 2014-01-28 17:16:38
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发布于 2012-11-04 22:36:02
您可能想看看database_cleaner gem,它在规范中抽象了清理数据库
发布于 2012-11-04 22:28:01
Mongoid组中的这个discussion(删除Mongoid3中的所有集合)似乎是相关的。有两种方法purge!和truncate!。Purge删除集合,这也意味着索引。Truncate只删除每个集合中的文档,这意味着您可以保留索引,但它比purge慢。
https://stackoverflow.com/questions/13216952
复制相似问题