The question/problem I'm trying to work through is, in Rails, how do
you deal with a mixture of "code tables" and test fixtures. I'm not
sure what "code tables" are really called, but I'm referring to tables
containing data that's more like configuration. For example I've got
three tables named 'authorities', 'roles' and 'authorities_roles'
representing a many-to-many (habtm) relationship between authorities
and roles. The authorities table is essentially static, the records
will change very rarely (only when there's an update to the system).
The roles table has a set of default roles, and allows users to create
their own roles. Make sense?
Somewhere I thought I read that my "code table" data should be moved
out of the fixtures and into a migration. Easy enough. But now my
tests fail miserably. For one going from unit to functional tests,
all the records are deleted.
So how do you get the migrations and fixtures to play well together?
Jason
Ceaser
Jason
- Jamis
Thanks,
Jason
For a complete listing of rake tasks that ships with rails do "rake
-T". So if you want to load the fixtures into dev you would do:
RAILS_ENV=development rake db:fixtures:load
-Ben
* I'm still loading my base data sets as inserts in my migrations.
* My fixture files now contain *only* test fixtures, none of the base data.
* I set the 'self.pre_loaded_fixtures = true' and
'self.use_transactional_fixtures = true' in my test_helper.rb
* I took out all the fixture declarations in my test, and now have
them load fixtures from the database.
* I wrote a rake task which loads the fixtures, but doesn't delete the
existing data. So I can insert data into a table in my migration, and
then insert additional rows in table using the fixtures.
Now the only problem I'm having is when I run the tests with Rake, it
calls 'db:test:prepare' which recreates the structure, but leaves the
tables empty.
Anyone know how to change that? I was just going to write another Rake task...
Jason
P.S. - If you care, you can find the rake task on my blog:
http://www.jtanium.com/blog/?p=41
Lee
In the short term I wrote a simple one-liner shell script to do
exactly what I'm talking about, but now I realize that a new Rake task
is definitely the way to go.
Thanks,
Jason
P.S. - In case you didn't get the memo: Ruby (metaclasses in this
case) rules! Long live Ruby!