Permalink
Browse files

Merge remote branch 'thieso2/master'

Conflicts:
	lib/after_commit/connection_adapters.rb
  • Loading branch information...
2 parents f2d0f79 + 0fafa25 commit fdef0576ec71a6ea64bea3fd8dadc5f60e25bbfe @jasoncodes jasoncodes committed Apr 28, 2010
Showing with 31 additions and 3 deletions.
  1. +5 −0 init.rb
  2. +3 −2 lib/after_commit/connection_adapters.rb
  3. +23 −1 test/after_commit_test.rb
View
@@ -1 +1,6 @@
require 'after_commit'
+
+# enable TestBypass by default in RAILS_ENV == 'test'
+ActiveRecord::Base.class_eval do
+ include AfterCommit::TestBypass if RAILS_ENV == 'test'
+end
@@ -73,7 +73,7 @@ def old_transaction_key
def trigger_before_commit_callbacks
AfterCommit.records(self).each do |record|
- record.send :callback, :before_commit
+ record.send :callback, :before_commit unless AfterCommit.destroyed_records(self).include? record
end
end
@@ -104,8 +104,9 @@ 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
+ record.send :callback, :after_commit unless AfterCommit.destroyed_records(self).include? record
end
end
View
@@ -4,9 +4,12 @@ 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
@@ -23,6 +26,11 @@ 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
@@ -37,6 +45,11 @@ 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 Foo < ActiveRecord::Base
@@ -128,7 +141,16 @@ def test_after_commit_on_update_is_called
end
def test_after_commit_on_destroy_is_called
- assert_equal true, MockRecord.create!.destroy.after_commit_on_destroy_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
end
def test_after_commit_does_not_trigger_when_transaction_rolls_back

0 comments on commit fdef057

Please sign in to comment.