I got hit by this today and it was so confusing that it took me a long time to sort out. That makes it a prime canidate to post here to make sure it doesn’t get me or you ever again.
I’m a huge fan of the migration system in Rails. It makes it very easy to track changes to you database schema. That’s a good thing!
The issue I ran into today was this - I have been working on my workstation at home for several days. It meant I generated both a lot of code and a lot of tests.
Today I showed up at the office -
svn update
rake setup_test_db (It's a custom task that has actually been superceded by a series of commands in standard rails)
rake
This should bring my laptop up to date, reload the test db, and run all tests. This helps me make sure everything is still on track. Immediately, a huge batch of tests failed - because they couldn’t find the tables I had recently created. After a heck of a lot of head banging - I found the solution.
I was hit by a bit of the old Rails magic. As far as I can tell, the version your test system is going to fixate on is set by your development db.
Small disclaimer - this happened on Rails Edge it may or may not hold true for the current offical release
So in my case, I started running the tests before I touched the development db. That meant that the test db migrated back to the version that was stored in my development db - which was three versions lower than the current one.
The solution was to
rake db:migrate
That brought the development system up to spead and then the tests ran flawlessly.
So if you do revert your development system to a previous version be prepared for the tests to work on that version as well.
Leave a Reply
Moderation Active: Old stuff here... Therefore your comment on this post will be moderated (i.e. don't submit twice !)