Commit c2ed7db3231ad0999848d13313ea18c8292e0f04
Exists in
master
and in
1 other branch
Merge pull request #685 from brianvanburken/devise-fix
Fixed password reset token not working for Devise in current Errbit build.
Showing
3 changed files
with
33 additions
and
2 deletions
Show diff stats
app/views/devise/mailer/reset_password_instructions.html.haml
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | %p | 10 | %p |
11 | We hear you'd like to change your password. You can do that by visiting the link below: | 11 | We hear you'd like to change your password. You can do that by visiting the link below: |
12 | %p | 12 | %p |
13 | - = edit_password_url @resource, :reset_password_token => @resource.reset_password_token | 13 | + = edit_password_url @resource, :reset_password_token => @token |
14 | %tr | 14 | %tr |
15 | %td.content(valign="top") | 15 | %td.content(valign="top") |
16 | %div | 16 | %div |
app/views/devise/mailer/reset_password_instructions.text.erb
@@ -2,7 +2,7 @@ Hello, | @@ -2,7 +2,7 @@ Hello, | ||
2 | 2 | ||
3 | We hear you'd like to change your password. You can do that by visiting the link below: | 3 | We hear you'd like to change your password. You can do that by visiting the link below: |
4 | 4 | ||
5 | - <%= edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %> | 5 | + <%= edit_password_url(@resource, :reset_password_token => @token) %> |
6 | 6 | ||
7 | If you didn't request this, please ignore this email. Your password won't change unless you access the link above and create a new one. | 7 | If you didn't request this, please ignore this email. Your password won't change unless you access the link above and create a new one. |
8 | 8 |
@@ -0,0 +1,31 @@ | @@ -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 |