From 52a66826907bebe81b13ea6bd417f13a05443507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 17 Feb 2016 17:31:46 +0100 Subject: [PATCH] FIX: don't create an EmailLog when we can't send a digest --- lib/email/sender.rb | 4 ++++ spec/components/email/sender_spec.rb | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/email/sender.rb b/lib/email/sender.rb index f0cef9ff2..6168b086d 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -23,6 +23,10 @@ module Email def send return if SiteSetting.disable_emails + + return if ActionMailer::Base::NullMail === @message + return if ActionMailer::Base::NullMail === (@message.message rescue nil) + return skip(I18n.t('email_log.message_blank')) if @message.blank? return skip(I18n.t('email_log.message_to_blank')) if @message.to.blank? diff --git a/spec/components/email/sender_spec.rb b/spec/components/email/sender_spec.rb index b77844e01..1fc6d71ad 100644 --- a/spec/components/email/sender_spec.rb +++ b/spec/components/email/sender_spec.rb @@ -7,7 +7,13 @@ describe Email::Sender do SiteSetting.expects(:disable_emails).returns(true) Mail::Message.any_instance.expects(:deliver_now).never message = Mail::Message.new(to: "hello@world.com" , body: "hello") - Email::Sender.new(message, :hello).send + expect(Email::Sender.new(message, :hello).send).to eq(nil) + end + + it "doesn't deliver mail when the message is of type NullMail" do + Mail::Message.any_instance.expects(:deliver_now).never + message = ActionMailer::Base::NullMail.new + expect(Email::Sender.new(message, :hello).send).to eq(nil) end it "doesn't deliver mail when the message is nil" do