在一个应用程序中,我使用 Minitest 和 fixtures 完成测试套件,我遇到了这样的问题,我无法解决,也找不到解决方案。
我有一个模型 Survey
和它的固定装置 test/fixtures/surveys.yml
:
one:
user: admin
name: Survey one
description: This is survey one
company: university
review_type: 1
two:
user: admin
name: Survey two
description: This is survey two
company: university
此外,我有命名空间 surveys
并且有一个问题模型 - Surveys::Question
(具有多态关联),它具有相应的固定装置 test/fixtures/surveys/questions.yml
:
one:
sentence: Survey question one?
display_order: 1
question_type: 0
questionable: one (Survey)
two:
sentence: Survey question two?
display_order: 2
question_type: 1
questionable: one (Survey)
到目前为止一切顺利,一切正常。但是每当我尝试向固定装置添加另一个 questions
定义时,让我们说:
three:
sentence: Survey question three?
display_order: 3
question_type: 2
questionable: one (Survey)
引发了一个错误:ActiveRecord::Fixture::FixtureError: table "surveys"has no column named "sentence"
完全跟不上,怎么突然ActiveRecord::Fixtures
跟不上
如果对此有任何建议,我将不胜感激。
最佳答案
确保您的数据库架构没有更改,并且您没有删除或重命名数据库中的列或表。每当您更改架构并运行迁移时,请务必在运行测试之前运行它:
rake db:test:prepare
然后尝试再次运行您的测试。如果您遇到相同的错误,则表明您的测试数据库缺少该列。检查您的迁移以确保。
此外,您认为您可能需要 test/fixtures/surveys.yml
中的 three:
吗?
关于ruby-on-rails - Rails fixtures 和命名空间模型 - ActiveRecord::Fixture::FixtureError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50221962/