Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3cf773b1
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,发现更多精彩内容 >>
提交
3cf773b1
编写于
8月 29, 2008
作者:
J
James Mead
提交者:
Joshua Peek
8月 29, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ActionMailer should respond_to? to methods handled by method_missing [#700 state:resolved]
Signed-off-by:
N
Joshua Peek
<
josh@joshpeek.com
>
上级
99492bad
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
5 deletion
+68
-5
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+16
-5
actionmailer/test/mail_service_test.rb
actionmailer/test/mail_service_test.rb
+52
-0
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
3cf773b1
...
@@ -374,11 +374,16 @@ def mailer_name
...
@@ -374,11 +374,16 @@ def mailer_name
alias_method
:controller_name
,
:mailer_name
alias_method
:controller_name
,
:mailer_name
alias_method
:controller_path
,
:mailer_name
alias_method
:controller_path
,
:mailer_name
def
method_missing
(
method_symbol
,
*
parameters
)
#:nodoc:
def
respond_to?
(
method_symbol
,
include_private
=
false
)
#:nodoc:
case
method_symbol
.
id2name
matches_dynamic_method?
(
method_symbol
)
||
super
when
/^create_([_a-z]\w*)/
then
new
(
$1
,
*
parameters
).
mail
end
when
/^deliver_([_a-z]\w*)/
then
new
(
$1
,
*
parameters
).
deliver!
when
"new"
then
nil
def
method_missing
(
method_symbol
,
*
parameters
)
#:nodoc:
match
=
matches_dynamic_method?
(
method_symbol
)
case
match
[
1
]
when
'create'
then
new
(
match
[
2
],
*
parameters
).
mail
when
'deliver'
then
new
(
match
[
2
],
*
parameters
).
deliver!
when
'new'
then
nil
else
super
else
super
end
end
end
end
...
@@ -424,6 +429,12 @@ def template_root
...
@@ -424,6 +429,12 @@ def template_root
def
template_root
=
(
root
)
def
template_root
=
(
root
)
self
.
view_paths
=
ActionView
::
Base
.
process_view_paths
(
root
)
self
.
view_paths
=
ActionView
::
Base
.
process_view_paths
(
root
)
end
end
private
def
matches_dynamic_method?
(
method_name
)
#:nodoc:
method_name
=
method_name
.
to_s
/(create|deliver)_([_a-z]\w*)/
.
match
(
method_name
)
||
/^(new)$/
.
match
(
method_name
)
end
end
end
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
...
...
actionmailer/test/mail_service_test.rb
浏览文件 @
3cf773b1
...
@@ -968,3 +968,55 @@ def test_send_method
...
@@ -968,3 +968,55 @@ def test_send_method
end
end
end
end
end
end
class
RespondToTest
<
Test
::
Unit
::
TestCase
class
RespondToMailer
<
ActionMailer
::
Base
;
end
def
setup
set_delivery_method
:test
end
def
teardown
restore_delivery_method
end
def
test_should_respond_to_new
assert
RespondToMailer
.
respond_to?
(
:new
)
end
def
test_should_respond_to_create_with_template_suffix
assert
RespondToMailer
.
respond_to?
(
:create_any_old_template
)
end
def
test_should_respond_to_deliver_with_template_suffix
assert
RespondToMailer
.
respond_to?
(
:deliver_any_old_template
)
end
def
test_should_not_respond_to_new_with_template_suffix
assert
!
RespondToMailer
.
respond_to?
(
:new_any_old_template
)
end
def
test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
assert
!
RespondToMailer
.
respond_to?
(
:createany_old_template
)
end
def
test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
assert
!
RespondToMailer
.
respond_to?
(
:deliverany_old_template
)
end
def
test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
assert
!
RespondToMailer
.
respond_to?
(
:create_Any_old_template
)
end
def
test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
assert
!
RespondToMailer
.
respond_to?
(
:deliver_Any_old_template
)
end
def
test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
assert
!
RespondToMailer
.
respond_to?
(
:create_1_template
)
end
def
test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
assert
!
RespondToMailer
.
respond_to?
(
:deliver_1_template
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录