diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/async.rb | 41 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 28 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/queued_message.rb | 27 | ||||
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 9 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 6 | ||||
-rw-r--r-- | actionmailer/test/mailers/async_mailer.rb | 1 |
6 files changed, 51 insertions, 61 deletions
diff --git a/actionmailer/lib/action_mailer/async.rb b/actionmailer/lib/action_mailer/async.rb deleted file mode 100644 index a364342745..0000000000 --- a/actionmailer/lib/action_mailer/async.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'delegate' - -module ActionMailer - module Async - def method_missing(method_name, *args) - if action_methods.include?(method_name.to_s) - QueuedMessage.new(queue, self, method_name, *args) - else - super - end - end - - def queue - Rails.queue - end - - class QueuedMessage < ::Delegator - attr_reader :queue - - def initialize(queue, mailer_class, method_name, *args) - @queue = queue - @mailer_class = mailer_class - @method_name = method_name - @args = args - end - - def __getobj__ - @actual_message ||= @mailer_class.send(:new, @method_name, *@args).message - end - - def run - __getobj__.deliver - end - - # Will push the message onto the Queue to be processed - def deliver - @queue << self - end - end - end -end
\ No newline at end of file diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 4a099553c0..35ac0423a5 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,4 +1,5 @@ require 'mail' +require 'action_mailer/queued_message' require 'action_mailer/collector' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/hash/except' @@ -464,19 +465,6 @@ module ActionMailer #:nodoc: super || action_methods.include?(method.to_s) end - # Will force ActionMailer to push new messages to the queue defined - # in the ActionMailer class when set to true. - # - # class WelcomeMailer < ActionMailer::Base - # self.async = true - # end - def async=(truth) - if truth - require 'action_mailer/async' - extend ActionMailer::Async - end - end - protected def set_payload_for_mail(payload, mail) #:nodoc: @@ -491,10 +479,18 @@ module ActionMailer #:nodoc: payload[:mail] = mail.encoded end - def method_missing(method, *args) #:nodoc: - return super unless respond_to?(method) - new(method, *args).message + def method_missing(method_name, *args) + if action_methods.include?(method_name.to_s) + QueuedMessage.new(queue, self, method_name, *args) + else + super + end end + + def queue + Rails.queue + end + end attr_internal :message diff --git a/actionmailer/lib/action_mailer/queued_message.rb b/actionmailer/lib/action_mailer/queued_message.rb new file mode 100644 index 0000000000..e5868ab43b --- /dev/null +++ b/actionmailer/lib/action_mailer/queued_message.rb @@ -0,0 +1,27 @@ +require 'delegate' + +module ActionMailer + class QueuedMessage < ::Delegator + attr_reader :queue + + def initialize(queue, mailer_class, method_name, *args) + @queue = queue + @mailer_class = mailer_class + @method_name = method_name + @args = args + end + + def __getobj__ + @actual_message ||= @mailer_class.send(:new, @method_name, *@args).message + end + + def run + __getobj__.deliver + end + + # Will push the message onto the Queue to be processed + def deliver + @queue << self + end + end +end diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 99c44179fd..e5f9bae897 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -11,6 +11,7 @@ end require 'minitest/autorun' require 'action_mailer' require 'action_mailer/test_case' +require 'rails/queueing' silence_warnings do # These external dependencies have warnings :/ @@ -27,6 +28,14 @@ ActionView::Template.register_template_handler :bak, lambda { |template| "Lame b FIXTURE_LOAD_PATH = File.expand_path('fixtures', File.dirname(__FILE__)) ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH +class ActionMailer::Base < AbstractController::Base + class << self + def queue + @queue ||= Rails::Queueing::Container.new(Rails::Queueing::SynchronousQueue.new) + end + end +end + class MockSMTP def self.deliveries @@deliveries diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index c7b8f47d89..862b954f9e 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -575,11 +575,11 @@ class BaseTest < ActiveSupport::TestCase end test "being able to put proc's into the defaults hash and they get evaluated on mail sending" do - mail1 = ProcMailer.welcome + mail1 = ProcMailer.welcome['X-Proc-Method'] yesterday = 1.day.ago Time.stubs(:now).returns(yesterday) - mail2 = ProcMailer.welcome - assert(mail1['X-Proc-Method'].to_s.to_i > mail2['X-Proc-Method'].to_s.to_i) + mail2 = ProcMailer.welcome['X-Proc-Method'] + assert(mail1.to_s.to_i > mail2.to_s.to_i) end test "we can call other defined methods on the class as needed" do diff --git a/actionmailer/test/mailers/async_mailer.rb b/actionmailer/test/mailers/async_mailer.rb index ce601e7343..8a87e2e1cf 100644 --- a/actionmailer/test/mailers/async_mailer.rb +++ b/actionmailer/test/mailers/async_mailer.rb @@ -1,3 +1,2 @@ class AsyncMailer < BaseMailer - self.async = true end |