aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRobin Dupret <robin.dupret@gmail.com>2017-07-16 14:54:04 +0200
committerRobin Dupret <robin.dupret@gmail.com>2017-07-16 15:10:39 +0200
commit3777701f1380f3814bd5313b225586dec64d4104 (patch)
treee77262bb855ee85c59b618648f17e2473854c815 /railties
parent48b249927375465a7102acc71c2dfb8d49af8309 (diff)
downloadrails-3777701f1380f3814bd5313b225586dec64d4104.tar.gz
rails-3777701f1380f3814bd5313b225586dec64d4104.tar.bz2
rails-3777701f1380f3814bd5313b225586dec64d4104.zip
Properly expand the environment's name
Running the `console` and `dbconsole` commands with a regular argument as the environment's name automatically expand it to match an existing environment (e.g. dev for development). This feature wasn't available using the `--environment` (a.k.a `-e`) option.
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md5
-rw-r--r--railties/lib/rails/command/environment_argument.rb7
-rw-r--r--railties/lib/rails/commands/console/console_command.rb3
-rw-r--r--railties/lib/rails/commands/dbconsole/dbconsole_command.rb3
-rw-r--r--railties/test/commands/console_test.rb5
-rw-r--r--railties/test/commands/dbconsole_test.rb6
6 files changed, 22 insertions, 7 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 0edf1015a0..db55d4fd69 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Properly expand shortcuts for environment's name running the `console`
+ and `dbconsole` commands.
+
+ *Robin Dupret*
+
* Passing the environment's name as a regular argument to the
`rails dbconsole` and `rails console` commands is deprecated.
The `-e` option should be used instead.
diff --git a/railties/lib/rails/command/environment_argument.rb b/railties/lib/rails/command/environment_argument.rb
index 3469463db5..9582509840 100644
--- a/railties/lib/rails/command/environment_argument.rb
+++ b/railties/lib/rails/command/environment_argument.rb
@@ -7,6 +7,9 @@ module Rails
included do
argument :environment, optional: true, banner: "environment"
+
+ class_option :environment, aliases: "-e", type: :string,
+ desc: "Specifies the environment to run this console under (test/development/production)."
end
private
@@ -19,7 +22,9 @@ module Rails
"will be removed in the next Rails " \
"version. Please, use the -e option " \
"instead."
- elsif !options[:environment]
+ elsif options[:environment]
+ self.options = options.merge(environment: acceptable_environment(options[:environment]))
+ else
self.options = options.merge(environment: Rails::Command.environment)
end
end
diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb
index 1da1e331f1..6f9a1f022b 100644
--- a/railties/lib/rails/commands/console/console_command.rb
+++ b/railties/lib/rails/commands/console/console_command.rb
@@ -70,9 +70,6 @@ module Rails
class_option :sandbox, aliases: "-s", type: :boolean, default: false,
desc: "Rollback database modifications on exit."
- class_option :environment, aliases: "-e", type: :string,
- desc: "Specifies the environment to run this console under (test/development/production)."
-
def initialize(args = [], local_options = {}, config = {})
console_options = []
diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb
index 383149eb81..a66eb16421 100644
--- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb
+++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb
@@ -151,9 +151,6 @@ module Rails
class_option :header, type: :boolean
- class_option :environment, aliases: "-e", type: :string,
- desc: "Specifies the environment to run this console under (test/development/production)."
-
class_option :connection, aliases: "-c", type: :string,
desc: "Specifies the connection to use."
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index 08c560146c..a7169e16fb 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -82,6 +82,11 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
assert_match(/\sspecial-production\s/, output)
end
+ def test_e_option_is_properly_expanded
+ start ["-e", "prod"]
+ assert_match(/\sproduction\s/, output)
+ end
+
def test_environment_option
start ["--environment=special-production"]
assert_match(/\sspecial-production\s/, output)
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index e6a67c2c49..4f55eb9aa6 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -105,6 +105,12 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
end
end
+ def test_rails_env_is_development_when_environment_option_is_dev
+ stub_available_environments([ "development", "test" ]) do
+ assert_match("development", parse_arguments([ "-e", "dev" ])[:environment])
+ end
+ end
+
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
assert_deprecated do
stub_available_environments([ "dev" ]) do