Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
Index: test/test_gem_source_info_cache.rb =================================================================== --- test/test_gem_source_info_cache.rb (revision 1692) +++ test/test_gem_source_info_cache.rb (working copy) @@ -271,6 +271,32 @@ assert_equal [@a2.full_name], gems end + # Replicates above but verifies #add_specs works with no splatting + def test_read_user_cache_without_splat + FileUtils.chmod 0444, @sic.user_cache_file + FileUtils.chmod 0444, @sic.latest_user_cache_file + + @si = Gem::SourceIndex.new + @si.add_specs([@a1, @a2]) + + @sice = Gem::SourceInfoCacheEntry.new @si, 0 + + @sic.set_cache_data({ @gem_repo => @sice }) + @sic.update + @sic.write_cache + @sic.reset_cache_data + + user_cache_data = @sic.cache_data.to_a.sort + + assert_equal 1, user_cache_data.length + user_cache_data = user_cache_data.first + + assert_equal @gem_repo, user_cache_data.first + + gems = user_cache_data.last.source_index.map { |_,spec| spec.full_name } + assert_equal [@a2.full_name], gems + end + def test_search si = Gem::SourceIndex.new si.add_spec @a1 @@ -411,6 +437,47 @@ assert_equal [@a2.full_name], gems end + # Replicates _from_scratch but verifies #add_specs works with no splat + def test_write_cache_user_from_scratch_without_splat + FileUtils.rm_rf @sic.user_cache_file + FileUtils.rm_rf @sic.latest_user_cache_file + + FileUtils.chmod 0444, @sic.system_cache_file + FileUtils.chmod 0444, @sic.latest_system_cache_file + + @si = Gem::SourceIndex.new + @si.add_specs([@a1, @a2]) + + @sice = Gem::SourceInfoCacheEntry.new @si, 0 + + @sic.set_cache_data({ @gem_repo => @sice }) + @sic.update + + @sic.write_cache + + assert File.exist?(@sic.user_cache_file), 'system_cache_file' + assert File.exist?(@sic.latest_user_cache_file), + 'latest_system_cache_file' + + user_cache_data = read_cache(@sic.user_cache_file).to_a.sort + assert_equal 1, user_cache_data.length, 'user_cache_data length' + user_cache_data = user_cache_data.first + + assert_equal @gem_repo, user_cache_data.first + + gems = user_cache_data.last.source_index.map { |_,spec| spec.full_name } + assert_equal [@a1.full_name, @a2.full_name], gems + + user_cache_data = read_cache(@sic.latest_user_cache_file).to_a.sort + assert_equal 1, user_cache_data.length + user_cache_data = user_cache_data.first + + assert_equal @gem_repo, user_cache_data.first + + gems = user_cache_data.last.source_index.map { |_,spec| spec.full_name } + assert_equal [@a2.full_name], gems + end + def test_write_cache_user_no_directory FileUtils.rm_rf File.dirname(@sic.user_cache_file) FileUtils.chmod 0444, @sic.system_cache_file Index: lib/rubygems/source_index.rb =================================================================== --- lib/rubygems/source_index.rb (revision 1692) +++ lib/rubygems/source_index.rb (working copy) @@ -169,6 +169,7 @@ # Add gem specifications to the source index. def add_specs(*gem_specs) + gem_specs = gem_specs.first if gem_specs.first.kind_of? Array gem_specs.each do |spec| add_spec spec end Index: lib/rubygems/source_info_cache.rb =================================================================== --- lib/rubygems/source_info_cache.rb (revision 1692) +++ lib/rubygems/source_info_cache.rb (working copy) @@ -147,7 +147,7 @@ latest = sice.source_index.latest_specs new_si = Gem::SourceIndex.new - new_si.add_specs(*latest) + new_si.add_specs(latest) latest_sice = Gem::SourceInfoCacheEntry.new new_si, sice.size latest_cache_data[repo] = latest_sice
From the Design Piracy series on my blog: