2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-26 07:05:13 -05:00
|
|
|
require "abstract_unit"
|
|
|
|
require "rails/command"
|
|
|
|
require "rails/commands/generate/generate_command"
|
|
|
|
require "rails/commands/secrets/secrets_command"
|
2019-01-23 17:24:52 -05:00
|
|
|
require "rails/commands/db/system/change/change_command"
|
2017-02-26 07:05:13 -05:00
|
|
|
|
|
|
|
class Rails::Command::BaseTest < ActiveSupport::TestCase
|
|
|
|
test "printing commands" do
|
|
|
|
assert_equal %w(generate), Rails::Command::GenerateCommand.printing_commands
|
2017-07-06 08:40:33 -04:00
|
|
|
assert_equal %w(secrets:setup secrets:edit secrets:show), Rails::Command::SecretsCommand.printing_commands
|
2019-01-23 17:24:52 -05:00
|
|
|
assert_equal %w(db:system:change), Rails::Command::Db::System::ChangeCommand.printing_commands
|
2017-02-26 07:05:13 -05:00
|
|
|
end
|
2020-02-18 00:59:06 -05:00
|
|
|
|
2021-03-03 17:13:36 -05:00
|
|
|
test "ARGV is populated" do
|
|
|
|
class Rails::Command::ArgvCommand < Rails::Command::Base
|
|
|
|
def check_populated(*args)
|
|
|
|
raise "not populated" if ARGV.empty? || ARGV != args
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised { Rails::Command.invoke("argv:check_populated", %w[foo bar]) }
|
|
|
|
end
|
|
|
|
|
2020-02-18 00:59:06 -05:00
|
|
|
test "ARGV is isolated" do
|
|
|
|
class Rails::Command::ArgvCommand < Rails::Command::Base
|
2021-03-03 17:13:36 -05:00
|
|
|
def check_isolated
|
2020-02-18 00:59:06 -05:00
|
|
|
ARGV << "isolate this"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-03 17:13:36 -05:00
|
|
|
original_argv = ARGV.dup
|
|
|
|
ARGV.clear
|
2020-02-18 00:59:06 -05:00
|
|
|
|
2021-03-03 17:13:36 -05:00
|
|
|
Rails::Command.invoke("argv:check_isolated")
|
|
|
|
assert_empty ARGV
|
2020-02-18 00:59:06 -05:00
|
|
|
ensure
|
2021-03-03 17:13:36 -05:00
|
|
|
ARGV.replace(original_argv)
|
2020-02-18 00:59:06 -05:00
|
|
|
end
|
2017-02-26 07:05:13 -05:00
|
|
|
end
|