Permalink
Browse files

Merge branch 'master' of https://github.com/elomar/delayed_job

* 'master' of https://github.com/elomar/delayed_job:
  Inject behavior into ActionMailer only after it's loaded
  • Loading branch information...
2 parents 02d2e14 + 89ef669 commit b3d883411e233a57c047413dab8e85ce4d65faf6 @bkeepers bkeepers committed Dec 1, 2010
Showing with 14 additions and 7 deletions.
  1. +6 −6 lib/delayed/performable_mailer.rb
  2. +4 −0 lib/delayed/railtie.rb
  3. +4 −1 spec/spec_helper.rb
@@ -1,21 +1,21 @@
-require 'action_mailer'
+require 'mail'
module Delayed
class PerformableMailer < PerformableMethod
def perform
object.send(method_name, *args).deliver
end
end
-end
-ActionMailer::Base.class_eval do
- def self.delay(options = {})
- Delayed::DelayProxy.new(Delayed::PerformableMailer, self, options)
+ module DelayMail
+ def delay(options = {})
+ DelayProxy.new(PerformableMailer, self, options)
+ end
end
end
Mail::Message.class_eval do
def delay(*args)
raise RuntimeError, "Use MyMailer.delay.mailer_action(args) to delay sending of emails."
end
-end
+end
@@ -5,6 +5,10 @@ module Delayed
class Railtie < Rails::Railtie
initializer :after_initialize do
Delayed::Worker.guess_backend
+
+ ActiveSupport.on_load(:action_mailer) do
+ ActionMailer::Base.send(:extend, Delayed::DelayMail)
+ end
end
rake_tasks do
View
@@ -5,6 +5,7 @@
require 'rspec'
require 'logger'
+require 'rails'
require 'active_record'
require 'action_mailer'
@@ -13,7 +14,6 @@
Delayed::Worker.logger = Logger.new('/tmp/dj.log')
ENV['RAILS_ENV'] = 'test'
-require 'rails'
config = YAML.load(File.read('spec/database.yml'))
ActiveRecord::Base.configurations = {'test' => config['mysql']}
@@ -53,3 +53,6 @@ def whatever(n, _); tell*n; end
# 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.send(:extend, Delayed::DelayMail)

0 comments on commit b3d8834

Please sign in to comment.