aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/locking_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-07-19 15:50:12 -0600
committerSean Griffin <sean@thoughtbot.com>2015-07-19 15:52:31 -0600
commit8cd1d5a41cf54f0dfde2b2d0d406457a6a58dbeb (patch)
treef6d73b4779bed275d29f91c2301047534e122fb6 /activerecord/test/cases/locking_test.rb
parent0ed096ddf5416fefa3afacb72c64632c02826f95 (diff)
downloadrails-8cd1d5a41cf54f0dfde2b2d0d406457a6a58dbeb.tar.gz
rails-8cd1d5a41cf54f0dfde2b2d0d406457a6a58dbeb.tar.bz2
rails-8cd1d5a41cf54f0dfde2b2d0d406457a6a58dbeb.zip
Fix the test that was broken by #16445 rather than deleting it
Since the counter cache was properly being updated, the model became stale. Simply reloading the model before attempting to destroy is sufficient for this case. I believe this is enough of an edge case to be a valid change to the tests, even though it represents a potential breaking change.
Diffstat (limited to 'activerecord/test/cases/locking_test.rb')
-rw-r--r--activerecord/test/cases/locking_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index 839bbea5bb..2e1363334d 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -263,6 +263,18 @@ class OptimisticLockingTest < ActiveRecord::TestCase
end
end
+ def test_polymorphic_destroy_with_dependencies_and_lock_version
+ car = Car.create!
+
+ assert_difference 'car.wheels.count' do
+ car.wheels << Wheel.create!
+ end
+ assert_difference 'car.wheels.count', -1 do
+ car.reload.destroy
+ end
+ assert car.destroyed?
+ end
+
def test_removing_has_and_belongs_to_many_associations_upon_destroy
p = RichPerson.create! first_name: 'Jon'
p.treasures.create!