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

Add Gem.disable_system_update_message to disable gem update --system if needed.

This commit is contained in:
Josef Šimánek 2020-06-14 00:26:23 +02:00 committed by Hiroshi SHIBATA
parent 49c42b6012
commit 3ab1cfc325
Notes: git 2020-06-15 21:21:01 +09:00
3 changed files with 28 additions and 0 deletions

View file

@ -1187,6 +1187,12 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# other. # other.
class << self class << self
##
# RubyGems distributors (like operating system package managers) can
# disable RubyGems update by setting this to error message printed to
# end-users on gem update --system instead of actual update.
attr_accessor :disable_system_update_message
## ##
# Hash of loaded Gem::Specification keyed by name # Hash of loaded Gem::Specification keyed by name

View file

@ -262,6 +262,11 @@ command to remove old versions.
# Update RubyGems software to the latest version. # Update RubyGems software to the latest version.
def update_rubygems def update_rubygems
if Gem.disable_system_update_message
alert_error Gem.disable_system_update_message
return
end
check_update_arguments check_update_arguments
version, requirement = rubygems_target_version version, requirement = rubygems_target_version

View file

@ -238,6 +238,23 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@ui.error @ui.error
end end
def test_execute_system_with_disabled_update
old_disable_system_update_message = Gem.disable_system_update_message
Gem.disable_system_update_message = "Please use package manager instead."
@cmd.options[:args] = []
@cmd.options[:system] = true
use_ui @ui do
@cmd.execute
end
assert_empty @ui.output
assert_equal "ERROR: Please use package manager instead.\n", @ui.error
ensure
Gem.disable_system_update_message = old_disable_system_update_message
end
# before: # before:
# a1 -> c1.2 # a1 -> c1.2
# after: # after: