Skip to content
Browse files

Merge branch 'master' of git@github.com:aef/rubygems

  • Loading branch information...
2 parents 2263dd6 + a175e1d commit 72e5dc4decff5bf3aff47dc9049bfef962a884ed @aef committed Feb 3, 2011
View
8 UPGRADING.rdoc
@@ -28,10 +28,16 @@ Use the Normal Upgrade Recipe below.
=== Normal Downgrade
+==== With rubygems 1.6.0 and higher:
+
+ $ gem update --system 1.3.7
+
+==== With rubygems 1.5.0 and lower:
+
Use sudo/su as appropriate:
$ gem install rubygems-update -v 1.3.7
- $ update_rubygems
+ $ update_rubygems _1.3.7_
Replace 1.3.7 with whatever version you want to downgrade to. This
recipe can also be used to upgrade to a specific version instead of
View
66 lib/rubygems/commands/update_command.rb
@@ -21,9 +21,13 @@ def initialize
add_install_update_options
- add_option('--system',
+ OptionParser.accept Gem::Requirement do |value|
+ Gem::Requirement.new value
+ end
+
+ add_option('--system [VERSION]', Gem::Requirement,
'Update the RubyGems system software') do |value, options|
- options[:system] = value
+ options[:system] = value || Gem::Requirement.default
end
add_local_remote_options
@@ -47,30 +51,7 @@ def execute
hig = {}
if options[:system] then
- say "Updating RubyGems"
-
- unless options[:args].empty? then
- raise "No gem names are allowed with the --system option"
- end
-
- rubygems_update = Gem::Specification.new
- rubygems_update.name = 'rubygems-update'
- rubygems_update.version = Gem::Version.new Gem::VERSION
- hig['rubygems-update'] = rubygems_update
-
- options[:user_install] = false
-
- Gem.source_index.refresh!
-
- update_gems = Gem.source_index.find_name 'rubygems-update'
-
- latest_update_gem = update_gems.sort_by { |s| s.version }.last
-
- say "Updating RubyGems to #{latest_update_gem.version}"
- installed = do_rubygems_update latest_update_gem.version
-
- say "RubyGems system software updated" if installed
-
+ update_rubygems
return
else
say "Updating installed gems"
@@ -131,11 +112,33 @@ def execute
end
##
- # Update the RubyGems software to +version+.
+ # Update RubyGems software to the latest version.
+
+ def update_rubygems
+ say "Updating RubyGems"
+
+ unless options[:args].empty? then
+ raise "No gem names are allowed with the --system option"
+ end
+
+ options[:user_install] = false
+
+ Gem.source_index.refresh!
+
+ req = if Gem::Requirement === options[:system] then
+ options[:system]
+ else
+ Gem::Requirement.new
+ end
+
+ update_gems = Gem.source_index.find_name 'rubygems-update', req
+ latest_update_gem = update_gems.last
+
+ say "Updating RubyGems to #{latest_update_gem.version}"
+ version = latest_update_gem.version
- def do_rubygems_update(version)
args = []
- args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
+ args << '--prefix' << Gem.prefix if Gem.prefix
args << '--no-rdoc' unless options[:generate_rdoc]
args << '--no-ri' unless options[:generate_ri]
args << '--no-format-executable' if options[:no_format_executable]
@@ -148,8 +151,9 @@ def do_rubygems_update(version)
# Make sure old rubygems isn't loaded
old = ENV["RUBYOPT"]
- ENV.delete("RUBYOPT")
- system setup_cmd
+ ENV.delete("RUBYOPT") if old
+ installed = system setup_cmd
+ say "RubyGems system software updated" if installed
ENV["RUBYOPT"] = old if old
end
end
View
20 lib/rubygems/test_case.rb
@@ -430,6 +430,7 @@ def util_gzip(data)
# Additional +prerelease+ gems may also be created:
#
# +@a2_pre+:: gem a version 2.a
+ # TODO: nuke this and fix tests. this should speed up a lot
def util_make_gems(prerelease = false)
@a1 = quick_gem 'a', '1' do |s|
@@ -453,11 +454,12 @@ def util_make_gems(prerelease = false)
s.require_paths = %w[lib]
end
- @a2 = quick_gem('a', '2', &init)
- @a3a = quick_gem('a', '3.a', &init)
+ @a2 = quick_gem('a', '2', &init)
+ @a3a = quick_gem('a', '3.a', &init)
@a_evil9 = quick_gem('a_evil', '9', &init)
- @b2 = quick_gem('b', '2', &init)
- @c1_2 = quick_gem('c', '1.2', &init)
+ @b2 = quick_gem('b', '2', &init)
+ @c1_2 = quick_gem('c', '1.2', &init)
+
@pl1 = quick_gem 'pl', '1' do |s| # l for legacy
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
@@ -471,12 +473,12 @@ def util_make_gems(prerelease = false)
util_build_gem @a2_pre
end
- write_file File.join(*%W[gems #{@a1.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@a1.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@a2.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])
[@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].each do |spec|
util_build_gem spec
View
124 test/rubygems/test_gem_commands_update_command.rb
@@ -48,6 +48,126 @@ def test_execute
assert_empty out
end
+ def util_setup_rubygem version
+ gem = quick_gem('rubygems-update', version.to_s) do |s|
+ s.files = %w[setup.rb]
+ end
+ write_file File.join(*%W[gems #{gem.original_name} setup.rb])
+ util_build_gem gem
+ util_setup_spec_fetcher gem
+ gem
+ end
+
+ def util_setup_rubygem9
+ @rubygem9 = util_setup_rubygem 9
+ end
+
+ def util_setup_rubygem8
+ @rubygem9 = util_setup_rubygem 8
+ end
+
+ def test_execute_system
+ util_clear_gems
+ util_setup_rubygem9
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = true # --system
+ @cmd.options[:generate_rdoc] = false
+ @cmd.options[:generate_ri] = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating RubyGems", out.shift
+ assert_equal "Updating RubyGems to 9", out.shift
+ assert_equal "Installing RubyGems 9", out.shift
+ assert_equal "RubyGems system software updated", out.shift
+
+ assert_empty out
+ end
+
+ def test_execute_system_multiple
+ util_clear_gems
+ util_setup_rubygem9
+ util_setup_rubygem8
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = true # --system
+ @cmd.options[:generate_rdoc] = false
+ @cmd.options[:generate_ri] = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating RubyGems", out.shift
+ assert_equal "Updating RubyGems to 9", out.shift
+ assert_equal "Installing RubyGems 9", out.shift
+ assert_equal "RubyGems system software updated", out.shift
+
+ assert_empty out
+ end
+
+ def test_execute_system_specific
+ util_clear_gems
+ util_setup_rubygem9
+ util_setup_rubygem8
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = Gem::Requirement.new("8")
+ @cmd.options[:generate_rdoc] = false
+ @cmd.options[:generate_ri] = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating RubyGems", out.shift
+ assert_equal "Updating RubyGems to 8", out.shift
+ assert_equal "Installing RubyGems 8", out.shift
+ assert_equal "RubyGems system software updated", out.shift
+
+ assert_empty out
+ end
+
+ def test_execute_system_options_plain
+ @cmd.handle_options %w[--system]
+
+ expected = {
+ :generate_ri => true,
+ :system => Gem::Requirement.default,
+ :force => false,
+ :args => [],
+ :generate_rdoc => true,
+ }
+
+ assert_equal expected, @cmd.options
+ end
+
+ def test_execute_system_options_bad
+ assert_raises ArgumentError do
+ @cmd.handle_options %w[--system fuck-you]
+ end
+ end
+
+ def test_execute_system_options_specific
+ @cmd.handle_options %w[--system 1.3.7]
+
+ expected = {
+ :generate_ri => true,
+ :system => Gem::Requirement.new(["= 1.3.7"]),
+ :force => false,
+ :args => [],
+ :generate_rdoc => true,
+ }
+
+ assert_equal expected, @cmd.options
+ end
+
# before:
# a1 -> c1.2
# after:
@@ -65,9 +185,9 @@ def test_execute_dependencies
@a2.add_dependency 'c', '2'
@a2.add_dependency 'b', '2'
- @b2_path = File.join @gemhome, 'cache', @b2.file_name
+ @b2_path = File.join @gemhome, 'cache', @b2.file_name
@c1_2_path = File.join @gemhome, 'cache', @c1_2.file_name
- @c2_path = File.join @gemhome, 'cache', @c2.file_name
+ @c2_path = File.join @gemhome, 'cache', @c2.file_name
@source_index = Gem::SourceIndex.new
@source_index.add_spec @a1

0 comments on commit 72e5dc4

Please sign in to comment.
Something went wrong with that request. Please try again.