mongoid/mongoid — pull request #3712 by phstc (2014-06-27 19:54:18+00:00)
Title: Check MONGOID_ENV first to get the env_name

When the environment is not supplied in the `load!` method:

```ruby
Mongoid.load!('config/mongoid.yml')
```

Mongoid tries to find the environment looking for Rails, then Sinatra, then RACK_ENV, then MONGOID_ENV (last option).

Which makes Mongoid a little bit more coupled with these frameworks.

I'm using Mongoid in a standalone Ruby application and I was loading Mongoid without supplying the environment, because I was setting `ENV['MONGOID_ENV'] = ENV['MY_APPLICATION_ENV']` before the `.load!`, but then I added a gem that includes railties, by including railties it was making Rails to be defined + `Rails.env => 'development` by default

```shell
21: def env_name
=> 22: binding.pry
23: return Rails.env if defined?(Rails)
24: return Sinatra::Base.environment.to_s if defined?(Sinatra)
25: ENV["RACK_ENV"] || ENV["MONGOID_ENV"] || raise(Errors::NoEnvironment.new)
26: end
4.1.1@2.0.0 (Mongoid::Config::Environment)> Rails.env
=> "development"
```

My tests (test environment) started to delete (DatabaseCleaner) my development database. Luckily the production hosts had RAILS_ENV defined (I don't know why), otherwise the production would try to access development database.

Changing the load order would make Mongoid less coupled.