Skip to content

Commit 2cf7426

Browse files
committed
Fix OptimisticLocking tests
1 parent 72416d2 commit 2cf7426

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/cases/coerced_tests.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,3 +1035,26 @@ def test_change_columns_coerced
10351035
assert_nothing_raised { @connection.rename_column(:group, :order, :values) }
10361036
end
10371037
end
1038+
1039+
1040+
1041+
class OptimisticLockingTest < ActiveRecord::TestCase
1042+
# We do not allow updating identities, but we can test using a non-identity key
1043+
coerce_tests! :test_update_with_dirty_primary_key
1044+
def test_update_with_dirty_primary_key_coerced
1045+
assert_raises(ActiveRecord::RecordNotUnique) do
1046+
record = StringKeyObject.find('record1')
1047+
record.id = 'record2'
1048+
record.save!
1049+
end
1050+
1051+
record = StringKeyObject.find('record1')
1052+
record.id = 'record42'
1053+
record.save!
1054+
1055+
assert StringKeyObject.find('record42')
1056+
assert_raises(ActiveRecord::RecordNotFound) do
1057+
StringKeyObject.find('record1')
1058+
end
1059+
end
1060+
end

0 commit comments

Comments
 (0)