Skip to content

Commit

Permalink
fix: Update the link used for email address change in the confirmatio…
Browse files Browse the repository at this point in the history
…n mail (#5937)
  • Loading branch information
civilcoder55 committed Dec 6, 2022
1 parent 06434bc commit a82b999
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/views/devise/mailer/confirmation_instructions.html.erb
Expand Up @@ -11,9 +11,11 @@
<p>You can confirm your account email through the link below:</p>
<% end %>
<% if @resource.confirmed? %>
<% if @resource.unconfirmed_email.present? %>
<p><%= link_to 'Confirm my account', frontend_url('auth/confirmation', confirmation_token: @token) %></p>
<% elsif @resource.confirmed? %>
<p><%= link_to 'Login to my account', frontend_url('auth/sign_in') %></p>
<% elsif account_user&.inviter.present? && @resource.unconfirmed_email.blank? %>
<% elsif account_user&.inviter.present? %>
<p><%= link_to 'Confirm my account', frontend_url('auth/password/edit', reset_password_token: @resource.send(:set_reset_password_token)) %></p>
<% else %>
<p><%= link_to 'Confirm my account', frontend_url('auth/confirmation', confirmation_token: @token) %></p>
Expand Down
15 changes: 15 additions & 0 deletions spec/mailers/confirmation_instructions_spec.rb
Expand Up @@ -63,6 +63,21 @@
end
end

context 'when user is confirmed and updates the email' do
before do
confirmable_user.confirm
confirmable_user.update!(email: 'user@example.com')
end

it 'sends a confirmation link' do
confirmation_mail = Devise::Mailer.confirmation_instructions(confirmable_user.reload, nil, {})

expect(confirmation_mail.body).to include('app/auth/confirmation?confirmation_token')
expect(confirmation_mail.body).not_to include('app/auth/password/edit')
expect(confirmable_user.unconfirmed_email.blank?).to be false
end
end

context 'when user already confirmed' do
before do
confirmable_user.confirm
Expand Down

0 comments on commit a82b999

Please sign in to comment.