rails/rails — pull request #3949 by samoli (2011-12-12 16:30:39+00:00)
Title: Environment names with hyphens no longer working when specified as a console argument

It's no longer possible to use hyphens in environment names with rails console or rails dbconsole:

$ rails c special-production
Loading development environment (Rails 3.0.9)
/Users/sam/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/magic-file.rb:7:in `initialize': No such file or directory - special-production (Errno::ENOENT)

I think this was introduced in this commit: https://github.com/rails/rails/commit/8cb594a2e1808cd7d93f3593afed0414016fc56f#railties/lib/rails/commands/console.rb

The relevant code in console.rb and dbconsole.rb is:

# Has to set the RAILS_ENV before config/application is required
if ARGV.first && !ARGV.first.index("-") && env = ARGV.shift # has to shift the env ARGV so IRB doesn't freak
ENV['RAILS_ENV'] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
end

I assume this was included to stop hyphen prefixed arguments from leaking in to the environment name. In this pull request I've changed it slightly so it only checks the first character.

I've tested it manually but I can't find any relevant tests to update. I'm happy to write some if someone can point me in the right direction.

Thanks!