Permalink
Browse files

Test polymorphic record with optimistic locking and counter cache sho…

…uld be destoyed without catching the ActiveRecord::StaleObjectError.
  • Loading branch information...
dmitry committed Sep 9, 2011
1 parent ac1a363 commit edd2f21e8095fe4a38e812025b4d9fd0e0cc28f1
Showing with 14 additions and 1 deletion.
  1. +12 −0 activerecord/test/cases/locking_test.rb
  2. +1 −1 activerecord/test/models/car.rb
  3. +1 −0 activerecord/test/schema/schema.rb
@@ -6,6 +6,9 @@
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 @@ def test_update_without_attributes_does_not_only_update_lock_version
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
@@ -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)
@@ -105,6 +105,7 @@ def create_table(*args, &block)
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|

0 comments on commit edd2f21

Please sign in to comment.