mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow template to be explicitly specified #1448 [tuxie@dekadance.se]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1575 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
2455f96a6e
commit
813a8b9d2a
3 changed files with 31 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Allow template to be explicitly specified #1448 [tuxie@dekadance.se]
|
||||
|
||||
* Allow specific "multipart/xxx" content-type to be set on multipart messages #1412 [Flurin Egger]
|
||||
|
||||
* Unquoted @ characters in headers are now accepted in spite of RFC 822 #1206
|
||||
|
|
|
@ -143,7 +143,7 @@ module ActionMailer #:nodoc:
|
|||
cattr_accessor :default_content_type
|
||||
|
||||
adv_attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers,
|
||||
:bcc, :cc, :charset, :content_type
|
||||
:bcc, :cc, :charset, :content_type, :template
|
||||
|
||||
attr_reader :mail
|
||||
|
||||
|
@ -161,6 +161,7 @@ module ActionMailer #:nodoc:
|
|||
@bcc = @cc = @from = @recipients = @sent_on = @subject = nil
|
||||
@charset = @@default_charset.dup
|
||||
@content_type = @@default_content_type.dup
|
||||
@template = method_name
|
||||
@parts = []
|
||||
@headers = {}
|
||||
@body = {}
|
||||
|
@ -173,7 +174,7 @@ module ActionMailer #:nodoc:
|
|||
# which include the content-type in their file name (i.e.,
|
||||
# "the_template_file.text.html.rhtml", etc.).
|
||||
if @parts.empty?
|
||||
templates = Dir.glob("#{template_path}/#{method_name}.*")
|
||||
templates = Dir.glob("#{template_path}/#{@template}.*")
|
||||
templates.each do |path|
|
||||
type = (File.basename(path).split(".")[1..-2] || []).join("/")
|
||||
next if type.empty?
|
||||
|
@ -188,8 +189,8 @@ module ActionMailer #:nodoc:
|
|||
# normal template exists (or if there were no implicit parts) we render
|
||||
# it.
|
||||
template_exists = @parts.empty?
|
||||
template_exists ||= Dir.glob("#{template_path}/#{method_name}.*").any? { |i| i.split(".").length == 2 }
|
||||
@body = render_message(method_name, @body) if template_exists
|
||||
template_exists ||= Dir.glob("#{template_path}/#{@template}.*").any? { |i| i.split(".").length == 2 }
|
||||
@body = render_message(@template, @body) if template_exists
|
||||
|
||||
# Finally, if there are other message parts and a textual body exists,
|
||||
# we shift it onto the front of the parts and set the body to nil (so
|
||||
|
|
|
@ -127,6 +127,16 @@ class TestMailer < ActionMailer::Base
|
|||
content_type "text/html"
|
||||
end
|
||||
|
||||
def custom_template(recipient)
|
||||
recipients recipient
|
||||
subject "[Signed up] Welcome #{recipient}"
|
||||
from "system@loudthinking.com"
|
||||
sent_on Time.local(2004, 12, 12)
|
||||
template "signed_up"
|
||||
|
||||
body["recipient"] = recipient
|
||||
end
|
||||
|
||||
class <<self
|
||||
attr_accessor :received_body
|
||||
end
|
||||
|
@ -179,6 +189,20 @@ class ActionMailerTest < Test::Unit::TestCase
|
|||
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
||||
end
|
||||
|
||||
def test_custom_template
|
||||
expected = new_mail
|
||||
expected.to = @recipient
|
||||
expected.subject = "[Signed up] Welcome #{@recipient}"
|
||||
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
||||
expected.from = "system@loudthinking.com"
|
||||
expected.date = Time.local(2004, 12, 12)
|
||||
|
||||
created = nil
|
||||
assert_nothing_raised { created = TestMailer.create_custom_template(@recipient) }
|
||||
assert_not_nil created
|
||||
assert_equal expected.encoded, created.encoded
|
||||
end
|
||||
|
||||
def test_cancelled_account
|
||||
expected = new_mail
|
||||
expected.to = @recipient
|
||||
|
|
Loading…
Reference in a new issue