mongomapper/mongomapper — pull request #571 by syntruth (2014-05-07 19:33:37+00:00)
Title: Fix for Document-only Mongo::Connection setup.

If you have a Single `MongoMapper::Document` class that sets up its own
`Mongo::Connection` via calling the `#connection` method, *and you have
not* already set up a global `Mongo::Connection` via
`MongoMapper.connection=` then the first query to that Document will
crash.

This is because when `#database` is called, it calls `#connection` with
no arguments -- on line 44, connection.db(database_name) -- this
ultimately reset the Document's `@connection` ivar to nil, resulting
in the crash.

Instead, I think the `#connection` method should check to see if the
`@connection` ivar has already been set and only set it to
`MongoMapper.connection` *only if* `@connection` is nil.

This still results in a global localhost connection if the `@connection`
ivar has not previously been set.