2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-06-06 14:17:44 -04:00
|
|
|
require "cases/helper"
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
class TestRecord < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
|
2008-01-21 12:20:51 -05:00
|
|
|
class TestUnconnectedAdapter < ActiveRecord::TestCase
|
2015-03-10 22:21:19 -04:00
|
|
|
self.use_transactional_tests = false
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
def setup
|
2012-10-26 10:51:02 -04:00
|
|
|
@underlying = ActiveRecord::Base.connection
|
|
|
|
@specification = ActiveRecord::Base.remove_connection
|
2019-03-04 10:10:36 -05:00
|
|
|
|
|
|
|
# Clear out connection info from other pids (like a fork parent) too
|
2019-11-05 17:05:54 -05:00
|
|
|
ActiveRecord::ConnectionAdapters::PoolConfig.discard_pools!
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2014-03-14 00:35:58 -04:00
|
|
|
teardown do
|
2006-02-26 18:12:01 -05:00
|
|
|
@underlying = nil
|
2012-10-26 10:51:02 -04:00
|
|
|
ActiveRecord::Base.establish_connection(@specification)
|
2011-01-08 13:33:33 -05:00
|
|
|
load_schema if in_memory_db?
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2006-02-26 18:12:01 -05:00
|
|
|
def test_connection_no_longer_established
|
2004-11-23 20:04:44 -05:00
|
|
|
assert_raise(ActiveRecord::ConnectionNotEstablished) do
|
2006-02-26 18:12:01 -05:00
|
|
|
TestRecord.find(1)
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-02-26 18:12:01 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
assert_raise(ActiveRecord::ConnectionNotEstablished) do
|
2006-02-26 18:12:01 -05:00
|
|
|
TestRecord.new.save
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
end
|
2006-02-26 18:12:01 -05:00
|
|
|
|
2019-01-24 09:51:02 -05:00
|
|
|
def test_error_message_when_connection_not_established
|
|
|
|
error = assert_raise(ActiveRecord::ConnectionNotEstablished) do
|
|
|
|
TestRecord.find(1)
|
|
|
|
end
|
|
|
|
|
2020-01-07 16:40:15 -05:00
|
|
|
assert_equal "No connection pool for 'ActiveRecord::Base' found.", error.message
|
2019-01-24 09:51:02 -05:00
|
|
|
end
|
|
|
|
|
2006-02-26 18:12:01 -05:00
|
|
|
def test_underlying_adapter_no_longer_active
|
2018-05-12 22:26:10 -04:00
|
|
|
assert_not @underlying.active?, "Removed adapter should no longer be active"
|
2006-02-26 18:12:01 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|