diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-09-04 00:02:38 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-09-04 00:02:38 +0000 |
commit | 528618a91082748133488fefbf5f57cf8b96ed75 (patch) | |
tree | a560639cb12de229e868d657dea678c33862badf /activerecord/test/locking_test.rb | |
parent | 9b18c1cb5768b0777b16bccdbfc3891a86af4558 (diff) | |
download | rails-528618a91082748133488fefbf5f57cf8b96ed75.tar.gz rails-528618a91082748133488fefbf5f57cf8b96ed75.tar.bz2 rails-528618a91082748133488fefbf5f57cf8b96ed75.zip |
Optimistic locking: gracefully handle nil versions, treat as zero. Closes #5908.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4958 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/locking_test.rb')
-rw-r--r-- | activerecord/test/locking_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb index 00df4bb8e4..80f0dc8496 100644 --- a/activerecord/test/locking_test.rb +++ b/activerecord/test/locking_test.rb @@ -2,6 +2,12 @@ require 'abstract_unit' require 'fixtures/person' require 'fixtures/legacy_thing' +class LockWithoutDefault < ActiveRecord::Base; end + +class LockWithCustomColumnWithoutDefault < ActiveRecord::Base + set_locking_column :custom_lock_version +end + class OptimisticLockingTest < Test::Unit::TestCase fixtures :people, :legacy_things @@ -56,6 +62,16 @@ class OptimisticLockingTest < Test::Unit::TestCase assert_equal 1, p1.lock_version assert_equal p1.lock_version, Person.new(p1.attributes).lock_version end + + def test_lock_without_default_sets_version_to_zero + t1 = LockWithoutDefault.new + assert_equal 0, t1.lock_version + end + + def test_lock_with_custom_column_without_default_sets_version_to_zero + t1 = LockWithCustomColumnWithoutDefault.new + assert_equal 0, t1.custom_lock_version + end end |