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
|
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
|
|
|
|
|
|
|
def test_underlying_adapter_no_longer_active
|
|
|
|
assert !@underlying.active?, "Removed adapter should no longer be active"
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|