title: Testing ActiveRecord against multiple databases in Travis (without dummy rails apps)
body: <p>I'm currently working on getting the <code>activerecord_any_of</code> library set up to use TravisCI for automated testing across multiple database types.</p>
  
  <p>Currently I have the following:</p>
  
  <p>In <code>.travis.yml</code></p>
  
  <pre><code>language: ruby
  script:
    - bundle exec rake test
  before_script:
    - mysql -e 'create database activerecord_any_of_test;'
    - psql -c 'create database activerecord_any_of_test;' -U postgres
  before_install:
    - gem install bundler # use the latest bundler, since Travis doesn't update for us
  rvm:
    - 1.9.3
    - 2.0.0
    - 2.1.1
    - rbx
    - jruby-19mode
  env:
    - DB=mysql
    - DB=sqlite3
    - DB=sqlite3mem
    - DB=postgresql
  gemfile:
    - gemfiles/rails3.gemfile
    - gemfiles/rails4.gemfile
    - gemfiles/rails_edge.gemfile
  matrix:
    allow_failures:
      - gemfile: gemfiles/rails_edge.gemfile
      - env: DB=postgresql
      - env: DB=mysql
  </code></pre>
  
  <p>And <code>database.yml</code>:</p>
  
  <pre><code>sqlite3:
    adapter: &lt;%= "jdbc" if defined? JRUBY_VERSION %&gt;sqlite3
    database: activerecord_any_of.sqlite3.db
  sqlite3mem:
    adapter: &lt;%= "jdbc" if defined? JRUBY_VERSION %&gt;sqlite3
    database: ":memory:"
  postgresql:
    adapter: postgresql
    encoding: unicode
    database: activerecord_any_of_test
    pool: 5
    username: postgres
    password:
    min_messages: warning
  mysql:
    adapter: &lt;%= defined?(JRUBY_VERSION) ? "jdbcmysql" : "mysql2" %&gt;
    host: localhost
    username: root
    password:
    database: activerecord_any_of_test
    encoding: utf8
  ## Add DB Configuration to run Oracle tests
  oracle:
    adapter: oracle_enhanced
    host: localhost
    username: activerecord_any_of_dev
    password:
    database: xe
  </code></pre>
  
  <p>And my <code>test_helper.rb</code></p>
  
  <pre><code>plugin_test_dir = File.dirname(__FILE__)
  
  require 'rubygems'
  require 'bundler/setup'
  
  require 'rails'
  require 'active_record'
  require 'activerecord_any_of'
  
  require "rails/test_help"
  require 'combustion/database'
  require 'database_cleaner'
  
  require 'pry'
  require 'logger'
  require 'yaml'
  require 'erb'
  
  require 'support/models'
  
  ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
  
  ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
  ActiveRecord::Base.establish_connection(ENV["DB"] ||= "sqlite3mem")
  ActiveRecord::Migration.verbose = false
  
  Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]])
  load(File.join(plugin_test_dir, "db", "schema.rb"))
  
  ActiveSupport::TestCase.fixture_path = "#{plugin_test_dir}/fixtures"
  ActiveSupport::TestCase.use_transactional_fixtures = true
  ActiveSupport::TestCase.teardown do
    unless /sqlite/ === ENV['DB']
      Combustion::Database.drop_database(ActiveRecord::Base.configurations[ENV['DB']])
    end
  end
  </code></pre>
  
  <p>When I run the tests on TravisCI, I get <code>sqlite</code> and <code>sqlitemem</code> matrices running just fine in most cases. However, when running against MySQL, I get the following errors:</p>
  
  <pre><code>Mysql2::Error: Unknown database activerecord_any_of_test
  </code></pre>
  
  <p>And when running against PostgreSQL I get the error:</p>
  
  <pre><code>ActiveRecord::StatementInvalid: PG::ConnectionBad: connection is closed: ROLLBACK
  </code></pre>
  
  <p>Since I'm creating the databases, I don't see why there would be any problems. As far as I can tell, I've configured the <code>database.yml</code> to use the proper credentials. Maybe I'm using <code>Combustion::Database</code> wrong? How can I properly connect to my databases in my tests?</p>
  
  <p>I've adapted the setup used in <a href="https://github.com/collectiveidea/awesome_nested_set" rel="nofollow">awesome_nested_set</a> for setting up the tests for <a href="https://github.com/shekibobo/activerecord_any_of/tree/travis-setup" rel="nofollow">activerecord_any_of</a>. <a href="https://travis-ci.org/shekibobo/activerecord_any_of" rel="nofollow">Failing tests</a> can be seen on Travis.</p>