作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在测试一些遗留代码。其中一个表有一个 enum
列。 (我知道,别恨,不是我写的)。
在尝试运行单元测试之前一切正常。突然,数据库架构将 enum
列保存为 varchar(0)
。显然不允许我设置任何值。
这是我的大问题。如何向 rake test:units
添加 Hook 来调整列类型?它是 enum
还是只是 varchar(100)
并不重要。
谢谢!
最佳答案
所以这个问题的解决方案比我预想的要容易。在 environment.rb
文件中有一个部分:
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
取消最后一行的注释意味着两件事。首先,模式以 SQL 而不是 Ruby 导出。其次,保留数据库特定的数据类型。
config.active_record.schema_format = :sql
关于mysql - Rails 单元测试中的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18959922/
我是一名优秀的程序员,十分优秀!