Plugin Testing with a Database

Posted by Lance Ivy Mon, 17 Mar 2008 22:08:00 GMT

When I develop a plugin that extends ActiveRecord, I’m really not content to stub out all the database access. I feel that tests should be reasonably complete, and to me that means not making a lot of assumptions about what’s going on underneath the hood of the supporting framework (in this case, ActiveRecord). But at the same time, I hate depending on an application in order to develop and test a plugin.

So I figured out how to package database access into a plugin (thanks to rick olson’s acts_as_paranoid testing). The highlights:

  • uses an in-memory SQLite3 database
  • loads from a database schema
  • a collection of ActiveRecord models designed to compactly represent all the different associations
  • provides basic fixtures for all models
  • maintains a separate test log
  • does not assume that you’re testing your plugin

I’ve adapted the method for a couple plugins so far, and today decided to take the next step and create my own plugin template with all these goodies. I didn’t/won’t make it a generator, but I did package it up to share (MIT-style). Simply unzip this template somewhere, delete whatever internals are simply cruft for your purposes, and search-and-replace the string {template} with your own plugin name to get started.

Attachment

Posted in , ,  | Tags , , , , ,  | no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment