Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
70ae89c3
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 搜索 >>
提交
70ae89c3
编写于
1月 05, 2013
作者:
A
Akira Matsuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unnecessary begin..rescue..end, use only rescue
上级
3e8134a7
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
94 addition
and
123 deletion
+94
-123
actionpack/lib/action_dispatch/testing/assertions/routing.rb
actionpack/lib/action_dispatch/testing/assertions/routing.rb
+3
-5
actionpack/lib/action_view/helpers/debug_helper.rb
actionpack/lib/action_view/helpers/debug_helper.rb
+6
-8
actionpack/test/abstract/abstract_controller_test.rb
actionpack/test/abstract/abstract_controller_test.rb
+3
-5
actionpack/test/abstract/helper_test.rb
actionpack/test/abstract/helper_test.rb
+4
-6
actionpack/test/controller/filters_test.rb
actionpack/test/controller/filters_test.rb
+3
-5
actionpack/test/controller/render_test.rb
actionpack/test/controller/render_test.rb
+7
-9
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+23
-25
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
+5
-7
activerecord/test/cases/adapters/mysql2/schema_test.rb
activerecord/test/cases/adapters/mysql2/schema_test.rb
+5
-7
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+5
-7
activesupport/lib/active_support/core_ext/kernel/reporting.rb
...vesupport/lib/active_support/core_ext/kernel/reporting.rb
+3
-4
activesupport/lib/active_support/core_ext/marshal.rb
activesupport/lib/active_support/core_ext/marshal.rb
+11
-13
activesupport/lib/active_support/inflector/methods.rb
activesupport/lib/active_support/inflector/methods.rb
+6
-8
activesupport/test/core_ext/duration_test.rb
activesupport/test/core_ext/duration_test.rb
+6
-8
activesupport/test/dependencies_test.rb
activesupport/test/dependencies_test.rb
+4
-6
未找到文件。
actionpack/lib/action_dispatch/testing/assertions/routing.rb
浏览文件 @
70ae89c3
...
...
@@ -208,11 +208,9 @@ def recognized_request_for(path, extras = {})
end
def
fail_on
(
exception_class
)
begin
yield
rescue
exception_class
=>
e
raise
MiniTest
::
Assertion
,
e
.
message
end
yield
rescue
exception_class
=>
e
raise
MiniTest
::
Assertion
,
e
.
message
end
end
end
...
...
actionpack/lib/action_view/helpers/debug_helper.rb
浏览文件 @
70ae89c3
...
...
@@ -27,14 +27,12 @@ module DebugHelper
# new_record: true
# </pre>
def
debug
(
object
)
begin
Marshal
::
dump
(
object
)
object
=
ERB
::
Util
.
html_escape
(
object
.
to_yaml
).
gsub
(
" "
,
" "
).
html_safe
content_tag
(
:pre
,
object
,
:class
=>
"debug_dump"
)
rescue
Exception
# errors from Marshal or YAML
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
content_tag
(
:code
,
object
.
to_yaml
,
:class
=>
"debug_dump"
)
end
Marshal
::
dump
(
object
)
object
=
ERB
::
Util
.
html_escape
(
object
.
to_yaml
).
gsub
(
" "
,
" "
).
html_safe
content_tag
(
:pre
,
object
,
:class
=>
"debug_dump"
)
rescue
Exception
# errors from Marshal or YAML
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
content_tag
(
:code
,
object
.
to_yaml
,
:class
=>
"debug_dump"
)
end
end
end
...
...
actionpack/test/abstract/abstract_controller_test.rb
浏览文件 @
70ae89c3
...
...
@@ -157,13 +157,11 @@ class WithLayouts < PrefixedViews
private
def
self
.
layout
(
formats
)
find_template
(
name
.
underscore
,
{
:formats
=>
formats
},
:_prefixes
=>
[
"layouts"
])
rescue
ActionView
::
MissingTemplate
begin
find_template
(
name
.
underscore
,
{
:formats
=>
formats
},
:_prefixes
=>
[
"layouts"
])
find_template
(
"application"
,
{
:formats
=>
formats
},
:_prefixes
=>
[
"layouts"
])
rescue
ActionView
::
MissingTemplate
begin
find_template
(
"application"
,
{
:formats
=>
formats
},
:_prefixes
=>
[
"layouts"
])
rescue
ActionView
::
MissingTemplate
end
end
end
...
...
actionpack/test/abstract/helper_test.rb
浏览文件 @
70ae89c3
...
...
@@ -69,12 +69,10 @@ def test_helpers_with_symbol
end
def
test_declare_missing_helper
begin
AbstractHelpers
.
helper
:missing
flunk
"should have raised an exception"
rescue
LoadError
=>
e
assert_equal
"helpers/missing_helper.rb"
,
e
.
path
end
AbstractHelpers
.
helper
:missing
flunk
"should have raised an exception"
rescue
LoadError
=>
e
assert_equal
"helpers/missing_helper.rb"
,
e
.
path
end
def
test_helpers_with_module_through_block
...
...
actionpack/test/controller/filters_test.rb
浏览文件 @
70ae89c3
...
...
@@ -450,11 +450,9 @@ class ErrorToRescue < Exception; end
class
RescuingAroundFilterWithBlock
def
around
(
controller
)
begin
yield
rescue
ErrorToRescue
=>
ex
controller
.
__send__
:render
,
:text
=>
"I rescued this:
#{
ex
.
inspect
}
"
end
yield
rescue
ErrorToRescue
=>
ex
controller
.
__send__
:render
,
:text
=>
"I rescued this:
#{
ex
.
inspect
}
"
end
end
...
...
actionpack/test/controller/render_test.rb
浏览文件 @
70ae89c3
...
...
@@ -793,15 +793,13 @@ def test_render
end
def
test_line_offset
begin
get
:render_line_offset
flunk
"the action should have raised an exception"
rescue
StandardError
=>
exc
line
=
exc
.
backtrace
.
first
assert
(
line
=~
%r{:(
\d
+):}
)
assert_equal
"1"
,
$1
,
"The line offset is wrong, perhaps the wrong exception has been raised, exception was:
#{
exc
.
inspect
}
"
end
get
:render_line_offset
flunk
"the action should have raised an exception"
rescue
StandardError
=>
exc
line
=
exc
.
backtrace
.
first
assert
(
line
=~
%r{:(
\d
+):}
)
assert_equal
"1"
,
$1
,
"The line offset is wrong, perhaps the wrong exception has been raised, exception was:
#{
exc
.
inspect
}
"
end
# :ported: compatibility
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
70ae89c3
...
...
@@ -647,32 +647,30 @@ def exec_no_cache(sql, binds)
end
def
exec_cache
(
sql
,
binds
)
stmt_key
=
prepare_statement
sql
# Clear the queue
@connection
.
get_last_result
@connection
.
send_query_prepared
(
stmt_key
,
binds
.
map
{
|
col
,
val
|
type_cast
(
val
,
col
)
})
@connection
.
block
@connection
.
get_last_result
rescue
PGError
=>
e
# Get the PG code for the failure. Annoyingly, the code for
# prepared statements whose return value may have changed is
# FEATURE_NOT_SUPPORTED. Check here for more details:
# http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/cache/plancache.c#l573
begin
stmt_key
=
prepare_statement
sql
# Clear the queue
@connection
.
get_last_result
@connection
.
send_query_prepared
(
stmt_key
,
binds
.
map
{
|
col
,
val
|
type_cast
(
val
,
col
)
})
@connection
.
block
@connection
.
get_last_result
rescue
PGError
=>
e
# Get the PG code for the failure. Annoyingly, the code for
# prepared statements whose return value may have changed is
# FEATURE_NOT_SUPPORTED. Check here for more details:
# http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/cache/plancache.c#l573
begin
code
=
e
.
result
.
result_error_field
(
PGresult
::
PG_DIAG_SQLSTATE
)
rescue
raise
e
end
if
FEATURE_NOT_SUPPORTED
==
code
@statements
.
delete
sql_key
(
sql
)
retry
else
raise
e
end
code
=
e
.
result
.
result_error_field
(
PGresult
::
PG_DIAG_SQLSTATE
)
rescue
raise
e
end
if
FEATURE_NOT_SUPPORTED
==
code
@statements
.
delete
sql_key
(
sql
)
retry
else
raise
e
end
end
...
...
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
浏览文件 @
70ae89c3
...
...
@@ -49,13 +49,11 @@ def test_exec_insert_string
end
def
test_tables_quoting
begin
@conn
.
tables
(
nil
,
"foo-bar"
,
nil
)
flunk
rescue
=>
e
# assertion for *quoted* database properly
assert_match
(
/database 'foo-bar'/
,
e
.
inspect
)
end
@conn
.
tables
(
nil
,
"foo-bar"
,
nil
)
flunk
rescue
=>
e
# assertion for *quoted* database properly
assert_match
(
/database 'foo-bar'/
,
e
.
inspect
)
end
def
test_pk_and_sequence_for
...
...
activerecord/test/cases/adapters/mysql2/schema_test.rb
浏览文件 @
70ae89c3
...
...
@@ -37,13 +37,11 @@ def test_table_exists_wrong_schema
end
def
test_tables_quoting
begin
@connection
.
tables
(
nil
,
"foo-bar"
,
nil
)
flunk
rescue
=>
e
# assertion for *quoted* database properly
assert_match
(
/database 'foo-bar'/
,
e
.
inspect
)
end
@connection
.
tables
(
nil
,
"foo-bar"
,
nil
)
flunk
rescue
=>
e
# assertion for *quoted* database properly
assert_match
(
/database 'foo-bar'/
,
e
.
inspect
)
end
end
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
70ae89c3
...
...
@@ -300,13 +300,11 @@ def test_initialize_with_attributes
end
def
test_initialize_with_invalid_attribute
begin
Topic
.
new
({
"title"
=>
"test"
,
"last_read(1i)"
=>
"2005"
,
"last_read(2i)"
=>
"2"
,
"last_read(3i)"
=>
"31"
})
rescue
ActiveRecord
::
MultiparameterAssignmentErrors
=>
ex
assert_equal
(
1
,
ex
.
errors
.
size
)
assert_equal
(
"last_read"
,
ex
.
errors
[
0
].
attribute
)
end
Topic
.
new
({
"title"
=>
"test"
,
"last_read(1i)"
=>
"2005"
,
"last_read(2i)"
=>
"2"
,
"last_read(3i)"
=>
"31"
})
rescue
ActiveRecord
::
MultiparameterAssignmentErrors
=>
ex
assert_equal
(
1
,
ex
.
errors
.
size
)
assert_equal
(
"last_read"
,
ex
.
errors
[
0
].
attribute
)
end
def
test_create_after_initialize_without_block
...
...
activesupport/lib/active_support/core_ext/kernel/reporting.rb
浏览文件 @
70ae89c3
...
...
@@ -59,10 +59,9 @@ def silence_stream(stream)
#
# puts 'This code gets executed and nothing related to ZeroDivisionError was seen'
def
suppress
(
*
exception_classes
)
begin
yield
rescue
Exception
=>
e
raise
unless
exception_classes
.
any?
{
|
cls
|
e
.
kind_of?
(
cls
)
}
end
yield
rescue
Exception
=>
e
raise
unless
exception_classes
.
any?
{
|
cls
|
e
.
kind_of?
(
cls
)
}
end
# Captures the given stream and returns it:
...
...
activesupport/lib/active_support/core_ext/marshal.rb
浏览文件 @
70ae89c3
module
Marshal
class
<<
self
def
load_with_autoloading
(
source
)
begin
load_without_autoloading
(
source
)
rescue
ArgumentError
,
NameError
=>
exc
if
exc
.
message
.
match
(
%r|undefined class/module (.+)|
)
# try loading the class/module
$1
.
constantize
# if it is a IO we need to go back to read the object
source
.
rewind
if
source
.
respond_to?
(
:rewind
)
retry
else
raise
exc
end
load_without_autoloading
(
source
)
rescue
ArgumentError
,
NameError
=>
exc
if
exc
.
message
.
match
(
%r|undefined class/module (.+)|
)
# try loading the class/module
$1
.
constantize
# if it is a IO we need to go back to read the object
source
.
rewind
if
source
.
respond_to?
(
:rewind
)
retry
else
raise
exc
end
end
alias_method_chain
:load
,
:autoloading
end
end
\ No newline at end of file
end
activesupport/lib/active_support/inflector/methods.rb
浏览文件 @
70ae89c3
...
...
@@ -266,14 +266,12 @@ def constantize(camel_cased_word)
# 'UnknownModule'.safe_constantize # => nil
# 'UnknownModule::Foo::Bar'.safe_constantize # => nil
def
safe_constantize
(
camel_cased_word
)
begin
constantize
(
camel_cased_word
)
rescue
NameError
=>
e
raise
unless
e
.
message
=~
/(uninitialized constant|wrong constant name)
#{
const_regexp
(
camel_cased_word
)
}
$/
||
e
.
name
.
to_s
==
camel_cased_word
.
to_s
rescue
ArgumentError
=>
e
raise
unless
e
.
message
=~
/not missing constant
#{
const_regexp
(
camel_cased_word
)
}
\!$/
end
constantize
(
camel_cased_word
)
rescue
NameError
=>
e
raise
unless
e
.
message
=~
/(uninitialized constant|wrong constant name)
#{
const_regexp
(
camel_cased_word
)
}
$/
||
e
.
name
.
to_s
==
camel_cased_word
.
to_s
rescue
ArgumentError
=>
e
raise
unless
e
.
message
=~
/not missing constant
#{
const_regexp
(
camel_cased_word
)
}
\!$/
end
# Returns the suffix that should be added to a number to denote the position
...
...
activesupport/test/core_ext/duration_test.rb
浏览文件 @
70ae89c3
...
...
@@ -50,14 +50,12 @@ def test_plus_with_time
end
def
test_argument_error
begin
1
.
second
.
ago
(
''
)
flunk
(
"no exception was raised"
)
rescue
ArgumentError
=>
e
assert_equal
'expected a time or date, got ""'
,
e
.
message
,
"ensure ArgumentError is not being raised by dependencies.rb"
rescue
Exception
=>
e
flunk
(
"ArgumentError should be raised, but we got
#{
e
.
class
}
instead"
)
end
1
.
second
.
ago
(
''
)
flunk
(
"no exception was raised"
)
rescue
ArgumentError
=>
e
assert_equal
'expected a time or date, got ""'
,
e
.
message
,
"ensure ArgumentError is not being raised by dependencies.rb"
rescue
Exception
=>
e
flunk
(
"ArgumentError should be raised, but we got
#{
e
.
class
}
instead"
)
end
def
test_fractional_weeks
...
...
activesupport/test/dependencies_test.rb
浏览文件 @
70ae89c3
...
...
@@ -363,12 +363,10 @@ def test_non_existing_const_raises_name_error_with_fully_qualified_name
end
def
test_smart_name_error_strings
begin
Object
.
module_eval
"ImaginaryObject"
flunk
"No raise!!"
rescue
NameError
=>
e
assert
e
.
message
.
include?
(
"uninitialized constant ImaginaryObject"
)
end
Object
.
module_eval
"ImaginaryObject"
flunk
"No raise!!"
rescue
NameError
=>
e
assert
e
.
message
.
include?
(
"uninitialized constant ImaginaryObject"
)
end
def
test_loadable_constants_for_path_should_handle_empty_autoloads
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录