From 4fa6088b428e8a8a567cde1f660a209113f04dc3 Mon Sep 17 00:00:00 2001 From: Mykola Kyryk Date: Thu, 27 Dec 2012 17:04:54 +0200 Subject: 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. --- railties/lib/rails/commands/console.rb | 11 ++++++++++- railties/lib/rails/commands/dbconsole.rb | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails') 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) -- cgit v1.2.3