ruby-on-rails - Cucumber 规范看不到最新迁移添加的列

标签 ruby-on-rails activerecord cucumber

我有一个 cucumber 步骤,尝试填充对象,包括刚刚通过迁移添加的新列。该列名为is_active,错误为:

      unknown attribute: is_active (ActiveRecord::UnknownAttributeError)

这是由于这一行而引发的:

    city = City.find_or_create_by_name_and_state(:name => attributes['City'], :state => attributes['State'], :icao_code => attributes['ICAO'], :display_order => attributes['Order'], :is_active => attributes['Active'], :current_temperature => attributes['Current'])

奇怪的是,今天早些时候,我添加了 display_order 列,该列工作正常。

如果我从步骤中删除 :is_active 分配并在城市分配后添加“puts city.attributes”,则 is_active 不会列在属性中。但是,如果我从 Rails 控制台执行“City.new.attributes”,则 is_active 属性存在。

cucumber 测试似乎没有在正确的环境中执行,尽管它能够看到最近的display_order属性,该属性仅在开发环境中定义,就像最近的is_active一样属性。

有什么想法可以让 cucumber 看到该属性吗?

谢谢

菲尔

最佳答案

rake db:migrate
rake db:test:prepare

测试环境不使用开发中使用的相同数据库。您必须在每次实际更改数据库结构的迁移之后运行命令 rake db:test:prepare 来重新创建它。

该命令只是根据 schema.rb 文件(或 Structure.sql,这取决于项目的配置)创建测试数据库,该数据库是在运行迁移时创建/更新的。

Check the info from the rails guides

关于ruby-on-rails - Cucumber 规范看不到最新迁移添加的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9744637/

相关文章:

ruby-on-rails - 将时间合并到日期时间以更新日期时间

reactjs - React 与 cucumberjs 集成

java - 当我尝试安装 cucumber Eclipse 插件时,它没有安装并显示一些错误

ruby-on-rails - 渲染静态页面时 Rails 路由冲突

ruby-on-rails - 在 Cucumber 中重用 2 个不同模型之间的代码

mysql - rails : how to find all users older then n minutes ago where n is stored in joined group

java - 在Gradle中使用 cucumber 时在运行时添加必要的库文件

ruby-on-rails - 如何部署我的应用程序可以访问但其他人无法获取的 'private' gem?

sql - Rails 3 与 PostgreSQL : Problem with 'update_all' in joined table

ruby-on-rails - Refinerycms Rails 3.2.1