dmails: send email notifications in background job.
This commit is contained in:
@@ -149,7 +149,7 @@ class Dmail < ApplicationRecord
|
|||||||
|
|
||||||
def send_email
|
def send_email
|
||||||
if is_recipient? && !is_deleted? && to.receive_email_notifications? && to.can_receive_email?
|
if is_recipient? && !is_deleted? && to.receive_email_notifications? && to.can_receive_email?
|
||||||
UserMailer.dmail_notice(self).deliver_now
|
UserMailer.dmail_notice(self).deliver_later
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,14 @@ class DmailsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_redirected_to dmail_path(Dmail.last)
|
assert_redirected_to dmail_path(Dmail.last)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "send an email if the recipient has email notifications turned on" do
|
||||||
|
recipient = create(:user, receive_email_notifications: true, email_address: build(:email_address))
|
||||||
|
post_auth dmails_path, @user, params: { dmail: { to_name: recipient.name, title: "test", body: "test" }}
|
||||||
|
|
||||||
|
assert_redirected_to Dmail.last
|
||||||
|
assert_enqueued_emails 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "update action" do
|
context "update action" do
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
@user = FactoryBot.create(:user)
|
@user = FactoryBot.create(:user)
|
||||||
CurrentUser.user = @user
|
CurrentUser.user = @user
|
||||||
CurrentUser.ip_addr = "1.2.3.4"
|
CurrentUser.ip_addr = "1.2.3.4"
|
||||||
ActionMailer::Base.delivery_method = :test
|
|
||||||
ActionMailer::Base.perform_deliveries = true
|
|
||||||
ActionMailer::Base.deliveries = []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
@@ -86,20 +83,6 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "send an email if the user wants it" do
|
|
||||||
user = create(:user, receive_email_notifications: true, email_address: build(:email_address))
|
|
||||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
|
||||||
create(:dmail, to: user, owner: user, body: "test [[tagme]]")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create only one message for a split response" do
|
|
||||||
user = create(:user, receive_email_notifications: true, email_address: build(:email_address))
|
|
||||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
|
||||||
Dmail.create_split(from: CurrentUser.user, creator_ip_addr: "127.0.0.1", to_id: user.id, title: "foo", body: "foo")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "notify the recipient he has mail" do
|
should "notify the recipient he has mail" do
|
||||||
recipient = create(:user)
|
recipient = create(:user)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user