diff options
author | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-09-09 08:31:54 +0100 |
---|---|---|
committer | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-09-09 08:31:54 +0100 |
commit | edd2f21e8095fe4a38e812025b4d9fd0e0cc28f1 (patch) | |
tree | f5c6e656d2961e727c8de1c6aea846ad9f9c54c3 /activerecord/test | |
parent | ac1a363c6ed889d11e8fabd6dd69a8a6df9e3cfd (diff) | |
download | rails-edd2f21e8095fe4a38e812025b4d9fd0e0cc28f1.tar.gz rails-edd2f21e8095fe4a38e812025b4d9fd0e0cc28f1.tar.bz2 rails-edd2f21e8095fe4a38e812025b4d9fd0e0cc28f1.zip |
Test polymorphic record with optimistic locking and counter cache should be destoyed without catching the ActiveRecord::StaleObjectError.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/locking_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/models/car.rb | 2 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index 61baa55027..a809cd0aa7 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -6,6 +6,9 @@ require 'models/reader' require 'models/legacy_thing' require 'models/reference' require 'models/string_key_object' +require 'models/car' +require 'models/engine' +require 'models/wheel' class LockWithoutDefault < ActiveRecord::Base; end @@ -207,6 +210,15 @@ class OptimisticLockingTest < ActiveRecord::TestCase assert_equal lock_version, p1.lock_version end end + + def test_polymorphic_destroy_with_dependencies_and_lock_version + car = Car.create! + car.wheels << Wheel.create! + assert_equal 1, car.wheels.count + assert car.destroy + assert_equal 0, car.wheels.count + assert car.destroyed? + end end class OptimisticLockingWithSchemaChangeTest < ActiveRecord::TestCase diff --git a/activerecord/test/models/car.rb b/activerecord/test/models/car.rb index b9c2e8ec9a..6ff1329d8e 100644 --- a/activerecord/test/models/car.rb +++ b/activerecord/test/models/car.rb @@ -9,7 +9,7 @@ class Car < ActiveRecord::Base has_many :tyres has_many :engines, :dependent => :destroy - has_many :wheels, :as => :wheelable + has_many :wheels, :as => :wheelable, :dependent => :destroy scope :incl_tyres, includes(:tyres) scope :incl_engines, includes(:engines) diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 64e0452100..4b3afce812 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -105,6 +105,7 @@ ActiveRecord::Schema.define do t.string :name t.integer :engines_count t.integer :wheels_count + t.column :lock_version, :integer, :null => false, :default => 0 end create_table :categories, :force => true do |t| |