Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Dec 23, 2009
2 parents ec09545 + f737c2d commit e7ef57d
Show file tree
Hide file tree
Showing 42 changed files with 354 additions and 385 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem "pg", ">= 0.8.0"
gem "mysql", ">= 2.8.1"

# AP
gem "rack", "1.0.1", :git => "git://github.com/rails/rack.git"
gem "rack", "1.1.0", :git => "git://github.com/rack/rack.git"
gem "rack-test", "0.5.3"
gem "RedCloth", ">= 4.2.2"

Expand Down
15 changes: 0 additions & 15 deletions actionmailer/lib/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,3 @@ module ActionMailer
autoload :TestHelper
autoload :Utils
end

module Text
extend ActiveSupport::Autoload

autoload :Format, 'action_mailer/vendor/text_format'
end

module Net
extend ActiveSupport::Autoload

autoload :SMTP
end


require 'action_mailer/vendor/tmail'
63 changes: 19 additions & 44 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require 'active_support/core_ext/class'
require 'action_mailer/part'
require 'action_mailer/vendor/text_format'
require 'action_mailer/vendor/tmail'

module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
Expand Down Expand Up @@ -250,31 +253,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

Expand Down Expand Up @@ -346,24 +339,13 @@ class Base
# 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
Expand Down Expand Up @@ -453,18 +435,16 @@ def matches_dynamic_method?(method_name) #: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
Expand All @@ -473,7 +453,7 @@ def create!(method_name, *parameters) #: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

Expand All @@ -488,7 +468,7 @@ def deliver!(mail = @mail)
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
Expand All @@ -510,23 +490,18 @@ def initialize_defaults(method_name)
@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(
Expand Down
5 changes: 2 additions & 3 deletions actionmailer/lib/action_mailer/delivery_method.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "active_support/core_ext/class"
require 'active_support/core_ext/class'

module ActionMailer
module DeliveryMethod

autoload :File, 'action_mailer/delivery_method/file'
autoload :Sendmail, 'action_mailer/delivery_method/sendmail'
autoload :Smtp, 'action_mailer/delivery_method/smtp'
Expand Down Expand Up @@ -52,6 +52,5 @@ class Method
superclass_delegating_accessor :settings
self.settings = {}
end

end
end
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/delivery_method/smtp.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'net/smtp'

module ActionMailer
module DeliveryMethod
# A delivery method implementation which sends via smtp.
class Smtp < Method

self.settings = {
:address => "localhost",
:port => 25,
Expand All @@ -26,6 +27,5 @@ def perform_delivery(mail)
end
end
end

end
end
8 changes: 5 additions & 3 deletions actionmailer/test/mail_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def cancelled_account(recipient)
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)
Expand Down Expand Up @@ -301,6 +301,7 @@ def return_path
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"
Expand Down Expand Up @@ -1043,7 +1044,8 @@ def test_return_path_with_deliver
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

Expand Down
4 changes: 2 additions & 2 deletions actionmailer/test/url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def signed_up_with_url(recipient)
@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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/actionpack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|

s.add_dependency('activesupport', '= 3.0.pre')
s.add_dependency('activemodel', '= 3.0.pre')
s.add_dependency('rack', '~> 1.0.1')
s.add_dependency('rack', '~> 1.1.0')
s.add_dependency('rack-test', '~> 0.5.0')
s.add_dependency('rack-mount', '~> 0.3.2')
s.add_dependency('erubis', '~> 2.6.5')
Expand Down
16 changes: 7 additions & 9 deletions actionpack/lib/abstract_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
module AbstractController
extend ActiveSupport::Autoload

deferrable do
autoload :Base
autoload :Callbacks
autoload :Helpers
autoload :Layouts
autoload :LocalizedCache
autoload :Logger
autoload :Rendering
end
autoload :Base
autoload :Callbacks
autoload :Helpers
autoload :Layouts
autoload :LocalizedCache
autoload :Logger
autoload :Rendering
end
8 changes: 4 additions & 4 deletions actionpack/lib/abstract_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def action_methods
#
# ==== Returns
# self
def process(action)
def process(action, *args)
@_action_name = action_name = action.to_s

unless action_name = method_for_action(action_name)
Expand All @@ -93,7 +93,7 @@ def process(action)

@_response_body = nil

process_action(action_name)
process_action(action_name, *args)
end

private
Expand All @@ -113,8 +113,8 @@ def action_method?(name)
# 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
Expand Down
28 changes: 0 additions & 28 deletions actionpack/lib/abstract_controller/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,5 @@ def method_missing(*args, &block)
@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
Loading

0 comments on commit e7ef57d

Please sign in to comment.