【发布时间】:2017-08-03 19:47:59
【问题描述】:
我使用 Devise + Confirmable 进行用户身份验证,使用 Minitest + Capybara + 固定装置进行测试。只要我在运行前包含某种形式的登录(使用助手login_as(@user) 或使用 Capybara 进入登录页面)和 line@user.confirm,我就可以为用户进行工作登录测试。
我如何在灯具本身中确认用户,这样我就不必每次都包含这一行。
现在我有:
confirmed_at: Time.now
在 yml 中,但似乎没有什么区别。
这是一个有效的示例测试,如果它有助于说明:
def setup
@user = users(:user)
end
test 'user should be redirected to profile edit on first login' do
@user.confirm
visit(new_user_session_path)
fill_in('user_email', :with => @user.email)
fill_in('user_password', :with => 'foobar')
click_button('Log in')
assert_current_path(edit_user_registration_path)
end
和用户夹具:
user:
email: test1@example.com
confirmed_at: Time.now
encrypted_password: <%= Devise::Encryptor.digest(User, 'foobar') %>
sign_in_count: 0
【问题讨论】:
-
所以用户已经创建、保存但尚未确认?您想手动编辑该数据库字段吗?
-
据我所知,灯具实际上并没有保存到数据库中。当我查看开发数据库中的用户时,两个夹具用户都不在那里。
-
您好,我更新了我的答案。问题的解决方法是找到听到的。您需要按照指南中的方式配置它并调用方法 user.confirm!模块内部 ControllerMacros 方法 def login_user github.com/plataformatec/devise/wiki/…
标签: ruby-on-rails devise devise-confirmable