require 'test/unit' class TestMultipleOdbcConnectionWrapper < Test::Unit::TestCase def setup @original_odbc_config_path = OdbcConnectionWrapper.odbc_config_path OdbcConnectionWrapper.odbc_config_path = './tests/multiple_odbc_config/connections.yml' @testee = OdbcConnectionWrapper.new end def test_single_db_connections_is_also_used_as_default @testee.connect_me_to( "first_db" ) @testee.execute( "CREATE TABLE WRAPPER_TEST_TABLE( id INT )") assert( table_in_db?( "WRAPPER_TEST_TABLE" ) ) @testee.connect_me_to( "second_db" ) assert( !table_in_db?( "WRAPPER_TEST_TABLE" ) ) @testee.connect_me_to( "default" ) assert( table_in_db?( "WRAPPER_TEST_TABLE" ) ) end def teardown @testee.connect_me_to( "first_db" ) @testee.execute( "DROP TABLE WRAPPER_TEST_TABLE" ) if ( table_in_db?( "WRAPPER_TEST_TABLE" ) ) @testee.disconnect_me OdbcConnectionWrapper.odbc_config_path = @original_odbc_config_path end def test_connections_are_lazily_loaded assert_raise(ODBC::Error) {@testee.connect_me_to("i_do_not_exist")} end private def table_in_db?( table_name ) result_set = @testee.execute( "SELECT * FROM sysobjects WHERE type = 'U'" ) object_names = [] result_set.hashes.each do |row| object_names << row[:name] end return object_names.include?( table_name ) end end