0
votes

I am implementing an account settings feature where users can edit their name, email address, password, etc. It's based on Devise's registrations functionality which has an update method.

I would like to write a functional test for this using RSpec and Capybara, however the user needs to provide their current password to update account details. This is difficult because passwords are encrypted.

This is what I have so far, but obviously it doesn't work:

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
1

1 Answers

2
votes

Assuming you're using Factory-Girl (or equivalent) for creating your test objects you should be able to specify the password used to create the user

create :user, password: 'my_password'

and then reuse it later in the test

fill_in 'Current password', with: 'my_password'