2015-01-13 17:58:46 +01:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
feature LoginController do
|
2015-01-13 17:58:46 +01:00
|
|
|
let(:user) { create :user }
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
describe 'forgot password' do
|
|
|
|
before { visit forgot_password_path }
|
2015-01-13 17:58:46 +01:00
|
|
|
it 'is accessible' do
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to have_selector 'input[id=user_email]'
|
2015-01-13 17:58:46 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends a reset email' do
|
2015-04-24 15:19:57 +02:00
|
|
|
fill_in 'user_email', with: user.email
|
|
|
|
find('input[type=submit]').click
|
|
|
|
expect(page).to have_selector '.alert-success'
|
2015-01-13 17:58:46 +01:00
|
|
|
email = ActionMailer::Base.deliveries.first
|
2015-01-14 20:57:43 +01:00
|
|
|
expect(email.to).to eq [user.email]
|
2015-01-13 17:58:46 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
describe 'and reset it' do
|
2015-01-13 17:58:46 +01:00
|
|
|
let(:token) { user.reset_password_token }
|
|
|
|
let(:newpass) { user.new_random_password }
|
2015-04-24 15:19:57 +02:00
|
|
|
before { user.request_password_reset! }
|
|
|
|
before { visit new_password_path(id: user.id, token: token) }
|
2015-01-13 17:58:46 +01:00
|
|
|
|
|
|
|
it 'is accessible' do
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to have_selector 'input[type=password]'
|
2015-01-13 17:58:46 +01:00
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
describe 'with wrong token' do
|
|
|
|
let(:token) { 'foobar' }
|
|
|
|
it 'is not accessible' do
|
|
|
|
expect(page).to have_selector '.alert-error'
|
|
|
|
expect(page).to_not have_selector 'input[type=password]'
|
|
|
|
end
|
2015-01-13 17:58:46 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes the password' do
|
2015-04-24 15:19:57 +02:00
|
|
|
fill_in 'user_password', with: newpass
|
|
|
|
fill_in 'user_password_confirmation', with: newpass
|
|
|
|
find('input[type=submit]').click
|
2015-01-13 17:58:46 +01:00
|
|
|
expect(User.authenticate(user.email, newpass)).to eq user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|