未验证 提交 3c1a8ee7 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

Merge pull request #30956 from CJStadler/with-lock-changed-deprecation

Fix deprecation warnings from with_lock
上级 fe37da4e
...@@ -62,7 +62,7 @@ module Pessimistic ...@@ -62,7 +62,7 @@ module Pessimistic
# the locked record. # the locked record.
def lock!(lock = true) def lock!(lock = true)
if persisted? if persisted?
if changed? if has_changes_to_save?
raise(<<-MSG.squish) raise(<<-MSG.squish)
Locking a record with unpersisted changes is not supported. Use Locking a record with unpersisted changes is not supported. Use
`save` to persist the changes, or `reload` to discard them `save` to persist the changes, or `reload` to discard them
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
require "models/engine" require "models/engine"
require "models/wheel" require "models/wheel"
require "models/treasure" require "models/treasure"
require "models/frog"
class LockWithoutDefault < ActiveRecord::Base; end class LockWithoutDefault < ActiveRecord::Base; end
...@@ -653,6 +654,16 @@ def test_lock_raises_when_the_record_is_dirty ...@@ -653,6 +654,16 @@ def test_lock_raises_when_the_record_is_dirty
end end
end end
def test_locking_in_after_save_callback
assert_nothing_raised do
frog = ::Frog.create(name: "Old Frog")
frog.name = "New Frog"
assert_not_deprecated do
frog.save!
end
end
end
def test_with_lock_commits_transaction def test_with_lock_commits_transaction
person = Person.find 1 person = Person.find 1
person.with_lock do person.with_lock do
......
# frozen_string_literal: true
class Frog < ActiveRecord::Base
after_save do
with_lock do
end
end
end
...@@ -347,6 +347,10 @@ ...@@ -347,6 +347,10 @@
t.string :token t.string :token
end end
create_table :frogs, force: true do |t|
t.string :name
end
create_table :funny_jokes, force: true do |t| create_table :funny_jokes, force: true do |t|
t.string :name t.string :name
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册