From b1a0cd417dd5e82709fb8027b7c29de180152bfe Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 15 Oct 2014 00:04:47 -0700 Subject: [PATCH] Avoid a deprecation warning by poly-filling #deliver_now and #deliver_now --- config/application.rb | 5 +++++ config/initializers/00-rails-master-polyfills.rb | 8 ++++++++ lib/email/sender.rb | 2 +- script/test_email_settings.rb | 2 +- spec/components/email/sender_spec.rb | 14 +++++++------- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 config/initializers/00-rails-master-polyfills.rb diff --git a/config/application.rb b/config/application.rb index 3e0010aef71..acc2d501733 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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" diff --git a/config/initializers/00-rails-master-polyfills.rb b/config/initializers/00-rails-master-polyfills.rb new file mode 100644 index 00000000000..c32131a9ae9 --- /dev/null +++ b/config/initializers/00-rails-master-polyfills.rb @@ -0,0 +1,8 @@ +unless rails_master? + +class Mail::Message + alias_method :deliver_now, :deliver + alias_method :deliver_now!, :deliver! +end + +end diff --git a/lib/email/sender.rb b/lib/email/sender.rb index bc16b2bf98c..8fcbd1c5f14 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -115,7 +115,7 @@ module Email end begin - @message.deliver + @message.deliver_now rescue *SMTP_CLIENT_ERRORS => e return skip(e.message) end diff --git a/script/test_email_settings.rb b/script/test_email_settings.rb index fe7fdb54d27..dc8422edd60 100644 --- a/script/test_email_settings.rb +++ b/script/test_email_settings.rb @@ -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" diff --git a/spec/components/email/sender_spec.rb b/spec/components/email/sender_spec.rb index 3853f82ca15..f3b027d8ef8 100644 --- a/spec/components/email/sender_spec.rb +++ b/spec/components/email/sender_spec.rb @@ -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