CouchDB Testing Tip
Posted by code_monkey_steve, Wed May 13 13:52:00 UTC 2009
Finished my first stab at converting my current toy project from AR 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:
# 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(File.read(Rails.root.to_s + '/config/couchdb.yml'))['test']
CouchPotato.couchrest_database.recreate!
end
task 'db:test:purge' => 'couchdb:test:purge'
1 BTW, have I mentioned how cool factory_girl is? Another new tool for my bag of tricks.
Hey Steve,
It was good to chat with you today. I was looking over your blog after the interview—looks good.
You mention factory girl…I LOVE factory girl and use it all the time. We’re using it at kashless. One issue I ran into with it is test speed: when I create all my test data directly into the test, the tests run much slower than re-using a bunch of preloaded test data. I created a gem to address this (which we’re using at Kashless). Check it out if you’re interested. It works seemlessly with factory girl.
http://github.com/myronmarston/factory_data_preloader/tree/master
- Myron
Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.