Commit d7c421d92df34725e8eb6a1d12224f7cbc57ebf3
1 parent
0c8eb756
Exists in
master
and in
1 other branch
Valid token for reset password tested.
Showing
1 changed file
with
31 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +require 'acceptance/acceptance_helper' | |
| 2 | + | |
| 3 | +feature 'password reset token' do | |
| 4 | + let(:user) { Fabricate :user } | |
| 5 | + | |
| 6 | + scenario 'receives correct password reset token' do | |
| 7 | + host = ActionMailer::Base.default_url_options.values_at(:host).first | |
| 8 | + port = ActionMailer::Base.default_url_options.values_at(:port).first | |
| 9 | + port = port.blank? ? '' : ':' + port | |
| 10 | + regex = %r{http://#{host}#{port}/users/password/edit\?reset_password_token=([A-Za-z0-9\-_]+)} | |
| 11 | + | |
| 12 | + visit 'https://brighterr.herokuapp.com/users/password/new' | |
| 13 | + fill_in 'Email', with: user.email | |
| 14 | + click_button 'Send me reset password instructions' | |
| 15 | + expect(page).to have_content I18n.t('devise.passwords.send_instructions') | |
| 16 | + | |
| 17 | + mail = ActionMailer::Base.deliveries.last | |
| 18 | + expect(mail.subject).to match(/Reset password instructions/) | |
| 19 | + expect(mail.body.encoded).to_not be_empty | |
| 20 | + expect(mail.body.encoded).to match(/change your password/) | |
| 21 | + expect(mail.body.encoded).to match(regex) | |
| 22 | + if mail.body.encoded =~ regex | |
| 23 | + visit "/users/password/edit?reset_password_token=#{$1}" | |
| 24 | + expect(page).to have_content 'Change your password' | |
| 25 | + fill_in 'New password', with: 'test12345' | |
| 26 | + fill_in 'Type your new password again', with: 'test12345' | |
| 27 | + click_button 'Change my password' | |
| 28 | + expect(page).to_not have_content 'Reset password token is invalid' | |
| 29 | + end | |
| 30 | + end | |
| 31 | +end | ... | ... |