Commit 3c7c2d8b authored by Marius Rackwitz's avatar Marius Rackwitz

[Cache] Ensure to verify cached specification

Even when cached_spec isn't used further with local podspecs, it still must be read from file to verify that it was correctly written before, because that also indicates that the cached pod is valid.
parent b883987d
......@@ -76,10 +76,10 @@ module Pod
# was found in the download cache.
#
def cached_pod(request)
cached_spec = cached_spec(request)
path = path_for_pod(request)
spec_path = path_for_spec(request)
spec = request.spec || cached_spec(request)
return unless spec && path.directory? && spec_path.file?
return unless cached_spec && path.directory?
spec = request.spec || cached_spec
Response.new(path, spec, request.params)
end
......@@ -92,6 +92,8 @@ module Pod
def cached_spec(request)
path = path_for_spec(request)
path.file? && Specification.from_file(path)
rescue JSON::ParserError
nil
end
# @param [Request] request
......
......@@ -75,6 +75,24 @@ module Pod
end
describe 'when the cache is incomplete' do
shared 'it falls back to download the pod' do
describe 'when downloading a released pod' do
it 'does download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@request)
end
end
describe 'when downloading an unreleased pod' do
it 'does download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@unreleased_request)
end
end
end
before do
[@request, @unreleased_request].each do |request|
path_for_pod = @cache.send(:path_for_pod, request)
......@@ -86,20 +104,20 @@ module Pod
end
end
describe 'when downloading a released pod' do
it 'does download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@request)
end
describe 'because the spec is missing' do
behaves_like 'it falls back to download the pod'
end
describe 'when downloading an unreleased pod' do
it 'does download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@unreleased_request)
describe 'because the spec is invalid' do
before do
[@request, @unreleased_request].each do |request|
path_for_spec = @cache.send(:path_for_spec, request)
path_for_spec.dirname.mkpath
path_for_spec.open('w') { |f| f << '{' }
end
end
behaves_like 'it falls back to download the pod'
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment