Permalink
Browse files

Fix PostgreSQL unit test failures that only occur when using the old …

…'postgres' driver.

[#1748 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent b281a6a commit 9bcf01b23c25e640da7908ac8b1b49fbf7d2e51a @FooBarWidget FooBarWidget committed with jeremy Jan 13, 2009
@@ -89,7 +89,7 @@ def outside_transaction?
# - The block will be run without doing anything. All database statements
# that happen within the block are effectively appended to the already
# open database transaction.
- # - However, if +requires_new+ is set, the block will be wrapped in a
+ # - However, if +:requires_new+ is set, the block will be wrapped in a
# database savepoint acting as a sub-transaction.
#
# === Caveats
@@ -113,8 +113,12 @@ def outside_transaction?
def transaction(options = {})
options.assert_valid_keys :requires_new, :joinable
- last_transaction_joinable, @transaction_joinable =
- @transaction_joinable, options[:joinable] || true
+ last_transaction_joinable = @transaction_joinable
+ if options.has_key?(:joinable)
+ @transaction_joinable = options[:joinable]
+ else
+ @transaction_joinable = true
+ end
requires_new = options[:requires_new] || !last_transaction_joinable
transaction_open = false
@@ -141,7 +145,7 @@ def transaction(options = {})
rollback_to_savepoint
end
end
- raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback
+ raise unless database_transaction_rollback.is_a?(ActiveRecord::Rollback)
end
ensure
@transaction_joinable = last_transaction_joinable
@@ -533,13 +533,11 @@ def rollback_db_transaction
execute "ROLLBACK"
end
- if PGconn.public_method_defined?(:transaction_status)
- # ruby-pg defines Ruby constants for transaction status,
- # ruby-postgres does not.
- PQTRANS_IDLE = defined?(PGconn::PQTRANS_IDLE) ? PGconn::PQTRANS_IDLE : 0
-
+ if defined?(PGconn::PQTRANS_IDLE)
+ # The ruby-pg driver supports inspecting the transaction status,
+ # while the ruby-postgres driver does not.
def outside_transaction?
- @connection.transaction_status == PQTRANS_IDLE
+ @connection.transaction_status == PGconn::PQTRANS_IDLE
end
end
@@ -321,9 +321,8 @@ def test_rollback_when_commit_raises
end
end
- if current_adapter?(:PostgreSQLAdapter) && PGconn.public_method_defined?(:transaction_status)
+ if current_adapter?(:PostgreSQLAdapter) && defined?(PGconn::PQTRANS_IDLE)
def test_outside_transaction_works
- Topic.logger.info("-------------")
assert Topic.connection.outside_transaction?
Topic.connection.begin_db_transaction
assert !Topic.connection.outside_transaction?

0 comments on commit 9bcf01b

Please sign in to comment.