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.

Filed Under: | Tags:

Comments

  1. Jake 01.16.07 / 07AM
    Hi, I've had no luck getting oracle to work in rails on my G4. Think I could have a go with your oracle enabled bundle?
  2. lori 01.16.07 / 07AM
    Ummm... Sure, but I think using Locomotive is slower, so I would recommend giving it another try with straight Oracle. First, get the Oracle instant client working: There are 4 zip files that need to be downloaded, and unzipped, all into ONE directory, for instance /Developer/Applications/Oracle/instantclient10_1 * instantclient-basic.macosx-10.1.0.3.zip * instantclient-jdbc.macosx-10.1.0.3.zip * instantclient-sqlplus.macosx-10.1.0.3.zip * instantclient-sdk.macosx-10.1.0.3.zip Then you must: 1. Add the instantclient directory to your PATH. 2. Add the instantclient directory to DYLD_FALLBACK_LIBRARY_PATH 3. Create an environment variable called SQLPATH and point it at the instantclient directory If you want to use tnsnames.ora, then: 1. create a tnsnames.ora 2. place it in your home directory 3. Create an environment variable called TNS_ADMIN, and point it at your home directory At this point, you should be able to use sqlplus, and connect to any database in your tnsnames.ora file. Then you need to build the OCI8 driver: * download and install ruby-oci8 (at rubyforge), following the instructions for Oracle InstantClient * sudo ruby setup.rb config -- --with-instant-client=/Developer/Applications/Oracle/instantclient10_1 * make * sudo make install At this point, you should be able to use any database from your tnsnames.ora file with a section in your database.yml file like this: development: adapter: oci host: myhost/mysid username: development password: mypass If all that fails to work for you, then let me know (lori@ this domain, sans the blog.) and I'll post that bundle for you.

Have your say

A name is required. You may use HTML in your comments.