rubygems-update 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (172) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +248 -0
  3. data/README +2 -0
  4. data/Rakefile +47 -23
  5. data/bin/gem +9 -4
  6. data/bin/update_rubygems +15 -1
  7. data/examples/application/bin/myapp +0 -0
  8. data/lib/rubygems.rb +506 -373
  9. data/lib/rubygems/builder.rb +14 -7
  10. data/lib/rubygems/command.rb +9 -9
  11. data/lib/rubygems/command_manager.rb +1 -0
  12. data/lib/rubygems/commands/cleanup_command.rb +67 -69
  13. data/lib/rubygems/commands/environment_command.rb +16 -10
  14. data/lib/rubygems/commands/fetch_command.rb +7 -9
  15. data/lib/rubygems/commands/install_command.rb +9 -3
  16. data/lib/rubygems/commands/list_command.rb +2 -4
  17. data/lib/rubygems/commands/mirror_command.rb +1 -1
  18. data/lib/rubygems/commands/query_command.rb +52 -5
  19. data/lib/rubygems/commands/sources_command.rb +19 -10
  20. data/lib/rubygems/commands/specification_command.rb +10 -6
  21. data/lib/rubygems/commands/uninstall_command.rb +23 -6
  22. data/lib/rubygems/commands/unpack_command.rb +15 -3
  23. data/lib/rubygems/commands/update_command.rb +27 -25
  24. data/lib/rubygems/custom_require.rb +1 -1
  25. data/lib/rubygems/defaults.rb +8 -1
  26. data/lib/rubygems/dependency_installer.rb +72 -104
  27. data/lib/rubygems/digest/digest_adapter.rb +0 -0
  28. data/lib/rubygems/digest/md5.rb +0 -0
  29. data/lib/rubygems/digest/sha1.rb +0 -0
  30. data/lib/rubygems/digest/sha2.rb +0 -0
  31. data/lib/rubygems/exceptions.rb +22 -1
  32. data/lib/rubygems/format.rb +16 -10
  33. data/lib/rubygems/indexer.rb +46 -33
  34. data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
  35. data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  36. data/lib/rubygems/indexer/master_index_builder.rb +9 -8
  37. data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
  38. data/lib/rubygems/install_update_options.rb +7 -1
  39. data/lib/rubygems/installer.rb +8 -5
  40. data/lib/rubygems/package.rb +17 -774
  41. data/lib/rubygems/package/f_sync_dir.rb +24 -0
  42. data/lib/rubygems/package/tar_header.rb +245 -0
  43. data/lib/rubygems/package/tar_input.rb +219 -0
  44. data/lib/rubygems/package/tar_output.rb +143 -0
  45. data/lib/rubygems/package/tar_reader.rb +86 -0
  46. data/lib/rubygems/package/tar_reader/entry.rb +99 -0
  47. data/lib/rubygems/package/tar_writer.rb +180 -0
  48. data/lib/rubygems/remote_fetcher.rb +131 -16
  49. data/lib/rubygems/requirement.rb +2 -0
  50. data/lib/rubygems/rubygems_version.rb +1 -1
  51. data/lib/rubygems/security.rb +1 -0
  52. data/lib/rubygems/server.rb +85 -104
  53. data/lib/rubygems/source_index.rb +412 -329
  54. data/lib/rubygems/source_info_cache.rb +232 -99
  55. data/lib/rubygems/source_info_cache_entry.rb +14 -4
  56. data/lib/rubygems/specification.rb +9 -10
  57. data/lib/rubygems/timer.rb +0 -0
  58. data/lib/rubygems/uninstaller.rb +56 -32
  59. data/lib/rubygems/user_interaction.rb +4 -10
  60. data/lib/rubygems/validator.rb +0 -0
  61. data/scripts/gemdoc.rb +0 -0
  62. data/scripts/specdoc.rb +0 -0
  63. data/setup.rb +56 -19
  64. data/test/gem_installer_test_case.rb +86 -0
  65. data/test/gem_installer_test_case.rbc +0 -0
  66. data/test/gem_package_tar_test_case.rb +146 -0
  67. data/test/gem_package_tar_test_case.rbc +0 -0
  68. data/test/gemutilities.rb +123 -38
  69. data/test/gemutilities.rbc +0 -0
  70. data/test/mockgemui.rb +5 -13
  71. data/test/mockgemui.rbc +0 -0
  72. data/test/private_key.pem +27 -0
  73. data/test/public_cert.pem +20 -0
  74. data/test/simple_gem.rbc +0 -0
  75. data/test/test_config.rbc +0 -0
  76. data/test/test_gem.rb +46 -4
  77. data/test/test_gem.rbc +0 -0
  78. data/test/test_gem_builder.rbc +0 -0
  79. data/test/test_gem_command.rbc +0 -0
  80. data/test/test_gem_command_manager.rb +4 -2
  81. data/test/test_gem_command_manager.rbc +0 -0
  82. data/test/test_gem_commands_build_command.rbc +0 -0
  83. data/test/test_gem_commands_cert_command.rb +5 -1
  84. data/test/test_gem_commands_cert_command.rbc +0 -0
  85. data/test/test_gem_commands_check_command.rbc +0 -0
  86. data/test/test_gem_commands_contents_command.rbc +0 -0
  87. data/test/test_gem_commands_dependency_command.rbc +0 -0
  88. data/test/test_gem_commands_environment_command.rb +17 -1
  89. data/test/test_gem_commands_environment_command.rbc +0 -0
  90. data/test/test_gem_commands_fetch_command.rb +6 -5
  91. data/test/test_gem_commands_fetch_command.rbc +0 -0
  92. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  93. data/test/test_gem_commands_install_command.rb +36 -28
  94. data/test/test_gem_commands_install_command.rbc +0 -0
  95. data/test/test_gem_commands_mirror_command.rbc +0 -0
  96. data/test/test_gem_commands_pristine_command.rbc +0 -0
  97. data/test/test_gem_commands_query_command.rb +143 -19
  98. data/test/test_gem_commands_query_command.rbc +0 -0
  99. data/test/test_gem_commands_server_command.rb +1 -1
  100. data/test/test_gem_commands_server_command.rbc +0 -0
  101. data/test/test_gem_commands_sources_command.rb +67 -9
  102. data/test/test_gem_commands_sources_command.rbc +0 -0
  103. data/test/test_gem_commands_specification_command.rb +3 -2
  104. data/test/test_gem_commands_specification_command.rbc +0 -0
  105. data/test/test_gem_commands_unpack_command.rb +46 -4
  106. data/test/test_gem_commands_unpack_command.rbc +0 -0
  107. data/test/test_gem_commands_update_command.rb +174 -0
  108. data/test/test_gem_commands_update_command.rbc +0 -0
  109. data/test/test_gem_config_file.rbc +0 -0
  110. data/test/test_gem_dependency.rbc +0 -0
  111. data/test/test_gem_dependency_installer.rb +172 -187
  112. data/test/test_gem_dependency_installer.rbc +0 -0
  113. data/test/test_gem_dependency_list.rbc +0 -0
  114. data/test/test_gem_digest.rb +0 -0
  115. data/test/test_gem_digest.rbc +0 -0
  116. data/test/test_gem_doc_manager.rbc +0 -0
  117. data/test/test_gem_ext_configure_builder.rb +9 -6
  118. data/test/test_gem_ext_configure_builder.rbc +0 -0
  119. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  120. data/test/test_gem_ext_rake_builder.rbc +0 -0
  121. data/test/test_gem_format.rb +1 -1
  122. data/test/test_gem_format.rbc +0 -0
  123. data/test/test_gem_gem_path_searcher.rbc +0 -0
  124. data/test/test_gem_gem_runner.rbc +0 -0
  125. data/test/test_gem_indexer.rb +7 -2
  126. data/test/test_gem_indexer.rbc +0 -0
  127. data/test/test_gem_install_update_options.rbc +0 -0
  128. data/test/test_gem_installer.rb +5 -84
  129. data/test/test_gem_installer.rbc +0 -0
  130. data/test/test_gem_local_remote_options.rbc +0 -0
  131. data/test/test_gem_outdated_command.rbc +0 -0
  132. data/test/test_gem_package_tar_header.rb +137 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rb +119 -0
  135. data/test/test_gem_package_tar_input.rbc +0 -0
  136. data/test/test_gem_package_tar_output.rb +104 -0
  137. data/test/test_gem_package_tar_output.rbc +0 -0
  138. data/test/test_gem_package_tar_reader.rb +53 -0
  139. data/test/test_gem_package_tar_reader.rbc +0 -0
  140. data/test/test_gem_package_tar_reader_entry.rb +116 -0
  141. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  142. data/test/test_gem_package_tar_writer.rb +151 -0
  143. data/test/test_gem_package_tar_writer.rbc +0 -0
  144. data/test/test_gem_platform.rbc +0 -0
  145. data/test/test_gem_remote_fetcher.rb +189 -17
  146. data/test/test_gem_remote_fetcher.rbc +0 -0
  147. data/test/test_gem_requirement.rbc +0 -0
  148. data/test/test_gem_server.rb +13 -12
  149. data/test/test_gem_server.rbc +0 -0
  150. data/test/test_gem_source_index.rb +305 -56
  151. data/test/test_gem_source_index.rbc +0 -0
  152. data/test/test_gem_source_info_cache.rb +179 -53
  153. data/test/test_gem_source_info_cache.rbc +0 -0
  154. data/test/test_gem_source_info_cache_entry.rb +41 -10
  155. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  156. data/test/test_gem_specification.rb +7 -7
  157. data/test/test_gem_specification.rbc +0 -0
  158. data/test/test_gem_stream_ui.rbc +0 -0
  159. data/test/test_gem_uninstaller.rb +43 -0
  160. data/test/test_gem_uninstaller.rbc +0 -0
  161. data/test/test_gem_validator.rbc +0 -0
  162. data/test/test_gem_version.rb +1 -1
  163. data/test/test_gem_version.rbc +0 -0
  164. data/test/test_gem_version_option.rbc +0 -0
  165. data/test/test_kernel.rb +1 -0
  166. data/test/test_kernel.rbc +0 -0
  167. metadata +85 -8
  168. metadata.gz.sig +0 -0
  169. data/lib/rubygems/gem_open_uri.rb +0 -7
  170. data/lib/rubygems/open-uri.rb +0 -773
  171. data/test/test_open_uri.rb +0 -13
  172. data/test/test_package.rb +0 -608
@@ -53,10 +53,10 @@ class TestGemServer < RubyGemTestCase
53
53
  assert_equal 200, @res.status, @res.body
54
54
  assert @res['date']
55
55
  assert_equal 'text/plain', @res['content-type']
56
- yaml = Zlib::Inflate.inflate(@res.body)
57
- assert_match %r|Gem::Specification|, yaml
58
- assert_match %r|name: a|, yaml
59
- assert_match %r|version: "1"|, yaml
56
+
57
+ spec = YAML.load Zlib::Inflate.inflate(@res.body)
58
+ assert_equal 'a', spec.name
59
+ assert_equal Gem::Version.new(1), spec.version
60
60
  end
61
61
 
62
62
  def test_quick_a_1_mswin32_gemspec_rz
@@ -72,10 +72,11 @@ class TestGemServer < RubyGemTestCase
72
72
  assert_equal 200, @res.status, @res.body
73
73
  assert @res['date']
74
74
  assert_equal 'text/plain', @res['content-type']
75
- yaml = Zlib::Inflate.inflate(@res.body)
76
- assert_match %r|Gem::Specification|, yaml
77
- assert_match %r|name: a|, yaml
78
- assert_match %r|version: "1"|, yaml
75
+
76
+ spec = YAML.load Zlib::Inflate.inflate(@res.body)
77
+ assert_equal 'a', spec.name
78
+ assert_equal Gem::Version.new(1), spec.version
79
+ assert_equal Gem::Platform.local, spec.platform
79
80
  end
80
81
 
81
82
  def test_quick_common_substrings
@@ -91,10 +92,10 @@ class TestGemServer < RubyGemTestCase
91
92
  assert_equal 200, @res.status, @res.body
92
93
  assert @res['date']
93
94
  assert_equal 'text/plain', @res['content-type']
94
- yaml = Zlib::Inflate.inflate @res.body
95
- assert_match %r|Gem::Specification|, yaml
96
- assert_match %r|name: a$|, yaml
97
- assert_match %r|version: "1"|, yaml
95
+
96
+ spec = YAML.load Zlib::Inflate.inflate(@res.body)
97
+ assert_equal 'a', spec.name
98
+ assert_equal Gem::Version.new(1), spec.version
98
99
  end
99
100
 
100
101
  def test_quick_z_9_gemspec_rz
Binary file
@@ -36,7 +36,8 @@ class TestGemSourceIndex < RubyGemTestCase
36
36
 
37
37
  use_ui @ui do
38
38
  fetched_index = @source_index.fetch_bulk_index @uri
39
- assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
39
+ assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
40
+ @c1_2.full_name].sort,
40
41
  fetched_index.gems.map { |n,s| n }.sort
41
42
  end
42
43
 
@@ -82,7 +83,8 @@ class TestGemSourceIndex < RubyGemTestCase
82
83
 
83
84
  use_ui @ui do
84
85
  fetched_index = @source_index.fetch_bulk_index @uri
85
- assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
86
+ assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
87
+ @c1_2.full_name].sort,
86
88
  fetched_index.gems.map { |n,s| n }.sort
87
89
  end
88
90
 
@@ -105,7 +107,8 @@ class TestGemSourceIndex < RubyGemTestCase
105
107
 
106
108
  use_ui @ui do
107
109
  fetched_index = @source_index.fetch_bulk_index @uri
108
- assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
110
+ assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
111
+ @c1_2.full_name].sort,
109
112
  fetched_index.gems.map { |n,s| n }.sort
110
113
  end
111
114
 
@@ -123,7 +126,8 @@ class TestGemSourceIndex < RubyGemTestCase
123
126
  util_setup_bulk_fetch false
124
127
  use_ui @ui do
125
128
  fetched_index = @source_index.fetch_bulk_index @uri
126
- assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
129
+ assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
130
+ @c1_2.full_name].sort,
127
131
  fetched_index.gems.map { |n,s| n }.sort
128
132
  end
129
133
 
@@ -136,11 +140,32 @@ class TestGemSourceIndex < RubyGemTestCase
136
140
  end
137
141
 
138
142
  def test_fetch_quick_index
139
- quick_index = util_zip @gem_names
140
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
143
+ index = util_zip @gem_names
144
+ latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
145
+
146
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = index
147
+ @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = latest_index
148
+
149
+ quick_index = @source_index.fetch_quick_index @uri, false
150
+ assert_equal [@a2.full_name, @b2.full_name].sort,
151
+ quick_index.sort
152
+
153
+ paths = @fetcher.paths
154
+
155
+ assert_equal "#{@gem_repo}/quick/latest_index.rz", paths.shift
156
+
157
+ assert paths.empty?, paths.join(', ')
158
+ end
159
+
160
+ def test_fetch_quick_index_all
161
+ index = util_zip @gem_names
162
+ latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
163
+
164
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = index
165
+ @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = latest_index
141
166
 
142
- quick_index = @source_index.fetch_quick_index @uri
143
- assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
167
+ quick_index = @source_index.fetch_quick_index @uri, true
168
+ assert_equal [@a1.full_name, @a2.full_name, @b2.full_name].sort,
144
169
  quick_index.sort
145
170
 
146
171
  paths = @fetcher.paths
@@ -155,7 +180,7 @@ class TestGemSourceIndex < RubyGemTestCase
155
180
  proc { raise Exception }
156
181
 
157
182
  e = assert_raise Gem::OperationNotSupportedError do
158
- @source_index.fetch_quick_index @uri
183
+ @source_index.fetch_quick_index @uri, true
159
184
  end
160
185
 
161
186
  assert_equal 'No quick index found: Exception', e.message
@@ -167,41 +192,201 @@ class TestGemSourceIndex < RubyGemTestCase
167
192
  assert paths.empty?, paths.join(', ')
168
193
  end
169
194
 
195
+ def test_fetch_quick_index_fallback
196
+ index = util_zip @gem_names
197
+
198
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = index
199
+
200
+ quick_index = @source_index.fetch_quick_index @uri, false
201
+ assert_equal @gem_names.split, quick_index.sort
202
+
203
+ paths = @fetcher.paths
204
+
205
+ assert_equal "#{@gem_repo}/quick/latest_index.rz", paths.shift
206
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
207
+
208
+ assert paths.empty?, paths.join(', ')
209
+ end
210
+
211
+ def test_fetch_quick_index_subdir
212
+ latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
213
+ repo = URI.parse "#{@gem_repo}/~nobody/mirror/"
214
+
215
+ @fetcher.data["#{repo}quick/latest_index.rz"] = latest_index
216
+
217
+ quick_index = @source_index.fetch_quick_index repo, false
218
+ assert_equal [@a2.full_name, @b2.full_name].sort,
219
+ quick_index.sort
220
+
221
+ paths = @fetcher.paths
222
+
223
+ assert_equal "#{repo}quick/latest_index.rz", paths.shift
224
+
225
+ assert paths.empty?, paths.join(', ')
226
+ end
227
+
228
+ def test_fetch_single_spec
229
+ a1_spec_url = "#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
230
+ @fetcher.data[a1_spec_url] = util_zip Marshal.dump(@a1)
231
+
232
+ spec = @source_index.send :fetch_single_spec, URI.parse(@gem_repo),
233
+ @a1.full_name
234
+
235
+ assert_equal @a1.full_name, spec.full_name
236
+
237
+ paths = @fetcher.paths
238
+
239
+ assert_equal a1_spec_url, paths.shift
240
+
241
+ assert paths.empty?, paths.join(', ')
242
+ end
243
+
244
+ def test_fetch_single_spec_subdir
245
+ repo = URI.parse "#{@gem_repo}/~nobody/mirror/"
246
+
247
+ a1_spec_url = "#{repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
248
+ @fetcher.data[a1_spec_url] = util_zip Marshal.dump(@a1)
249
+
250
+ spec = @source_index.send :fetch_single_spec, repo, @a1.full_name
251
+
252
+ assert_equal @a1.full_name, spec.full_name
253
+
254
+ paths = @fetcher.paths
255
+
256
+ assert_equal a1_spec_url, paths.shift
257
+
258
+ assert paths.empty?, paths.join(', ')
259
+ end
260
+
261
+ def test_fetch_single_spec_yaml
262
+ a1_spec_url = "#{@gem_repo}/quick/#{@a1.full_name}.gemspec.rz"
263
+ @fetcher.data[a1_spec_url] = util_zip @a1.to_yaml
264
+
265
+ repo = URI.parse @gem_repo
266
+
267
+ spec = @source_index.send :fetch_single_spec, repo, @a1.full_name
268
+
269
+ assert_equal @a1.full_name, spec.full_name
270
+
271
+ paths = @fetcher.paths
272
+
273
+ assert_equal "#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz", paths.shift
274
+ assert_equal a1_spec_url, paths.shift
275
+
276
+ assert paths.empty?, paths.join(', ')
277
+ end
278
+
279
+ def test_fetch_single_spec_yaml_subdir
280
+ repo = URI.parse "#{@gem_repo}/~nobody/mirror/"
281
+
282
+ a1_spec_url = "#{repo}quick/#{@a1.full_name}.gemspec.rz"
283
+ @fetcher.data[a1_spec_url] = util_zip @a1.to_yaml
284
+
285
+ spec = @source_index.send :fetch_single_spec, repo, @a1.full_name
286
+
287
+ assert_equal @a1.full_name, spec.full_name
288
+
289
+ paths = @fetcher.paths
290
+
291
+ assert_equal "#{repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz", paths.shift
292
+ assert_equal a1_spec_url, paths.shift
293
+
294
+ assert paths.empty?, paths.join(', ')
295
+ end
296
+
170
297
  def test_find_missing
171
- missing = @source_index.find_missing [@gem3.full_name]
172
- assert_equal [@gem3.full_name], missing
298
+ missing = @source_index.find_missing [@b2.full_name]
299
+ assert_equal [@b2.full_name], missing
173
300
  end
174
301
 
175
302
  def test_find_missing_none_missing
176
- missing = @source_index.find_missing @gem_names.split
303
+ missing = @source_index.find_missing [
304
+ @a1.full_name, @a2.full_name, @c1_2.full_name
305
+ ]
306
+
177
307
  assert_equal [], missing
178
308
  end
179
309
 
180
310
  def test_latest_specs
181
- spec = quick_gem @gem1.name, '1'
182
- @source_index.add_spec spec
311
+ p1_ruby = quick_gem 'p', '1'
312
+ p1_platform = quick_gem 'p', '1' do |spec|
313
+ spec.platform = Gem::Platform::CURRENT
314
+ end
315
+
316
+ a1_platform = quick_gem @a1.name, (@a1.version) do |s|
317
+ s.platform = Gem::Platform.new 'x86-my_platform1'
318
+ end
319
+
320
+ a2_platform = quick_gem @a2.name, (@a2.version) do |s|
321
+ s.platform = Gem::Platform.new 'x86-my_platform1'
322
+ end
323
+
324
+ a2_platform_other = quick_gem @a2.name, (@a2.version) do |s|
325
+ s.platform = Gem::Platform.new 'x86-other_platform1'
326
+ end
327
+
328
+ a3_platform_other = quick_gem @a2.name, (@a2.version.bump) do |s|
329
+ s.platform = Gem::Platform.new 'x86-other_platform1'
330
+ end
331
+
332
+ @source_index.add_spec p1_ruby
333
+ @source_index.add_spec p1_platform
334
+ @source_index.add_spec a1_platform
335
+ @source_index.add_spec a2_platform
336
+ @source_index.add_spec a2_platform_other
337
+ @source_index.add_spec a3_platform_other
183
338
 
184
339
  expected = [
185
- @gem1.full_name,
186
- @gem2.full_name,
187
- @gem4.full_name,
340
+ @a2.full_name,
341
+ a2_platform.full_name,
342
+ a3_platform_other.full_name,
343
+ @c1_2.full_name,
344
+ @a_evil9.full_name,
345
+ p1_ruby.full_name,
346
+ p1_platform.full_name,
188
347
  ].sort
189
348
 
190
- assert_equal expected, @source_index.latest_specs.map { |s| s.full_name }.sort
349
+ latest_specs = @source_index.latest_specs.map { |s| s.full_name }.sort
350
+
351
+ assert_equal expected, latest_specs
352
+ end
353
+
354
+ def test_load_gems_in
355
+ spec_dir1 = File.join @gemhome, 'specifications'
356
+ spec_dir2 = File.join @tempdir, 'gemhome2', 'specifications'
357
+
358
+ FileUtils.rm_r spec_dir1
359
+
360
+ FileUtils.mkdir_p spec_dir1
361
+ FileUtils.mkdir_p spec_dir2
362
+
363
+ a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end
364
+ a2 = quick_gem 'a', '1' do |spec| spec.author = 'author 2' end
365
+
366
+ File.open File.join(spec_dir1, "#{a1.full_name}.gemspec"), 'w' do |fp|
367
+ fp.write a1.to_ruby
368
+ end
369
+
370
+ File.open File.join(spec_dir2, "#{a2.full_name}.gemspec"), 'w' do |fp|
371
+ fp.write a2.to_ruby
372
+ end
373
+
374
+ @source_index.load_gems_in spec_dir1, spec_dir2
375
+
376
+ assert_equal a1.author, @source_index.specification(a1.full_name).author
191
377
  end
192
378
 
193
379
  def test_outdated
194
- sic = Gem::SourceInfoCache.new
195
- Gem::SourceInfoCache.instance_variable_set :@cache, sic
380
+ util_setup_source_info_cache
196
381
 
197
382
  assert_equal [], @source_index.outdated
198
383
 
199
- updated = quick_gem @gem1.name, (@gem1.version.bump)
384
+ updated = quick_gem @a2.name, (@a2.version.bump)
200
385
  util_setup_source_info_cache updated
201
386
 
202
387
  assert_equal [updated.name], @source_index.outdated
203
388
 
204
- updated_platform = quick_gem @gem1.name, (updated.version.bump) do |s|
389
+ updated_platform = quick_gem @a2.name, (updated.version.bump) do |s|
205
390
  s.platform = Gem::Platform.new 'x86-other_platform1'
206
391
  end
207
392
 
@@ -211,28 +396,36 @@ class TestGemSourceIndex < RubyGemTestCase
211
396
  end
212
397
 
213
398
  def test_remove_extra
214
- @source_index.remove_extra [@gem1.full_name]
215
- assert_equal [@gem1.full_name], @source_index.gems.map { |n,s| n }
399
+ @source_index.add_spec @a1
400
+ @source_index.add_spec @a2
401
+ @source_index.add_spec @pl1
402
+
403
+ @source_index.remove_extra [@a1.full_name, @pl1.full_name]
404
+
405
+ assert_equal [@a1.full_name],
406
+ @source_index.gems.map { |n,s| n }.sort
216
407
  end
217
408
 
218
409
  def test_remove_extra_no_changes
219
- gems = @gem_names.split.sort
410
+ gems = [@a1.full_name, @a2.full_name]
411
+ @source_index.add_spec @a1
412
+ @source_index.add_spec @a2
413
+
220
414
  @source_index.remove_extra gems
415
+
221
416
  assert_equal gems, @source_index.gems.map { |n,s| n }.sort
222
417
  end
223
418
 
224
419
  def test_search
225
- assert_equal [@gem1, @gem4], @source_index.search("gem_one")
226
- assert_equal [@gem1], @source_index.search("gem_one", "= 2")
420
+ assert_equal [@a1, @a2, @a_evil9], @source_index.search('a')
421
+ assert_equal [@a2], @source_index.search('a', '= 2')
227
422
 
228
- assert_equal [], @source_index.search("bogusstring")
229
- assert_equal [], @source_index.search("gem_one", "= 3.2.1")
423
+ assert_equal [], @source_index.search('bogusstring')
424
+ assert_equal [], @source_index.search('a', '= 3')
230
425
 
231
- @a1 = quick_gem 'a', '1'
232
- @a2 = quick_gem 'a', '2'
233
-
234
- source_index = Gem::SourceIndex.new @a1.full_name => @a1,
235
- @a2.full_name => @a2
426
+ source_index = Gem::SourceIndex.new
427
+ source_index.add_spec @a1
428
+ source_index.add_spec @a2
236
429
 
237
430
  assert_equal [@a1], source_index.search(@a1.name, '= 1')
238
431
 
@@ -276,7 +469,7 @@ class TestGemSourceIndex < RubyGemTestCase
276
469
  end
277
470
 
278
471
  def test_specification
279
- assert_equal @gem1, @source_index.specification(@gem1.full_name)
472
+ assert_equal @a1, @source_index.specification(@a1.full_name)
280
473
 
281
474
  assert_nil @source_index.specification("foo-1.2.4")
282
475
  end
@@ -298,9 +491,11 @@ class TestGemSourceIndex < RubyGemTestCase
298
491
  assert_equal [], @source_index.gems.keys.sort
299
492
 
300
493
  use_ui @ui do
301
- @source_index.update @uri
494
+ @source_index.update @uri, true
302
495
 
303
- assert_equal @gem_names.split, @source_index.gems.keys.sort
496
+ assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
497
+ @c1_2.full_name],
498
+ @source_index.gems.keys.sort
304
499
  end
305
500
 
306
501
  paths = @fetcher.paths
@@ -315,15 +510,42 @@ class TestGemSourceIndex < RubyGemTestCase
315
510
  old_gem_conf = Gem.configuration
316
511
  Gem.configuration = Gem::ConfigFile.new([])
317
512
 
513
+ latest_names = [@a2, @a_evil9, @b2, @c1_2].map { |s| s.full_name }
514
+ latest_index = util_zip latest_names.join("\n")
515
+ @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = latest_index
516
+
517
+ marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
518
+ "#{@b2.full_name}.gemspec.rz"
519
+ @fetcher.data[marshal_uri] = util_zip Marshal.dump(@b2)
520
+
521
+ use_ui @ui do
522
+ @source_index.update @uri, false
523
+
524
+ assert_equal latest_names, @source_index.gems.keys.sort
525
+ end
526
+
527
+ paths = @fetcher.paths
528
+ assert_equal "#{@gem_repo}/quick/latest_index.rz", paths.shift
529
+ assert_equal marshal_uri, paths.shift
530
+
531
+ assert paths.empty?, paths.join(', ')
532
+ ensure
533
+ Gem.configuration = old_gem_conf
534
+ end
535
+
536
+ def test_update_incremental_all
537
+ old_gem_conf = Gem.configuration
538
+ Gem.configuration = Gem::ConfigFile.new([])
539
+
318
540
  quick_index = util_zip @all_gem_names.join("\n")
319
541
  @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
320
542
 
321
543
  marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
322
- "#{@gem3.full_name}.gemspec.rz"
323
- @fetcher.data[marshal_uri] = util_zip Marshal.dump(@gem3)
544
+ "#{@b2.full_name}.gemspec.rz"
545
+ @fetcher.data[marshal_uri] = util_zip Marshal.dump(@b2)
324
546
 
325
547
  use_ui @ui do
326
- @source_index.update @uri
548
+ @source_index.update @uri, true
327
549
 
328
550
  assert_equal @all_gem_names, @source_index.gems.keys.sort
329
551
  end
@@ -345,13 +567,13 @@ class TestGemSourceIndex < RubyGemTestCase
345
567
  @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
346
568
 
347
569
  marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
348
- "#{@gem3.full_name}.gemspec.rz"
570
+ "#{@b2.full_name}.gemspec.rz"
349
571
 
350
- yaml_uri = "#{@gem_repo}/quick/#{@gem3.full_name}.gemspec.rz"
351
- @fetcher.data[yaml_uri] = util_zip @gem3.to_yaml
572
+ yaml_uri = "#{@gem_repo}/quick/#{@b2.full_name}.gemspec.rz"
573
+ @fetcher.data[yaml_uri] = util_zip @b2.to_yaml
352
574
 
353
575
  use_ui @ui do
354
- @source_index.update @uri
576
+ @source_index.update @uri, true
355
577
 
356
578
  assert_equal @all_gem_names, @source_index.gems.keys.sort
357
579
  end
@@ -374,16 +596,16 @@ class TestGemSourceIndex < RubyGemTestCase
374
596
  @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
375
597
 
376
598
  marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
377
- "#{@gem3.full_name}.gemspec.rz"
378
- marshal_data = Marshal.dump(@gem3)
599
+ "#{@b2.full_name}.gemspec.rz"
600
+ marshal_data = Marshal.dump(@b2)
379
601
  marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
380
602
  @fetcher.data[marshal_uri] = util_zip marshal_data
381
603
 
382
- yaml_uri = "#{@gem_repo}/quick/#{@gem3.full_name}.gemspec.rz"
383
- @fetcher.data[yaml_uri] = util_zip @gem3.to_yaml
604
+ yaml_uri = "#{@gem_repo}/quick/#{@b2.full_name}.gemspec.rz"
605
+ @fetcher.data[yaml_uri] = util_zip @b2.to_yaml
384
606
 
385
607
  use_ui @ui do
386
- @source_index.update @uri
608
+ @source_index.update @uri, true
387
609
 
388
610
  assert_equal @all_gem_names, @source_index.gems.keys.sort
389
611
  end
@@ -398,22 +620,48 @@ class TestGemSourceIndex < RubyGemTestCase
398
620
  Gem.configuration = old_gem_conf
399
621
  end
400
622
 
623
+ def test_update_subdir
624
+ @gem_repo = @gem_repo + "/subdir"
625
+
626
+ util_setup_bulk_fetch true
627
+
628
+ @source_index.gems.replace({})
629
+ assert_equal [], @source_index.gems.keys.sort
630
+
631
+ uri = @uri.to_s + "/subdir"
632
+
633
+ use_ui @ui do
634
+ @source_index.update uri, true
635
+
636
+ assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
637
+ @c1_2.full_name],
638
+ @source_index.gems.keys.sort
639
+ end
640
+
641
+ paths = @fetcher.paths
642
+
643
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
644
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
645
+
646
+ assert paths.empty?, paths.join(', ')
647
+ end
648
+
401
649
  def test_update_with_missing
402
650
  marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
403
- "#{@gem3.full_name}.gemspec.rz"
404
- dumped = Marshal.dump(@gem3)
651
+ "#{@c1_2.full_name}.gemspec.rz"
652
+ dumped = Marshal.dump @c1_2
405
653
  @fetcher.data[marshal_uri] = util_zip(dumped)
406
654
 
407
655
  use_ui @ui do
408
- @source_index.update_with_missing @uri, [@gem3.full_name]
656
+ @source_index.update_with_missing @uri, [@c1_2.full_name]
409
657
  end
410
658
 
411
- spec = @source_index.specification(@gem3.full_name)
659
+ spec = @source_index.specification(@c1_2.full_name)
412
660
  # We don't care about the equality of undumped attributes
413
- @gem3.files = spec.files
414
- @gem3.loaded_from = spec.loaded_from
661
+ @c1_2.files = spec.files
662
+ @c1_2.loaded_from = spec.loaded_from
415
663
 
416
- assert_equal @gem3, spec
664
+ assert_equal @c1_2, spec
417
665
  end
418
666
 
419
667
  def util_setup_bulk_fetch(compressed)
@@ -427,3 +675,4 @@ class TestGemSourceIndex < RubyGemTestCase
427
675
  end
428
676
 
429
677
  end
678
+