fix: Update the link used for email address change in the confirmation mail (#5937)

This commit is contained in:
OMAR.A 2022-12-06 02:17:27 +02:00 committed by GitHub
parent 06434bc655
commit a82b9991b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -11,9 +11,11 @@
<p>You can confirm your account email through the link below:</p> <p>You can confirm your account email through the link below:</p>
<% end %> <% 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> <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> <p><%= link_to 'Confirm my account', frontend_url('auth/password/edit', reset_password_token: @resource.send(:set_reset_password_token)) %></p>
<% else %> <% else %>
<p><%= link_to 'Confirm my account', frontend_url('auth/confirmation', confirmation_token: @token) %></p> <p><%= link_to 'Confirm my account', frontend_url('auth/confirmation', confirmation_token: @token) %></p>

View file

@ -63,6 +63,21 @@ RSpec.describe 'Confirmation Instructions', type: :mailer do
end end
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 context 'when user already confirmed' do
before do before do
confirmable_user.confirm confirmable_user.confirm