Problems with your fixtures using Oracle on Rails?
Posted by admin, Fri Jan 12 03:37:15 UTC 2007
I finally figured out the problem I had with fixtures in my unit and functional tests yesterday, so I thought I should share.
Our Rails application is deployed on Oracle, but the developers tend to use MySQL, because we use Intel iMacs, and using a PPC Locomotive bundle with the PPC Oracle driver is not exactly the fastest way to develop.
Our unit and functional tests evolved over time, to test some of the weird differences between MySQL and Oracle, just so we can catch problems at build time, instead of when we roll out to the staging/test server and inflict them on our tester. And, over time, we have come to use very few fixtures, because they always seem to cause problems in the Oracle build. We never really understood why they caused problems, we just wanted to make things work, so we put up with the need to create objects on-the-fly, and found ways to do it that were not too repetitive.
But NOT any more. Because I figured out the root cause of the fixture problems with Oracle yesterday. This week I’m working with both Rails 1.1.6 and Rails 1.2RC2 in order to prepare for the release of Rails 1.2. And I kept running into this circular pattern of test failures, where I would make a change to fix a failure in one test, and then a completely different test would fail when I switched to Rails 1.2. Fix that one, and another test would fail when I ran against Oracle. Fix that one, and another completely different test would fail back with Rails 1.1.6 and MySQL. I was really tearing my hair out. After a liberal sprinkling of debugging statements, the light bulb finally went off.
The id’s being used by my fixtures were clashing with the id’s being auto-generated by the Oracle sequences. So, I just ran through my fixture files, and altered all the id’s to be huge numbers, so they would never clash with the auto-generated id’s. And magically, all my weird test failures went away.
So, I’ll have to go back through some of my tests now, and remove some of the on-the-fly object creation, and just rely on fixtures again. I’m looking forward to it, now that I understand.