aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/lib/action_mailer/base.rb60
-rw-r--r--actionmailer/test/mail_service_test.rb8
-rw-r--r--actionmailer/test/url_test.rb4
-rw-r--r--actionpack/lib/abstract_controller/base.rb8
-rw-r--r--actionpack/lib/abstract_controller/logger.rb28
-rw-r--r--actionpack/lib/action_controller.rb1
-rw-r--r--actionpack/lib/action_controller/base.rb1
-rw-r--r--actionpack/lib/action_controller/metal/logger.rb34
8 files changed, 63 insertions, 81 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 40aff7f0d8..b2c355c7ae 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -250,31 +250,21 @@ module ActionMailer #:nodoc:
# <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
# +implicit_parts_order+.
- class Base
+ class Base < AbstractController::Base
include AdvAttrAccessor, PartContainer, Quoting, Utils
include AbstractController::Rendering
include AbstractController::LocalizedCache
include AbstractController::Layouts
-
include AbstractController::Helpers
- helper ActionMailer::MailHelper
- if Object.const_defined?(:ActionController)
- include ActionController::UrlWriter
- end
+ helper ActionMailer::MailHelper
+ include ActionController::UrlWriter
include ActionMailer::DeprecatedBody
private_class_method :new #:nodoc:
- class_inheritable_accessor :view_paths
- self.view_paths = []
-
- attr_internal :formats
-
- cattr_accessor :logger
-
@@raise_delivery_errors = true
cattr_accessor :raise_delivery_errors
@@ -346,24 +336,13 @@ module ActionMailer #:nodoc:
# have multiple mailer methods share the same template.
adv_attr_accessor :template
- # The mail and action_name instances referenced by this mailer.
- attr_reader :mail, :action_name
-
- # Where the response body is stored.
- attr_internal :response_body
-
# Override the mailer name, which defaults to an inflected version of the
# mailer's class name. If you want to use a template in a non-standard
# location, you can use this to specify that location.
- attr_writer :mailer_name
+ adv_attr_accessor :mailer_name
- def mailer_name(value = nil)
- if value
- @mailer_name = value
- else
- @mailer_name || self.class.mailer_name
- end
- end
+ # Expose the internal mail
+ attr_reader :mail
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
@@ -453,18 +432,16 @@ module ActionMailer #:nodoc:
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
# method, for instance).
- def initialize(method_name=nil, *parameters) #:nodoc:
- @_formats = []
- @_response_body = nil
+ def initialize(method_name=nil, *args) #:nodoc:
super()
- create!(method_name, *parameters) if method_name
+ process(method_name, *args) if method_name
end
- # Initialize the mailer via the given +method_name+. The body will be
+ # Process the mailer via the given +method_name+. The body will be
# rendered and a new TMail::Mail object created.
- def create!(method_name, *parameters) #:nodoc:
+ def process(method_name, *args) #:nodoc:
initialize_defaults(method_name)
- __send__(method_name, *parameters)
+ super
# Create e-mail parts
create_parts
@@ -473,7 +450,7 @@ module ActionMailer #:nodoc:
@subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
:default => method_name.humanize)
- # build the mail object itself
+ # Build the mail object itself
@mail = create_mail
end
@@ -488,7 +465,7 @@ module ActionMailer #:nodoc:
logger.debug "\n#{mail.encoded}"
end
- ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do
+ ActiveSupport::Notifications.instrument(:deliver_mail, :mail => mail) do
begin
self.delivery_method.perform_delivery(mail) if perform_deliveries
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
@@ -510,23 +487,18 @@ module ActionMailer #:nodoc:
@implicit_parts_order ||= @@default_implicit_parts_order.dup
@mime_version ||= @@default_mime_version.dup if @@default_mime_version
- @mailer_name ||= self.class.mailer_name
+ @mailer_name ||= self.class.mailer_name.dup
@template ||= method_name
- @action_name = @template
@parts ||= []
@headers ||= {}
@sent_on ||= Time.now
- ActiveSupport::Deprecation.silence do
- super # Run deprecation hooks
- end
+ super # Run deprecation hooks
end
def create_parts
- ActiveSupport::Deprecation.silence do
- super # Run deprecation hooks
- end
+ super # Run deprecation hooks
if String === response_body
@parts.unshift Part.new(
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 697265b8ec..1cd3bc77c4 100644
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -34,13 +34,13 @@ class TestMailer < ActionMailer::Base
def from_with_name
from "System <system@loudthinking.com>"
recipients "root@loudthinking.com"
- body "Nothing to see here."
+ render :text => "Nothing to see here."
end
def from_without_name
from "system@loudthinking.com"
recipients "root@loudthinking.com"
- body "Nothing to see here."
+ render :text => "Nothing to see here."
end
def cc_bcc(recipient)
@@ -301,6 +301,7 @@ class TestMailer < ActionMailer::Base
render :text => "testing"
end
+ # This tests body calls accepeting a hash, which is deprecated.
def body_ivar(recipient)
recipients recipient
subject "Body as a local variable"
@@ -1043,7 +1044,8 @@ EOF
end
def test_body_is_stored_as_an_ivar
- mail = TestMailer.create_body_ivar(@recipient)
+ mail = nil
+ ActiveSupport::Deprecation.silence { mail = TestMailer.create_body_ivar(@recipient) }
assert_equal "body: foo\nbar: baz", mail.body
end
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
index 18eb355e7d..1140613132 100644
--- a/actionmailer/test/url_test.rb
+++ b/actionmailer/test/url_test.rb
@@ -12,8 +12,8 @@ class TestMailer < ActionMailer::Base
@from = "system@loudthinking.com"
@sent_on = Time.local(2004, 12, 12)
- @body["recipient"] = recipient
- @body["welcome_url"] = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
+ @recipient = recipient
+ @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
end
class <<self
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb
index 9d57c52429..efea81aa71 100644
--- a/actionpack/lib/abstract_controller/base.rb
+++ b/actionpack/lib/abstract_controller/base.rb
@@ -84,7 +84,7 @@ module AbstractController
#
# ==== Returns
# self
- def process(action)
+ def process(action, *args)
@_action_name = action_name = action.to_s
unless action_name = method_for_action(action_name)
@@ -93,7 +93,7 @@ module AbstractController
@_response_body = nil
- process_action(action_name)
+ process_action(action_name, *args)
end
private
@@ -113,8 +113,8 @@ module AbstractController
# Call the action. Override this in a subclass to modify the
# behavior around processing an action. This, and not #process,
# is the intended way to override action dispatching.
- def process_action(method_name)
- send_action(method_name)
+ def process_action(method_name, *args)
+ send_action(method_name, *args)
end
# Actually call the method associated with the action. Override
diff --git a/actionpack/lib/abstract_controller/logger.rb b/actionpack/lib/abstract_controller/logger.rb
index 27ba5be45f..e3bcd28da7 100644
--- a/actionpack/lib/abstract_controller/logger.rb
+++ b/actionpack/lib/abstract_controller/logger.rb
@@ -29,33 +29,5 @@ module AbstractController
@str.send(*args, &block)
end
end
-
- # Override process_action in the AbstractController::Base
- # to log details about the method.
- def process_action(action)
- result = ActiveSupport::Notifications.instrument(:process_action,
- :controller => self, :action => action) do
- super
- end
-
- if logger
- log = DelayedLog.new do
- "\n\nProcessing #{self.class.name}\##{action_name} " \
- "to #{request.formats} (for #{request_origin}) " \
- "[#{request.method.to_s.upcase}]"
- end
-
- logger.info(log)
- end
-
- result
- end
-
- private
- # Returns the request origin with the IP and time. This needs to be cached,
- # otherwise we would get different results for each time it calls.
- def request_origin
- @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
- end
end
end
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index e31b795cd2..8b3a444cda 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -21,6 +21,7 @@ module ActionController
autoload :Helpers
autoload :HideActions
autoload :Layouts
+ autoload :Logger
autoload :MimeResponds
autoload :RackDelegation
autoload :Compatibility
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 452f0cd4f0..f75b6ed641 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -14,6 +14,7 @@ module ActionController
include ActionController::Layouts
include ActionController::ConditionalGet
include ActionController::RackDelegation
+ include ActionController::Logger
include ActionController::Benchmarking
include ActionController::Configuration
diff --git a/actionpack/lib/action_controller/metal/logger.rb b/actionpack/lib/action_controller/metal/logger.rb
new file mode 100644
index 0000000000..956d7dd371
--- /dev/null
+++ b/actionpack/lib/action_controller/metal/logger.rb
@@ -0,0 +1,34 @@
+require 'abstract_controller/logger'
+
+module ActionController
+ module Logger
+ # Override process_action in the AbstractController::Base
+ # to log details about the method.
+ def process_action(action)
+ result = ActiveSupport::Notifications.instrument(:process_action,
+ :controller => self, :action => action) do
+ super
+ end
+
+ if logger
+ log = AbstractController::Logger::DelayedLog.new do
+ "\n\nProcessing #{self.class.name}\##{action_name} " \
+ "to #{request.formats} (for #{request_origin}) " \
+ "[#{request.method.to_s.upcase}]"
+ end
+
+ logger.info(log)
+ end
+
+ result
+ end
+
+ private
+
+ # Returns the request origin with the IP and time. This needs to be cached,
+ # otherwise we would get different results for each time it calls.
+ def request_origin
+ @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
+ end
+ end
+end