Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4fbd8adf
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 搜索 >>
提交
4fbd8adf
编写于
3月 14, 2011
作者:
C
Christopher Meiklejohn
提交者:
Jon Leighton
5月 08, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't quote ID's as Arel will quote them -- follow same conventions as the delete method.
上级
a45f300e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
2 deletion
+52
-2
activerecord/lib/active_record/locking/optimistic.rb
activerecord/lib/active_record/locking/optimistic.rb
+1
-1
activerecord/test/cases/locking_test.rb
activerecord/test/cases/locking_test.rb
+35
-1
activerecord/test/fixtures/string_key_objects.yml
activerecord/test/fixtures/string_key_objects.yml
+7
-0
activerecord/test/models/string_key_object.rb
activerecord/test/models/string_key_object.rb
+3
-0
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+6
-0
未找到文件。
activerecord/lib/active_record/locking/optimistic.rb
浏览文件 @
4fbd8adf
...
@@ -94,7 +94,7 @@ def update(attribute_names = @attributes.keys) #:nodoc:
...
@@ -94,7 +94,7 @@ def update(attribute_names = @attributes.keys) #:nodoc:
relation
=
self
.
class
.
unscoped
relation
=
self
.
class
.
unscoped
stmt
=
relation
.
where
(
stmt
=
relation
.
where
(
relation
.
table
[
self
.
class
.
primary_key
].
eq
(
quoted_
id
).
and
(
relation
.
table
[
self
.
class
.
primary_key
].
eq
(
id
).
and
(
relation
.
table
[
lock_col
].
eq
(
quote_value
(
previous_lock_value
))
relation
.
table
[
lock_col
].
eq
(
quote_value
(
previous_lock_value
))
)
)
).
arel
.
compile_update
(
arel_attributes_values
(
false
,
false
,
attribute_names
))
).
arel
.
compile_update
(
arel_attributes_values
(
false
,
false
,
attribute_names
))
...
...
activerecord/test/cases/locking_test.rb
浏览文件 @
4fbd8adf
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
require
'models/reader'
require
'models/reader'
require
'models/legacy_thing'
require
'models/legacy_thing'
require
'models/reference'
require
'models/reference'
require
'models/string_key_object'
class
LockWithoutDefault
<
ActiveRecord
::
Base
;
end
class
LockWithoutDefault
<
ActiveRecord
::
Base
;
end
...
@@ -18,7 +19,40 @@ class ReadonlyFirstNamePerson < Person
...
@@ -18,7 +19,40 @@ class ReadonlyFirstNamePerson < Person
end
end
class
OptimisticLockingTest
<
ActiveRecord
::
TestCase
class
OptimisticLockingTest
<
ActiveRecord
::
TestCase
fixtures
:people
,
:legacy_things
,
:references
fixtures
:people
,
:legacy_things
,
:references
,
:string_key_objects
def
test_non_integer_lock_existing
s1
=
StringKeyObject
.
find
(
"record1"
)
s2
=
StringKeyObject
.
find
(
"record1"
)
assert_equal
0
,
s1
.
lock_version
assert_equal
0
,
s2
.
lock_version
s1
.
name
=
'updated record'
s1
.
save!
assert_equal
1
,
s1
.
lock_version
assert_equal
0
,
s2
.
lock_version
s2
.
name
=
'doubly updated record'
assert_raise
(
ActiveRecord
::
StaleObjectError
)
{
s2
.
save!
}
end
def
test_non_integer_lock_destroy
s1
=
StringKeyObject
.
find
(
"record1"
)
s2
=
StringKeyObject
.
find
(
"record1"
)
assert_equal
0
,
s1
.
lock_version
assert_equal
0
,
s2
.
lock_version
s1
.
name
=
'updated record'
s1
.
save!
assert_equal
1
,
s1
.
lock_version
assert_equal
0
,
s2
.
lock_version
assert_raise
(
ActiveRecord
::
StaleObjectError
)
{
s2
.
destroy
}
assert
s1
.
destroy
assert
s1
.
frozen?
assert
s1
.
destroyed?
assert_raises
(
ActiveRecord
::
RecordNotFound
)
{
StringKeyObject
.
find
(
"record1"
)
}
end
def
test_lock_existing
def
test_lock_existing
p1
=
Person
.
find
(
1
)
p1
=
Person
.
find
(
1
)
...
...
activerecord/test/fixtures/string_key_objects.yml
0 → 100644
浏览文件 @
4fbd8adf
first
:
id
:
record1
name
:
first record
second
:
id
:
record2
name
:
second record
activerecord/test/models/string_key_object.rb
0 → 100644
浏览文件 @
4fbd8adf
class
StringKeyObject
<
ActiveRecord
::
Base
set_primary_key
:id
end
activerecord/test/schema/schema.rb
浏览文件 @
4fbd8adf
...
@@ -543,6 +543,12 @@ def create_table(*args, &block)
...
@@ -543,6 +543,12 @@ def create_table(*args, &block)
t
.
string
:sponsorable_type
t
.
string
:sponsorable_type
end
end
create_table
:string_key_objects
,
:id
=>
false
,
:primary_key
=>
:id
,
:force
=>
true
do
|
t
|
t
.
string
:id
t
.
string
:name
t
.
integer
:lock_version
,
:null
=>
false
,
:default
=>
0
end
create_table
:students
,
:force
=>
true
do
|
t
|
create_table
:students
,
:force
=>
true
do
|
t
|
t
.
string
:name
t
.
string
:name
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录