1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
Index: test/test_gem_source_info_cache.rb
===================================================================
@@ -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
===================================================================
@@ -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
===================================================================
@@ -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
|