让 Cucumber 运行迁移而不是架构加载

发布于 2024-08-02 06:57:25 字数 160 浏览 3 评论 0原文

因此,我在迁移中加载了一些数据,例如,在创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅沫记忆 2024-08-09 06:57:25

不要使用迁移来加载数据。这被广泛认为是一种不好的做法,因为在构建 schema.rb 时不会保留数据加载。

从 rake 任务或其他方法加载数据,您可以将其挂接到 env.rb 文件的开始博客

begin do
  Role.create :name=>"admin"
  `rake RAILS_ENV="test" db:load_data_for_testing `
end

或类似的东西中。

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

begin do
  Role.create :name=>"admin"
  `rake RAILS_ENV="test" db:load_data_for_testing `
end

Or something like that.

霊感 2024-08-09 06:57:25

我也遇到过类似的问题,并追溯到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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文