提交 af43674c 编写于 作者: J José Valim

Fix failing tests on AM about render(:body => Hash).

上级 bdc39fad
......@@ -93,10 +93,12 @@ def deliver!(mail = @_message)
def render(*args)
options = args.last.is_a?(Hash) ? args.last : {}
if options[:body]
if options[:body].is_a?(Hash)
ActiveSupport::Deprecation.warn(':body in render deprecated. Please use instance ' <<
'variables as assigns instead', caller[0,1])
body options.delete(:body)
options[:body].each { |k,v| instance_variable_set(:"@#{k}", v) }
end
super
end
......
......@@ -204,12 +204,8 @@ def initialize_defaults(method_name)
def create_parts
if String === @body
self.response_body = @body
end
if String === response_body
@parts.unshift create_inline_part(response_body)
else
@parts.unshift create_inline_part(@body)
elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ }
self.class.view_paths.first.find_all(@template, {}, @mailer_name).each do |template|
@parts << create_inline_part(render_to_body(:_template => template), template.mime_type)
end
......
......@@ -14,7 +14,7 @@ def spam
from "tester@example.com"
@world = "Earth"
render(:inline => "Hello, <%= @world %>", :layout => 'spam')
body render(:inline => "Hello, <%= @world %>", :layout => 'spam')
end
def nolayout
......@@ -23,7 +23,7 @@ def nolayout
from "tester@example.com"
@world = "Earth"
render(:inline => "Hello, <%= @world %>", :layout => false)
body render(:inline => "Hello, <%= @world %>", :layout => false)
end
def multipart(type = nil)
......
......@@ -7,7 +7,7 @@ def inline_template
from "tester@example.com"
@world = "Earth"
render :inline => "Hello, <%= @world %>"
body render(:inline => "Hello, <%= @world %>")
end
def file_template
......@@ -16,16 +16,7 @@ def file_template
from "tester@example.com"
@recipient = 'test@localhost'
render :file => "templates/signed_up"
end
def implicit_body
recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
@recipient = 'test@localhost'
render :template => "templates/signed_up"
body render(:file => "templates/signed_up")
end
def rxml_template
......@@ -40,21 +31,13 @@ def included_subtemplate
from "tester@example.com"
end
def mailer_accessor
recipients 'test@localhost'
subject "Mailer Accessor"
from "tester@example.com"
render :inline => "Look, <%= mailer.subject %>!"
end
def no_instance_variable
recipients 'test@localhost'
subject "No Instance Variable"
from "tester@example.com"
silence_warnings do
render :inline => "Look, subject.nil? is <%= @subject.nil? %>!"
body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!")
end
end
......@@ -81,13 +64,11 @@ def build_multipart_message(assigns = {})
part "text/html" do |p|
p.body = build_body_part('html', assigns)
p.transfer_encoding = "base64"
end
end
def build_body_part(content_type, assigns, options = {})
render "#{template}.#{content_type}", :body => assigns
# render options.merge(:file => "#{template}.#{content_type}", :body => assigns)
end
end
......@@ -122,11 +103,6 @@ def teardown
restore_delivery_method
end
def test_implicit_body
mail = RenderMailer.implicit_body
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_inline_template
mail = RenderMailer.inline_template
assert_equal "Hello, Earth", mail.body.to_s.strip
......@@ -147,11 +123,6 @@ def test_included_subtemplate
assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
end
def test_mailer_accessor
mail = RenderMailer.mailer_accessor.deliver
assert_equal "Look, Mailer Accessor!", mail.body.to_s.strip
end
def test_no_instance_variable
mail = RenderMailer.no_instance_variable.deliver
assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
......@@ -159,12 +130,12 @@ def test_no_instance_variable
def test_legacy_multipart_alternative
mail = RenderMailer.multipart_alternative.deliver
assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("foo: bar", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
assert_equal("<strong>foo</strong> bar", email.parts[1].body.encoded)
assert_equal(2, mail.parts.size)
assert_equal("multipart/alternative", mail.mime_type)
assert_equal("text/plain", mail.parts[0].mime_type)
assert_equal("foo: bar", mail.parts[0].body.encoded)
assert_equal("text/html", mail.parts[1].mime_type)
assert_equal("<strong>foo</strong> bar", mail.parts[1].body.encoded)
end
end
......
......@@ -27,20 +27,19 @@ def cancelled_account(recipient)
subject "[Cancelled] Goodbye #{recipient}"
from "system@loudthinking.com"
sent_on Time.local(2004, 12, 12)
render :text => "Goodbye, Mr. #{recipient}"
body "Goodbye, Mr. #{recipient}"
end
def from_with_name
from "System <system@loudthinking.com>"
recipients "root@loudthinking.com"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def from_without_name
from "system@loudthinking.com"
recipients "root@loudthinking.com"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def cc_bcc(recipient)
......@@ -51,7 +50,7 @@ def cc_bcc(recipient)
cc "nobody@loudthinking.com"
bcc "root@loudthinking.com"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def different_reply_to(recipient)
......@@ -61,7 +60,7 @@ def different_reply_to(recipient)
sent_on Time.local(2008, 5, 23)
reply_to "atraver@gmail.com"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def iso_charset(recipient)
......@@ -73,7 +72,7 @@ def iso_charset(recipient)
bcc "root@loudthinking.com"
charset "iso-8859-1"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def unencoded_subject(recipient)
......@@ -84,7 +83,7 @@ def unencoded_subject(recipient)
cc "nobody@loudthinking.com"
bcc "root@loudthinking.com"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def extended_headers(recipient)
......@@ -96,7 +95,7 @@ def extended_headers(recipient)
bcc "Grytøyr <stian3@example.net>"
charset "iso-8859-1"
render :text => "Nothing to see here."
body "Nothing to see here."
end
def utf8_body(recipient)
......@@ -108,7 +107,7 @@ def utf8_body(recipient)
bcc "Foo áëô îü <extended@example.net>"
charset "utf-8"
render :text => "åœö blah"
body "åœö blah"
end
def multipart_with_mime_version(recipient)
......@@ -158,7 +157,7 @@ def explicitly_multipart_example(recipient, ct=nil)
attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "foo.jpg"),
:data => "123456789"
render :text => "plain text default"
body "plain text default"
end
def implicitly_multipart_example(recipient, cs = nil, order = nil)
......@@ -187,12 +186,12 @@ def html_mail(recipient)
from "test@example.com"
content_type "text/html"
render :text => "<em>Emphasize</em> <strong>this</strong>"
body "<em>Emphasize</em> <strong>this</strong>"
end
def html_mail_with_underscores(recipient)
subject "html mail with underscores"
render :text => %{<a href="http://google.com" target="_blank">_Google</a>}
body %{<a href="http://google.com" target="_blank">_Google</a>}
end
def custom_template(recipient)
......@@ -219,7 +218,7 @@ def various_newlines(recipient)
subject "various newlines"
from "test@example.com"
render :text => "line #1\nline #2\rline #3\r\nline #4\r\r" +
body "line #1\nline #2\rline #3\r\nline #4\r\r" +
"line #5\n\nline#6\r\n\r\nline #7"
end
......@@ -282,7 +281,7 @@ def headers_with_nonalpha_chars(recipient)
from "One: Two <test@example.com>"
cc "Three: Four <test@example.com>"
bcc "Five: Six <test@example.com>"
render :text => "testing"
body "testing"
end
def custom_content_type_attributes
......@@ -290,7 +289,7 @@ def custom_content_type_attributes
subject "custom content types"
from "some.one@somewhere.test"
content_type "text/plain; format=flowed"
render :text => "testing"
body "testing"
end
def return_path
......@@ -298,13 +297,13 @@ def return_path
subject "return path test"
from "some.one@somewhere.test"
headers["return-path"] = "another@somewhere.test"
render :text => "testing"
body "testing"
end
def subject_with_i18n(recipient)
recipients recipient
from "system@loudthinking.com"
render :text => "testing"
body "testing"
end
class << self
......@@ -1111,7 +1110,7 @@ def test_attr
class MethodNamingTest < ActiveSupport::TestCase
class TestMailer < ActionMailer::Base
def send
render :text => 'foo'
body 'foo'
end
end
......
......@@ -11,7 +11,7 @@ def basic
recipients "somewhere@example.com"
subject "basic"
from "basic@example.com"
render :text => "Hello world"
body "Hello world"
end
def receive(mail)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册