Skip to content
Permalink
Browse files
Remove deprecated environment argument from the rails commands
  • Loading branch information
rafaelfranca committed Jan 17, 2019
1 parent 9d39f81 commit e20589c9be09c7272d73492d4b0f7b24e5595571
@@ -1,3 +1,7 @@
* Remove deprecated `environment` argument from the rails commands.

*Rafael Mendonça França*

* Remove deprecated `capify!`.

*Rafael Mendonça França*
@@ -8,23 +8,13 @@ module EnvironmentArgument #:nodoc:
extend ActiveSupport::Concern

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
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]
if options[:environment]
self.options = options.merge(environment: acceptable_environment(options[:environment]))
else
self.options = options.merge(environment: Rails::Command.environment)
@@ -149,7 +149,7 @@ def test_sandbox
end

def test_environment_option_and_irb_option
spawn_console("test -- --verbose")
spawn_console("-e test -- --verbose")

write_prompt "a = 1", "a = 1"
write_prompt "puts Rails.env", "puts Rails.env\r\ntest"
@@ -94,28 +94,7 @@ def test_environment_option
assert_match(/\sspecial-production\s/, output)
end

def test_rails_env_is_production_when_first_argument_is_p
assert_deprecated do
start ["p"]
assert_match(/\sproduction\s/, output)
end
end

def test_rails_env_is_test_when_first_argument_is_t
assert_deprecated do
start ["t"]
assert_match(/\stest\s/, output)
end
end

def test_rails_env_is_development_when_argument_is_d
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
def test_rails_env_is_dev_when_environment_option_is_dev_and_dev_env_is_present
Rails::Command::ConsoleCommand.class_eval do
alias_method :old_environments, :available_environments

@@ -124,9 +103,7 @@ def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
end
end

assert_deprecated do
assert_match("dev", parse_arguments(["dev"])[:environment])
end
assert_match("dev", parse_arguments(["-e", "dev"])[:environment])
ensure
Rails::Command::ConsoleCommand.class_eval do
undef_method :available_environments
@@ -99,28 +99,12 @@ def test_env
ENV["RACK_ENV"] = nil
end

def test_rails_env_is_development_when_argument_is_dev
assert_deprecated do
stub_available_environments([ "development", "test" ]) do
assert_match("development", parse_arguments([ "dev" ])[:environment])
end
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
assert_match("dev", parse_arguments([ "dev" ])[:environment])
end
end
end

def test_mysql
start(adapter: "mysql2", database: "db")
assert_not aborted
@@ -265,14 +249,14 @@ def test_print_help_short
stdout = capture(:stdout) do
Rails::Command.invoke(:dbconsole, ["-h"])
end
assert_match(/rails dbconsole \[environment\]/, stdout)
assert_match(/rails dbconsole \[options\]/, stdout)
end

def test_print_help_long
stdout = capture(:stdout) do
Rails::Command.invoke(:dbconsole, ["--help"])
end
assert_match(/rails dbconsole \[environment\]/, stdout)
assert_match(/rails dbconsole \[options\]/, stdout)
end

attr_reader :aborted, :output

0 comments on commit e20589c

Please sign in to comment.