diff options
author | Steve Klabnik <steve@steveklabnik.com> | 2013-02-24 08:30:48 -0800 |
---|---|---|
committer | Steve Klabnik <steve@steveklabnik.com> | 2013-02-24 08:30:48 -0800 |
commit | c3d001b04854d4592d2a16aeddf1b9be006b58a8 (patch) | |
tree | 96ac74e06a870ed4fb3bde573f482556f1826869 /activerecord/test | |
parent | 83a9efb8292dcea15defc5c913b66e2c456937c0 (diff) | |
parent | d98763a602ecffa1d375fa974d7c5de8b1145358 (diff) | |
download | rails-c3d001b04854d4592d2a16aeddf1b9be006b58a8.tar.gz rails-c3d001b04854d4592d2a16aeddf1b9be006b58a8.tar.bz2 rails-c3d001b04854d4592d2a16aeddf1b9be006b58a8.zip |
Merge pull request #9356 from senny/988_multiple_actions_for_after_commit
multiple actions for :on option with `after_commit` and `after_rollback`
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index fd5651b4e0..eb4ffd4498 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -312,3 +312,38 @@ class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase assert_equal true, topic.record_updated end end + +class CallbacksOnMultipleActionsTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + class TopicWithCallbacksOnMultipleActions < ActiveRecord::Base + self.table_name = :topics + + after_commit(on: [:create, :destroy]) { |record| record.history << :create_and_destroy } + after_commit(on: [:create, :update]) { |record| record.history << :create_and_update } + after_commit(on: [:update, :destroy]) { |record| record.history << :update_and_destroy } + + def clear_history + @history = [] + end + + def history + @history ||= [] + end + end + + def test_after_commit_on_multiple_actions + topic = TopicWithCallbacksOnMultipleActions.new + topic.save + assert_equal [:create_and_update, :create_and_destroy], topic.history + + topic.clear_history + topic.approved = true + topic.save + assert_equal [:update_and_destroy, :create_and_update], topic.history + + topic.clear_history + topic.destroy + assert_equal [:update_and_destroy, :create_and_destroy], topic.history + end +end |