rspec,未知属性问题 [英] rspec, unknown attribute question
问题描述
我正在浏览(优秀的)railstutorial.org 站点,有一个关于 rspec 的基本问题.
I am working through the (excellent) railstutorial.org site have have a basic question about rspec.
当我在新用户模型上运行以下测试时,我收到未知属性:用户名"消息和失败的测试.
When I run the below test on a new user model, I get an "unknown attribute: username" message and a failed test.
before(:each) do
@attr = { :lname_e => "User", :fname_e => "Test", :email => "user@example.com", :username => "testUser" }
end
it "should create a new instance given valid attributes" do
User.create!(@attr)
end
错误语法是
Failures:
1) User should create a new instance given valid attributes
Failure/Error: User.create!(@attr)
unknown attribute: username
# ./spec/models/user_spec.rb:11:in `block (2 levels) in <top (required)>'
该字段在 users 表(字符串)中,它在模型中作为 attr_accessible 并且在控制台中,我可以在测试中使用完全相同的语法创建一个用户.这个用户名"字段是在创建初始表后通过迁移添加的,这里还有其他文件需要更新吗?
The field is in the users table (string), it's in the model as attr_accessible and in the console I can create a user with exactly the same syntax in the test. This "username" field was added via a migration after creating the initial table, is there some other file I need to update here?
谢谢,
推荐答案
您是否运行了 rake db:test:prepare
?
这篇关于rspec,未知属性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!