Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6003dafc
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 搜索 >>
提交
6003dafc
编写于
1月 24, 2018
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #30391 from jbourassa/fix-actionmailer-lambda-default
Fix actionmailer lambda default
上级
d25c2e7c
fbb2fc8a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
2 deletion
+34
-2
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+6
-0
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+11
-1
actionmailer/test/base_test.rb
actionmailer/test/base_test.rb
+9
-0
actionmailer/test/mailers/proc_mailer.rb
actionmailer/test/mailers/proc_mailer.rb
+8
-1
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
6003dafc
*
Bring back proc with arity of 1 in
`ActionMailer::Base.default`
proc
since it was supported in Rails 5.0 but not deprecated.
*Jimmy Bourassa*
## Rails 5.2.0.beta2 (November 28, 2017) ##
*
No changes.
...
...
actionmailer/lib/action_mailer/base.rb
浏览文件 @
6003dafc
...
...
@@ -889,7 +889,7 @@ def apply_defaults(headers)
default_values
=
self
.
class
.
default
.
map
do
|
key
,
value
|
[
key
,
value
.
is_a?
(
Proc
)
?
instance_exec
(
&
value
)
:
value
compute_default
(
value
)
]
end
.
to_h
...
...
@@ -898,6 +898,16 @@ def apply_defaults(headers)
headers_with_defaults
end
def
compute_default
(
value
)
return
value
unless
value
.
is_a?
(
Proc
)
if
value
.
arity
==
1
instance_exec
(
self
,
&
value
)
else
instance_exec
(
&
value
)
end
end
def
assign_headers_to_message
(
message
,
headers
)
assignable
=
headers
.
except
(
:parts_order
,
:content_type
,
:body
,
:template_name
,
:template_path
,
:delivery_method
,
:delivery_method_options
)
...
...
actionmailer/test/base_test.rb
浏览文件 @
6003dafc
...
...
@@ -725,6 +725,15 @@ def self.previewing_email(mail); end
assert
(
ProcMailer
.
welcome
[
"x-has-to-proc"
].
to_s
==
"symbol"
)
end
test
"proc default values can have arity of 1 where arg is a mailer instance"
do
assert_equal
(
ProcMailer
.
welcome
[
"X-Lambda-Arity-1-arg"
].
to_s
,
"complex_value"
)
assert_equal
(
ProcMailer
.
welcome
[
"X-Lambda-Arity-1-self"
].
to_s
,
"complex_value"
)
end
test
"proc default values with fixed arity of 0 can be called"
do
assert_equal
(
"0"
,
ProcMailer
.
welcome
[
"X-Lambda-Arity-0"
].
to_s
)
end
test
"we can call other defined methods on the class as needed"
do
mail
=
ProcMailer
.
welcome
assert_equal
(
"Thanks for signing up this afternoon"
,
mail
.
subject
)
...
...
actionmailer/test/mailers/proc_mailer.rb
浏览文件 @
6003dafc
...
...
@@ -4,12 +4,19 @@ class ProcMailer < ActionMailer::Base
default
to:
"system@test.lindsaar.net"
,
"X-Proc-Method"
=>
Proc
.
new
{
Time
.
now
.
to_i
.
to_s
},
subject:
Proc
.
new
{
give_a_greeting
},
"x-has-to-proc"
=>
:symbol
"x-has-to-proc"
=>
:symbol
,
"X-Lambda-Arity-0"
=>
->
()
{
"0"
},
"X-Lambda-Arity-1-arg"
=>
->
(
arg
)
{
arg
.
computed_value
},
"X-Lambda-Arity-1-self"
=>
->
(
_
)
{
self
.
computed_value
}
def
welcome
mail
end
def
computed_value
"complex_value"
end
private
def
give_a_greeting
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录