Demonstration; demo or die

I like these fixtures files I am writing for the testing units. That
makes a lot of sense to me.

As I get to about the 60% point in my little web-application-to-learn-
rails, I have started to do little demonstrations. “See, you login
here, then you look for a student, assign them to your ‘parent’ sheet,
then put in your emergency contacts like this…” and I realize that
what I REALLY want (what I really really want) is to be able to reset
the database to a demonstration position. So I don’t have to delete
associations and start from a blank page again to show it off.

The testing stuff is a little opaque to me.

If I wrote a bunch of fixture files, is there a simple way to say,
“Dump the records out of the tables in the db, load these in for the
demonstration…” or should I just start writing a script that empties
the tables and reads in the YAML files manually?

I’d hate to be duplicating work that’s already sitting in this clever,
shiny machine I’ve installed on my iMac.

Thanks,
–Colin

Depending on your database, sure. I often take my production database
and bring it over to my development machine, especially when something
is broken and I want to fix it.

With postgresql, I do:

pg_dump eq2guild_development > production-20071018.sql
svn add production-20071018.sql

and then on my development machine:

svn up
dropdb eq2guild_development
createdb -E utf8 eq2guild_development
psql -q eq2guild_development < production-20071018.sql

I suspect you could write a Ruby script that would take all the active
record entries and write a yaml file. After all, Toon.find(1).to_yaml
will even produce pretty good code for it.
I suspect there are ways to load yaml fixtures into a ‘demo’ database
– in fact, is there any reason you can’t have a demo environment,
just like production, test, and development?

–Michael

The excellent AR_Fixtures plugin can be used to dump tables into
fixtures,and there’s a rake task for loading fixtures back in.

I personally create my own rake task to bootstrap a database for a demo,
so
I can keep my fixtures solely for testing.