Travis CI is an awesome continuous integration service that’s free for open-source projects.
If you’d like to test your app against multiple database engines, it’s fairly simple. For these examples, I’m testing my app against SQLite, MySQL, and PostgreSQL.
Edit your #{Rails.root}/.travis.yml (and replace myapp with your app name):
language: ruby rvm: - 1.9.3 env: - DB=sqlite - DB=mysql - DB=postgresql script: - RAILS_ENV=test bundle exec rake --trace db:migrate test before_script: - mysql -e 'create database myapp_test' - psql -c 'create database myapp_test' -U postgres
And your config/database.yml:
sqlite: &sqlite adapter: sqlite3 database: db/<%= Rails.env %>.sqlite3 mysql: &mysql adapter: mysql2 username: root password: database: myapp_<%= Rails.env %> postgresql: &postgresql adapter: postgresql username: postgres password: database: myapp_<%= Rails.env %> min_messages: ERROR defaults: &defaults pool: 5 timeout: 5000 host: localhost <<: *<%= ENV['DB'] || "postgresql" %> development: <<: *defaults test: <<: *defaults production: <<: *defaults # TODO: Add erb-echo of credentials
How does this work?
The only tricky line is this:
<<: *<%= ENV['DB'] || "postgresql" %>
The database.yml is pulled through the ERB interpreter first, and then parsed as YAML. The DB default is "postgresql" (which you could change, of course), and is overridden by the DB environment variable. The only glitch to this approach is if you use a database engine that doesn't have a section defined (like "oracle"), you get a fairly cryptic error message from ActiveRecord that the "database driver must be specified".
Do you have an example I can look at?
Certainly! Chromotype is an example Rails application that is using this setup successfully (along with Minitest!).

