Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f734ec48
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,发现更多精彩内容 >>
提交
f734ec48
编写于
8月 20, 2012
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
define singleton methods rather than adding and removing methods
上级
79d21ddd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
32 addition
and
45 deletion
+32
-45
activerecord/test/cases/transactions_test.rb
activerecord/test/cases/transactions_test.rb
+32
-45
未找到文件。
activerecord/test/cases/transactions_test.rb
浏览文件 @
f734ec48
...
...
@@ -121,22 +121,17 @@ def test_update_attributes_should_rollback_on_failure!
end
def
test_cancellation_from_before_destroy_rollbacks_in_destroy
add_cancelling_before_destroy_with_db_side_effect_to_topic
begin
add_cancelling_before_destroy_with_db_side_effect_to_topic
@first
nbooks_before_destroy
=
Book
.
count
status
=
@first
.
destroy
assert
!
status
assert_nothing_raised
(
ActiveRecord
::
RecordNotFound
)
{
@first
.
reload
}
@first
.
reload
assert_equal
nbooks_before_destroy
,
Book
.
count
ensure
remove_cancelling_before_destroy_with_db_side_effect_to_topic
end
end
def
test_cancellation_from_before_filters_rollbacks_in_save
%w(validation save)
.
each
do
|
filter
|
send
(
"add_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
begin
define_method
(
"test_cancellation_from_before_filters_rollbacks_in_
#{
filter
}
"
)
do
send
(
"add_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
,
@first
)
nbooks_before_save
=
Book
.
count
original_author_name
=
@first
.
author_name
@first
.
author_name
+=
'_this_should_not_end_up_in_the_db'
...
...
@@ -144,27 +139,21 @@ def test_cancellation_from_before_filters_rollbacks_in_save
assert
!
status
assert_equal
original_author_name
,
@first
.
reload
.
author_name
assert_equal
nbooks_before_save
,
Book
.
count
ensure
send
(
"remove_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
end
end
end
def
test_cancellation_from_before_filters_rollbacks_in_save!
%w(validation save)
.
each
do
|
filter
|
send
(
"add_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
begin
define_method
(
"test_cancellation_from_before_filters_rollbacks_in_
#{
filter
}
!"
)
do
send
(
"add_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
,
@first
)
nbooks_before_save
=
Book
.
count
original_author_name
=
@first
.
author_name
@first
.
author_name
+=
'_this_should_not_end_up_in_the_db'
begin
@first
.
save!
flunk
rescue
rescue
ActiveRecord
::
RecordInvalid
,
ActiveRecord
::
RecordNotSaved
end
assert_equal
original_author_name
,
@first
.
reload
.
author_name
assert_equal
nbooks_before_save
,
Book
.
count
ensure
send
(
"remove_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
end
end
end
...
...
@@ -475,14 +464,12 @@ def define_callback_method(callback_method)
end
%w(validation save destroy)
.
each
do
|
filter
|
define_method
(
"add_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
do
Topic
.
class_eval
<<-
eoruby
,
__FILE__
,
__LINE__
+
1
remove_method :before_
#{
filter
}
_for_transaction
def before_
#{
filter
}
_for_transaction
define_method
(
"add_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
do
|
topic
|
meta
=
class
<<
topic
;
self
;
end
meta
.
send
(
"define_method"
,
"before_
#{
filter
}
_for_transaction"
)
do
Book
.
create
false
end
eoruby
end
define_method
(
"remove_cancelling_before_
#{
filter
}
_with_db_side_effect_to_topic"
)
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录