mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
fisting after_rollback and after commit callbacks
This commit is contained in:
@@ -235,7 +235,7 @@ module ActiveRecord
|
||||
:after_initialize, :after_find, :after_touch, :before_validation, :after_validation,
|
||||
:before_save, :around_save, :after_save, :before_create, :around_create,
|
||||
:after_create, :before_update, :around_update, :after_update,
|
||||
:before_destroy, :around_destroy, :after_destroy
|
||||
:before_destroy, :around_destroy, :after_destroy, :after_commit, :after_rollback
|
||||
]
|
||||
|
||||
included do
|
||||
|
||||
@@ -461,7 +461,12 @@ class CallbacksTest < ActiveRecord::TestCase
|
||||
[ :before_validation, :proc ],
|
||||
[ :before_validation, :object ],
|
||||
[ :before_validation, :block ],
|
||||
[ :before_validation, :returning_false ]
|
||||
[ :before_validation, :returning_false ],
|
||||
[ :after_rollback, :block ],
|
||||
[ :after_rollback, :object ],
|
||||
[ :after_rollback, :proc ],
|
||||
[ :after_rollback, :string ],
|
||||
[ :after_rollback, :method ],
|
||||
], david.history
|
||||
end
|
||||
|
||||
|
||||
@@ -260,22 +260,26 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase
|
||||
|
||||
class TopicWithObserverAttachedObserver < ActiveRecord::Observer
|
||||
def after_commit(record)
|
||||
record.history.push :"TopicWithObserverAttachedObserver#after_commit"
|
||||
record.history.push "after_commit"
|
||||
end
|
||||
|
||||
def after_rollback(record)
|
||||
record.history.push :"TopicWithObserverAttachedObserver#after_rollback"
|
||||
record.history.push "after_rollback"
|
||||
end
|
||||
end
|
||||
|
||||
def test_after_commit_called
|
||||
assert TopicWithObserverAttachedObserver.instance, 'should have observer'
|
||||
|
||||
topic = TopicWithObserverAttached.new
|
||||
topic.save!
|
||||
|
||||
assert_equal topic.history, [:"TopicWithObserverAttachedObserver#after_commit"]
|
||||
assert_equal %w{ after_commit }, topic.history
|
||||
end
|
||||
|
||||
def test_after_rollback_called
|
||||
assert TopicWithObserverAttachedObserver.instance, 'should have observer'
|
||||
|
||||
topic = TopicWithObserverAttached.new
|
||||
|
||||
Topic.transaction do
|
||||
@@ -283,6 +287,6 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
assert_equal topic.history, [:"TopicWithObserverObserver#after_rollback"]
|
||||
assert_equal %w{ after_rollback }, topic.history
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user