rails/rails — pull request #6276 by samoli (2012-05-11 23:44:27+00:00)
Title: Fix various bugs with console arguments and improve test coverage

Fixes these bugs with rails console:

```term
$ rails c special-production
Loading development environment

$ rails c -e test
invalid option: -e (OptionParser::InvalidOption)

$ rails c --environment=test
invalid option: --environment=test (OptionParser::InvalidOption)

$ rails c RAILS_ENV=test
Loading development environment
No such file or directory - special-test (Errno::ENOENT)
```

Console commands that use IRB need the ENV['RAILS_ENV'] to be set before config/application.rb loads and shifts ARGV so IRB doesn't fail.

The code to set this up was previously executed outside of a class definition in commands/console.rb and commands/dbconsole.rb . I've moved it to a class to remove duplication and add tests.

It seems that the original intention was that all these methods of setting the environment should be supported. (Plus it makes it consistent with other commands.)

```term
$ rails c --help
Usage: console [environment] [options]
-s, --sandbox Rollback database modifications on exit.
-e, --environment=name Specifies the environment to run this console under (test/development/production).
Default: development
--debugger Enable the debugger.
```

See also https://github.com/rails/rails/pull/3949 which pull request replaces.