Navigation Menu

Skip to content

Commit

Permalink
Fixes transaction callbacks tests
Browse files Browse the repository at this point in the history
[#4640 state:committed]

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information
spastorino authored and wycats committed May 18, 2010
1 parent b439d85 commit 03c3d1e
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions activerecord/test/cases/transaction_callbacks_test.rb
Expand Up @@ -58,26 +58,24 @@ def test_call_after_commit_after_transaction_commits
end

def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record
commit_callback = []
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
@first.after_commit_block(:create){|r| r.history << :rollback_on_create}
@first.after_commit_block(:update){|r| r.history << :rollback_on_update}
@first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}

@first.save!
assert_equal [:commit_on_update], @first.history
end

def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_record
commit_callback = []
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
@first.after_commit_block(:create){|r| r.history << :rollback_on_create}
@first.after_commit_block(:update){|r| r.history << :rollback_on_update}
@first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}

@first.destroy
assert_equal [:commit_on_destroy], @first.history
Expand All @@ -88,9 +86,9 @@ def test_only_call_after_commit_on_create_after_transaction_commits_for_new_reco
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
@new_record.after_commit_block(:create){|r| r.history << :rollback_on_create}
@new_record.after_commit_block(:update){|r| r.history << :rollback_on_update}
@new_record.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}

@new_record.save!
assert_equal [:commit_on_create], @new_record.history
Expand All @@ -109,13 +107,12 @@ def test_call_after_rollback_after_transaction_rollsback
end

def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_existing_record
commit_callback = []
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
@first.after_commit_block(:create){|r| r.history << :rollback_on_create}
@first.after_commit_block(:update){|r| r.history << :rollback_on_update}
@first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}

Topic.transaction do
@first.save!
Expand All @@ -126,13 +123,12 @@ def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_exis
end

def test_only_call_after_rollback_on_destroy_after_transaction_rollsback_for_destroyed_record
commit_callback = []
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
@first.after_commit_block(:destroy){|r| r.history << :commit_on_update}
@first.after_commit_block(:create){|r| r.history << :rollback_on_create}
@first.after_commit_block(:update){|r| r.history << :rollback_on_update}
@first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}

Topic.transaction do
@first.destroy
Expand All @@ -147,9 +143,9 @@ def test_only_call_after_rollback_on_create_after_transaction_rollsback_for_new_
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
@new_record.after_commit_block(:create){|r| r.history << :rollback_on_create}
@new_record.after_commit_block(:update){|r| r.history << :rollback_on_update}
@new_record.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}

Topic.transaction do
@new_record.save!
Expand Down Expand Up @@ -198,7 +194,7 @@ def @second.commits(i=0); @commits ||= 0; @commits += i if i; end

assert_equal 1, @first.commits
assert_equal 0, @first.rollbacks
assert_equal 1, @second.commits
assert_equal 0, @second.commits
assert_equal 1, @second.rollbacks
end

Expand Down

0 comments on commit 03c3d1e

Please sign in to comment.