Speeds up fixtures when using myisam tables
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tasks
test
README.textile
init.rb

README.textile

FastFixture

FastFixture makes your tests go faster if you use MyISAM tables

There are sometimes good reasons to use Mysql MyISAM tables in your application – for instance certain types of queries are quick, and they migrate much faster than InnoDB tables. But they don’t support transactions, and therefore transactional fixtures do not work.

But now you can use FastFixture to clone your development database to your test database instead of Rails’s built in clone rake task.

FastFixture clones your database whilst changing the table type from MyISAM to InnoDB, so all your test tables end up being InnoDB. This simple change allows you to use transactional fixtures, making your tests way faster.

Installation

  ./script/plugin install git://github.com/sdsykes/fast_fixture.git

Usage

To clone development to test:

  rake db:fast_fixture_clone

Once your DB is cloned, you can change to using transactional fixtures, which is a setting in test/test_helper.rb

  self.use_transactional_fixtures = true

Performance

We found our tests went from taking eight and a half minutes to almost exactly three minutes. That’s a 65% reduction in running time.

Caveats

InnoDB doesn’t support full text indexes, so if you use those this won’t work.

Tests

To run the tests you need to first make two databases called fast_fixture_test and fast_fixture_test_test, and have a user rails/no password that can access these and also can delete and create databases.
Then run test/test.rb – it will load a schema to fast_fixture_test, and will clone the database to fast_fixture_test_test. This will be checked for correctness.

Extra options

To clone auxiliary_development to auxiliary_test (if you are using multiple dbs):

  rake db:fast_fixture_clone[auxiliary]

Beware, the Rails transactional fixture code needs to be modded to send BEGIN and ROLLBACK statements to all DBs in use, instead of just one. Contact me if you need this.

Author

Stephen Sykes (sdsykes)
© 2009