mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix failing tests on AM about render(:body => Hash).
This commit is contained in:
parent
bdc39fad36
commit
af43674c1c
6 changed files with 36 additions and 68 deletions
|
@ -93,10 +93,12 @@ module ActionMailer
|
|||
|
||||
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 @@ module ActionMailer
|
|||
|
||||
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 @@ class AutoLayoutMailer < ActionMailer::Base
|
|||
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 @@ class AutoLayoutMailer < ActionMailer::Base
|
|||
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 @@ class RenderMailer < ActionMailer::Base
|
|||
from "tester@example.com"
|
||||
|
||||
@world = "Earth"
|
||||
render :inline => "Hello, <%= @world %>"
|
||||
body render(:inline => "Hello, <%= @world %>")
|
||||
end
|
||||
|
||||
def file_template
|
||||
|
@ -16,16 +16,7 @@ class RenderMailer < ActionMailer::Base
|
|||
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 @@ class RenderMailer < ActionMailer::Base
|
|||
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 @@ class RenderMailer < ActionMailer::Base
|
|||
|
||||
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 @@ class RenderHelperTest < Test::Unit::TestCase
|
|||
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 @@ class RenderHelperTest < Test::Unit::TestCase
|
|||
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 @@ class RenderHelperTest < Test::Unit::TestCase
|
|||
|
||||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
bcc "Foo áëô îü <extended@example.net>"
|
||||
charset "utf-8"
|
||||
|
||||
render :text => "åœö blah"
|
||||
body "åœö blah"
|
||||
end
|
||||
|
||||
def multipart_with_mime_version(recipient)
|
||||
|
@ -158,7 +157,7 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ class TestMailer < ActionMailer::Base
|
|||
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 @@ end
|
|||
class MethodNamingTest < ActiveSupport::TestCase
|
||||
class TestMailer < ActionMailer::Base
|
||||
def send
|
||||
render :text => 'foo'
|
||||
body 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class AMSubscriberTest < ActionMailer::TestCase
|
|||
recipients "somewhere@example.com"
|
||||
subject "basic"
|
||||
from "basic@example.com"
|
||||
render :text => "Hello world"
|
||||
body "Hello world"
|
||||
end
|
||||
|
||||
def receive(mail)
|
||||
|
|
Loading…
Reference in a new issue