Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
db6847dc
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 搜索 >>
提交
db6847dc
编写于
9月 24, 2017
作者:
M
Mikkel Malmberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add assert_enqueued_email_with to ActionMailer::TestHelper
上级
36888b93
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
0 deletion
+92
-0
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+8
-0
actionmailer/lib/action_mailer/test_helper.rb
actionmailer/lib/action_mailer/test_helper.rb
+42
-0
actionmailer/test/test_helper_test.rb
actionmailer/test/test_helper_test.rb
+42
-0
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
db6847dc
*
Add
`assert_enqueued_email_with`
test helper.
assert_enqueued_email_with ContactMailer, :welcome do
ContactMailer.welcome.deliver_later
end
*Mikkel Malmberg*
*
Allow Action Mailer classes to configure their delivery job.
class MyMailer < ApplicationMailer
...
...
actionmailer/lib/action_mailer/test_helper.rb
浏览文件 @
db6847dc
...
...
@@ -93,6 +93,48 @@ def assert_enqueued_emails(number, &block)
assert_enqueued_jobs
number
,
only:
[
ActionMailer
::
DeliveryJob
,
ActionMailer
::
Parameterized
::
DeliveryJob
],
&
block
end
# Asserts that a specific email has been enqueued, optionally
# matching arguments.
#
# def test_email
# ContactMailer.welcome.deliver_later
# assert_enqueued_email_with ContactMailer, :welcome
# end
#
# def test_email_with_arguments
# ContactMailer.welcome("Hello", "Goodbye").deliver_later
# assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
# end
#
# If a block is passed, that block should cause the specified email
# to be enqueued.
#
# def test_email_in_block
# assert_enqueued_email_with ContactMailer, :welcome do
# ContactMailer.welcome.deliver_later
# end
# end
#
# If `args` is provided as a Hash, a parameterized email is matched.
#
# def test_parameterized_email
# assert_enqueued_email_with ContactMailer, :welcome,
# args: {email: 'user@example.com} do
# ContactMailer.with(email: 'user@example.com').welcome.deliver_later
# end
# end
def
assert_enqueued_email_with
(
mailer
,
method
,
args:
nil
,
queue:
"mailers"
,
&
block
)
if
args
.
is_a?
Hash
job
=
ActionMailer
::
Parameterized
::
DeliveryJob
args
=
[
mailer
.
to_s
,
method
.
to_s
,
"deliver_now"
,
args
]
else
job
=
ActionMailer
::
DeliveryJob
args
=
[
mailer
.
to_s
,
method
.
to_s
,
"deliver_now"
,
*
args
]
end
assert_enqueued_with
(
job:
job
,
args:
args
,
queue:
queue
,
&
block
)
end
# Asserts that no emails are enqueued for later delivery.
#
# def test_no_emails
...
...
actionmailer/test/test_helper_test.rb
浏览文件 @
db6847dc
...
...
@@ -10,6 +10,18 @@ def test
to:
"test@example.com"
,
from:
"tester@example.com"
end
def
test_args
(
recipient
,
name
)
mail
body:
render
(
inline:
"Hello,
#{
name
}
"
),
to:
recipient
,
from:
"tester@example.com"
end
def
test_parameter_args
mail
body:
render
(
inline:
"All is
#{
params
[
:all
]
}
"
),
to:
"test@example.com"
,
from:
"tester@example.com"
end
end
class
TestHelperMailerTest
<
ActionMailer
::
TestCase
...
...
@@ -207,6 +219,36 @@ def test_assert_no_enqueued_emails_failure
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_enqueued_email_with
assert_nothing_raised
do
assert_enqueued_email_with
TestHelperMailer
,
:test
do
silence_stream
(
$stdout
)
do
TestHelperMailer
.
test
.
deliver_later
end
end
end
end
def
test_assert_enqueued_email_with_args
assert_nothing_raised
do
assert_enqueued_email_with
TestHelperMailer
,
:test_args
,
args:
[
"some_email"
,
"some_name"
]
do
silence_stream
(
$stdout
)
do
TestHelperMailer
.
test_args
(
"some_email"
,
"some_name"
).
deliver_later
end
end
end
end
def
test_assert_enqueued_email_with_parameterized_args
assert_nothing_raised
do
assert_enqueued_email_with
TestHelperMailer
,
:test_parameter_args
,
args:
{
all:
"good"
}
do
silence_stream
(
$stdout
)
do
TestHelperMailer
.
with
(
all:
"good"
).
test_parameter_args
.
deliver_later
end
end
end
end
end
class
AnotherTestHelperMailerTest
<
ActionMailer
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录