Skip to content
Browse files

Revert "Do not call before_commit and after_commit for records that w…

…ere destroyed in the transaction. You can now use after_commit as an equivalent for after_save."

This reverts commit a9d6023.

Conflicts:

	lib/after_commit/connection_adapters.rb
  • Loading branch information...
1 parent 60b18cd commit c0284ba2fd7c3a3daee5b5ec85c3bdbcc865d0d6 @jasoncodes jasoncodes committed
Showing with 3 additions and 26 deletions.
  1. +2 −3 lib/after_commit/connection_adapters.rb
  2. +1 −23 test/after_commit_test.rb
View
5 lib/after_commit/connection_adapters.rb
@@ -75,7 +75,7 @@ def old_transaction_key
def trigger_before_commit_callbacks
AfterCommit.records(self).each do |record|
- record.send :callback, :before_commit unless AfterCommit.destroyed_records(self).include? record
+ record.send :callback, :before_commit
end
end
@@ -106,9 +106,8 @@ def trigger_before_rollback_callbacks
def trigger_after_commit_callbacks
# Trigger the after_commit callback for each of the committed
# records.
-
AfterCommit.records(self).each do |record|
- record.send :callback, :after_commit unless AfterCommit.destroyed_records(self).include? record
+ record.send :callback, :after_commit
end
end
View
24 test/after_commit_test.rb
@@ -4,12 +4,9 @@ class MockRecord < ActiveRecord::Base
attr_accessor :before_commit_on_create_called
attr_accessor :before_commit_on_update_called
attr_accessor :before_commit_on_destroy_called
- attr_accessor :before_commit_called
attr_accessor :after_commit_on_create_called
attr_accessor :after_commit_on_update_called
attr_accessor :after_commit_on_destroy_called
- attr_accessor :after_commit_called
-
before_commit_on_create :do_before_create
def do_before_create
@@ -26,11 +23,6 @@ def do_before_destroy
self.before_commit_on_destroy_called = true
end
- before_commit :do_before_commit
- def do_before_commit
- self.before_commit_called = true
- end
-
after_commit_on_create :do_after_create
def do_after_create
self.after_commit_on_create_called = true
@@ -45,11 +37,6 @@ def do_after_update
def do_after_destroy
self.after_commit_on_destroy_called = true
end
-
- after_commit :do_after_commit
- def do_after_commit
- self.after_commit_called = true
- end
end
class CountingRecord < ActiveRecord::Base
@@ -152,16 +139,7 @@ def test_after_commit_on_update_is_called
end
def test_after_commit_on_destroy_is_called
- record = MockRecord.create!
-
- # reset states set by create!
- record.before_commit_called = false
- record.after_commit_called = false
- record.destroy
-
- assert_equal true, record.after_commit_on_destroy_called
- assert_equal false, record.after_commit_called
- assert_equal false, record.before_commit_called
+ assert_equal true, MockRecord.create!.destroy.after_commit_on_destroy_called
end
def test_after_commit_does_not_trigger_when_transaction_rolls_back

0 comments on commit c0284ba

Please sign in to comment.
Something went wrong with that request. Please try again.