diff options
author | Hongli Lai (Phusion) <hongli@phusion.nl> | 2008-10-09 17:57:49 +0200 |
---|---|---|
committer | Hongli Lai (Phusion) <hongli@phusion.nl> | 2008-11-03 20:56:28 +0100 |
commit | fb2325e35855d62abd2c76ce03feaa3ca7992e4f (patch) | |
tree | 4864fc83385f6329441b950a83f807a97f59b1e3 /activerecord/test/cases | |
parent | e916aa7ea1613be966959c05ad41d13fee55a683 (diff) | |
download | rails-fb2325e35855d62abd2c76ce03feaa3ca7992e4f.tar.gz rails-fb2325e35855d62abd2c76ce03feaa3ca7992e4f.tar.bz2 rails-fb2325e35855d62abd2c76ce03feaa3ca7992e4f.zip |
Reimplement Jeremy's PostgreSQL automatic transaction state introspection code.
- Fixed compatibility with the old 'postgres' driver which doesn't support
transaction state introspection.
- Added unit tests for it.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 069ba9d6c5..0c69fee8f2 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -310,6 +310,7 @@ class TransactionTest < ActiveRecord::TestCase def test_rollback_when_commit_raises Topic.connection.expects(:begin_db_transaction) Topic.connection.expects(:commit_db_transaction).raises('OH NOES') + Topic.connection.expects(:outside_transaction?).returns(false) Topic.connection.expects(:rollback_db_transaction) assert_raise RuntimeError do @@ -319,6 +320,39 @@ class TransactionTest < ActiveRecord::TestCase end end end + + if current_adapter?(:PostgreSQLAdapter) && PGconn.public_method_defined?(:transaction_status) + def test_outside_transaction_works + Topic.logger.info("-------------") + assert Topic.connection.outside_transaction? + Topic.connection.begin_db_transaction + assert !Topic.connection.outside_transaction? + Topic.connection.rollback_db_transaction + assert Topic.connection.outside_transaction? + end + + uses_mocha 'mocking connection.rollback_db_transaction' do + def test_rollback_wont_be_executed_if_no_transaction_active + assert_raise RuntimeError do + Topic.transaction do + Topic.connection.rollback_db_transaction + Topic.connection.expects(:rollback_db_transaction).never + raise "Rails doesn't scale!" + end + end + end + end + + def test_open_transactions_count_is_reset_to_zero_if_no_transaction_active + Topic.transaction do + Topic.transaction do + Topic.connection.rollback_db_transaction + end + assert_equal 0, Topic.connection.open_transactions + end + assert_equal 0, Topic.connection.open_transactions + end + end def test_sqlite_add_column_in_transaction_raises_statement_invalid return true unless current_adapter?(:SQLite3Adapter, :SQLiteAdapter) |