Avoid a deprecation warning by poly-filling #deliver_now and #deliver_now

This commit is contained in:
Godfrey Chan 2014-10-15 00:04:47 -07:00
parent 7351917ee4
commit b1a0cd417d
5 changed files with 22 additions and 9 deletions

View File

@ -110,6 +110,11 @@ module Discourse
# see: http://stackoverflow.com/questions/11894180/how-does-one-correctly-add-custom-sql-dml-in-migrations/11894420#11894420
config.active_record.schema_format = :sql
if rails_master?
# Opt-into the default behavior in Rails 5
# config.active_record.raise_in_transactional_callbacks = true
end
# per https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet
config.pbkdf2_iterations = 64000
config.pbkdf2_algorithm = "sha256"

View File

@ -0,0 +1,8 @@
unless rails_master?
class Mail::Message
alias_method :deliver_now, :deliver
alias_method :deliver_now!, :deliver!
end
end

View File

@ -115,7 +115,7 @@ module Email
end
begin
@message.deliver
@message.deliver_now
rescue *SMTP_CLIENT_ERRORS => e
return skip(e.message)
end

View File

@ -38,7 +38,7 @@ end
message = EmailTestMailer.email_test(MAILFROM, MAILTO)
begin
message.deliver()
message.deliver_now()
rescue SocketError => e
print "Delivery failed: "+e.message.strip()+"\n"
print " Is the server hostname correct?\n"

View File

@ -5,25 +5,25 @@ describe Email::Sender do
it "doesn't deliver mail when mails are disabled" do
SiteSetting.expects(:disable_emails).returns(true)
Mail::Message.any_instance.expects(:deliver).never
Mail::Message.any_instance.expects(:deliver_now).never
message = Mail::Message.new(to: "hello@world.com" , body: "hello")
Email::Sender.new(message, :hello).send
end
it "doesn't deliver mail when the message is nil" do
Mail::Message.any_instance.expects(:deliver).never
Mail::Message.any_instance.expects(:deliver_now).never
Email::Sender.new(nil, :hello).send
end
it "doesn't deliver when the to address is nil" do
message = Mail::Message.new(body: 'hello')
message.expects(:deliver).never
message.expects(:deliver_now).never
Email::Sender.new(message, :hello).send
end
it "doesn't deliver when the body is nil" do
message = Mail::Message.new(to: 'eviltrout@test.domain')
message.expects(:deliver).never
message.expects(:deliver_now).never
Email::Sender.new(message, :hello).send
end
@ -53,14 +53,14 @@ describe Email::Sender do
let(:message) do
message = Mail::Message.new to: 'eviltrout@test.domain',
body: '**hello**'
message.stubs(:deliver)
message.stubs(:deliver_now)
message
end
let(:email_sender) { Email::Sender.new(message, :valid_type) }
it 'calls deliver' do
message.expects(:deliver).once
message.expects(:deliver_now).once
email_sender.send
end
@ -131,7 +131,7 @@ describe Email::Sender do
context 'with a user' do
let(:message) do
message = Mail::Message.new to: 'eviltrout@test.domain', body: 'test body'
message.stubs(:deliver)
message.stubs(:deliver_now)
message
end