diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/fixtures/db_definitions/schema.rb | 8 | ||||
-rw-r--r-- | activerecord/test/locking_test.rb | 16 |
2 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb index e06c14b6ae..6f4aca971e 100644 --- a/activerecord/test/fixtures/db_definitions/schema.rb +++ b/activerecord/test/fixtures/db_definitions/schema.rb @@ -49,4 +49,12 @@ ActiveRecord::Schema.define do t.column :sink_id, :integer, :null => false end add_index :edges, [:source_id, :sink_id], :unique => true, :name => 'unique_edge_index' + + create_table :lock_without_defaults, :force => true do |t| + t.column :lock_version, :integer + end + + create_table :lock_with_custom_column_without_defaults, :force => true do |t| + t.column :custom_lock_version, :integer + end end 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 |