我尝试使用FactoryGirl创建有效的auth_user
,我的工厂看起来像这样:
FactoryGirl.define do
factory :auth_user, class: AuthUser do
username 'Test'
first_name 'Wilson'
last_name 'Mandela'
email 'test@test.com'
password 'password'
password_confirmation 'password'
is_staff true
is_active true
is_superuser true
last_login DateTime.now
date_joined DateTime.now
end
end
当我尝试在这样的Rspec中创建auth_user
时:auth_user = create(:auth_user)
然后我收到以下错误:
Mysql2 ::错误:字段'密码'没有默认值:INSERT INTO auth_user
似乎Devise不接受工厂中的password
和password_confirmation
字段。我还能做些什么来创建测试auth_user
?我无法在Devise Wiki上找到任何帮助,但我可能忽略了它。有人可以帮忙吗?
答案 0 :(得分:0)
您收到的错误表明您的数据库表中有一个名为password
的字段。这会给你带来麻烦,因为它会与Devise的同名虚拟属性冲突。
数据库中的字段应调用encrypted_password
,这是您在运行rails generate devise auth_user
时应创建的字段。如果情况并非如此,或者您添加了另一个名为password
的字段,请修复迁移,然后运行rake db:migrate:redo VERSION=20150...etc-for-that-migration
。