Friday, August 1, 2008

Composite Primary Keys (CPK) and RSpec Fixtures

I was banging my head against the proverbial wall all week.  This morning's travail was an error like this in my specs:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.first
/path/to/rails/app/vendor/gems/composite_primary_keys-1.0.5/lib/composite_primary_keys/base.rb:239:in `find_from_ids'

...After some digging, I found a page that explained the problem, and revealed that you need this in your spec/spec_helper.rb file:

load 'composite_primary_keys/fixtures.rb'

I feel much better now.