diff options
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 17 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_update_command.rb | 20 |
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index bac9c82fc8..a822f095bf 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -74,6 +74,13 @@ command to remove old versions. end end + def check_oldest_rubygems(version) # :nodoc: + if oldest_supported_version > version + alert_error "rubygems #{version} is not supported. The oldest supported version is #{oldest_supported_version}" + terminate_interaction 1 + end + end + def check_update_arguments # :nodoc: unless options[:args].empty? alert_error "Gem names are not allowed with the --system option" @@ -214,7 +221,7 @@ command to remove old versions. rubygems_update.version = version hig = { - 'rubygems-update' => rubygems_update + 'rubygems-update' => rubygems_update, } gems_to_update = which_to_update hig, options[:args], :system @@ -272,6 +279,8 @@ command to remove old versions. check_latest_rubygems version + check_oldest_rubygems version + update_gem 'rubygems-update', version installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement @@ -309,4 +318,10 @@ command to remove old versions. result end + + private + + def oldest_supported_version + @oldest_supported_version ||= Gem::Version.new("2.5.2") + end end diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 65a70b2b74..eed799c5aa 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -158,6 +158,26 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_empty out end + def test_execute_system_specific_older_than_minimum_supported_rubygems + spec_fetcher do |fetcher| + fetcher.download 'rubygems-update', "2.5.1" do |s| + s.files = %w[setup.rb] + end + end + + @cmd.options[:args] = [] + @cmd.options[:system] = "2.5.1" + + assert_raises Gem::MockGemUi::TermError do + use_ui @ui do + @cmd.execute + end + end + + assert_empty @ui.output + assert_equal "ERROR: rubygems 2.5.1 is not supported. The oldest supported version is 2.5.2\n", @ui.error + end + def test_execute_system_specific_older_than_3_2_removes_plugins_dir spec_fetcher do |fetcher| fetcher.download 'rubygems-update', 3.1 do |s| |