Passively Multiplay

Posts Tagged ‘testing’

Ruby on Rails: Using UUIDs and Having Functional Tests

Tuesday, March 11th, 2008

Duncan has written previously about UUIDs and our use of them in PMOG. We did run into a issue with tests while using UUIDs and so I wrote a plugin to help mitigate the problems.

The Problem

During development the database is built using the migrations, which correctly build the table ID’s as UUIDs if you’ve implemented them as we have. However, when you run tests, the test database is built using the schema.rb file that is generated by the ActiveRecord core. It assumes auto-incrementing integers as the ID column and ignores your special UUIDs.

The Solution

Head over to the plugin I created with help from Mark Daggett on the Google Code site: http://code.google.com/p/uuid-schema-dumper/ and install it in your rails app as a plugin.

./script/plugin install http://uuid-schema-dumper.googlecode.com/svn/trunk/

Then, run the db dumper rake task: (You only have to do this once)

rake db:schema:dump

You’ll notice in your schema.rb file that the column ID’s now match your migration UUIDs. Thus, your tests will run without a hitch (so far as UUIDs are concerned)

Leave comments if you have any problems :)