Marko Anastasov wrote this on February 19, 2009

Preparing the test database for Rails

Ryan Bates has [covered]]( to contribute to Rails with Git. Since Rails is on GitHub, the basic workflow goes pretty much as you’d expect if you’re familiar with git.

If you want to file a bug for ActiveRecord for example, it’s most helpful to provide or extend an existing test case. See file RUNNING_UNIT_TESTS in the activerecord directory. Here’s how you prepare a MySQL test database:

create database activerecord_unittest;
create database activerecord_unittest2;
grant all on activerecord_unittest.* TO rails@localhost;
grant all on activerecord_unittest2.* TO rails@localhost;

These tests use a number of models, defined in activerecord/test/models/. Running

rake test_mysql TEST=test/cases/aaa_create_tables_test.rb

creates the tables defined in schema.rb. After that you can run tests by specifying the db adapter, like

rake test_mysql TEST=test/cases/base_test.rb
comments powered by Disqus

About Marko Anastasov

Rendered Text co-founder. Started with code, currently more focused on people and words. Foosball striker and entry-level cyclist.

Suggested Reads

Rails Testing Handbook

A new ebook on building test-driven Rails apps with RSpec and Cucumber.

At Rendered Text, we have a long history with Ruby on Rails. Checking the blog archive reminds me that we published first posts about working with Rails way back in 2009.


Rendered Text is a software company. For questions regarding Semaphore, please visit Otherwise, feel free to get in touch any time by sending us an email.