Sha256: 731a6c3ef2952df08c83fd7fecf3b9245ff96efd62861686d509997cdff7fc34

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marjoree-0.0.9 ./tests/marjoree/test_odbc_connection_wrapper.rb