2015-05-11 14:31:31 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
feature 'Password reset' do
|
2015-09-30 15:38:21 -04:00
|
|
|
describe 'throttling' do
|
|
|
|
it 'sends reset instructions when not previously sent' do
|
2015-12-09 12:45:26 -05:00
|
|
|
user = create(:user)
|
|
|
|
forgot_password(user)
|
2015-09-30 15:38:21 -04:00
|
|
|
|
2015-12-09 12:45:26 -05:00
|
|
|
expect(page).to have_content(I18n.t('devise.passwords.send_paranoid_instructions'))
|
2015-09-30 15:38:21 -04:00
|
|
|
expect(current_path).to eq new_user_session_path
|
2015-12-09 12:45:26 -05:00
|
|
|
expect(user.recently_sent_password_reset?).to be_truthy
|
2015-09-30 15:38:21 -04:00
|
|
|
end
|
2015-05-11 14:31:31 -04:00
|
|
|
|
2015-09-30 15:38:21 -04:00
|
|
|
it 'sends reset instructions when previously sent more than a minute ago' do
|
|
|
|
user = create(:user)
|
|
|
|
user.send_reset_password_instructions
|
|
|
|
user.update_attribute(:reset_password_sent_at, 5.minutes.ago)
|
|
|
|
|
2015-12-09 12:45:26 -05:00
|
|
|
expect{ forgot_password(user) }.to change{ user.reset_password_sent_at }
|
|
|
|
expect(page).to have_content(I18n.t('devise.passwords.send_paranoid_instructions'))
|
2015-09-30 15:38:21 -04:00
|
|
|
expect(current_path).to eq new_user_session_path
|
|
|
|
end
|
|
|
|
|
2015-12-09 12:45:26 -05:00
|
|
|
it 'throttles multiple resets in a short timespan' do
|
2015-09-30 15:38:21 -04:00
|
|
|
user = create(:user)
|
|
|
|
user.send_reset_password_instructions
|
2015-12-09 12:45:26 -05:00
|
|
|
# Reload because PG handles datetime less precisely than Ruby/Rails
|
|
|
|
user.reload
|
2015-09-30 15:38:21 -04:00
|
|
|
|
2015-12-09 12:45:26 -05:00
|
|
|
expect{ forgot_password(user) }.not_to change{ user.reset_password_sent_at }
|
|
|
|
expect(page).to have_content(I18n.t('devise.passwords.send_paranoid_instructions'))
|
|
|
|
expect(current_path).to eq new_user_session_path
|
2015-09-30 15:38:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def forgot_password(user)
|
2015-12-09 12:45:26 -05:00
|
|
|
visit root_path
|
2015-09-30 14:35:00 -04:00
|
|
|
click_on 'Forgot your password?'
|
|
|
|
fill_in 'Email', with: user.email
|
|
|
|
click_button 'Reset password'
|
|
|
|
user.reload
|
|
|
|
end
|
2015-05-11 14:31:31 -04:00
|
|
|
end
|