Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1e2f63db
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 搜索 >>
提交
1e2f63db
编写于
6月 20, 2017
作者:
R
Rafael França
提交者:
Ryuta Kamizono
3月 06, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #28914 from bogdanvlviv/fix-touch-with-optimistic-locking
Fix ActiveRecord::Persistence#touch with locking
上级
e498052c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
3 deletion
+33
-3
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/persistence.rb
activerecord/lib/active_record/persistence.rb
+1
-1
activerecord/test/cases/locking_test.rb
activerecord/test/cases/locking_test.rb
+25
-2
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+2
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
1e2f63db
*
`ActiveRecord::Persistence#touch`
does not work well when optimistic locking enabled and
`locking_column`
, without default value, is null in the database.
*bogdanvlviv*
*
Fix destroying existing object does not work well when optimistic locking enabled and
`locking column`
is null in the database.
...
...
activerecord/lib/active_record/persistence.rb
浏览文件 @
1e2f63db
...
...
@@ -522,7 +522,7 @@ def touch(*names, time: nil)
if
locking_enabled?
locking_column
=
self
.
class
.
locking_column
scope
=
scope
.
where
(
locking_column
=>
_read_attribute
(
locking_column
))
scope
=
scope
.
where
(
locking_column
=>
read_attribute_before_type_cast
(
locking_column
))
changes
[
locking_column
]
=
increment_lock
end
...
...
activerecord/test/cases/locking_test.rb
浏览文件 @
1e2f63db
...
...
@@ -226,10 +226,33 @@ def test_lock_without_default_sets_version_to_zero
assert_equal
0
,
t1
.
lock_version_before_type_cast
end
def
test_touch_existing_lock_without_default_should_work_with_null_in_the_database
ActiveRecord
::
Base
.
connection
.
execute
(
"INSERT INTO lock_without_defaults(title) VALUES('title1')"
)
t1
=
LockWithoutDefault
.
last
assert_equal
0
,
t1
.
lock_version
assert_nil
t1
.
lock_version_before_type_cast
t1
.
touch
assert_equal
1
,
t1
.
lock_version
end
def
test_touch_stale_object_with_lock_without_default
t1
=
LockWithoutDefault
.
create!
(
title:
"title1"
)
stale_object
=
LockWithoutDefault
.
find
(
t1
.
id
)
t1
.
update!
(
title:
"title2"
)
assert_raises
(
ActiveRecord
::
StaleObjectError
)
do
stale_object
.
touch
end
end
def
test_lock_without_default_should_work_with_null_in_the_database
ActiveRecord
::
Base
.
connection
.
execute
(
"INSERT INTO lock_without_defaults(title) VALUES('title1')"
)
t1
=
LockWithoutDefault
.
last
t2
=
LockWithoutDefault
.
last
t2
=
LockWithoutDefault
.
find
(
t1
.
id
)
assert_equal
0
,
t1
.
lock_version
assert_nil
t1
.
lock_version_before_type_cast
...
...
@@ -286,7 +309,7 @@ def test_lock_with_custom_column_without_default_should_work_with_null_in_the_da
ActiveRecord
::
Base
.
connection
.
execute
(
"INSERT INTO lock_without_defaults_cust(title) VALUES('title1')"
)
t1
=
LockWithCustomColumnWithoutDefault
.
last
t2
=
LockWithCustomColumnWithoutDefault
.
last
t2
=
LockWithCustomColumnWithoutDefault
.
find
(
t1
.
id
)
assert_equal
0
,
t1
.
custom_lock_version
assert_nil
t1
.
custom_lock_version_before_type_cast
...
...
activerecord/test/schema/schema.rb
浏览文件 @
1e2f63db
...
...
@@ -459,11 +459,13 @@
create_table
:lock_without_defaults
,
force:
true
do
|
t
|
t
.
column
:title
,
:string
t
.
column
:lock_version
,
:integer
t
.
timestamps
null:
true
end
create_table
:lock_without_defaults_cust
,
force:
true
do
|
t
|
t
.
column
:title
,
:string
t
.
column
:custom_lock_version
,
:integer
t
.
timestamps
null:
true
end
create_table
:magazines
,
force:
true
do
|
t
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录