Browse Source

Only send required confirmation emails

pull/1820/head
Jack S 3 years ago
parent
commit
b39c7869f9
  1. 8
      app/mailers/devise_notify_mailer.rb
  2. 7
      spec/requests/users_controller_spec.rb

8
app/mailers/devise_notify_mailer.rb

@ -35,17 +35,17 @@ class DeviseNotifyMailer < Devise::Mailer
end
def confirmation_instructions(record, token, _opts = {})
username = record.email
if email_changed?(record)
username = record.unconfirmed_email
if someone_else_changed_email?(record)
send_email_changed_to_old_email(record)
send_email_changed_to_new_email(record, token)
else
send_confirmation_email(record.unconfirmed_email, record, token, record.unconfirmed_email)
send_confirmation_email(record.email, record, token, record.unconfirmed_email)
end
else
send_confirmation_email(record.email, record, token, record.email)
end
send_confirmation_email(record.email, record, token, username)
end
def intercept_send?(email)
@ -83,7 +83,7 @@ class DeviseNotifyMailer < Devise::Mailer
link = "#{user_confirmation_url}?confirmation_token=#{token}"
send_email(
record.email,
record.unconfirmed_email,
User::FOR_NEW_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID,
{
new_email: record.unconfirmed_email,

7
spec/requests/users_controller_spec.rb

@ -1720,6 +1720,8 @@ RSpec.describe UsersController, type: :request do
expect(notify_client).to receive(:send_email).with(email_address: other_user.email, template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
expect(notify_client).to receive(:send_email).with(email_address: new_email, template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
expect(notify_client).not_to receive(:send_email)
patch "/users/#{other_user.id}", headers:, params:
end
@ -1729,7 +1731,6 @@ RSpec.describe UsersController, type: :request do
end
it "sends a new flow emails" do
expect(notify_client).to receive(:send_email).with(
email_address: other_user.email,
template_id: User::FOR_OLD_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID,
@ -1740,7 +1741,7 @@ RSpec.describe UsersController, type: :request do
).once
expect(notify_client).to receive(:send_email).with(
email_address: other_user.email,
email_address: new_email,
template_id: User::FOR_NEW_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID,
personalisation: {
new_email:,
@ -1749,6 +1750,8 @@ RSpec.describe UsersController, type: :request do
},
).once
expect(notify_client).not_to receive(:send_email)
patch "/users/#{other_user.id}", headers:, params:
end
end

Loading…
Cancel
Save