diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-03 08:18:52 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-03 08:36:49 +0900 |
commit | fa31a06de58af6822080ebb69775340fd6219e8d (patch) | |
tree | d3e9d1e0ad9ba3aace81a39a25d08e87f2141d91 /activerecord | |
parent | 32aa7cdd8f031dc756fdde3501efca7ff72bf576 (diff) | |
download | rails-fa31a06de58af6822080ebb69775340fd6219e8d.tar.gz rails-fa31a06de58af6822080ebb69775340fd6219e8d.tar.bz2 rails-fa31a06de58af6822080ebb69775340fd6219e8d.zip |
`record.destroy` on new record won't invoke after create commit callbacks
Fixes #32806.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 82adb19f5b..e5397401fd 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -431,7 +431,7 @@ module ActiveRecord actions.any? do |action| case action when :create - transaction_record_state(:new_record) + persisted? && transaction_record_state(:new_record) when :destroy defined?(@_trigger_destroy_callback) && @_trigger_destroy_callback when :update diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index 05941c75ac..7c87030801 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -139,6 +139,14 @@ class TransactionCallbacksTest < ActiveRecord::TestCase assert_equal [], reply.history end + def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_new_record + new_record = TopicWithCallbacks.new(title: "New topic", written_on: Date.today) + add_transaction_execution_blocks new_record + + new_record.destroy + assert_equal [:commit_on_destroy], new_record.history + end + def test_only_call_after_commit_on_create_and_doesnt_leaky r = ReplyWithCallbacks.new(content: "foo") r.save_on_after_create = true |