1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #13868 from mauricio/bug-13788

Correctly send the string given to lock! and reload(:lock) to the lock scope - fixes #13788
This commit is contained in:
Yves Senn 2014-01-29 07:40:52 -08:00
commit 40e7fe3451
3 changed files with 22 additions and 1 deletions

View file

@ -1,3 +1,13 @@
* Correctly send an user provided statement to a `lock!()` call.
person.lock! 'FOR SHARE NOWAIT'
# Before: SELECT * ... LIMIT 1 FOR UPDATE
# After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
Fixes #13788.
*Maurício Linhares*
* Handle aliased attributes `select()`, `order()` and `reorder()`.
*Tsutomu Kuroda*

View file

@ -389,7 +389,7 @@ module ActiveRecord
fresh_object =
if options && options[:lock]
self.class.unscoped { self.class.lock.find(id) }
self.class.unscoped { self.class.lock(options[:lock]).find(id) }
else
self.class.unscoped { self.class.find(id) }
end

View file

@ -431,6 +431,17 @@ unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter) || in_memory_db?
assert_equal old, person.reload.first_name
end
if current_adapter?(:PostgreSQLAdapter)
def test_lock_sending_custom_lock_statement
Person.transaction do
person = Person.find(1)
assert_sql(/LIMIT 1 FOR SHARE NOWAIT/) do
person.lock!('FOR SHARE NOWAIT')
end
end
end
end
if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
def test_no_locks_no_wait
first, second = duel { Person.find 1 }