mongoid/mongoid — pull request #1422 by mortice (2011-11-11 14:12:24+00:00)
Title: Raise an error when RACK_ENV is not set

Currently, if you use Mongoid in a non-rails app and call Mongoid.load! with RACK_ENV not set (as might happen if you're running with Pow and have no explicit default for RACK_ENV in your config.ru), everything goes fine until you try to interact with Mongo, at which point, you get an ugly "Database should be a Mongo::DB, not NilClass" error out of config.rb at line 236.

The only way to diagnose this issue as an end-user is to inspect the source for config.rb.

This patches Mongoid.load! to raise an error at the point of failure - trying to load the yaml config with no RACK_ENV set.

I've used the translate method within the error's initializer but have not added the message into the various locale files. I assume that's something that will happen downstream of this change.