foodsoft/spec/integration/login_spec.rb

47 lines
1.3 KiB
Ruby
Raw Normal View History

2015-01-13 17:58:46 +01:00
require_relative '../spec_helper'
feature LoginController do
2015-01-13 17:58:46 +01:00
let(:user) { create :user }
describe 'forgot password' do
before { visit forgot_password_path }
2015-01-13 17:58:46 +01:00
it 'is accessible' do
expect(page).to have_selector 'input[id=user_email]'
2015-01-13 17:58:46 +01:00
end
it 'sends a reset email' do
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
expect(email.to).to eq [user.email]
2015-01-13 17:58:46 +01:00
end
end
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 }
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
expect(page).to have_selector 'input[type=password]'
2015-01-13 17:58:46 +01:00
end
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
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