Liquid Media's Apps

HABTM fixtures causing load of nonexistent model

... and now let me shed some light on this unintuitive blog title ...

In my Rails 2.1.1 project, I have two models, Collection and SubjectCategory and they are related by a has_and_belongs_to_many. In my fixtures, I had corresponding collections.yml, subject_categories.yml, and the habtm collections_subject_categories.csv file. Everything works fine, and my test suite isn't creating any problems, but the other day when I happened to look at the log/test.log file I saw:

Unable to load collections_subject_category, underlying cause no such file to load -- collections_subject_category 

 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require'
...

A strange error, considering the test suite actually works. Turns out that the test suite is trying to load a model called CollectionsSubjectCategory and its corresponding collections_subject_category.rb source file.

This is obviously wrong behaviour. The correct solution would be to create a fork of Rails on GitHub, fix the problem, notify someone of my fix, and then wait and wonder and potentially maintain my fork ad infinitum. Instead, I created a fix with a hack; in app/models/collections_subject_category.rb:

class CollectionsSubjectCategory
end

Awful, I know, but now I avoid spurious errors in my test.log.

Tagged awful, fix, fork, github, habtm, and rails.
blog comments powered by Disqus