In the same way that the db:seeds rake task is all but unusable (mostly because it will never report a data format error), custom rake tasks using ActiveRecord should be banned.
Two days I have spent try to preload my application for an application to do some integration testing with only ‘ArgumentError: undefined class/module’ errors to show.
In my frustration, I decided to write a small ruby script to read in the exact same YAML file and create the database records. The main reason for writing this script was to see if I could get a hint of any errors in my model or YAML file.
And indeed, that’s what I started to find: a typo in a migration, missed columns, unencoded characters. Piece by piece I was able to take the error reports and fix things to the point where the script and YAML file could create all the data I needed. Taking this YAML file to the rake task. Nothing. Still the same error. Rake and ActiveRecord really aren’t a winning combination. one hours scripting trumps 2 days rake-induced hair-pulling. No more.