Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
82370345
Commit
82370345
authored
Dec 27, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support both 0 and NULL lock_versions
parent
fd27be93
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
6 deletions
+46
-6
config/initializers/active_record_locking.rb
config/initializers/active_record_locking.rb
+2
-6
spec/initializers/active_record_locking_spec.rb
spec/initializers/active_record_locking_spec.rb
+44
-0
No files found.
config/initializers/active_record_locking.rb
View file @
82370345
...
...
@@ -19,12 +19,7 @@ module ActiveRecord
return
0
if
attribute_names
.
empty?
lock_col
=
self
.
class
.
locking_column
previous_lock_value
=
send
(
lock_col
).
to_i
# This line is added as a patch
previous_lock_value
=
nil
if
previous_lock_value
==
'0'
||
previous_lock_value
==
0
increment_lock
attribute_names
+=
[
lock_col
]
...
...
@@ -35,7 +30,8 @@ module ActiveRecord
affected_rows
=
relation
.
where
(
self
.
class
.
primary_key
=>
id
,
lock_col
=>
previous_lock_value
# Patched because when `lock_version` is read as `0`, it may actually be `NULL` in the DB.
lock_col
=>
previous_lock_value
==
0
?
[
nil
,
0
]
:
previous_lock_value
).
update_all
(
attributes_for_update
(
attribute_names
).
map
do
|
name
|
[
name
,
_read_attribute
(
name
)]
...
...
spec/initializers/active_record_locking_spec.rb
0 → 100644
View file @
82370345
# frozen_string_literal: true
require
'spec_helper'
describe
'ActiveRecord locking'
do
let
(
:issue
)
{
create
(
:issue
)
}
shared_examples
'locked model'
do
before
do
issue
.
update_column
(
:lock_version
,
start_lock_version
)
end
it
'can be updated'
do
issue
.
update
(
title:
"New title"
)
expect
(
issue
.
reload
.
lock_version
).
to
eq
(
new_lock_version
)
end
it
'can be deleted'
do
expect
{
issue
.
destroy
}.
to
change
{
Issue
.
count
}.
by
(
-
1
)
end
end
context
'when lock_version is NULL'
do
let
(
:start_lock_version
)
{
nil
}
let
(
:new_lock_version
)
{
1
}
it_behaves_like
'locked model'
end
context
'when lock_version is 0'
do
let
(
:start_lock_version
)
{
0
}
let
(
:new_lock_version
)
{
1
}
it_behaves_like
'locked model'
end
context
'when lock_version is 1'
do
let
(
:start_lock_version
)
{
1
}
let
(
:new_lock_version
)
{
2
}
it_behaves_like
'locked model'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment