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?
|
2013-06-12 08:15:15 -04:00
|
|
|
spec = ActiveRecord::Base.connection_config
|
|
|
|
ActiveRecord::Base.establish_connection(spec)
|
|
|
|
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!
|
|
|
|
assert_raises(ActiveRecord::StatementInvalid) do
|
2015-04-23 17:05:03 -04:00
|
|
|
silence_warnings do
|
|
|
|
@connection.execute "SELECT count(*) from products"
|
|
|
|
end
|
2013-11-08 10:57:51 -05:00
|
|
|
end
|
2013-06-12 08:15:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|