diff options
author | Arthur Nogueira Neves <arthurnn@gmail.com> | 2015-02-24 19:25:11 -0500 |
---|---|---|
committer | Arthur Nogueira Neves <arthurnn@gmail.com> | 2015-02-24 19:25:11 -0500 |
commit | 27ce16aa9b348f32d866a697e1dd6cb061ce0ed2 (patch) | |
tree | b0676474e5a8018f31233de49a6415dd61edfadf /activerecord/test/cases/transaction_callbacks_test.rb | |
parent | f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4 (diff) | |
parent | 45755135fe9669d1ba3c8567c517559a6a291304 (diff) | |
download | rails-27ce16aa9b348f32d866a697e1dd6cb061ce0ed2.tar.gz rails-27ce16aa9b348f32d866a697e1dd6cb061ce0ed2.tar.bz2 rails-27ce16aa9b348f32d866a697e1dd6cb061ce0ed2.zip |
Merge pull request #18936 from arthurnn/txn_callbacks
Spike on new transaction callbacks
Diffstat (limited to 'activerecord/test/cases/transaction_callbacks_test.rb')
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index f185cda263..e868022fed 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -400,3 +400,63 @@ class CallbacksOnMultipleActionsTest < ActiveRecord::TestCase assert_equal [:update_and_destroy, :create_and_destroy], topic.history end end + + +class TransactionEnrollmentCallbacksTest < ActiveRecord::TestCase + + class TopicWithoutTransactionalEnrollmentCallbacks < ActiveRecord::Base + self.table_name = :topics + + before_commit_without_transaction_enrollment { |r| r.history << :before_commit } + after_commit_without_transaction_enrollment { |r| r.history << :after_commit } + after_rollback_without_transaction_enrollment { |r| r.history << :rollback } + + def history + @history ||= [] + end + end + + def setup + @topic = TopicWithoutTransactionalEnrollmentCallbacks.create! + end + + def test_commit_does_not_run_transactions_callbacks_without_enrollment + @topic.transaction do + @topic.content = 'foo' + @topic.save! + end + assert @topic.history.empty? + end + + def test_commit_run_transactions_callbacks_with_explicit_enrollment + @topic.transaction do + 2.times do + @topic.content = 'foo' + @topic.save! + end + @topic.class.connection.add_transaction_record(@topic) + end + assert_equal [:before_commit, :after_commit], @topic.history + end + + def test_rollback_does_not_run_transactions_callbacks_without_enrollment + @topic.transaction do + @topic.content = 'foo' + @topic.save! + raise ActiveRecord::Rollback + end + assert @topic.history.empty? + end + + def test_rollback_run_transactions_callbacks_with_explicit_enrollment + @topic.transaction do + 2.times do + @topic.content = 'foo' + @topic.save! + end + @topic.class.connection.add_transaction_record(@topic) + raise ActiveRecord::Rollback + end + assert_equal [:rollback], @topic.history + end +end |