From a82b9991b3d7e309ba81881215d91ec80fc80bfa Mon Sep 17 00:00:00 2001 From: "OMAR.A" <58332033+civilcoder55@users.noreply.github.com> Date: Tue, 6 Dec 2022 02:17:27 +0200 Subject: [PATCH] fix: Update the link used for email address change in the confirmation mail (#5937) --- .../mailer/confirmation_instructions.html.erb | 6 ++++-- spec/mailers/confirmation_instructions_spec.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb index 32ea3fe91..7e1338b19 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.erb +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -11,9 +11,11 @@
You can confirm your account email through the link below:
<% end %> -<% if @resource.confirmed? %> +<% if @resource.unconfirmed_email.present? %> +<%= link_to 'Confirm my account', frontend_url('auth/confirmation', confirmation_token: @token) %>
+<% elsif @resource.confirmed? %><%= link_to 'Login to my account', frontend_url('auth/sign_in') %>
-<% elsif account_user&.inviter.present? && @resource.unconfirmed_email.blank? %> +<% elsif account_user&.inviter.present? %><%= link_to 'Confirm my account', frontend_url('auth/password/edit', reset_password_token: @resource.send(:set_reset_password_token)) %>
<% else %><%= link_to 'Confirm my account', frontend_url('auth/confirmation', confirmation_token: @token) %>
diff --git a/spec/mailers/confirmation_instructions_spec.rb b/spec/mailers/confirmation_instructions_spec.rb index ebf9faf4b..a6f3f63af 100644 --- a/spec/mailers/confirmation_instructions_spec.rb +++ b/spec/mailers/confirmation_instructions_spec.rb @@ -63,6 +63,21 @@ RSpec.describe 'Confirmation Instructions', type: :mailer do 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