Permalink
Browse files

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.
  • Loading branch information...
robin850 committed Jun 8, 2017
1 parent 1acd9a6 commit 48b249927375465a7102acc71c2dfb8d49af8309
View
@@ -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.
@@ -13,6 +13,12 @@ module EnvironmentArgument #:nodoc:
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
@@ -47,7 +47,7 @@ def test_start_with_sandbox
end
def test_console_with_environment
start ["-e production"]
start ["-e", "production"]
assert_match(/\sproduction\s/, output)
end
@@ -88,18 +88,24 @@ def test_environment_option
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 @@ def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
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
@@ -98,14 +98,18 @@ def test_env
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

0 comments on commit 48b2499

Please sign in to comment.