List changed attrs in pessimistic lock error
If `record.lock!` fails because the record has unpersisted changes, it can help to see which attributes changed.
This commit is contained in:
parent
2197814074
commit
3212ae7f6b
@ -71,6 +71,7 @@ def lock!(lock = true)
|
||||
Locking a record with unpersisted changes is not supported. Use
|
||||
`save` to persist the changes, or `reload` to discard them
|
||||
explicitly.
|
||||
Changed attributes: #{changed.map(&:inspect).join(', ')}.
|
||||
MSG
|
||||
end
|
||||
|
||||
|
@ -706,9 +706,10 @@ def test_lock_does_not_raise_when_the_object_is_not_dirty
|
||||
def test_lock_raises_when_the_record_is_dirty
|
||||
person = Person.find 1
|
||||
person.first_name = "fooman"
|
||||
assert_raises(RuntimeError) do
|
||||
error = assert_raises(RuntimeError) do
|
||||
person.lock!
|
||||
end
|
||||
assert_match(/Changed attributes: "first_name"/, error.message)
|
||||
end
|
||||
|
||||
def test_locking_in_after_save_callback
|
||||
|
Loading…
Reference in New Issue
Block a user