aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-09-12 14:23:07 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-09-12 15:32:22 -0300
commit45537f00b4b412d4dc6f9ae746aa24346e6b705a (patch)
tree7d1fea890d11a8ef0c123e34a053d3d9bbb0b010
parent9bb4850e7bf864e0277140ab6d3d4ae67ef68170 (diff)
downloadrails-45537f00b4b412d4dc6f9ae746aa24346e6b705a.tar.gz
rails-45537f00b4b412d4dc6f9ae746aa24346e6b705a.tar.bz2
rails-45537f00b4b412d4dc6f9ae746aa24346e6b705a.zip
Allow users to configure the queue for the mailers
This allow the users to do: config.action_mailer.queue = MyQueue.new and class UsersMailer < ActionMailer::Base self.queue = MyQueue.new end
-rw-r--r--actionmailer/lib/action_mailer/base.rb7
-rw-r--r--actionmailer/lib/action_mailer/railtie.rb2
-rw-r--r--actionmailer/test/abstract_unit.rb9
-rw-r--r--railties/test/application/initializers/frameworks_test.rb17
4 files changed, 22 insertions, 13 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 35ac0423a5..9cc00ca5a1 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -389,6 +389,8 @@ module ActionMailer #:nodoc:
:parts_order => [ "text/plain", "text/enriched", "text/html" ]
}.freeze
+ class_attribute :queue
+
class << self
# Register one or more Observers which will be notified when mail is delivered.
def register_observers(*observers)
@@ -486,11 +488,6 @@ module ActionMailer #:nodoc:
super
end
end
-
- def queue
- Rails.queue
- end
-
end
attr_internal :message
diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb
index 8679096735..1fa689de5b 100644
--- a/actionmailer/lib/action_mailer/railtie.rb
+++ b/actionmailer/lib/action_mailer/railtie.rb
@@ -19,6 +19,8 @@ module ActionMailer
options.javascripts_dir ||= paths["public/javascripts"].first
options.stylesheets_dir ||= paths["public/stylesheets"].first
+ options.queue ||= app.queue
+
# make sure readers methods get compiled
options.asset_path ||= app.config.asset_path
options.asset_host ||= app.config.asset_host
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb
index e5f9bae897..1167387def 100644
--- a/actionmailer/test/abstract_unit.rb
+++ b/actionmailer/test/abstract_unit.rb
@@ -27,14 +27,7 @@ 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
+ActionMailer::Base.queue = Rails::Queueing::SynchronousQueue.new
class MockSMTP
def self.deliveries
diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb
index fbce97e1a9..1eb5fce384 100644
--- a/railties/test/application/initializers/frameworks_test.rb
+++ b/railties/test/application/initializers/frameworks_test.rb
@@ -50,6 +50,23 @@ module ApplicationTests
assert_equal "test.rails", ActionMailer::Base.default_url_options[:host]
end
+ test "uses the default queue for ActionMailer" do
+ require "#{app_path}/config/environment"
+ assert_kind_of Rails::Queueing::Container, ActionMailer::Base.queue
+ end
+
+ test "allows me to configure queue for ActionMailer" do
+ app_file "config/environments/development.rb", <<-RUBY
+ AppTemplate::Application.configure do
+ Rails.queue[:mailer] = Rails::Queueing::TestQueue.new
+ config.action_mailer.queue = Rails.queue[:mailer]
+ end
+ RUBY
+
+ require "#{app_path}/config/environment"
+ assert_kind_of Rails::Queueing::TestQueue, ActionMailer::Base.queue
+ end
+
test "does not include url helpers as action methods" do
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do