aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transaction_callbacks_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2019-04-02 16:36:07 -0700
committerGitHub <noreply@github.com>2019-04-02 16:36:07 -0700
commit59bed68d5e37b994f5e607c3d2b8c5424a0948b9 (patch)
treec1ff0b535dd314d2d509056a4d70ae0ff34c205a /activerecord/test/cases/transaction_callbacks_test.rb
parent798f175c65bbfd95b3fa0dd639ca08ae8485d5d1 (diff)
downloadrails-59bed68d5e37b994f5e607c3d2b8c5424a0948b9.tar.gz
rails-59bed68d5e37b994f5e607c3d2b8c5424a0948b9.tar.bz2
rails-59bed68d5e37b994f5e607c3d2b8c5424a0948b9.zip
Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`. (#35804)
Diffstat (limited to 'activerecord/test/cases/transaction_callbacks_test.rb')
-rw-r--r--activerecord/test/cases/transaction_callbacks_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index aa6b7915a2..e88d20a453 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -38,6 +38,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
before_commit { |record| record.do_before_commit(nil) }
after_commit { |record| record.do_after_commit(nil) }
+ after_save_commit { |record| record.do_after_commit(:save) }
after_create_commit { |record| record.do_after_commit(:create) }
after_update_commit { |record| record.do_after_commit(:update) }
after_destroy_commit { |record| record.do_after_commit(:destroy) }
@@ -110,6 +111,17 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
assert_equal [:after_commit], @first.history
end
+ def test_only_call_after_commit_on_save_after_transaction_commits_for_saving_record
+ record = TopicWithCallbacks.new(title: "New topic", written_on: Date.today)
+ record.after_commit_block(:save) { |r| r.history << :after_save }
+
+ record.save!
+ assert_equal [:after_save], record.history
+
+ record.update!(title: "Another topic")
+ assert_equal [:after_save, :after_save], record.history
+ end
+
def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record
add_transaction_execution_blocks @first