debian-mirror-gitlab/spec/features/password_reset_spec.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
require 'spec_helper'
feature 'Password reset', feature: true do
2015-10-24 18:46:33 +05:30
describe 'throttling' do
it 'sends reset instructions when not previously sent' do
visit root_path
forgot_password(create(:user))
2015-09-11 14:41:01 +05:30
2015-10-24 18:46:33 +05:30
expect(page).to have_content(I18n.t('devise.passwords.send_instructions'))
expect(current_path).to eq new_user_session_path
end
2015-09-11 14:41:01 +05:30
2015-10-24 18:46:33 +05:30
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-09-11 14:41:01 +05:30
visit root_path
2015-10-24 18:46:33 +05:30
forgot_password(user)
2015-09-11 14:41:01 +05:30
2015-10-24 18:46:33 +05:30
expect(page).to have_content(I18n.t('devise.passwords.send_instructions'))
2015-09-11 14:41:01 +05:30
expect(current_path).to eq new_user_session_path
end
2015-10-24 18:46:33 +05:30
it "throttles multiple resets in a short timespan" do
user = create(:user)
user.send_reset_password_instructions
2015-09-11 14:41:01 +05:30
visit root_path
2015-10-24 18:46:33 +05:30
forgot_password(user)
2015-09-11 14:41:01 +05:30
2015-10-24 18:46:33 +05:30
expect(page).to have_content(I18n.t('devise.passwords.recently_reset'))
expect(current_path).to eq new_user_password_path
2015-09-11 14:41:01 +05:30
end
end
2015-10-24 18:46:33 +05:30
def forgot_password(user)
click_on 'Forgot your password?'
fill_in 'Email', with: user.email
click_button 'Reset password'
user.reload
end
2015-09-11 14:41:01 +05:30
end