diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 42d6f6046b..54b1251010 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -173,10 +173,11 @@ command to remove old versions. highest_remote_gem.first end - def install_rubygems(version) # :nodoc: + def install_rubygems(spec) # :nodoc: args = update_rubygems_arguments + version = spec.version - update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}" + update_dir = File.join spec.base_dir, 'gems', "rubygems-update-#{version}" Dir.chdir update_dir do say "Installing RubyGems #{version}" unless options[:silent] @@ -290,9 +291,7 @@ command to remove old versions. installed_gems = update_gem('rubygems-update', version) if installed_gems.empty? || installed_gems.first.version != version return if installed_gems.empty? - version = installed_gems.first.version - - install_rubygems version + install_rubygems installed_gems.first end def update_rubygems_arguments # :nodoc: diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index c765e9a8df..b5e9f004d1 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -191,6 +191,37 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_empty out end + def test_execute_system_update_installed_in_non_default_gem_path + rubygems_update_spec = quick_gem "rubygems-update", 9 do |s| + write_file File.join(@tempdir, 'setup.rb') + + s.files += %w[setup.rb] + end + + util_setup_spec_fetcher rubygems_update_spec + + rubygems_update_package = Gem::Package.build rubygems_update_spec + + gemhome2 = "#{@gemhome}2" + + Gem::Installer.at(rubygems_update_package, :install_dir => gemhome2).install + + Gem.use_paths @gemhome, [gemhome2, @gemhome] + + @cmd.options[:args] = [] + @cmd.options[:system] = true + + use_ui @ui do + @cmd.execute + end + + out = @ui.output.split "\n" + assert_equal "Installing RubyGems 9", out.shift + assert_equal "RubyGems system software updated", out.shift + + assert_empty out + end + def test_execute_system_specific spec_fetcher do |fetcher| fetcher.download 'rubygems-update', 8 do |s|