aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-03-05 04:14:51 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-03-06 02:03:31 +0900
commit263f01d93da118dc150c6ac816e70dcf10de2608 (patch)
tree71442d6fa769733252a0c76ff7da20234c20bd04 /activerecord/test
parentccac681122db9747fec9512076772bca345e24b9 (diff)
downloadrails-263f01d93da118dc150c6ac816e70dcf10de2608.tar.gz
rails-263f01d93da118dc150c6ac816e70dcf10de2608.tar.bz2
rails-263f01d93da118dc150c6ac816e70dcf10de2608.zip
Fix that after commit callbacks on update does not triggered when optimistic locking is enabled
This issue is caused by `@_trigger_update_callback` won't be updated due to `_update_record` in `Locking::Optimistic` doesn't call `super` when optimistic locking is enabled. Now optimistic locking concern when updating is supported by `_update_row` low level API, therefore overriding `_update_record` is no longer necessary. Removing the method just fix the issue. Closes #29096. Closes #29321. Closes #30823.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/transaction_callbacks_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index 1c7cec4dad..e89ac53732 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -394,6 +394,28 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
end
end
+class TransactionAfterCommitCallbacksWithOptimisticLockingTest < ActiveRecord::TestCase
+ class PersonWithCallbacks < ActiveRecord::Base
+ self.table_name = :people
+
+ after_create_commit { |record| record.history << :commit_on_create }
+ after_update_commit { |record| record.history << :commit_on_update }
+ after_destroy_commit { |record| record.history << :commit_on_destroy }
+
+ def history
+ @history ||= []
+ end
+ end
+
+ def test_after_commit_callbacks_with_optimistic_locking
+ person = PersonWithCallbacks.create!(first_name: "first name")
+ person.update!(first_name: "another name")
+ person.destroy
+
+ assert_equal [:commit_on_create, :commit_on_update, :commit_on_destroy], person.history
+ end
+end
+
class CallbacksOnMultipleActionsTest < ActiveRecord::TestCase
self.use_transactional_tests = false