Fix incremental index updates (#232) #364

Merged
merged 2 commits into from Nov 27, 2012
View
3 lib/rubygems/indexer.rb
@@ -584,6 +584,9 @@ def update_index
specs = map_gems_to_specs updated_gems
prerelease, released = specs.partition { |s| s.version.prerelease? }
+ Gem::Specification.dirs = []
+ Gem::Specification.add_specs(*specs)
+
files = build_marshal_gemspecs
Gem.time 'Updated indexes' do
View
5 lib/rubygems/test_case.rb
@@ -417,6 +417,11 @@ def util_build_gem(spec)
end
end
+ def util_remove_gem(spec)
+ FileUtils.rm_rf spec.cache_file
+ FileUtils.rm_rf spec.spec_file
+ end
+
##
# Removes all installed gems from +@gemhome+.
View
50 test/rubygems/test_gem_indexer.rb
@@ -494,6 +494,20 @@ def test_generate_index_prerelease_specs
prerelease_specs
end
+ ##
+ # Emulate the starting state of Gem::Specification in a live environment,
+ # where it will carry the list of system gems
+ def with_system_gems
+ Gem::Specification.reset
+
+ sys_gem = quick_spec 'systemgem', '1.0'
+ util_build_gem sys_gem
+ Gem::Specification.add_spec sys_gem
+ yield
+ util_remove_gem sys_gem
+ end
+
+
def test_update_index
use_ui @ui do
@indexer.generate_index
@@ -518,30 +532,32 @@ def test_update_index
FileUtils.mv @d2_1.cache_file, gems
FileUtils.mv @d2_1_a.cache_file, gems
- use_ui @ui do
- @indexer.update_index
- end
+ with_system_gems do
+ use_ui @ui do
+ @indexer.update_index
+ end
- assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
- specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
+ specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
- assert_includes specs_index, @d2_1_tuple
- refute_includes specs_index, @d2_1_a_tuple
+ assert_includes specs_index, @d2_1_tuple
+ refute_includes specs_index, @d2_1_a_tuple
- latest_specs_index = Marshal.load \
- Gem.read_binary(@indexer.dest_latest_specs_index)
+ latest_specs_index = Marshal.load \
+ Gem.read_binary(@indexer.dest_latest_specs_index)
- assert_includes latest_specs_index, @d2_1_tuple
- assert_includes latest_specs_index,
- [@d2_0.name, @d2_0.version, @d2_0.original_platform]
- refute_includes latest_specs_index, @d2_1_a_tuple
+ assert_includes latest_specs_index, @d2_1_tuple
+ assert_includes latest_specs_index,
+ [@d2_0.name, @d2_0.version, @d2_0.original_platform]
+ refute_includes latest_specs_index, @d2_1_a_tuple
- pre_specs_index = Marshal.load \
- Gem.read_binary(@indexer.dest_prerelease_specs_index)
+ pre_specs_index = Marshal.load \
+ Gem.read_binary(@indexer.dest_prerelease_specs_index)
- assert_includes pre_specs_index, @d2_1_a_tuple
- refute_includes pre_specs_index, @d2_1_tuple
+ assert_includes pre_specs_index, @d2_1_a_tuple
+ refute_includes pre_specs_index, @d2_1_tuple
+ end
end
def assert_indexed(dir, name)