mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Add a unified render method to ActionMailer (delegates to ActionView::Base#render)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2037 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Add a unified render method to ActionMailer (delegates to ActionView::Base#render)
|
||||
|
||||
* Move mailer initialization to a separate (overridable) method, so that subclasses may alter the various defaults #1727
|
||||
|
||||
* Look at content-location header (if available) to determine filename of attachments #1670
|
||||
|
||||
@@ -156,7 +156,7 @@ module ActionMailer #:nodoc:
|
||||
|
||||
adv_attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers,
|
||||
:bcc, :cc, :charset, :content_type, :implicit_parts_order,
|
||||
:template
|
||||
:template, :mailer_name
|
||||
|
||||
attr_reader :mail
|
||||
|
||||
@@ -269,17 +269,23 @@ module ActionMailer #:nodoc:
|
||||
@content_type = @@default_content_type.dup
|
||||
@implicit_parts_order = @@default_implicit_parts_order.dup
|
||||
@template = method_name
|
||||
@mailer_name = Inflector.underscore(self.class.name)
|
||||
@parts = []
|
||||
@headers = {}
|
||||
@body = {}
|
||||
end
|
||||
|
||||
def render_message(method_name, body)
|
||||
initialize_template_class(body).render_file(method_name)
|
||||
render :file => method_name, :body => body
|
||||
end
|
||||
|
||||
|
||||
def render(opts)
|
||||
body = opts.delete(:body)
|
||||
initialize_template_class(body).render(opts)
|
||||
end
|
||||
|
||||
def template_path
|
||||
template_root + "/" + Inflector.underscore(self.class.name)
|
||||
"#{template_root}/#{mailer_name}"
|
||||
end
|
||||
|
||||
def initialize_template_class(assigns)
|
||||
|
||||
48
actionmailer/test/mail_render_test.rb
Normal file
48
actionmailer/test/mail_render_test.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
$:.unshift(File.dirname(__FILE__) + "/../lib/")
|
||||
|
||||
require 'test/unit'
|
||||
require 'action_mailer'
|
||||
|
||||
class RenderMailer < ActionMailer::Base
|
||||
def inline_template(recipient)
|
||||
recipients recipient
|
||||
subject "using helpers"
|
||||
from "tester@example.com"
|
||||
body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" })
|
||||
end
|
||||
|
||||
def file_template(recipient)
|
||||
recipients recipient
|
||||
subject "using helpers"
|
||||
from "tester@example.com"
|
||||
body render(:file => "signed_up", :body => { :recipient => recipient })
|
||||
end
|
||||
|
||||
def initialize_defaults(method_name)
|
||||
super
|
||||
mailer_name "test_mailer"
|
||||
end
|
||||
end
|
||||
|
||||
RenderMailer.template_root = File.dirname(__FILE__) + "/fixtures"
|
||||
|
||||
class RenderHelperTest < Test::Unit::TestCase
|
||||
def setup
|
||||
ActionMailer::Base.delivery_method = :test
|
||||
ActionMailer::Base.perform_deliveries = true
|
||||
ActionMailer::Base.deliveries = []
|
||||
|
||||
@recipient = 'test@localhost'
|
||||
end
|
||||
|
||||
def test_inline_template
|
||||
mail = RenderMailer.create_inline_template(@recipient)
|
||||
assert_equal "Hello, Earth", mail.body.strip
|
||||
end
|
||||
|
||||
def test_file_template
|
||||
mail = RenderMailer.create_file_template(@recipient)
|
||||
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user