Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'walleyemi/master'

  • Loading branch information...
commit 6cbed09e112a67b12b0381f91c656b67ad1fb456 2 parents 349d8ce + 76ff89c
@pat authored
View
42 lib/after_commit/after_savepoint.rb
@@ -34,9 +34,23 @@ def include_after_savepoint_extension(adapter)
module TestConnectionAdapters
def self.included(base)
base.class_eval do
+
+ def after_callback_transaction_committed?
+ committed = (Thread.current[:after_callback_committed] || {})[unique_transaction_key]
+ return !committed.nil? && committed
+ end
+
+ def after_callback_mark_committed committed
+ (Thread.current[:after_callback_committed] ||= {})[unique_transaction_key] = committed
+ end
+
+ def after_callback_cleanup_committed
+ (Thread.current[:after_callback_committed] ||= {})[unique_transaction_key] = nil
+ end
+
def release_savepoint_with_callback
increment_transaction_pointer
- committed = false
+ after_callback_mark_committed false
begin
trigger_before_commit_callbacks
trigger_before_commit_on_create_callbacks
@@ -45,21 +59,15 @@ def release_savepoint_with_callback
trigger_before_commit_on_destroy_callbacks
release_savepoint_without_callback
- committed = true
-
+ after_callback_mark_committed true
trigger_after_commit_callbacks
trigger_after_commit_on_create_callbacks
trigger_after_commit_on_save_callbacks
trigger_after_commit_on_update_callbacks
trigger_after_commit_on_destroy_callbacks
- rescue Exception => e
- unless committed
- decrement_transaction_pointer
- rollback_to_savepoint
- increment_transaction_pointer
- end
- ensure
AfterCommit.cleanup(self)
+ after_callback_cleanup_committed
+ ensure
decrement_transaction_pointer
end
end
@@ -71,13 +79,17 @@ def release_savepoint_with_callback
def rollback_to_savepoint_with_callback
increment_transaction_pointer
begin
- trigger_before_rollback_callbacks
- rollback_to_savepoint_without_callback
- trigger_after_rollback_callbacks
+ # Only rollback if we have not already released rollback
+ unless after_callback_transaction_committed?
+ trigger_before_rollback_callbacks
+ rollback_to_savepoint_without_callback
+ trigger_after_rollback_callbacks
+ end
ensure
AfterCommit.cleanup(self)
- end
- decrement_transaction_pointer
+ after_callback_cleanup_committed
+ decrement_transaction_pointer
+ end
end
alias_method_chain :rollback_to_savepoint, :callback
end
View
1  lib/after_commit/connection_adapters.rb
@@ -183,6 +183,7 @@ def decrement_transaction_pointer
Thread.current[:after_commit_pointer] ||= 0
Thread.current[:after_commit_pointer] -= 1
end
+
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.