Skip to content

Commit

Permalink
Properly initialize ActionMailer outside railties
Browse files Browse the repository at this point in the history
The divided load was triggering errors when encountering an unexpected load order. This allows the dependencies to properly load in any configuration.
  • Loading branch information
albus522 committed Feb 18, 2019
1 parent b0adf2c commit 43b3591
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
4 changes: 0 additions & 4 deletions lib/delayed/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
module Delayed
class Railtie < Rails::Railtie
initializer :after_initialize do
ActiveSupport.on_load(:action_mailer) do
ActionMailer::Base.extend(Delayed::DelayMail)
end

Delayed::Worker.logger ||= if defined?(Rails)
Rails.logger
elsif defined?(RAILS_DEFAULT_LOGGER)
Expand Down
11 changes: 5 additions & 6 deletions lib/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
require 'delayed/exceptions'
require 'delayed/message_sending'
require 'delayed/performable_method'

if defined?(ActionMailer)
require 'action_mailer/version'
require 'delayed/performable_mailer'
end

require 'delayed/yaml_ext'
require 'delayed/lifecycle'
require 'delayed/plugin'
Expand All @@ -19,5 +13,10 @@
require 'delayed/deserialization_error'
require 'delayed/railtie' if defined?(Rails::Railtie)

ActiveSupport.on_load(:action_mailer) do
require 'delayed/performable_mailer'
ActionMailer::Base.extend(Delayed::DelayMail)
end

Object.send(:include, Delayed::MessageSending)
Module.send(:include, Delayed::MessageSendingClassMethods)
4 changes: 0 additions & 4 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require 'rspec'

require 'action_mailer'
require 'active_support/dependencies'
require 'active_record'

require 'delayed_job'
Expand Down Expand Up @@ -45,9 +44,6 @@ def self.root
# Add this directory so the ActiveSupport autoloading works
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)

# Add this to simulate Railtie initializer being executed
ActionMailer::Base.extend(Delayed::DelayMail)

# Used to test interactions between DJ and an ORM
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
ActiveRecord::Base.logger = Delayed::Worker.logger
Expand Down
1 change: 0 additions & 1 deletion spec/performable_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'helper'

require 'action_mailer'
class MyMailer < ActionMailer::Base
def signup(email)
mail :to => email, :subject => 'Delaying Emails', :from => '[email protected]', :body => 'Delaying Emails Body'
Expand Down

0 comments on commit 43b3591

Please sign in to comment.