【问题标题】:Use migrations to setup test database in Rails 3在 Rails 3 中使用迁移设置测试数据库
【发布时间】:2012-10-07 11:13:47
【问题描述】:

我有一些在我的迁移中创建触发器和函数的原始 sql 语句。它们不会在测试中调用。

如何使用正常迁移来设置测试数据库?为什么这不是默认方法?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 testing rails-migrations


    【解决方案1】:

    原因是测试数据库是从 schema.rb 文件恢复的。而且 Schema 转储不会创建过程、函数、fkeys 等。原因是 Rails 不鼓励使用它们。但是,您可以将架构转储格式更改为 sql。

    config.active_record.schema_format = :sql
    

    请参阅以下主题Why does rake db:migrate in Rails not add functions to the schema file?

    也可以查看这篇文章http://pivotallabs.com/users/jdean/blog/articles/1707-using-mysql-foreign-keys-procedures-and-triggers-with-rails

    【讨论】:

    • 我已经在 application.rb 中将 schema_format 设置为 sql。但只有标准的 shema.rb 被生成(和使用)。
    • 好的,现在已经创建了一个 structure.sql。但测试似乎忽略了它。
    猜你喜欢
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    相关资源
    最近更新 更多