我试图为我的user_tests
模型设置测试。
运行测试时我得到的错误(很多一个例子):minitest:
ERROR["test_should_get_new", Admin::TestConfigsControllerTest, 2016-01-07 13:04:02 +0100]
test_should_get_new#Admin::TestConfigsControllerTest (1452168242.12s)
ActiveRecord::Fixture::FixtureError:
ActiveRecord::Fixture::FixtureError: table "user_tests" has no column named "user".
没有名为user
的列,但有一个user_id
并且在其他灯具中,这是正确的。我的设置有什么问题,对于这个模型,无法找到列?
灯具user_tests.yml
:
user_test_one:
started: false
started_at:
finished: false
finished_at:
invited: true
invited_at: <%= Time.zone.now %>
user: michael
test_config: test_config_one
test_result:
test_result_type:
user_test_two:
started: false
started_at:
finished: false
finished_at:
test_result:
test_result_type:
invited: false
invited_at:
user: michael
test_config: test_config_two
test_result:
test_result_type:
此处user
,test_config
和test_result
都应指向user_id
,test_config_id
和test_result_id
列。所有都给出了相同类型的错误。
它适用于users.yml
,其中公司和user_group都是指向其他表的链接(请向Michael Hartle致敬,以获得优秀的Ruby on Rails教程):
michael:
first_name: Michael
last_name: Example
email: michael@example.com
password_digest: <%= User.digest('password') %>
admin: true
activated: true
activated_at: <%= Time.zone.now %>
company: my-company
user_group: my-company-groep
archer:
first_name: Sterling
last_name: Archer
email: duchess@example.gov
password_digest: <%= User.digest('password') %>
activated: true
activated_at: <%= Time.zone.now %>
company: my-company
user_group: my-company-groep
users_test.rb
模型的第一行:
class UserTest < ActiveRecord::Base
belongs_to :user, required: true
belongs_to :test_config, required: true
belongs_to :test_result, polymorphic: true
attr_accessor :step, :send_invitation
无法找到数据库的任何问题。以下是SQLite中users
和user_tests
表的屏幕截图:
有什么想法吗?
更新:它必须与测试没有找到此灯具的模型user_test.rb
(user_tests.yml
)。我可以将列user
和test_config
转换为包含_id
但是会出现created_at
和updated_at
列可能不为零的错误({{1 }})。这些应该由Rails处理,但不是。为什么呢?
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: NOT NULL constraint failed: user_tests.created_at
更新2 :我强烈怀疑问题是由于在模型/表格名称中包含“测试”而造成的
答案 0 :(得分:2)
将表格和user_test
(以及所有变体)中的所有相应代码重命名为user_survey
解决了这个问题。