diff --git a/app/models/dmail.rb b/app/models/dmail.rb index bf6533408..513c79966 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -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 diff --git a/test/functional/dmails_controller_test.rb b/test/functional/dmails_controller_test.rb index f62d01c1c..50eef56b1 100644 --- a/test/functional/dmails_controller_test.rb +++ b/test/functional/dmails_controller_test.rb @@ -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 diff --git a/test/unit/dmail_test.rb b/test/unit/dmail_test.rb index fcb73a25e..5f9f24c78 100644 --- a/test/unit/dmail_test.rb +++ b/test/unit/dmail_test.rb @@ -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)