Permalink
Browse files

Switched from nil to empty string for unfetched specs.

Switched tests to assert against latest_specs, since that's default.
Added unmodified fetch tests. (PING)
Fixed fetch_path to set loaded correctly. Brought commented out code back.
Added mtime to fetch_path.


git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1803 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
1 parent 4cd64c7 commit afa5e76591a6c3f2e7085b77946ea19304f14c40 zenspider committed Jun 24, 2008
@@ -132,7 +132,7 @@ def download(spec, source_uri, install_dir = Gem.dir)
##
# Downloads +uri+ and returns it as a String.
- def fetch_path(uri)
+ def fetch_path(uri, mtime = nil)
open_uri_or_path(uri) do |input|
data = input.read
data = Gem.gunzip data if uri.to_s =~ /gz$/
@@ -187,15 +187,16 @@ def load_specs(source_uri, file)
spec_path = source_uri + "#{file_name}.gz"
cache_dir = cache_dir spec_path
local_file = File.join(cache_dir, file_name)
+ loaded = false
if File.exist? local_file then
spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file)
- #if spec_dump.nil? then
- # spec_dump = Gem.read_binary local_file
- #else
- # loaded = true
- #end
+ if spec_dump.empty? then
+ spec_dump = Gem.read_binary local_file
+ else
+ loaded = true
+ end
else
spec_dump = @fetcher.fetch_path spec_path
loaded = true
@@ -30,7 +30,7 @@ def initialize
@paths = []
end
- def fetch_path(path)
+ def fetch_path path, mtime = nil
path = path.to_s
@paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
@@ -43,7 +43,7 @@ def fetch_path(path)
if data.respond_to?(:call) then
data.call
else
- data = Gem.gunzip data if path.to_s =~ /gz$/
+ data = Gem.gunzip data if path.to_s =~ /gz$/ unless data.empty?
data
end
end
@@ -415,6 +415,14 @@ def fetcher.open_uri_or_path(uri);
assert_equal 'uri', e.uri
end
+ def test_fetch_path_unmodified
+ fetcher = Gem::RemoteFetcher.new nil
+ util_stub_connection_for o(:request => o(:body => '', :code => 304,
+ :date => Time.at(0).to_s))
+
+ assert_equal '', fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
+ end
+
def test_get_proxy_from_env_empty
orig_env_HTTP_PROXY = ENV['HTTP_PROXY']
orig_env_http_proxy = ENV['http_proxy']
@@ -280,7 +280,7 @@ def test_load_specs
end
def test_load_specs_cached
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = ''
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
' ' * Marshal.dump(@latest_specs).length
@@ -294,9 +294,9 @@ def test_load_specs_cached
Marshal.dump @latest_specs, io
end
- specs = @sf.load_specs @uri, 'latest_specs'
+ latest_specs = @sf.load_specs @uri, 'latest_specs'
- assert_equal @specs, specs
+ assert_equal @latest_specs, latest_specs
end
end

0 comments on commit afa5e76

Please sign in to comment.