Permalink
Browse files

Added test case to verify that transaction callbacks are correctly pr…

…opagated to class observers

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 14be178 commit 141634ddc64c5f69a5351a04cdc90f14c79de9d5 @tobi tobi committed with spastorino Aug 10, 2010
Showing with 41 additions and 0 deletions.
  1. +41 −0 activerecord/test/cases/transaction_callbacks_test.rb
View
41 activerecord/test/cases/transaction_callbacks_test.rb
@@ -245,3 +245,44 @@ def @first.last_after_transaction_error; @last_transaction_error; end
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

0 comments on commit 141634d

Please sign in to comment.