dmails: send email notifications in background job.

This commit is contained in:
evazion
2020-03-14 19:33:28 -05:00
parent 0ef9d6e417
commit dc1742321d
3 changed files with 9 additions and 18 deletions

View File

@@ -149,7 +149,7 @@ class Dmail < ApplicationRecord
def send_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

View File

@@ -126,6 +126,14 @@ class DmailsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to dmail_path(Dmail.last)
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
context "update action" do

View File

@@ -6,9 +6,6 @@ class DmailTest < ActiveSupport::TestCase
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "1.2.3.4"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
teardown do
@@ -86,20 +83,6 @@ class DmailTest < ActiveSupport::TestCase
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
recipient = create(:user)