Add feature spec about managing passwords (with the courtesy of kemenaran)

This commit is contained in:
simon lehericey 2019-08-14 17:26:47 +02:00
parent 149b0b5797
commit 7fbedb78fb
2 changed files with 64 additions and 0 deletions

View file

@ -0,0 +1,57 @@
require 'spec_helper'
feature 'Managing password:' do
context 'for simple users' do
let(:user) { create(:user) }
let(:new_password) { 'a simple password' }
scenario 'a simple user can reset their password' do
visit root_path
click_on 'Connexion'
click_on 'Mot de passe oublié ?'
expect(page).to have_current_path(new_user_password_path)
fill_in 'Email', with: user.email
perform_enqueued_jobs do
click_on 'Réinitialiser'
end
expect(page).to have_content 'vous allez recevoir un lien de réinitialisation par email'
click_reset_password_link_for user.email
expect(page).to have_content 'Changement de mot de passe'
fill_in 'user_password', with: new_password
fill_in 'user_password_confirmation', with: new_password
click_on 'Changer le mot de passe'
expect(page).to have_content('Votre mot de passe a été changé avec succès')
end
end
context 'for admins' do
let(:user) { create(:user) }
let(:administrateur) { create(:administrateur, user: user) }
let(:new_password) { 'a new, long, and complicated password!' }
scenario 'an admin can reset their password' do
visit root_path
click_on 'Connexion'
click_on 'Mot de passe oublié ?'
expect(page).to have_current_path(new_user_password_path)
fill_in 'Email', with: user.email
perform_enqueued_jobs do
click_on 'Réinitialiser'
end
expect(page).to have_content 'vous allez recevoir un lien de réinitialisation par email'
click_reset_password_link_for user.email
expect(page).to have_content 'Changement de mot de passe'
fill_in 'user_password', with: new_password
fill_in 'user_password_confirmation', with: new_password
click_on 'Changer le mot de passe'
expect(page).to have_content('Votre mot de passe a été changé avec succès')
end
end
end

View file

@ -78,6 +78,13 @@ module FeatureHelpers
value
end
end
def click_reset_password_link_for(email)
reset_password_email = open_email(email)
token_params = reset_password_email.body.match(/reset_password_token=[^"]+/)
visit "/users/password/edit?#{token_params}"
end
end
RSpec.configure do |config|