Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Rase when calling `lock!` in a dirty record
- Loading branch information
|
|
@@ -1,3 +1,7 @@ |
|
|
* Raises when calling `lock!` in a dirty record. |
|
|
|
|
|
*Rafael Mendonça França* |
|
|
|
|
|
* Remove deprecated support to passing a class to `:class_name` on associations. |
|
|
|
|
|
*Rafael Mendonça França* |
|
|
|
@@ -63,12 +63,13 @@ module Pessimistic |
|
|
def lock!(lock = true) |
|
|
if persisted? |
|
|
if changed? |
|
|
ActiveSupport::Deprecation.warn(<<-MSG.squish) |
|
|
Locking a record with unpersisted changes is deprecated and will raise an |
|
|
exception in Rails 5.2. Use `save` to persist the changes, or `reload` to |
|
|
discard them explicitly. |
|
|
raise(<<-MSG.squish) |
|
|
Locking a record with unpersisted changes is not supported. Use |
|
|
`save` to persist the changes, or `reload` to discard them |
|
|
explicitly. |
|
|
MSG |
|
|
end |
|
|
|
|
|
reload(lock: lock) |
|
|
end |
|
|
self |
|
|
|
@@ -565,18 +565,18 @@ def test_eager_find_with_lock |
|
|
end |
|
|
end |
|
|
|
|
|
# Locking a record reloads it. |
|
|
def test_sane_lock_method |
|
|
def test_lock_does_not_raise_when_the_object_is_not_dirty |
|
|
person = Person.find 1 |
|
|
assert_nothing_raised do |
|
|
Person.transaction do |
|
|
person = Person.find 1 |
|
|
old, person.first_name = person.first_name, "fooman" |
|
|
# Locking a dirty record is deprecated |
|
|
assert_deprecated do |
|
|
person.lock! |
|
|
end |
|
|
assert_equal old, person.first_name |
|
|
end |
|
|
person.lock! |
|
|
end |
|
|
end |
|
|
|
|
|
def test_lock_raises_when_the_record_is_dirty |
|
|
person = Person.find 1 |
|
|
person.first_name = "fooman" |
|
|
assert_raises(RuntimeError) do |
|
|
person.lock! |
|
|
end |
|
|
end |
|
|
|
|
|