需要当前密码时,如何使用 Capybara 测试更新帐户信息?
How to test updating account information with Capybara when current password is required?
我正在实现一个帐户设置功能,用户可以在其中编辑他们的姓名、电子邮件地址、密码等。它基于具有 update
方法的 Devise 注册功能。
我想使用 RSpec 和 Capybara 为此编写一个功能测试,但是用户需要提供他们当前的密码才能更新帐户详细信息。这很难,因为密码是加密的。
这是我目前所拥有的,但显然它不起作用:
require 'rails_helper'
feature 'Updating account' do
scenario 'Updating name', :sidekiq_inline do
create :user
login_as User.first
visit edit_user_registration_path
fill_in 'Name', with: 'New name'
fill_in 'Current password', with: User.first.encrypted_password
click_button 'Save changes'
expect(current_path).to eq home_path
expect(page).to have_text 'Your account has been updated successfully.'
end
end
假设您使用 Factory-Girl(或等效工具)创建测试对象,您应该能够指定用于创建用户的密码
create :user, password: 'my_password'
稍后在测试中重复使用它
fill_in 'Current password', with: 'my_password'
我正在实现一个帐户设置功能,用户可以在其中编辑他们的姓名、电子邮件地址、密码等。它基于具有 update
方法的 Devise 注册功能。
我想使用 RSpec 和 Capybara 为此编写一个功能测试,但是用户需要提供他们当前的密码才能更新帐户详细信息。这很难,因为密码是加密的。
这是我目前所拥有的,但显然它不起作用:
require 'rails_helper'
feature 'Updating account' do
scenario 'Updating name', :sidekiq_inline do
create :user
login_as User.first
visit edit_user_registration_path
fill_in 'Name', with: 'New name'
fill_in 'Current password', with: User.first.encrypted_password
click_button 'Save changes'
expect(current_path).to eq home_path
expect(page).to have_text 'Your account has been updated successfully.'
end
end
假设您使用 Factory-Girl(或等效工具)创建测试对象,您应该能够指定用于创建用户的密码
create :user, password: 'my_password'
稍后在测试中重复使用它
fill_in 'Current password', with: 'my_password'