As far as the legacy database and the test database, you should
definitely not have all the data from production loading and unloading
between each spec. That's what fixtures, mocks and stubs are for.
True. So, I'll norrow down my question and focus on the first in a
line of problems I'm having:
Recreating the database from the schema. Here's the general
scenario...
Running a rails app with a few new tables of it's own against a
massive legacy database that is connected to a PHP app.
So to distinguish the tables that are used by the new rails app we
prefix the tables in the database because the PHP coders are SQL
jockeys, and like to hand code all their calls and live on the mysql
prompt:
config.active_record.table_name_prefix = "rb_"
In our models we have to explicitly set the table names and keys of
those models that connect to the 'legacy' tables, thus bypassing the
global rb_ prefix:
class User < ActiveRecord::Base
set_table_name 'member'
set_primary_key 'memberid'
When the schema.rb is created at rake db:migrate time it is created
correctly (all the table names are correct upon inspection).
However, when other rake tasks are run, like rake spec, for example,
it will attempt to recreate database and prepends all the tables in
schema.rb with our active record prefix, rb_
So now our formerly clean test database has a members table and an
rb_members table.
In reality your specs should rarely need to touch the database anyway.
We have done that. That is EXACTLY why there SHOULD be a way to
ENTIRELY BYPASS the database. Wouldn't it be nice if we could
decouple testing from the database entirely? That's what I am
advocating, and I would be very happy to hear of a way to do that.
BUT rspec insists on rebuilding the database even though we've got
everything mocked, and won't be using it.
You should create mocks and stubs to test against. I'd recommend
looking a bit deeper into rSpec about when an how to touch the test
database. It sounds to me like your putting the cart before the horse.
I think people should be able to choose if they want to pull the cart
themselves, just ride the horse and leave the cart behind, or let the
horse pull the cart. I am in complete agreement with convention over
configuration, but I really do need to know how to make rake not
rebuild my database.
I do not have time to write hundreds of migrations for these tables
and 'convention' of letting schema.rb rebuild the database doesn't
work. As I explained above the database is not created the same way
from the schema as the schema is created from the database apparently.
I think that might be a bug in Rails?
Thanks,
Peter Boling