Permalink
Browse files

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.
  • Loading branch information...
robin850 committed Jul 16, 2017
1 parent 48b2499 commit 3777701f1380f3814bd5313b225586dec64d4104
View
@@ -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.
@@ -7,6 +7,9 @@ module EnvironmentArgument #:nodoc:
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 @@ def extract_environment_option_from_argument
"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
@@ -70,9 +70,6 @@ class ConsoleCommand < Base # :nodoc:
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 = []
@@ -151,9 +151,6 @@ class DbconsoleCommand < Base # :nodoc:
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."
@@ -82,6 +82,11 @@ def test_e_option
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)
@@ -105,6 +105,12 @@ def test_rails_env_is_development_when_argument_is_dev
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

0 comments on commit 3777701

Please sign in to comment.