diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-02-21 14:54:17 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-02-21 15:02:52 +0100 |
commit | d98763a602ecffa1d375fa974d7c5de8b1145358 (patch) | |
tree | 9496be3ba3800210590d58c2d7e42c853421368b /activerecord/test | |
parent | b0fa9b59c8c9cac52d4eb4d8d984b85d4a753e97 (diff) | |
download | rails-d98763a602ecffa1d375fa974d7c5de8b1145358.tar.gz rails-d98763a602ecffa1d375fa974d7c5de8b1145358.tar.bz2 rails-d98763a602ecffa1d375fa974d7c5de8b1145358.zip |
multiple actions for :on option with `after_commit` and `after_rollback`
Closes #988.
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 |