aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRobin Dupret <robin.dupret@gmail.com>2017-06-09 00:15:41 +0200
committerRobin Dupret <robin.dupret@gmail.com>2017-07-16 15:10:34 +0200
commit48b249927375465a7102acc71c2dfb8d49af8309 (patch)
tree9f4d2ec7e7dfe01eb67715945e4ccc4c0508375f /railties
parent1acd9a6464668d4d54ab30d016829f60b70dbbeb (diff)
downloadrails-48b249927375465a7102acc71c2dfb8d49af8309.tar.gz
rails-48b249927375465a7102acc71c2dfb8d49af8309.tar.bz2
rails-48b249927375465a7102acc71c2dfb8d49af8309.zip
Deprecate environment as an argument for dbconsole and console
People should rather rely on the `-e` or `--environment` options to specify in which environment they want to work. This will allow us to specify the connection to pick as a regular argument in the future.
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md14
-rw-r--r--railties/lib/rails/command/environment_argument.rb6
-rw-r--r--railties/test/commands/console_test.rb24
-rw-r--r--railties/test/commands/dbconsole_test.rb12
4 files changed, 44 insertions, 12 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 1c93f7408c..0edf1015a0 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,17 @@
+* 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.
+
+ Previously:
+
+ $ bin/rails dbconsole production
+
+ Now:
+
+ $ bin/rails dbconsole -e production
+
+ *Robin Dupret*, *Kasper Timm Hansen*
+
* Allow to pass a custom connection name to the `rails dbconsole`
command when using a 3-level database configuration.
diff --git a/railties/lib/rails/command/environment_argument.rb b/railties/lib/rails/command/environment_argument.rb
index 05eac34155..3469463db5 100644
--- a/railties/lib/rails/command/environment_argument.rb
+++ b/railties/lib/rails/command/environment_argument.rb
@@ -13,6 +13,12 @@ module Rails
def extract_environment_option_from_argument
if environment
self.options = options.merge(environment: acceptable_environment(environment))
+
+ ActiveSupport::Deprecation.warn "Passing the environment's name as a " \
+ "regular argument is deprecated and " \
+ "will be removed in the next Rails " \
+ "version. Please, use the -e option " \
+ "instead."
elsif !options[:environment]
self.options = options.merge(environment: Rails::Command.environment)
end
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index 4fc082e4ca..08c560146c 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -47,7 +47,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_console_with_environment
- start ["-e production"]
+ start ["-e", "production"]
assert_match(/\sproduction\s/, output)
end
@@ -88,18 +88,24 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_rails_env_is_production_when_first_argument_is_p
- start ["p"]
- assert_match(/\sproduction\s/, output)
+ assert_deprecated do
+ start ["p"]
+ assert_match(/\sproduction\s/, output)
+ end
end
def test_rails_env_is_test_when_first_argument_is_t
- start ["t"]
- assert_match(/\stest\s/, output)
+ assert_deprecated do
+ start ["t"]
+ assert_match(/\stest\s/, output)
+ end
end
def test_rails_env_is_development_when_argument_is_d
- start ["d"]
- assert_match(/\sdevelopment\s/, output)
+ assert_deprecated do
+ start ["d"]
+ assert_match(/\sdevelopment\s/, output)
+ end
end
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
@@ -111,7 +117,9 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
end
- assert_match("dev", parse_arguments(["dev"])[:environment])
+ assert_deprecated do
+ assert_match("dev", parse_arguments(["dev"])[:environment])
+ end
ensure
Rails::Command::ConsoleCommand.class_eval do
undef_method :available_environments
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index 94bfe3a652..e6a67c2c49 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -98,14 +98,18 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
end
def test_rails_env_is_development_when_argument_is_dev
- stub_available_environments([ "development", "test" ]) do
- assert_match("development", parse_arguments([ "dev" ])[:environment])
+ assert_deprecated do
+ stub_available_environments([ "development", "test" ]) do
+ assert_match("development", parse_arguments([ "dev" ])[:environment])
+ end
end
end
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
- stub_available_environments([ "dev" ]) do
- assert_match("dev", parse_arguments([ "dev" ])[:environment])
+ assert_deprecated do
+ stub_available_environments([ "dev" ]) do
+ assert_match("dev", parse_arguments([ "dev" ])[:environment])
+ end
end
end