2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-12 08:15:15 -04:00
|
|
|
require "cases/helper"
|
|
|
|
|
|
|
|
class TestRecord < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestDisconnectedAdapter < ActiveRecord::TestCase
|
2015-03-10 22:21:19 -04:00
|
|
|
self.use_transactional_tests = false
|
2013-06-12 08:15:15 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@connection = ActiveRecord::Base.connection
|
|
|
|
end
|
|
|
|
|
2014-03-14 00:35:58 -04:00
|
|
|
teardown do
|
2013-06-28 06:37:42 -04:00
|
|
|
return if in_memory_db?
|
2019-12-17 12:20:37 -05:00
|
|
|
db_config = ActiveRecord::Base.connection_db_config
|
|
|
|
ActiveRecord::Base.establish_connection(db_config)
|
2013-06-12 08:15:15 -04:00
|
|
|
end
|
|
|
|
|
2013-11-08 10:57:51 -05:00
|
|
|
unless in_memory_db?
|
|
|
|
test "can't execute statements while disconnected" do
|
2013-06-12 08:15:15 -04:00
|
|
|
@connection.execute "SELECT count(*) from products"
|
2013-11-08 10:57:51 -05:00
|
|
|
@connection.disconnect!
|
2020-09-10 06:09:53 -04:00
|
|
|
assert_raises(ActiveRecord::ConnectionNotEstablished) do
|
2020-09-02 03:39:41 -04:00
|
|
|
@connection.execute "SELECT count(*) from products"
|
2013-11-08 10:57:51 -05:00
|
|
|
end
|
2013-06-12 08:15:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|