I finally used fixtures
I finally had a project where I thought fixtures and unit testing made sense and now I’m wondering why wasn’t I doing this all along?
I have been using rake migrations pretty much since I started using RoR. But default data hasnt been much of an issue on my projects until this last one. So I looked into fixtures and Im regretting not taking the time sooner to get to know fixtures better.
One cool thing I came accross was how to handle foriegn keys when loading fixtures. It kept choking on fixtures:load because by default it will load fixtures in alphabetical order. For example: My fixture for accounts has a FK of user_id but the accounts fixture will be loaded before the users fixture is. Thus my FK problem.
I found some clever ruby scripts that alter the ENV variables and so on but i thought a more direct approach was to just run it like this
rake db:fixtures:load FIXTURES=users,accounts
Pretty cool.