Sha256: b528a261d1b4f6942feb307de5b4807778c779814fdc1492c651e193e639228f

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

require File.join(File.dirname(__FILE__), "../_lib")

module MoSQL
  class Test::Functional < MoSQL::Test
    attr_reader :sequel, :mongo

    def sql_test_uri
      ENV['MONGOSQL_TEST_SQL'] || 'postgres:///test'
    end
    def mongo_test_uri
      ENV['MONGOSQL_TEST_MONGO'] || 'mongodb://localhost'
    end
    def mongo_test_dbname
      ENV['MONGOSQL_TEST_MONGO_DB'] || 'test'
    end

    def connect_sql
      begin
        conn = Sequel.connect(sql_test_uri)
        conn.extension :pg_array
        conn.test_connection
        conn
      rescue Sequel::DatabaseConnectionError
        $stderr.puts <<EOF

*********************************************************************
Unable to connect to PostgreSQL database at `#{sql_test_uri}'. Either
configure a PostgresSQL database running locally without
authentication with a 'test' database, or set \$MONGOSQL_TEST_SQL in
the environment.
*********************************************************************

EOF
        exit(1)
      end
    end

    def connect_mongo
      begin
        Mongo::Connection.from_uri(mongo_test_uri)
      rescue Mongo::ConnectionFailure, Mongo::ConnectionError
        $stderr.puts <<EOF

*********************************************************************
Unable to connect to MongoDB database at `#{mongo_test_uri}'. Either
configure a MongoDB database running on localhost without
authentication with a 'test' database, or set \$MONGOSQL_TEST_MONGO in
the environment.
*********************************************************************

EOF
        exit(1)
      end
    end

    def mongo_db
      mongo.db(mongo_test_dbname)
    end

    def setup
      Sequel.default_timezone = :utc
      @sequel = connect_sql
      @mongo  = connect_mongo
      super
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mosql-0.4.3 test/functional/_lib.rb
mosql-0.4.2 test/functional/_lib.rb
mosql-0.4.1 test/functional/_lib.rb
mosql-0.4.0 test/functional/_lib.rb