为 seeds.rb 编写规范
在项目中,seeds.rb
变得越来越复杂。我们有一个 seeds/
目录,其中包含要加载的数据的 yml 文件。它应该在重新运行时起作用,并且不应该重复记录(这在模型中是允许的)。好吧,seeds.rb 应该被测试,它用于更新生产。不过,我并没有思考这个问题,想知道是否将逻辑移至 lib/ 并照常编写规范。你会怎么办?
Rails 3 与 rspec。
In a project, the seeds.rb
is getting complicated. We have a seeds/
directory with yml files containing data to be loaded. It should work on re-runs and it should not duplicate records (this is allowed in model). Well, the seeds.rb should be tested, it is used to update production. I'm not getting my head around this one though, wondering wether or not to move the logic to lib/
and write specs as normal. What would you do?
rails 3 with rspec.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该尝试一下 Seed-fu gem:
https://github.com/mbleigh/seed-fu
它不会生成重复的记录,并且可以帮助保持数据的一致性。
I think you should try out the seed-fu gem:
https://github.com/mbleigh/seed-fu
It doesn't generate duplicate records and can help maintain the consistency of the data.