diff options
author | Tobias Lütke <tobi@jadedpixel.com> | 2010-08-09 21:33:02 -0400 |
---|---|---|
committer | Tobias Lütke <tobi@jadedpixel.com> | 2010-08-09 21:36:06 -0400 |
commit | cb9295c8a1c97f07a7a41af420831794fe9c1b35 (patch) | |
tree | deb6ac91a67973618b6fc2b9b057fa58945bff04 | |
parent | a5d401aa998c085670fb94387304cc4e1b098412 (diff) | |
download | rails-cb9295c8a1c97f07a7a41af420831794fe9c1b35.tar.gz rails-cb9295c8a1c97f07a7a41af420831794fe9c1b35.tar.bz2 rails-cb9295c8a1c97f07a7a41af420831794fe9c1b35.zip |
Added test case to verify that transaction callbacks are correctly propagated to class observers
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index ffc2cd638f..d72c4bf7c4 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -245,3 +245,44 @@ class TransactionCallbacksTest < ActiveRecord::TestCase assert_equal [:after_rollback], @second.history end end + + +class TransactionObserverCallbacksTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + fixtures :topics + + class TopicWithObserverAttached < ActiveRecord::Base + set_table_name :topics + def history + @history ||= [] + end + end + + class TopicWithObserverAttachedObserver < ActiveRecord::Observer + def after_commit(record) + record.history.push :"TopicWithObserverAttachedObserver#after_commit" + end + + def after_rollback(record) + record.history.push :"TopicWithObserverAttachedObserver#after_rollback" + end + end + + def test_after_commit_called + topic = TopicWithObserverAttached.new + topic.save! + + assert topic.history, [:"TopicWithObserverAttachedObserver#after_commit"] + end + + def test_after_rollback_called + topic = TopicWithObserverAttached.new + + Topic.transaction do + topic.save! + raise ActiveRecord::Rollback + end + + assert topic.history, [:"TopicWithObserverObserver#after_rollback"] + end +end |