Add test for reset password

This commit is contained in:
wvengen 2015-01-13 17:58:46 +01:00
parent cfdfe5f23e
commit 8a4b65c4a5
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
require_relative '../spec_helper'
describe LoginController, :type => :feature do
let(:user) { create :user }
describe 'forgot password', :type => :feature do
it 'is accessible' do
get forgot_password_path
expect(response).to be_success
end
it 'sends a reset email' do
post reset_password_path, user: {email: user.email}
email = ActionMailer::Base.deliveries.first
expect((email.to rescue [])).to eq [user.email]
end
end
describe 'reset password', :type => :feature do
let(:token) { user.reset_password_token }
let(:newpass) { user.new_random_password }
before do
post reset_password_path, user: {email: user.email}
user.reload
end
it 'is accessible' do
get new_password_path, id: user.id, token: token
expect(response).to be_success
end
it 'is not accessible with wrong token' do
get new_password_path, id: user.id, token: '123'
expect(response).to_not be_success
end
it 'changes the password' do
patch update_password_path, id: user.id, token: token, user: {password: newpass, password_confirmation: newpass}
expect(page).to_not have_selector('.alert-error')
expect(User.authenticate(user.email, newpass)).to eq user
end
end
end