Skip to content

Commit

Permalink
Make tests run without deprecation warning (just one left).
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim authored and wycats committed Nov 1, 2009
1 parent 418c3f8 commit e9667ad
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 79 deletions.
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/deprecated_body.rb
Expand Up @@ -18,11 +18,11 @@ def initialize_defaults(method_name)
def create_parts
if String === @body
ActiveSupport::Deprecation.warn('body is deprecated. To set the body with a text ' <<
'call render(:text => "body").', caller[7,1])
'call render(:text => "body").', caller[0,10])
self.response_body = @body
elsif @body.is_a?(Hash) && !@body.empty?
ActiveSupport::Deprecation.warn('body is deprecated. To set assigns simply ' <<
'use instance variables', caller[7,1])
'use instance variables', caller[0,10])
@body.each { |k, v| instance_variable_set(:"@#{k}", v) }
end
end
Expand Down
21 changes: 11 additions & 10 deletions actionmailer/test/mail_helper_test.rb
Expand Up @@ -20,28 +20,29 @@ def use_example_helper(recipient)
recipients recipient
subject "using helpers"
from "tester@example.com"
self.body = { :text => "emphasize me!" }

@text = "emphasize me!"
end

def use_mail_helper(recipient)
recipients recipient
subject "using mailing helpers"
from "tester@example.com"
self.body = { :text =>
"But soft! What light through yonder window breaks? It is the east, " +
"and Juliet is the sun. Arise, fair sun, and kill the envious moon, " +
"which is sick and pale with grief that thou, her maid, art far more " +
"fair than she. Be not her maid, for she is envious! Her vestal " +
"livery is but sick and green, and none but fools do wear it. Cast " +
"it off!"
}

@text = "But soft! What light through yonder window breaks? It is the east, " +
"and Juliet is the sun. Arise, fair sun, and kill the envious moon, " +
"which is sick and pale with grief that thou, her maid, art far more " +
"fair than she. Be not her maid, for she is envious! Her vestal " +
"livery is but sick and green, and none but fools do wear it. Cast " +
"it off!"
end

def use_helper_method(recipient)
recipients recipient
subject "using helpers"
from "tester@example.com"
self.body = { :text => "emphasize me!" }

@text = "emphasize me!"
end

private
Expand Down
8 changes: 6 additions & 2 deletions actionmailer/test/mail_layout_test.rb
Expand Up @@ -11,14 +11,18 @@ def spam(recipient)
recipients recipient
subject "You have a mail"
from "tester@example.com"
body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })

@world = "Earth"
render(:inline => "Hello, <%= @world %>", :layout => 'spam')
end

def nolayout(recipient)
recipients recipient
subject "You have a mail"
from "tester@example.com"
body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })

@world = "Earth"
render(:inline => "Hello, <%= @world %>", :layout => false)
end

def multipart(recipient, type = nil)
Expand Down
15 changes: 11 additions & 4 deletions actionmailer/test/mail_render_test.rb
Expand Up @@ -5,22 +5,27 @@ def inline_template(recipient)
recipients recipient
subject "using helpers"
from "tester@example.com"
body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" })

@world = "Earth"
render :inline => "Hello, <%= @world %>"
end

def file_template(recipient)
recipients recipient
subject "using helpers"
from "tester@example.com"
body render(:file => "templates/signed_up", :body => { :recipient => recipient })

@recipient = recipient
render :file => "templates/signed_up"
end

def implicit_body(recipient)
recipients recipient
subject "using helpers"
from "tester@example.com"

render(:template => "templates/signed_up", :body => { :recipient => recipient })
@recipient = recipient
render :template => "templates/signed_up"
end

def rxml_template(recipient)
Expand All @@ -39,7 +44,9 @@ def included_old_subtemplate(recipient)
recipients recipient
subject "Including another template in the one being rendered"
from "tester@example.com"
body render(:inline => "Hello, <%= render \"subtemplate\" %>", :body => { :world => "Earth" })

@world = "Earth"
render :inline => "Hello, <%= render \"subtemplate\" %>"
end

def initialize_defaults(method_name)
Expand Down
137 changes: 77 additions & 60 deletions actionmailer/test/mail_service_test.rb
Expand Up @@ -15,18 +15,20 @@ def multipart_with_template_path_with_dots(recipient)

class TestMailer < ActionMailer::Base
def signed_up(recipient)
@recipients = recipient
@subject = "[Signed up] Welcome #{recipient}"
@from = "system@loudthinking.com"
@body["recipient"] = recipient
recipients recipient
subject "[Signed up] Welcome #{recipient}"
from "system@loudthinking.com"

@recipient = recipient
end

def cancelled_account(recipient)
self.recipients = recipient
self.subject = "[Cancelled] Goodbye #{recipient}"
self.from = "system@loudthinking.com"
self.sent_on = Time.local(2004, 12, 12)
self.body = "Goodbye, Mr. #{recipient}"
recipients recipient
subject "[Cancelled] Goodbye #{recipient}"
from "system@loudthinking.com"
sent_on Time.local(2004, 12, 12)

render :text => "Goodbye, Mr. #{recipient}"
end

def cc_bcc(recipient)
Expand All @@ -36,7 +38,8 @@ def cc_bcc(recipient)
sent_on Time.local(2004, 12, 12)
cc "nobody@loudthinking.com"
bcc "root@loudthinking.com"
body "Nothing to see here."

render :text => "Nothing to see here."
end

def different_reply_to(recipient)
Expand All @@ -45,50 +48,55 @@ def different_reply_to(recipient)
from "system@loudthinking.com"
sent_on Time.local(2008, 5, 23)
reply_to "atraver@gmail.com"
body "Nothing to see here."

render :text => "Nothing to see here."
end

def iso_charset(recipient)
@recipients = recipient
@subject = "testing isø charsets"
@from = "system@loudthinking.com"
@sent_on = Time.local 2004, 12, 12
@cc = "nobody@loudthinking.com"
@bcc = "root@loudthinking.com"
@body = "Nothing to see here."
@charset = "iso-8859-1"
recipients recipient
subject "testing isø charsets"
from "system@loudthinking.com"
sent_on Time.local(2004, 12, 12)
cc "nobody@loudthinking.com"
bcc "root@loudthinking.com"
charset "iso-8859-1"

render :text => "Nothing to see here."
end

def unencoded_subject(recipient)
@recipients = recipient
@subject = "testing unencoded subject"
@from = "system@loudthinking.com"
@sent_on = Time.local 2004, 12, 12
@cc = "nobody@loudthinking.com"
@bcc = "root@loudthinking.com"
@body = "Nothing to see here."
recipients recipient
subject "testing unencoded subject"
from "system@loudthinking.com"
sent_on Time.local(2004, 12, 12)
cc "nobody@loudthinking.com"
bcc "root@loudthinking.com"

render :text => "Nothing to see here."
end

def extended_headers(recipient)
@recipients = recipient
@subject = "testing extended headers"
@from = "Grytøyr <stian1@example.net>"
@sent_on = Time.local 2004, 12, 12
@cc = "Grytøyr <stian2@example.net>"
@bcc = "Grytøyr <stian3@example.net>"
@body = "Nothing to see here."
@charset = "iso-8859-1"
recipients recipient
subject "testing extended headers"
from "Grytøyr <stian1@example.net>"
sent_on Time.local(2004, 12, 12)
cc "Grytøyr <stian2@example.net>"
bcc "Grytøyr <stian3@example.net>"
charset "iso-8859-1"

render :text => "Nothing to see here."
end

def utf8_body(recipient)
@recipients = recipient
@subject = "testing utf-8 body"
@from = "Foo áëô îü <extended@example.net>"
@sent_on = Time.local 2004, 12, 12
@cc = "Foo áëô îü <extended@example.net>"
@bcc = "Foo áëô îü <extended@example.net>"
@body = "åœö blah"
@charset = "utf-8"
recipients recipient
subject "testing utf-8 body"
from "Foo áëô îü <extended@example.net>"
sent_on Time.local(2004, 12, 12)
cc "Foo áëô îü <extended@example.net>"
bcc "Foo áëô îü <extended@example.net>"
charset "utf-8"

render :text => "åœö blah"
end

def multipart_with_mime_version(recipient)
Expand Down Expand Up @@ -128,7 +136,6 @@ def explicitly_multipart_example(recipient, ct=nil)
subject "multipart example"
from "test@example.com"
sent_on Time.local(2004, 12, 12)
body "plain text default"
content_type ct if ct

part "text/html" do |p|
Expand All @@ -138,15 +145,18 @@ def explicitly_multipart_example(recipient, ct=nil)

attachment :content_type => "image/jpeg", :filename => "foo.jpg",
:body => "123456789"

render :text => "plain text default"
end

def implicitly_multipart_example(recipient, cs = nil, order = nil)
@recipients = recipient
@subject = "multipart example"
@from = "test@example.com"
@sent_on = Time.local 2004, 12, 12
@body = { "recipient" => recipient }
@charset = cs if cs
recipients recipient
subject "multipart example"
from "test@example.com"
sent_on Time.local(2004, 12, 12)

@charset = cs if cs
@recipient = recipient
@implicit_parts_order = order if order
end

Expand All @@ -155,20 +165,22 @@ def implicitly_multipart_with_utf8
subject "Foo áëô îü"
from "some.one@somewhere.test"
template "implicitly_multipart_example"
body ({ "recipient" => "no.one@nowhere.test" })

@recipient = "no.one@nowhere.test"
end

def html_mail(recipient)
recipients recipient
subject "html mail"
from "test@example.com"
body "<em>Emphasize</em> <strong>this</strong>"
content_type "text/html"

render :text => "<em>Emphasize</em> <strong>this</strong>"
end

def html_mail_with_underscores(recipient)
subject "html mail with underscores"
body %{<a href="http://google.com" target="_blank">_Google</a>}
render :text => %{<a href="http://google.com" target="_blank">_Google</a>}
end

def custom_template(recipient)
Expand All @@ -178,7 +190,7 @@ def custom_template(recipient)
sent_on Time.local(2004, 12, 12)
template "signed_up"

body["recipient"] = recipient
@recipient = recipient
end

def custom_templating_extension(recipient)
Expand All @@ -187,22 +199,24 @@ def custom_templating_extension(recipient)
from "system@loudthinking.com"
sent_on Time.local(2004, 12, 12)

body["recipient"] = recipient
@recipient = recipient
end

def various_newlines(recipient)
recipients recipient
subject "various newlines"
from "test@example.com"
body "line #1\nline #2\rline #3\r\nline #4\r\r" +
"line #5\n\nline#6\r\n\r\nline #7"

render :text => "line #1\nline #2\rline #3\r\nline #4\r\r" +
"line #5\n\nline#6\r\n\r\nline #7"
end

def various_newlines_multipart(recipient)
recipients recipient
subject "various newlines multipart"
from "test@example.com"
content_type "multipart/alternative"

part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r"
part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r"
end
Expand All @@ -212,10 +226,12 @@ def nested_multipart(recipient)
subject "nested multipart"
from "test@example.com"
content_type "multipart/mixed"

part :content_type => "multipart/alternative", :content_disposition => "inline", :headers => { "foo" => "bar" } do |p|
p.part :content_type => "text/plain", :body => "test text\nline #2"
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
end

attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
end

Expand All @@ -224,6 +240,7 @@ def nested_multipart_with_body(recipient)
subject "nested multipart with body"
from "test@example.com"
content_type "multipart/mixed"

part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
end
Expand Down Expand Up @@ -253,23 +270,23 @@ def headers_with_nonalpha_chars(recipient)
from "One: Two <test@example.com>"
cc "Three: Four <test@example.com>"
bcc "Five: Six <test@example.com>"
body "testing"
render :text => "testing"
end

def custom_content_type_attributes
recipients "no.one@nowhere.test"
subject "custom content types"
from "some.one@somewhere.test"
content_type "text/plain; format=flowed"
body "testing"
render :text => "testing"
end

def return_path
recipients "no.one@nowhere.test"
subject "return path test"
from "some.one@somewhere.test"
body "testing"
headers "return-path" => "another@somewhere.test"
render :text => "testing"
end

def body_ivar(recipient)
Expand Down Expand Up @@ -1024,7 +1041,7 @@ def test_attr
class MethodNamingTest < Test::Unit::TestCase
class TestMailer < ActionMailer::Base
def send
body 'foo'
render :text => 'foo'
end
end

Expand Down

0 comments on commit e9667ad

Please sign in to comment.