Permalink
Browse files

Merge pull request #13868 from mauricio/bug-13788

Correctly send the string given to lock! and reload(:lock) to the lock scope - fixes #13788
Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
1 parent 4e29dad commit 56ac83bb23480d7ddf68e66dd0a24a01b54f5910 @senny senny committed Jan 29, 2014
View
@@ -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*
+
* Active Record objects can now be correctly dumped, loaded and dumped again without issues.
Previously, if you did `YAML.dump`, `YAML.load` and then `YAML.dump` again
@@ -387,7 +387,7 @@ def reload(options = nil)
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
@@ -425,6 +425,17 @@ def test_with_lock_rolls_back_transaction
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 }

0 comments on commit 56ac83b

Please sign in to comment.