Skip to content

Commit

Permalink
Merge pull request #10925 from senny/10917_test_to_prevent_regression
Browse files Browse the repository at this point in the history
regression test + mysql2 adapter raises correct error if conn is closed.
Conflicts:

	activerecord/CHANGELOG.md
  • Loading branch information
senny committed Jun 15, 2013
1 parent f42e0fd commit a51d4e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## unreleased ##
* Fix mysql2 adapter raises the correct exception when executing a query on a
closed connection.

*Yves Senn*

* Fix the `:primary_key` option for `has_many` associations.
Fixes #10693.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ def select_rows(sql, name = nil)

# Executes the SQL statement in the context of this connection.
def execute(sql, name = nil)
# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
# made since we established the connection
@connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
if @connection
# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
# made since we established the connection
@connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
end

super
end
Expand Down
26 changes: 26 additions & 0 deletions activerecord/test/cases/disconnected_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "cases/helper"

class TestRecord < ActiveRecord::Base
end

class TestDisconnectedAdapter < ActiveRecord::TestCase
self.use_transactional_fixtures = false

def setup
@connection = ActiveRecord::Base.connection
end

def teardown
spec = ActiveRecord::Base.connection_config
ActiveRecord::Base.establish_connection(spec)
@connection = nil
end

test "can't execute statements while disconnected" do
@connection.execute "SELECT count(*) from products"
@connection.disconnect!
assert_raises(ActiveRecord::StatementInvalid) do
@connection.execute "SELECT count(*) from products"
end
end
end

0 comments on commit a51d4e6

Please sign in to comment.