1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix console tests.

This commit is contained in:
Kasper Timm Hansen 2016-09-15 21:56:03 +02:00
parent 03c982fa34
commit efd808755c
3 changed files with 33 additions and 7 deletions

View file

@ -13,6 +13,8 @@ module Rails
def extract_environment_option_from_argument
if environment
self.options = options.merge(environment: acceptable_environment(environment))
elsif !options[:environment]
self.options = options.merge(environment: Rails::Command.environment)
end
end

View file

@ -70,7 +70,7 @@ module Rails
class_option :sandbox, aliases: "-s", type: :boolean, default: false,
desc: "Rollback database modifications on exit."
class_option :environment, aliases: "-e", type: :string, default: Rails::Command.environment,
class_option :environment, aliases: "-e", type: :string,
desc: "Specifies the environment to run this console under (test/development/production)."
def perform

View file

@ -1,6 +1,7 @@
require "abstract_unit"
require "env_helpers"
require "rails/commands/console"
require "rails/command"
require "rails/commands/console/console_command"
class Rails::ConsoleTest < ActiveSupport::TestCase
include EnvHelpers
@ -102,13 +103,21 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
stubbed_console = Class.new(Rails::Console) do
def available_environments
Rails::Command::ConsoleCommand.class_eval do
alias_method :old_environments, :available_environments
define_method :available_environments do
["dev"]
end
end
options = stubbed_console.parse_arguments(["dev"])
assert_match("dev", options[:environment])
assert_match("dev", parse_arguments(["dev"])[:environment])
ensure
Rails::Command::ConsoleCommand.class_eval do
undef_method :available_environments
alias_method :available_environments, :old_environments
undef_method :old_environments
end
end
attr_reader :output
@ -148,6 +157,21 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def parse_arguments(args)
Rails::Console.parse_arguments(args)
Rails::Command::ConsoleCommand.class_eval do
alias_method :old_perform, :perform
define_method(:perform) do
extract_environment_option_from_argument
options
end
end
Rails::Command.invoke(:console, args)
ensure
Rails::Command::ConsoleCommand.class_eval do
undef_method :perform
alias_method :perform, :old_perform
undef_method :old_perform
end
end
end