Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
963fef7b
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,发现更多精彩内容 >>
提交
963fef7b
编写于
1月 01, 2019
作者:
G
Genadi Samokovarov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify the ActionableError.{dispatch,action} boundries
上级
a3110fe2
变更
3
展开全部
显示空白变更内容
内联
并排
Showing
3 changed file
with
84 addition
and
3860 deletion
+84
-3860
activesupport/lib/active_support/actionable_error.rb
activesupport/lib/active_support/actionable_error.rb
+7
-11
activesupport/test/actionable_error_test.rb
activesupport/test/actionable_error_test.rb
+7
-18
yarn.lock
yarn.lock
+70
-3831
未找到文件。
activesupport/lib/active_support/actionable_error.rb
浏览文件 @
963fef7b
...
...
@@ -15,8 +15,8 @@ module ActionableError
NonActionable
=
Class
.
new
(
StandardError
)
NoActions
=
Hash
.
new
do
|
_
,
label
|
# :nodoc:
raise
NonActionable
,
"Cannot find action
\"
#{
label
}
\"
for
#{
self
}
"
NoActions
=
Hash
.
new
do
|
_
,
name
|
# :nodoc:
raise
NonActionable
,
"Cannot find action
\"
#{
name
}
\"
"
end
included
do
...
...
@@ -25,19 +25,15 @@ module ActionableError
def
self
.
actions
(
error
)
# :nodoc:
case
error
when
String
actions
(
error
.
constantize
)
when
ActionableError
,
->
it
{
Class
===
it
&&
it
<
ActionableError
}
error
.
_actions
when
Exception
NoActions
else
raise
NonActionable
,
"
#{
error
}
is non-actionable"
NoActions
end
end
def
self
.
dispatch
(
error
,
label
)
# :nodoc:
actions
(
error
)[
label
].
call
def
self
.
dispatch
(
error
,
name
)
# :nodoc:
actions
(
error
.
is_a?
(
String
)
?
error
.
constantize
:
error
)[
name
].
call
end
module
ClassMethods
...
...
@@ -50,8 +46,8 @@ module ClassMethods
# ActiveRecord::Tasks::DatabaseTasks.migrate
# end
# end
def
action
(
label
,
&
block
)
_actions
[
label
]
=
block
def
action
(
name
,
&
block
)
_actions
[
name
]
=
block
end
end
end
...
...
activesupport/test/actionable_error_test.rb
浏览文件 @
963fef7b
...
...
@@ -21,44 +21,33 @@ class DispatchableError < StandardError
end
end
test
"
list
s all action of an actionable error"
do
test
"
return
s all action of an actionable error"
do
assert_equal
[
"Flip 1"
,
"Flip 2"
],
ActiveSupport
::
ActionableError
.
actions
(
DispatchableError
).
keys
assert_equal
[
"Flip 1"
,
"Flip 2"
],
ActiveSupport
::
ActionableError
.
actions
(
DispatchableError
.
new
).
keys
end
test
"raises an error when trying to get actions from non-actionable error classes"
do
assert_raises
ActiveSupport
::
ActionableError
::
NonActionable
do
ActiveSupport
::
ActionableError
.
actions
(
NonActionableError
)
end
assert_raises
ActiveSupport
::
ActionableError
::
NonActionable
do
ActiveSupport
::
ActionableError
.
actions
(
NonActionableError
.
name
)
end
end
test
"returns no actions from non-actionable exception instances"
do
test
"returns no actions for non-actionable errors"
do
assert
ActiveSupport
::
ActionableError
.
actions
(
Exception
).
empty?
assert
ActiveSupport
::
ActionableError
.
actions
(
Exception
.
new
).
empty?
end
test
"dispatches actions from
class and a label
"
do
test
"dispatches actions from
error and name
"
do
assert_changes
"DispatchableError.flip1"
,
from:
false
,
to:
true
do
ActiveSupport
::
ActionableError
.
dispatch
DispatchableError
,
"Flip 1"
end
end
test
"dispatches actions from
class name and a label
"
do
test
"dispatches actions from
error class as string and name
"
do
assert_changes
"DispatchableError.flip2"
,
from:
false
,
to:
true
do
ActiveSupport
::
ActionableError
.
dispatch
DispatchableError
.
name
,
"Flip 2"
end
end
test
"cannot dispatch
errors that do not include ActiveSupport::ActionableError
"
do
test
"cannot dispatch
missing actions
"
do
err
=
assert_raises
ActiveSupport
::
ActionableError
::
NonActionable
do
ActiveSupport
::
ActionableError
.
dispatch
NonActionableError
,
"action"
end
assert_equal
<<~
EXPECTED
.
chop
,
err
.
to_s
ActionableErrorTest::NonActionableError is non-actionable
EXPECTED
assert_equal
'Cannot find action "action"'
,
err
.
to_s
end
end
yarn.lock
浏览文件 @
963fef7b
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录