在 Rspec 运行之前自动加载 Mongoid 种子数据
有人在这里问了这个问题:
但是他们的解决方案只有在您要运行 db:test:prepare 时才有效,这取决于要加载的模式。 Mongoid 没有模式文件,并且 db:test:prepare 不执行任何操作,因此这不起作用。还有其他可行的策略吗?
Someone asked this question here:
How to load db:seed data into test database automatically?
But their solution only works if you are going to run db:test:prepare which depends on a schema to load. Mongoid doesn't have a schema file, and db:test:prepare doesn't do anything and so this is not working. Is there another strategy that would work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一个类似的问题。我认为特别是最后一个答案会对您有所帮助:
如何加载db:自动将数据种子到测试数据库中?
There is a similar question here. I think that especially the last answer would help you :
How to load db:seed data into test database automatically?
仅供参考,我想出了一种方法来满足我的要求。我在 mongoid.yml 中设置了一个名为 Seed 的数据库:
然后在我的模型中,我只让数据集使用类似这样的种子:
这实际上效果很好,因为生产、测试和开发都是从种子数据库中提取的,这就是我的想。而且我在运行测试时从不清理数据。
Just as a FYI, I figured out a way to meet my requirements. I set up a database called seed like so in mongoid.yml:
Then in my model I just have the datase use seeds like:
This actually works great because production, test, and development are all pulling from the seed database, which is what I want. And I'm never vacuuming out the data when running tests.