Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f30d73ba
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f30d73ba
编写于
1月 24, 2010
作者:
J
José Valim and Mikel Lindsaar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add new class delivery method API.
上级
7409b734
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
259 addition
and
271 deletion
+259
-271
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+17
-1
actionmailer/lib/action_mailer/deprecated_api.rb
actionmailer/lib/action_mailer/deprecated_api.rb
+15
-10
actionmailer/test/asset_host_test.rb
actionmailer/test/asset_host_test.rb
+5
-7
actionmailer/test/base_test.rb
actionmailer/test/base_test.rb
+54
-81
actionmailer/test/mail_helper_test.rb
actionmailer/test/mail_helper_test.rb
+13
-15
actionmailer/test/mail_layout_test.rb
actionmailer/test/mail_layout_test.rb
+20
-22
actionmailer/test/mail_render_test.rb
actionmailer/test/mail_render_test.rb
+31
-31
actionmailer/test/mail_service_test.rb
actionmailer/test/mail_service_test.rb
+72
-76
actionmailer/test/subscriber_test.rb
actionmailer/test/subscriber_test.rb
+9
-9
actionmailer/test/test_helper_test.rb
actionmailer/test/test_helper_test.rb
+12
-12
actionmailer/test/tmail_compat_test.rb
actionmailer/test/tmail_compat_test.rb
+9
-5
actionmailer/test/url_test.rb
actionmailer/test/url_test.rb
+2
-2
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
f30d73ba
...
...
@@ -253,6 +253,8 @@ module ActionMailer #:nodoc:
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
# +implicit_parts_order+.
class
Base
<
AbstractController
::
Base
abstract!
include
Quoting
include
AbstractController
::
Logger
...
...
@@ -264,8 +266,8 @@ class Base < AbstractController::Base
helper
ActionMailer
::
MailHelper
include
ActionMailer
::
DeprecatedApi
extend
ActionMailer
::
DeliveryMethods
include
ActionMailer
::
DeprecatedApi
add_delivery_method
:smtp
,
Mail
::
SMTP
,
:address
=>
"localhost"
,
...
...
@@ -370,6 +372,20 @@ def set_payload_for_mail(payload, mail) #:nodoc:
payload
[
:date
]
=
mail
.
date
payload
[
:mail
]
=
mail
.
encoded
end
def
respond_to?
(
method
,
*
args
)
super
||
action_methods
.
include?
(
method
.
to_s
)
end
protected
def
method_missing
(
method
,
*
args
)
if
action_methods
.
include?
(
method
.
to_s
)
new
(
method
,
*
args
).
message
else
super
end
end
end
attr_internal
:message
...
...
actionmailer/lib/action_mailer/deprecated_api.rb
浏览文件 @
f30d73ba
module
ActionMailer
#
TODO Remove this module all together in Rails 3.1. Ensure that super
#
hooks in ActionMailer::Base are removed as well
.
#
#
Moved here to allow us to add the new Mail API
#
Part of this API is deprecated and is going to be removed in Rails 3.1 (just check
#
the methods which give you a warning)
.
#
All the rest will be deprecated after 3.1 release instead, this allows a smoother
#
migration path.
module
DeprecatedApi
#:nodoc:
extend
ActiveSupport
::
Concern
...
...
@@ -83,8 +83,8 @@ module ClassMethods
# MyMailer.deliver(email)
def
deliver
(
mail
,
show_warning
=
true
)
if
show_warning
ActiveSupport
::
Deprecation
.
warn
"
ActionMailer::Base.deliver is deprecated, just
call "
<<
"deliver in the
instance instead"
,
caller
ActiveSupport
::
Deprecation
.
warn
"
#{
self
}
.deliver is deprecated,
call "
<<
"deliver in the
mailer instance instead"
,
caller
[
0
,
2
]
end
raise
"no mail object available for delivery!"
unless
mail
...
...
@@ -100,9 +100,14 @@ def respond_to?(method_symbol, include_private = false) #:nodoc:
def
method_missing
(
method_symbol
,
*
parameters
)
#:nodoc:
if
match
=
matches_dynamic_method?
(
method_symbol
)
case
match
[
1
]
when
'create'
then
new
(
match
[
2
],
*
parameters
).
message
when
'deliver'
then
new
(
match
[
2
],
*
parameters
).
deliver!
when
'new'
then
nil
when
'create'
ActiveSupport
::
Deprecation
.
warn
"
#{
self
}
.create_
#{
match
[
2
]
}
is deprecated, "
<<
"use
#{
self
}
.
#{
match
[
2
]
}
instead"
,
caller
[
0
,
2
]
new
(
match
[
2
],
*
parameters
).
message
when
'deliver'
ActiveSupport
::
Deprecation
.
warn
"
#{
self
}
.deliver_
#{
match
[
2
]
}
is deprecated, "
<<
"use
#{
self
}
.
#{
match
[
2
]
}
.deliver instead"
,
caller
[
0
,
2
]
new
(
match
[
2
],
*
parameters
).
deliver
else
super
end
else
...
...
@@ -167,7 +172,6 @@ def part(params)
# Add an attachment to a multipart message. This is simply a part with the
# content-disposition set to "attachment".
def
attachment
(
params
,
&
block
)
ActiveSupport
::
Deprecation
.
warn
"attachment is deprecated, please use the attachments API instead"
,
caller
[
0
,
2
]
params
=
{
:content_type
=>
params
}
if
String
===
params
params
[
:content
]
||=
params
.
delete
(
:data
)
||
params
.
delete
(
:body
)
...
...
@@ -259,6 +263,7 @@ def create_mail #:nodoc:
end
end
wrap_delivery_behavior!
m
.
content_transfer_encoding
=
'8bit'
unless
m
.
body
.
only_us_ascii?
@_message
...
...
actionmailer/test/asset_host_test.rb
浏览文件 @
f30d73ba
require
'abstract_unit'
class
AssetHostMailer
<
ActionMailer
::
Base
def
email_with_asset
(
recipient
)
recipients
recipient
def
email_with_asset
recipients
'test@localhost'
subject
"testing email containing asset path while asset_host is set"
from
"tester@example.com"
end
...
...
@@ -13,8 +13,6 @@ def setup
set_delivery_method
:test
ActionMailer
::
Base
.
perform_deliveries
=
true
ActionMailer
::
Base
.
deliveries
.
clear
@recipient
=
'test@localhost'
end
def
teardown
...
...
@@ -23,7 +21,7 @@ def teardown
def
test_asset_host_as_string
ActionController
::
Base
.
asset_host
=
"http://www.example.com"
mail
=
AssetHostMailer
.
deliver_email_with_asset
(
@recipient
)
mail
=
AssetHostMailer
.
email_with_asset
assert_equal
"<img alt=
\"
Somelogo
\"
src=
\"
http://www.example.com/images/somelogo.png
\"
/>"
,
mail
.
body
.
to_s
.
strip
end
...
...
@@ -35,7 +33,7 @@ def test_asset_host_as_one_arguement_proc
"http://assets.example.com"
end
}
mail
=
AssetHostMailer
.
deliver_email_with_asset
(
@recipient
)
mail
=
AssetHostMailer
.
email_with_asset
assert_equal
"<img alt=
\"
Somelogo
\"
src=
\"
http://images.example.com/images/somelogo.png
\"
/>"
,
mail
.
body
.
to_s
.
strip
end
...
...
@@ -48,7 +46,7 @@ def test_asset_host_as_two_arguement_proc
end
}
mail
=
nil
assert_nothing_raised
{
mail
=
AssetHostMailer
.
deliver_email_with_asset
(
@recipient
)
}
assert_nothing_raised
{
mail
=
AssetHostMailer
.
email_with_asset
}
assert_equal
"<img alt=
\"
Somelogo
\"
src=
\"
http://www.example.com/images/somelogo.png
\"
/>"
,
mail
.
body
.
to_s
.
strip
end
end
\ No newline at end of file
actionmailer/test/base_test.rb
浏览文件 @
f30d73ba
...
...
@@ -3,40 +3,6 @@
# class Notifier < ActionMailer::Base
# delivers_from 'notifications@example.com'
#
# def welcome(user)
# @user = user # available to the view
# mail(:subject => 'Welcome!', :to => user.email_address)
# # auto renders both welcome.text.erb and welcome.html.erb
# end
#
# def goodbye(user)
# headers["X-SPAM"] = 'Not-SPAM'
# mail(:subject => 'Goodbye', :to => user.email_address) do |format|
# format.html { render "shared_template "}
# format.text # goodbye.text.erb
# end
# end
#
# def surprise(user, gift)
# attachments[gift.name] = File.read(gift.path)
# mail(:subject => 'Surprise!', :to => user.email_address) do |format|
# format.html(:charset => "ascii") # surprise.html.erb
# format.text(:transfer_encoding => "base64") # surprise.text.erb
# end
# end
#
# def special_surprise(user, gift)
# attachments[gift.name] = { :content_type => "application/x-gzip", :content => File.read(gift.path) }
# mail(:to => 'special@example.com') # subject not required
# # auto renders both special_surprise.text.erb and special_surprise.html.erb
# end
# end
#
# mail = Notifier.welcome(user) # => returns a Mail object
# mail.deliver
#
# Notifier.welcome(user).deliver # => creates and sends the Mail in one step
class
BaseTest
<
ActiveSupport
::
TestCase
DEFAULT_HEADERS
=
{
:to
=>
'mikel@test.lindsaar.net'
,
...
...
@@ -44,8 +10,6 @@ class BaseTest < ActiveSupport::TestCase
:subject
=>
'The first email on new API!'
}
# TODO Think on the simple case where I want to send an e-mail
# with attachment and small text (without need to add a template).
class
BaseMailer
<
ActionMailer
::
Base
self
.
mailer_name
=
"base_mailer"
...
...
@@ -60,7 +24,7 @@ def attachment_with_content(hash = {})
end
def
attachment_with_hash
attachments
[
'invoice.jpg'
]
=
{
:
content
=>
"you smiling"
,
:mime_type
=>
"image/x-jpg"
,
attachments
[
'invoice.jpg'
]
=
{
:
data
=>
"you smiling"
,
:mime_type
=>
"image/x-jpg"
,
:transfer_encoding
=>
"base64"
}
mail
(
DEFAULT_HEADERS
)
end
...
...
@@ -93,12 +57,12 @@ def explicit_multipart_with_any(hash = {})
end
test
"method call to mail does not raise error"
do
assert_nothing_raised
{
BaseMailer
.
deliver_welcome
}
assert_nothing_raised
{
BaseMailer
.
welcome
.
deliver
}
end
# Basic mail usage without block
test
"mail() should set the headers of the mail message"
do
email
=
BaseMailer
.
deliver_welcome
email
=
BaseMailer
.
welcome
.
deliver
assert_equal
(
email
.
to
,
[
'mikel@test.lindsaar.net'
])
assert_equal
(
email
.
from
,
[
'jose@test.plataformatec.com'
])
assert_equal
(
email
.
subject
,
'The first email on new API!'
)
...
...
@@ -106,13 +70,13 @@ def explicit_multipart_with_any(hash = {})
test
"mail() with bcc, cc, content_type, charset, mime_version, reply_to and date"
do
@time
=
Time
.
now
email
=
BaseMailer
.
deliver_
welcome
(
:bcc
=>
'bcc@test.lindsaar.net'
,
:cc
=>
'cc@test.lindsaar.net'
,
:content_type
=>
'multipart/mixed'
,
:charset
=>
'iso-8559-1'
,
:mime_version
=>
'2.0'
,
:reply_to
=>
'reply-to@test.lindsaar.net'
,
:date
=>
@time
)
email
=
BaseMailer
.
welcome
(
:bcc
=>
'bcc@test.lindsaar.net'
,
:cc
=>
'cc@test.lindsaar.net'
,
:content_type
=>
'multipart/mixed'
,
:charset
=>
'iso-8559-1'
,
:mime_version
=>
'2.0'
,
:reply_to
=>
'reply-to@test.lindsaar.net'
,
:date
=>
@time
).
deliver
assert_equal
(
email
.
bcc
,
[
'bcc@test.lindsaar.net'
])
assert_equal
(
email
.
cc
,
[
'cc@test.lindsaar.net'
])
assert_equal
(
email
.
content_type
,
'multipart/mixed'
)
...
...
@@ -123,50 +87,50 @@ def explicit_multipart_with_any(hash = {})
end
test
"mail() renders the template using the method being processed"
do
email
=
BaseMailer
.
deliver_welcome
email
=
BaseMailer
.
welcome
.
deliver
assert_equal
(
"Welcome"
,
email
.
body
.
encoded
)
end
test
"can pass in :body to the mail method hash"
do
email
=
BaseMailer
.
deliver_welcome
(
:body
=>
"Hello there"
)
email
=
BaseMailer
.
welcome
(
:body
=>
"Hello there"
).
deliver
assert_equal
(
"text/plain"
,
email
.
mime_type
)
assert_equal
(
"Hello there"
,
email
.
body
.
encoded
)
end
# Custom headers
test
"custom headers"
do
email
=
BaseMailer
.
deliver_welcome
email
=
BaseMailer
.
welcome
.
deliver
assert_equal
(
"Not SPAM"
,
email
[
'X-SPAM'
].
decoded
)
end
# Attachments
test
"attachment with content"
do
email
=
BaseMailer
.
deliver_attachment_with_content
email
=
BaseMailer
.
attachment_with_content
.
deliver
assert_equal
(
1
,
email
.
attachments
.
length
)
assert_equal
(
'invoice.pdf'
,
email
.
attachments
[
0
].
filename
)
assert_equal
(
'This is test File content'
,
email
.
attachments
[
'invoice.pdf'
].
decoded
)
end
test
"attachment gets content type from filename"
do
email
=
BaseMailer
.
deliver_attachment_with_content
email
=
BaseMailer
.
attachment_with_content
.
deliver
assert_equal
(
'invoice.pdf'
,
email
.
attachments
[
0
].
filename
)
end
test
"attachment with hash"
do
email
=
BaseMailer
.
deliver_attachment_with_hash
email
=
BaseMailer
.
attachment_with_hash
.
deliver
assert_equal
(
1
,
email
.
attachments
.
length
)
assert_equal
(
'invoice.jpg'
,
email
.
attachments
[
0
].
filename
)
assert_equal
(
"
\312\213\254\232
)b"
,
email
.
attachments
[
'invoice.jpg'
].
decoded
)
end
test
"sets mime type to multipart/mixed when attachment is included"
do
email
=
BaseMailer
.
deliver_attachment_with_content
email
=
BaseMailer
.
attachment_with_content
.
deliver
assert_equal
(
1
,
email
.
attachments
.
length
)
assert_equal
(
"multipart/mixed"
,
email
.
mime_type
)
end
test
"adds the rendered template as part"
do
email
=
BaseMailer
.
deliver_attachment_with_content
email
=
BaseMailer
.
attachment_with_content
.
deliver
assert_equal
(
2
,
email
.
parts
.
length
)
assert_equal
(
"multipart/mixed"
,
email
.
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
0
].
mime_type
)
...
...
@@ -176,7 +140,7 @@ def explicit_multipart_with_any(hash = {})
end
test
"adds the given :body as part"
do
email
=
BaseMailer
.
deliver_attachment_with_content
(
:body
=>
"I'm the eggman"
)
email
=
BaseMailer
.
attachment_with_content
(
:body
=>
"I'm the eggman"
).
deliver
assert_equal
(
2
,
email
.
parts
.
length
)
assert_equal
(
"multipart/mixed"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
...
...
@@ -188,46 +152,46 @@ def explicit_multipart_with_any(hash = {})
# Defaults values
test
"uses default charset from class"
do
swap
BaseMailer
,
:default_charset
=>
"US-ASCII"
do
email
=
BaseMailer
.
deliver_welcome
email
=
BaseMailer
.
welcome
.
deliver
assert_equal
(
"US-ASCII"
,
email
.
charset
)
email
=
BaseMailer
.
deliver_welcome
(
:charset
=>
"iso-8559-1"
)
email
=
BaseMailer
.
welcome
(
:charset
=>
"iso-8559-1"
).
deliver
assert_equal
(
"iso-8559-1"
,
email
.
charset
)
end
end
test
"uses default content type from class"
do
swap
BaseMailer
,
:default_content_type
=>
"text/html"
do
email
=
BaseMailer
.
deliver_welcome
email
=
BaseMailer
.
welcome
.
deliver
assert_equal
(
"text/html"
,
email
.
mime_type
)
email
=
BaseMailer
.
deliver_welcome
(
:content_type
=>
"text/plain"
)
email
=
BaseMailer
.
welcome
(
:content_type
=>
"text/plain"
).
deliver
assert_equal
(
"text/plain"
,
email
.
mime_type
)
end
end
test
"uses default mime version from class"
do
swap
BaseMailer
,
:default_mime_version
=>
"2.0"
do
email
=
BaseMailer
.
deliver_welcome
email
=
BaseMailer
.
welcome
.
deliver
assert_equal
(
"2.0"
,
email
.
mime_version
)
email
=
BaseMailer
.
deliver_welcome
(
:mime_version
=>
"1.0"
)
email
=
BaseMailer
.
welcome
(
:mime_version
=>
"1.0"
).
deliver
assert_equal
(
"1.0"
,
email
.
mime_version
)
end
end
test
"subject gets default from I18n"
do
email
=
BaseMailer
.
deliver_welcome
(
:subject
=>
nil
)
email
=
BaseMailer
.
welcome
(
:subject
=>
nil
).
deliver
assert_equal
"Welcome"
,
email
.
subject
I18n
.
backend
.
store_translations
(
'en'
,
:actionmailer
=>
{
:base_mailer
=>
{
:welcome
=>
{
:subject
=>
"New Subject!"
}}})
email
=
BaseMailer
.
deliver_welcome
(
:subject
=>
nil
)
email
=
BaseMailer
.
welcome
(
:subject
=>
nil
).
deliver
assert_equal
"New Subject!"
,
email
.
subject
end
# Implicit multipart
test
"implicit multipart"
do
email
=
BaseMailer
.
deliver_implicit_multipart
email
=
BaseMailer
.
implicit_multipart
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
...
...
@@ -239,18 +203,18 @@ def explicit_multipart_with_any(hash = {})
test
"implicit multipart with sort order"
do
order
=
[
"text/html"
,
"text/plain"
]
swap
BaseMailer
,
:default_implicit_parts_order
=>
order
do
email
=
BaseMailer
.
deliver_implicit_multipart
email
=
BaseMailer
.
implicit_multipart
.
deliver
assert_equal
(
"text/html"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
mime_type
)
email
=
BaseMailer
.
deliver_implicit_multipart
(
:parts_order
=>
order
.
reverse
)
email
=
BaseMailer
.
implicit_multipart
(
:parts_order
=>
order
.
reverse
).
deliver
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
end
end
test
"implicit multipart with attachments creates nested parts"
do
email
=
BaseMailer
.
deliver_implicit_multipart
(
:attachments
=>
true
)
email
=
BaseMailer
.
implicit_multipart
(
:attachments
=>
true
).
deliver
assert_equal
(
"application/pdf"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternate"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
parts
[
0
].
mime_type
)
...
...
@@ -262,7 +226,7 @@ def explicit_multipart_with_any(hash = {})
test
"implicit multipart with attachments and sort order"
do
order
=
[
"text/html"
,
"text/plain"
]
swap
BaseMailer
,
:default_implicit_parts_order
=>
order
do
email
=
BaseMailer
.
deliver_implicit_multipart
(
:attachments
=>
true
)
email
=
BaseMailer
.
implicit_multipart
(
:attachments
=>
true
).
deliver
assert_equal
(
"application/pdf"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternate"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
parts
[
1
].
mime_type
)
...
...
@@ -272,7 +236,7 @@ def explicit_multipart_with_any(hash = {})
# Explicit multipart
test
"explicit multipart"
do
email
=
BaseMailer
.
deliver_explicit_multipart
email
=
BaseMailer
.
explicit_multipart
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
...
...
@@ -284,18 +248,18 @@ def explicit_multipart_with_any(hash = {})
test
"explicit multipart does not sort order"
do
order
=
[
"text/html"
,
"text/plain"
]
swap
BaseMailer
,
:default_implicit_parts_order
=>
order
do
email
=
BaseMailer
.
deliver_explicit_multipart
email
=
BaseMailer
.
explicit_multipart
.
deliver
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
email
=
BaseMailer
.
deliver_explicit_multipart
(
:parts_order
=>
order
.
reverse
)
email
=
BaseMailer
.
explicit_multipart
(
:parts_order
=>
order
.
reverse
).
deliver
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
end
end
test
"explicit multipart with attachments creates nested parts"
do
email
=
BaseMailer
.
deliver_explicit_multipart
(
:attachments
=>
true
)
email
=
BaseMailer
.
explicit_multipart
(
:attachments
=>
true
).
deliver
assert_equal
(
"application/pdf"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternate"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
parts
[
0
].
mime_type
)
...
...
@@ -305,7 +269,7 @@ def explicit_multipart_with_any(hash = {})
end
test
"explicit multipart with templates"
do
email
=
BaseMailer
.
deliver_explicit_multipart_templates
email
=
BaseMailer
.
explicit_multipart_templates
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
0
].
mime_type
)
...
...
@@ -315,7 +279,7 @@ def explicit_multipart_with_any(hash = {})
end
test
"explicit multipart with any"
do
email
=
BaseMailer
.
deliver_explicit_multipart_with_any
email
=
BaseMailer
.
explicit_multipart_with_any
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
...
...
@@ -324,21 +288,30 @@ def explicit_multipart_with_any(hash = {})
assert_equal
(
"Format with any!"
,
email
.
parts
[
1
].
body
.
encoded
)
end
test
"ActionMailer should be told when Mail gets delivered"
do
BaseMailer
.
deliveries
.
clear
BaseMailer
.
expects
(
:delivered_email
).
once
BaseMailer
.
deliver_welcome
assert_equal
(
1
,
BaseMailer
.
deliveries
.
length
)
# Class level API with method missing
test
"should respond to action methods"
do
assert
BaseMailer
.
respond_to?
(
:welcome
)
assert
BaseMailer
.
respond_to?
(
:implicit_multipart
)
assert
!
BaseMailer
.
respond_to?
(
:mail
)
assert
!
BaseMailer
.
respond_to?
(
:headers
)
end
test
"
C
alling just the action should return the generated mail object"
do
test
"
c
alling just the action should return the generated mail object"
do
BaseMailer
.
deliveries
.
clear
email
=
BaseMailer
.
welcome
assert_equal
(
0
,
BaseMailer
.
deliveries
.
length
)
assert_equal
(
'The first email on new API!'
,
email
.
subject
)
end
test
"Calling deliver on the action should deliver the mail object"
do
test
"calling deliver on the action should deliver the mail object"
do
BaseMailer
.
deliveries
.
clear
BaseMailer
.
expects
(
:delivered_email
).
once
BaseMailer
.
welcome
.
deliver
assert_equal
(
1
,
BaseMailer
.
deliveries
.
length
)
end
# Delivery hooks
test
"ActionMailer should be told when Mail gets delivered"
do
BaseMailer
.
deliveries
.
clear
BaseMailer
.
expects
(
:delivered_email
).
once
BaseMailer
.
welcome
.
deliver
...
...
actionmailer/test/mail_helper_test.rb
浏览文件 @
f30d73ba
...
...
@@ -10,22 +10,22 @@ class HelperMailer < ActionMailer::Base
helper
MailerHelper
helper
:example
def
use_helper
(
recipient
)
recipients
recipient
def
use_helper
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
end
def
use_example_helper
(
recipient
)
recipients
recipient
def
use_example_helper
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
@text
=
"emphasize me!"
end
def
use_mail_helper
(
recipient
)
recipients
recipient
def
use_mail_helper
recipients
'test@localhost'
subject
"using mailing helpers"
from
"tester@example.com"
...
...
@@ -37,8 +37,8 @@ def use_mail_helper(recipient)
"it off!"
end
def
use_helper_method
(
recipient
)
recipients
recipient
def
use_helper_method
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
...
...
@@ -53,7 +53,7 @@ def name_of_the_mailer_class
helper_method
:name_of_the_mailer_class
end
class
MailerHelperTest
<
Test
::
Uni
t
::
TestCase
class
MailerHelperTest
<
ActiveSuppor
t
::
TestCase
def
new_mail
(
charset
=
"utf-8"
)
mail
=
Mail
.
new
mail
.
set_content_type
"text"
,
"plain"
,
{
"charset"
=>
charset
}
if
charset
...
...
@@ -64,8 +64,6 @@ def setup
set_delivery_method
:test
ActionMailer
::
Base
.
perform_deliveries
=
true
ActionMailer
::
Base
.
deliveries
.
clear
@recipient
=
'test@localhost'
end
def
teardown
...
...
@@ -73,22 +71,22 @@ def teardown
end
def
test_use_helper
mail
=
HelperMailer
.
create_use_helper
(
@recipient
)
mail
=
HelperMailer
.
use_helper
assert_match
%r{Mr. Joe Person}
,
mail
.
encoded
end
def
test_use_example_helper
mail
=
HelperMailer
.
create_use_example_helper
(
@recipient
)
mail
=
HelperMailer
.
use_example_helper
assert_match
%r{<em><strong><small>emphasize me!}
,
mail
.
encoded
end
def
test_use_helper_method
mail
=
HelperMailer
.
create_use_helper_method
(
@recipient
)
mail
=
HelperMailer
.
use_helper_method
assert_match
%r{HelperMailer}
,
mail
.
encoded
end
def
test_use_mail_helper
mail
=
HelperMailer
.
create_use_mail_helper
(
@recipient
)
mail
=
HelperMailer
.
use_mail_helper
assert_match
%r{ But soft!}
,
mail
.
encoded
assert_match
%r{east, and
\r\n
Juliet}
,
mail
.
encoded
end
...
...
actionmailer/test/mail_layout_test.rb
浏览文件 @
f30d73ba
...
...
@@ -2,14 +2,14 @@
class
AutoLayoutMailer
<
ActionMailer
::
Base
def
hello
(
recipient
)
recipients
recipient
def
hello
recipients
'test@localhost'
subject
"You have a mail"
from
"tester@example.com"
end
def
spam
(
recipient
)
recipients
recipient
def
spam
recipients
'test@localhost'
subject
"You have a mail"
from
"tester@example.com"
...
...
@@ -17,8 +17,8 @@ def spam(recipient)
render
(
:inline
=>
"Hello, <%= @world %>"
,
:layout
=>
'spam'
)
end
def
nolayout
(
recipient
)
recipients
recipient
def
nolayout
recipients
'test@localhost'
subject
"You have a mail"
from
"tester@example.com"
...
...
@@ -26,8 +26,8 @@ def nolayout(recipient)
render
(
:inline
=>
"Hello, <%= @world %>"
,
:layout
=>
false
)
end
def
multipart
(
recipient
,
type
=
nil
)
recipients
recipient
def
multipart
(
type
=
nil
)
recipients
'test@localhost'
subject
"You have a mail"
from
"tester@example.com"
...
...
@@ -38,14 +38,14 @@ def multipart(recipient, type = nil)
class
ExplicitLayoutMailer
<
ActionMailer
::
Base
layout
'spam'
,
:except
=>
[
:logout
]
def
signup
(
recipient
)
recipients
recipient
def
signup
recipients
'test@localhost'
subject
"You have a mail"
from
"tester@example.com"
end
def
logout
(
recipient
)
recipients
recipient
def
logout
recipients
'test@localhost'
subject
"You have a mail"
from
"tester@example.com"
end
...
...
@@ -56,8 +56,6 @@ def setup
set_delivery_method
:test
ActionMailer
::
Base
.
perform_deliveries
=
true
ActionMailer
::
Base
.
deliveries
.
clear
@recipient
=
'test@localhost'
end
def
teardown
...
...
@@ -65,12 +63,12 @@ def teardown
end
def
test_should_pickup_default_layout
mail
=
AutoLayoutMailer
.
create_hello
(
@recipient
)
mail
=
AutoLayoutMailer
.
hello
assert_equal
"Hello from layout Inside"
,
mail
.
body
.
to_s
.
strip
end
def
test_should_pickup_multipart_layout
mail
=
AutoLayoutMailer
.
create_multipart
(
@recipient
)
mail
=
AutoLayoutMailer
.
multipart
# CHANGED: content_type returns an object
# assert_equal "multipart/alternative", mail.content_type
assert_equal
"multipart/alternative"
,
mail
.
mime_type
...
...
@@ -94,7 +92,7 @@ def test_should_pickup_multipart_layout
end
def
test_should_pickup_multipartmixed_layout
mail
=
AutoLayoutMailer
.
create_multipart
(
@recipient
,
"multipart/mixed"
)
mail
=
AutoLayoutMailer
.
multipart
(
"multipart/mixed"
)
# CHANGED: content_type returns an object
# assert_equal "multipart/mixed", mail.content_type
assert_equal
"multipart/mixed"
,
mail
.
mime_type
...
...
@@ -116,7 +114,7 @@ def test_should_pickup_multipartmixed_layout
end
def
test_should_fix_multipart_layout
mail
=
AutoLayoutMailer
.
create_multipart
(
@recipient
,
"text/plain"
)
mail
=
AutoLayoutMailer
.
multipart
(
"text/plain"
)
assert_equal
"multipart/alternative"
,
mail
.
mime_type
assert_equal
2
,
mail
.
parts
.
size
...
...
@@ -129,22 +127,22 @@ def test_should_fix_multipart_layout
def
test_should_pickup_layout_given_to_render
mail
=
AutoLayoutMailer
.
create_spam
(
@recipient
)
mail
=
AutoLayoutMailer
.
spam
assert_equal
"Spammer layout Hello, Earth"
,
mail
.
body
.
to_s
.
strip
end
def
test_should_respect_layout_false
mail
=
AutoLayoutMailer
.
create_nolayout
(
@recipient
)
mail
=
AutoLayoutMailer
.
nolayout
assert_equal
"Hello, Earth"
,
mail
.
body
.
to_s
.
strip
end
def
test_explicit_class_layout
mail
=
ExplicitLayoutMailer
.
create_signup
(
@recipient
)
mail
=
ExplicitLayoutMailer
.
signup
assert_equal
"Spammer layout We do not spam"
,
mail
.
body
.
to_s
.
strip
end
def
test_explicit_layout_exceptions
mail
=
ExplicitLayoutMailer
.
create_logout
(
@recipient
)
mail
=
ExplicitLayoutMailer
.
logout
assert_equal
"You logged out"
,
mail
.
body
.
to_s
.
strip
end
end
actionmailer/test/mail_render_test.rb
浏览文件 @
f30d73ba
require
'abstract_unit'
class
RenderMailer
<
ActionMailer
::
Base
def
inline_template
(
recipient
)
recipients
recipient
def
inline_template
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
...
...
@@ -10,46 +10,46 @@ def inline_template(recipient)
render
:inline
=>
"Hello, <%= @world %>"
end
def
file_template
(
recipient
)
recipients
recipient
def
file_template
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
@recipient
=
recipient
@recipient
=
'test@localhost'
render
:file
=>
"templates/signed_up"
end
def
implicit_body
(
recipient
)
recipients
recipient
def
implicit_body
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
@recipient
=
recipient
@recipient
=
'test@localhost'
render
:template
=>
"templates/signed_up"
end
def
rxml_template
(
recipient
)
recipients
recipient
def
rxml_template
recipients
'test@localhost'
subject
"rendering rxml template"
from
"tester@example.com"
end
def
included_subtemplate
(
recipient
)
recipients
recipient
def
included_subtemplate
recipients
'test@localhost'
subject
"Including another template in the one being rendered"
from
"tester@example.com"
end
def
mailer_accessor
(
recipient
)
recipients
recipient
def
mailer_accessor
recipients
'test@localhost'
subject
"Mailer Accessor"
from
"tester@example.com"
render
:inline
=>
"Look, <%= mailer.subject %>!"
end
def
no_instance_variable
(
recipient
)
recipients
recipient
def
no_instance_variable
recipients
'test@localhost'
subject
"No Instance Variable"
from
"tester@example.com"
...
...
@@ -65,16 +65,16 @@ def initialize_defaults(method_name)
end
class
FirstMailer
<
ActionMailer
::
Base
def
share
(
recipient
)
recipients
recipient
def
share
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
end
end
class
SecondMailer
<
ActionMailer
::
Base
def
share
(
recipient
)
recipients
recipient
def
share
recipients
'test@localhost'
subject
"using helpers"
from
"tester@example.com"
end
...
...
@@ -96,37 +96,37 @@ def teardown
end
def
test_implicit_body
mail
=
RenderMailer
.
create_implicit_body
(
@recipient
)
mail
=
RenderMailer
.
implicit_body
assert_equal
"Hello there,
\n\n
Mr. test@localhost"
,
mail
.
body
.
to_s
.
strip
end
def
test_inline_template
mail
=
RenderMailer
.
create_inline_template
(
@recipient
)
mail
=
RenderMailer
.
inline_template
assert_equal
"Hello, Earth"
,
mail
.
body
.
to_s
.
strip
end
def
test_file_template
mail
=
RenderMailer
.
create_file_template
(
@recipient
)
mail
=
RenderMailer
.
file_template
assert_equal
"Hello there,
\n\n
Mr. test@localhost"
,
mail
.
body
.
to_s
.
strip
end
def
test_rxml_template
mail
=
RenderMailer
.
deliver_rxml_template
(
@recipient
)
mail
=
RenderMailer
.
rxml_template
.
deliver
assert_equal
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
<test/>"
,
mail
.
body
.
to_s
.
strip
end
def
test_included_subtemplate
mail
=
RenderMailer
.
deliver_included_subtemplate
(
@recipient
)
mail
=
RenderMailer
.
included_subtemplate
.
deliver
assert_equal
"Hey Ho, let's go!"
,
mail
.
body
.
to_s
.
strip
end
def
test_mailer_accessor
mail
=
RenderMailer
.
deliver_mailer_accessor
(
@recipient
)
mail
=
RenderMailer
.
mailer_accessor
.
deliver
assert_equal
"Look, Mailer Accessor!"
,
mail
.
body
.
to_s
.
strip
end
def
test_no_instance_variable
mail
=
RenderMailer
.
deliver_no_instance_variable
(
@recipient
)
mail
=
RenderMailer
.
no_instance_variable
.
deliver
assert_equal
"Look, subject.nil? is true!"
,
mail
.
body
.
to_s
.
strip
end
end
...
...
@@ -145,13 +145,13 @@ def teardown
end
def
test_ordering
mail
=
FirstMailer
.
create_share
(
@recipient
)
mail
=
FirstMailer
.
share
assert_equal
"first mail"
,
mail
.
body
.
to_s
.
strip
mail
=
SecondMailer
.
create_share
(
@recipient
)
mail
=
SecondMailer
.
share
assert_equal
"second mail"
,
mail
.
body
.
to_s
.
strip
mail
=
FirstMailer
.
create_share
(
@recipient
)
mail
=
FirstMailer
.
share
assert_equal
"first mail"
,
mail
.
body
.
to_s
.
strip
mail
=
SecondMailer
.
create_share
(
@recipient
)
mail
=
SecondMailer
.
share
assert_equal
"second mail"
,
mail
.
body
.
to_s
.
strip
end
end
actionmailer/test/mail_service_test.rb
浏览文件 @
f30d73ba
此差异已折叠。
点击以展开。
actionmailer/test/subscriber_test.rb
浏览文件 @
f30d73ba
...
...
@@ -24,21 +24,21 @@ def set_logger(logger)
end
def
test_deliver_is_notified
TestMailer
.
deliver_basic
TestMailer
.
basic
.
deliver
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Sent mail to somewhere@example.com/
,
@logger
.
logged
(
:info
).
first
assert_equal
1
,
@logger
.
logged
(
:debug
).
size
assert_match
/Hello world/
,
@logger
.
logged
(
:debug
).
first
assert_equal
(
1
,
@logger
.
logged
(
:info
).
size
)
assert_match
(
/Sent mail to somewhere@example.com/
,
@logger
.
logged
(
:info
).
first
)
assert_equal
(
1
,
@logger
.
logged
(
:debug
).
size
)
assert_match
(
/Hello world/
,
@logger
.
logged
(
:debug
).
first
)
end
def
test_receive_is_notified
fixture
=
File
.
read
(
File
.
dirname
(
__FILE__
)
+
"/fixtures/raw_email"
)
TestMailer
.
receive
(
fixture
)
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Received mail/
,
@logger
.
logged
(
:info
).
first
assert_equal
1
,
@logger
.
logged
(
:debug
).
size
assert_match
/Jamis/
,
@logger
.
logged
(
:debug
).
first
assert_equal
(
1
,
@logger
.
logged
(
:info
).
size
)
assert_match
(
/Received mail/
,
@logger
.
logged
(
:info
).
first
)
assert_equal
(
1
,
@logger
.
logged
(
:debug
).
size
)
assert_match
(
/Jamis/
,
@logger
.
logged
(
:debug
).
first
)
end
end
\ No newline at end of file
actionmailer/test/test_helper_test.rb
浏览文件 @
f30d73ba
...
...
@@ -44,7 +44,7 @@ def test_encode
def
test_assert_emails
assert_nothing_raised
do
assert_emails
1
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
end
end
end
...
...
@@ -52,27 +52,27 @@ def test_assert_emails
def
test_repeated_assert_emails_calls
assert_nothing_raised
do
assert_emails
1
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
end
end
assert_nothing_raised
do
assert_emails
2
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
TestHelperMailer
.
test
.
deliver
end
end
end
def
test_assert_emails_with_no_block
assert_nothing_raised
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
assert_emails
1
end
assert_nothing_raised
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
TestHelperMailer
.
test
.
deliver
assert_emails
3
end
end
...
...
@@ -80,7 +80,7 @@ def test_assert_emails_with_no_block
def
test_assert_no_emails
assert_nothing_raised
do
assert_no_emails
do
TestHelperMailer
.
create_
test
TestHelperMailer
.
test
end
end
end
...
...
@@ -88,7 +88,7 @@ def test_assert_no_emails
def
test_assert_emails_too_few_sent
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_emails
2
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
end
end
...
...
@@ -98,8 +98,8 @@ def test_assert_emails_too_few_sent
def
test_assert_emails_too_many_sent
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_emails
1
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
TestHelperMailer
.
test
.
deliver
end
end
...
...
@@ -109,7 +109,7 @@ def test_assert_emails_too_many_sent
def
test_assert_no_emails_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_emails
do
TestHelperMailer
.
deliver_test
TestHelperMailer
.
test
.
deliver
end
end
...
...
actionmailer/test/tmail_compat_test.rb
浏览文件 @
f30d73ba
require
'abstract_unit'
class
TmailCompatTest
<
Test
::
Uni
t
::
TestCase
class
TmailCompatTest
<
ActiveSuppor
t
::
TestCase
def
test_set_content_type_raises_deprecation_warning
mail
=
Mail
.
new
assert_nothing_raised
do
mail
.
set_content_type
"text/plain"
assert_deprecated
do
assert_nothing_raised
do
mail
.
set_content_type
"text/plain"
end
end
assert_equal
mail
.
mime_type
,
"text/plain"
end
def
test_transfer_encoding_raises_deprecation_warning
mail
=
Mail
.
new
assert_nothing_raised
do
mail
.
transfer_encoding
"base64"
assert_deprecated
do
assert_nothing_raised
do
mail
.
transfer_encoding
"base64"
end
end
assert_equal
mail
.
content_transfer_encoding
,
"base64"
end
...
...
actionmailer/test/url_test.rb
浏览文件 @
f30d73ba
...
...
@@ -67,14 +67,14 @@ def test_signed_up_with_url
expected
.
date
=
Time
.
local
(
2004
,
12
,
12
)
created
=
nil
assert_nothing_raised
{
created
=
TestMailer
.
create_
signed_up_with_url
(
@recipient
)
}
assert_nothing_raised
{
created
=
TestMailer
.
signed_up_with_url
(
@recipient
)
}
assert_not_nil
created
expected
.
message_id
=
'<123@456>'
created
.
message_id
=
'<123@456>'
assert_equal
expected
.
encoded
,
created
.
encoded
assert_nothing_raised
{
TestMailer
.
deliver_signed_up_with_url
(
@recipient
)
}
assert_nothing_raised
{
TestMailer
.
signed_up_with_url
(
@recipient
).
deliver
}
assert_not_nil
ActionMailer
::
Base
.
deliveries
.
first
delivered
=
ActionMailer
::
Base
.
deliveries
.
first
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录