Permalink
Browse files

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

…opagated to class observers
  • Loading branch information...
1 parent a5d401a commit cb9295c8a1c97f07a7a41af420831794fe9c1b35 @tobi tobi committed Aug 10, 2010
Showing with 41 additions and 0 deletions.
  1. +41 −0 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 cb9295c

Please sign in to comment.