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

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

Fix deprecation warnings from with_lock
This commit is contained in:
Rafael França 2017-10-23 13:10:51 -04:00 committed by Rafael Mendonça França
parent fe37da4ebf
commit 3c1a8ee7d7
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
4 changed files with 24 additions and 1 deletions

View file

@ -62,7 +62,7 @@ module ActiveRecord
# the locked record.
def lock!(lock = true)
if persisted?
if changed?
if has_changes_to_save?
raise(<<-MSG.squish)
Locking a record with unpersisted changes is not supported. Use
`save` to persist the changes, or `reload` to discard them

View file

@ -15,6 +15,7 @@ require "models/bulb"
require "models/engine"
require "models/wheel"
require "models/treasure"
require "models/frog"
class LockWithoutDefault < ActiveRecord::Base; end
@ -653,6 +654,16 @@ unless in_memory_db?
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
person = Person.find 1
person.with_lock do

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
class Frog < ActiveRecord::Base
after_save do
with_lock do
end
end
end

View file

@ -347,6 +347,10 @@ ActiveRecord::Schema.define do
t.string :token
end
create_table :frogs, force: true do |t|
t.string :name
end
create_table :funny_jokes, force: true do |t|
t.string :name
end