Send Devise emails asynchronously (#13985)
* Change send_devise_notification to deliver later * Add tests to invitation emails * Fix spec
This commit is contained in:
parent
c347efd11b
commit
43f84c12ef
3 changed files with 23 additions and 3 deletions
|
|
@ -621,6 +621,15 @@ class User < ApplicationRecord
|
|||
"User:#{id}"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Send emails asynchronously
|
||||
# see https://github.com/heartcombo/devise#activejob-integration
|
||||
def send_devise_notification(notification, *args)
|
||||
message = devise_mailer.public_send(notification, self, *args)
|
||||
message.deliver_later
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sync_relevant_profile_fields_to_user_settings_table(users_setting_record)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,15 @@ RSpec.describe "/admin/invitations", type: :request do
|
|||
expect(User.last.registered).to be false
|
||||
end
|
||||
|
||||
it "enqueues an invitation email to be sent", :aggregate_failures do
|
||||
assert_enqueued_with(job: Devise.mailer.delivery_job) do
|
||||
post admin_invitations_path,
|
||||
params: { user: { email: "hey#{rand(1000)}@email.co", name: "Roger #{rand(1000)}" } }
|
||||
end
|
||||
|
||||
expect(enqueued_jobs.first[:args]).to match(array_including("invitation_instructions"))
|
||||
end
|
||||
|
||||
it "does not create an invitation if a user with that email exists" do
|
||||
expect do
|
||||
post admin_invitations_path,
|
||||
|
|
|
|||
|
|
@ -28,12 +28,14 @@ RSpec.describe "Authenticating with a password" do
|
|||
expect(page).to have_text("Invalid Email or password.")
|
||||
end
|
||||
|
||||
it "sends an email with the unlock link if the uset gets locked out" do
|
||||
it "sends an email with the unlock link if the uset gets locked out", :aggregate_failures do
|
||||
allow(User).to receive(:maximum_attempts).and_return(1)
|
||||
|
||||
expect do
|
||||
assert_enqueued_with(job: Devise.mailer.delivery_job) do
|
||||
submit_login_form(user.email, "wr0ng")
|
||||
end.to change { Devise.mailer.deliveries.count }.by(1)
|
||||
end
|
||||
|
||||
expect(enqueued_jobs.first[:args]).to match(array_including("unlock_instructions"))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue