未验证 提交 7b1ee9f5 编写于 作者: B bogdanvlviv

Add test cases for optimistic locking

Add test to ensure that locking_column cannot be updated explicitly.

Add test to prevent regression on creating new object with
explicit value locking_column.

Related to #28318
上级 42a80721
......@@ -167,6 +167,12 @@ def test_lock_new_when_explicitly_passing_nil
assert_equal 0, p1.lock_version
end
def test_lock_new_when_explicitly_passing_value
p1 = Person.new(first_name: "Douglas Adams", lock_version: 42)
p1.save!
assert_equal 42, p1.lock_version
end
def test_touch_existing_lock
p1 = Person.find(1)
assert_equal 0, p1.lock_version
......@@ -186,6 +192,19 @@ def test_touch_stale_object
end
end
def test_explicit_update_lock_column_raise_error
person = Person.find(1)
assert_raises(ActiveRecord::StaleObjectError) do
person.first_name = "Douglas Adams"
person.lock_version = 42
assert person.lock_version_changed?
person.save
end
end
def test_lock_column_name_existing
t1 = LegacyThing.find(1)
t2 = LegacyThing.find(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册