@@ -384,20 +384,50 @@ def setup
384
384
assert_predicate @connection , :active?
385
385
end
386
386
387
- test "transaction state is reset after a reconnect" do
387
+ test "materialized transaction state is reset after a reconnect" do
388
388
@connection . begin_transaction
389
389
assert_predicate @connection , :transaction_open?
390
+ @connection . materialize_transactions
391
+ assert raw_transaction_open? ( @connection )
390
392
@connection . reconnect!
391
393
assert_not_predicate @connection , :transaction_open?
394
+ assert_not raw_transaction_open? ( @connection )
392
395
end
393
396
394
- test "transaction state is reset after a disconnect" do
397
+ test "materialized transaction state is reset after a disconnect" do
395
398
@connection . begin_transaction
396
399
assert_predicate @connection , :transaction_open?
400
+ @connection . materialize_transactions
401
+ assert raw_transaction_open? ( @connection )
397
402
@connection . disconnect!
398
403
assert_not_predicate @connection , :transaction_open?
399
404
ensure
400
405
@connection . reconnect!
406
+ assert_not raw_transaction_open? ( @connection )
407
+ end
408
+
409
+ test "unmaterialized transaction state is reset after a reconnect" do
410
+ @connection . begin_transaction
411
+ assert_predicate @connection , :transaction_open?
412
+ assert_not raw_transaction_open? ( @connection )
413
+ @connection . reconnect!
414
+ assert_not_predicate @connection , :transaction_open?
415
+ assert_not raw_transaction_open? ( @connection )
416
+ @connection . materialize_transactions
417
+ assert_not raw_transaction_open? ( @connection )
418
+ end
419
+
420
+ test "unmaterialized transaction state is reset after a disconnect" do
421
+ @connection . begin_transaction
422
+ assert_predicate @connection , :transaction_open?
423
+ assert_not raw_transaction_open? ( @connection )
424
+ @connection . disconnect!
425
+ assert_not_predicate @connection , :transaction_open?
426
+ ensure
427
+ @connection . reconnect!
428
+ assert_not raw_transaction_open? ( @connection )
429
+ @connection . materialize_transactions
430
+ assert_not raw_transaction_open? ( @connection )
401
431
end
402
432
end
403
433
@@ -489,6 +519,31 @@ def test_reset_table_with_non_integer_pk
489
519
end
490
520
491
521
private
522
+ def raw_transaction_open? ( connection )
523
+ case connection . class ::ADAPTER_NAME
524
+ when "PostgreSQL"
525
+ connection . instance_variable_get ( :@raw_connection ) . transaction_status == ::PG ::PQTRANS_INTRANS
526
+ when "Mysql2"
527
+ begin
528
+ connection . instance_variable_get ( :@raw_connection ) . query ( "SAVEPOINT transaction_test" )
529
+ connection . instance_variable_get ( :@raw_connection ) . query ( "RELEASE SAVEPOINT transaction_test" )
530
+
531
+ true
532
+ rescue
533
+ false
534
+ end
535
+ when "SQLite"
536
+ begin
537
+ connection . instance_variable_get ( :@raw_connection ) . transaction { nil }
538
+ false
539
+ rescue
540
+ true
541
+ end
542
+ else
543
+ skip
544
+ end
545
+ end
546
+
492
547
def reset_fixtures ( *fixture_names )
493
548
ActiveRecord ::FixtureSet . reset_cache
494
549
0 commit comments