Rails connection pool management with test
def safely
begin
unless ActiveRecord::Base.connected?
ActiveRecord::Base.connection.verify!(0)
end
yield
rescue => e
status e.inspect
ensure
ActiveRecord::Base.connection_pool.release_connection
end
end