CouchDB Testing Tip

Posted by code_monkey_steve on May 12, 2009 May 12

Finished my first stab at converting my current toy project from ActiveRecord to CouchDB, and so far so good. I ran into an issue where associations aren’t getting saved, but I’m most likely just doing something stupid.

One minor annoyance is that, unlike ActiveRecord, the test database doesn’t get purged and after a while can get cluttered with randomly-generated fixtures1. No problem, just drop in this little Rake task to recreate the DB on each run:

{% highlight ruby %}

  1. lib/tasks/couchdb.rake
    require File.expand_path( RAILS_ROOT + ‘/config/environment’ )
    require ‘couch_potato’

task ‘couchdb:test:purge’ do
CouchPotato::Config.database_name =
YAML::load( + ‘/config/couchdb.yml’))[‘test’]
task ‘db:test:purge’ => ‘couchdb:test:purge’
{% endhighlight %}

1 BTW, have I mentioned how cool factory_girl is? Another new tool for my bag of tricks.