提交 210729c4 编写于 作者: V Vipul A M

Followup of #15771

Make sure we handle explicitly passed nil's to lock_version as well.
An explicitly passed nil value is now converted to 0 on LockingType,
so that we don't end up with ActiveRecord::StaleObjectError in update record
optimistic locking

Fixes #24695
上级 c9c5788a
......@@ -190,6 +190,10 @@ def deserialize(value)
super.to_i
end
def serialize(value)
super.to_i
end
def init_with(coder)
__setobj__(coder['subtype'])
end
......
......@@ -169,6 +169,12 @@ def test_lock_new_with_nil
assert_equal 1, p1.lock_version
end
def test_lock_new_when_explicitly_passing_nil
p1 = Person.new(:first_name => 'anika', lock_version: nil)
p1.save!
assert_equal 0, p1.lock_version
end
def test_touch_existing_lock
p1 = Person.find(1)
assert_equal 0, p1.lock_version
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册