1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use assert_equal correctly in transaction callback tests (exposing some of them as broken)

[#4612]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Paco Guzman 2010-05-17 08:19:48 +02:00 committed by Jeremy Kemper
parent a06e9b4602
commit c2fb8afaa0

View file

@ -54,7 +54,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
@first.after_rollback_block{|r| r.history << :after_rollback} @first.after_rollback_block{|r| r.history << :after_rollback}
@first.save! @first.save!
assert @first.history, [:after_commit] assert_equal [:after_commit], @first.history
end end
def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record
@ -67,7 +67,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
@first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy} @first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@first.save! @first.save!
assert @first.history, [:commit_on_update] assert_equal [:commit_on_update], @first.history
end end
def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_record def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_record
@ -80,7 +80,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
@first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy} @first.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@first.destroy @first.destroy
assert @first.history, [:commit_on_destroy] assert_equal [:commit_on_destroy], @first.history
end end
def test_only_call_after_commit_on_create_after_transaction_commits_for_new_record def test_only_call_after_commit_on_create_after_transaction_commits_for_new_record
@ -93,7 +93,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
@new_record.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy} @new_record.after_commit_block(:destroy){|r| r.history << :rollback_on_destroy}
@new_record.save! @new_record.save!
assert @new_record.history, [:commit_on_create] assert_equal [:commit_on_create], @new_record.history
end end
def test_call_after_rollback_after_transaction_rollsback def test_call_after_rollback_after_transaction_rollsback
@ -105,7 +105,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
assert @first.history, [:after_rollback] assert_equal [:after_rollback], @first.history
end end
def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_existing_record def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_existing_record
@ -122,7 +122,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
assert @first.history, [:rollback_on_update] assert_equal [:rollback_on_update], @first.history
end end
def test_only_call_after_rollback_on_destroy_after_transaction_rollsback_for_destroyed_record def test_only_call_after_rollback_on_destroy_after_transaction_rollsback_for_destroyed_record
@ -139,7 +139,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
assert @first.history, [:rollback_on_destroy] assert_equal [:rollback_on_destroy], @first.history
end end
def test_only_call_after_rollback_on_create_after_transaction_rollsback_for_new_record def test_only_call_after_rollback_on_create_after_transaction_rollsback_for_new_record
@ -156,7 +156,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
assert @new_record.history, [:rollback_on_create] assert_equal [:rollback_on_create], @new_record.history
end end
def test_call_after_rollback_when_commit_fails def test_call_after_rollback_when_commit_fails
@ -170,7 +170,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
@first.after_rollback_block{|r| r.history << :after_rollback} @first.after_rollback_block{|r| r.history << :after_rollback}
assert !@first.save rescue nil assert !@first.save rescue nil
assert @first.history == [:after_rollback] assert_equal [:after_rollback], @first.history
ensure ensure
@first.connection.class.send(:remove_method, :commit_db_transaction) @first.connection.class.send(:remove_method, :commit_db_transaction)
@first.connection.class.send(:alias_method, :commit_db_transaction, :real_method_commit_db_transaction) @first.connection.class.send(:alias_method, :commit_db_transaction, :real_method_commit_db_transaction)
@ -196,10 +196,10 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
end end
end end
assert 1, @first.commits assert_equal 1, @first.commits
assert 0, @first.rollbacks assert_equal 0, @first.rollbacks
assert 1, @second.commits assert_equal 1, @second.commits
assert 1, @second.rollbacks assert_equal 1, @second.rollbacks
end end
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint_when_release_savepoint_fails def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint_when_release_savepoint_fails
@ -221,8 +221,8 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
end end
end end
assert 1, @first.commits assert_equal 1, @first.commits
assert 2, @first.rollbacks assert_equal 2, @first.rollbacks
end end
def test_after_transaction_callbacks_should_not_raise_errors def test_after_transaction_callbacks_should_not_raise_errors
@ -232,13 +232,13 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
@first.after_rollback_block{|r| r.last_after_transaction_error = :rollback; raise "fail!";} @first.after_rollback_block{|r| r.last_after_transaction_error = :rollback; raise "fail!";}
@first.save! @first.save!
assert_equal @first.last_after_transaction_error, :commit assert_equal :commit, @first.last_after_transaction_error
Topic.transaction do Topic.transaction do
@first.save! @first.save!
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
assert_equal @first.last_after_transaction_error, :rollback assert_equal :rollback, @first.last_after_transaction_error
end end
end end