Skip to content

Commit

Permalink
Teach PostgreSQLAdapter#reset! to actually reset
Browse files Browse the repository at this point in the history
It wasn't doing anything beyond clearing the statement cache.
  • Loading branch information
matthewd authored and Jigish Patel committed Sep 9, 2014
1 parent dd05fe9 commit a43b24e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,12 @@ def reconnect!

def reset!
clear_cache!
super
reset_transaction
unless @connection.transaction_status == ::PG::PQTRANS_IDLE
@connection.query 'ROLLBACK'
end
@connection.query 'DISCARD ALL'
configure_connection
end

# Disconnects from the database if already connected. Otherwise, this
Expand Down
31 changes: 31 additions & 0 deletions activerecord/test/cases/adapters/postgresql/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,37 @@ def test_connection_options
assert_equal 'off', expect
end

def test_reset
@connection.query('ROLLBACK')
@connection.query('SET geqo TO off')

# Verify the setting has been applied.
expect = @connection.query('show geqo').first.first
assert_equal 'off', expect

@connection.reset!

# Verify the setting has been cleared.
expect = @connection.query('show geqo').first.first
assert_equal 'on', expect
end

def test_reset_with_transaction
@connection.query('ROLLBACK')
@connection.query('SET geqo TO off')

# Verify the setting has been applied.
expect = @connection.query('show geqo').first.first
assert_equal 'off', expect

@connection.query('BEGIN')
@connection.reset!

# Verify the setting has been cleared.
expect = @connection.query('show geqo').first.first
assert_equal 'on', expect
end

def test_tables_logs_name
@connection.tables('hello')
assert_equal 'SCHEMA', @subscriber.logged[0][1]
Expand Down

0 comments on commit a43b24e

Please sign in to comment.