让 Cucumber 运行迁移而不是架构加载
因此,我在迁移中加载了一些数据,例如,在创建 users 表时创建默认用户,在创建 foos 表时创建某些用户角色(如 foo_admin)。
问题是黄瓜不喜欢这样,因为它会加载模式。
我可以让黄瓜只运行迁移,还是有更好的做法来做这类事情?机械师被用作工厂(没有固定装置!)
So I have some data loading in migrations, for instance a default user is created when the users table is made, and certain user Roles are created (like foo_admin) are created when the foos table is made.
The problem is cucumber doesn't like this, since it does a schema load.
Can I either make cucumber just run the migrations instead, or is there a better practice for doing that type of thing? machinist is being used as the factory (no fixtures!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用迁移来加载数据。这被广泛认为是一种不好的做法,因为在构建 schema.rb 时不会保留数据加载。
从 rake 任务或其他方法加载数据,您可以将其挂接到 env.rb 文件的开始博客
或类似的东西中。
Don't use migrations to load data. It's widely considered to be a bad practice as the data loads are not preserved when building schema.rb.
Load your data from a rake task or another method that you can hook into your env.rb file's begin blog
Or something like that.
我也遇到过类似的问题,并追溯到rake中的依赖项。我的解决方案是直接运行 Cucumber 脚本而不使用 rake,但这可能需要在 Rails 中进行一些配置(使用 Merb 就可以了)。另一个解决方案是重写 rake 任务,使其依赖于 db:migrate 而不是 db:load_schema。
注意。我对最新版本的 Rails 缺乏经验,bin/cucumber 脚本或 env.rb 文件中可能也有加载架构文件的内容。
I have run into similar problems, and traced it back to the dependencies in rake. My solution was to run the cucumber script directly without rake, but this can require a some configuration in Rails (with Merb it works out f the box). The other solution is to override the rake task to it depends on db:migrate rather then db:load_schema.
NB. I've have little experience with recent versions of rails there may also be something in the bin/cucumber script or env.rb file that loads the schema file.