aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorMykola Kyryk <mykola.kyryk@onapp.com>2012-12-27 17:04:54 +0200
committerMykola Kyryk <mykola.kyryk@onapp.com>2013-01-04 17:05:49 +0200
commit4fa6088b428e8a8a567cde1f660a209113f04dc3 (patch)
tree705229b16967c5c415037b15713fc3e4b255be9e /railties/lib/rails
parentc9402c0258e85f125ce7cdc292381eb8b9dcbbe0 (diff)
downloadrails-4fa6088b428e8a8a567cde1f660a209113f04dc3.tar.gz
rails-4fa6088b428e8a8a567cde1f660a209113f04dc3.tar.bz2
rails-4fa6088b428e8a8a567cde1f660a209113f04dc3.zip
This commit fixes issue #8628
Allow environment name to start with a substring of the default environment names. For example: tes, pro, prod, dev, devel, etc. Fixing identation. Adding test for Rails::Console.parse_arguments method. Fix issue 8628 for Rails::DBConsole.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/commands/console.rb11
-rw-r--r--railties/lib/rails/commands/dbconsole.rb10
2 files changed, 19 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index aef7600fbd..35a9072f51 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -24,11 +24,20 @@ module Rails
if arguments.first && arguments.first[0] != '-'
env = arguments.first
- options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
+ if available_environments.include? env
+ options[:environment] = env
+ else
+ options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
+ end
end
options
end
+
+ private
+ def available_environments
+ Dir[Rails.root.join('config', 'environments', '*.rb')].map { |fname| File.basename(fname, '.*') }
+ end
end
attr_reader :options, :app, :console
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index 4a5674236d..353a64fd01 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -136,12 +136,20 @@ module Rails
if arguments.first && arguments.first[0] != '-'
env = arguments.first
- options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
+ if self.class.available_environments.include? env
+ options[:environment] = env
+ else
+ options[:environment] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
+ end
end
options
end
+ def self.available_environments
+ Dir[Rails.root.join('config', 'environments', '*.rb')].map { |fname| File.basename(fname, '.*') }
+ end
+
def find_cmd_and_exec(commands, *args)
commands = Array(commands)