Commit dcc87e5e authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Cache] Add specs for response for uncached pod

parent d0ef6973
......@@ -80,17 +80,18 @@ module Pod
result.checkout_options = download(request.name, target, request.params, request.head?)
if request.released_pod?
result.spec = request.spec
result.location = destination = path_for_pod(request, :params => result.checkout_options)
copy_and_clean(target, destination, request.spec)
write_spec(request.spec, path_for_spec(request, :params => result.checkout_options))
else
podspecs = Sandbox::PodspecFinder.new(target).podspecs
podspecs[request.name] = request.spec if request.spec
podspecs.each do |_, spec|
destination = path_for_pod(request, :name => spec.name, :params => result.checkout_options)
podspecs.each do |name, spec|
destination = path_for_pod(request, :name => name, :params => result.checkout_options)
copy_and_clean(target, destination, spec)
write_spec(spec, path_for_spec(request, :name => spec.name, :params => result.checkout_options))
if request.name == spec.name
write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options))
if request.name == name
result.location = destination
result.spec = spec
end
......
......@@ -26,7 +26,6 @@ module Pod
attr_reader :head
alias_method :head?, :head
# @param [Specification,Nil] spec
# see {#spec}
#
......@@ -61,13 +60,13 @@ module Pod
# @return [String] The slug used to store the files resulting from this
# download request.
#
def slug(name: self.name, params: self.params)
def slug(name: self.name, params: self.params, spec: self.spec)
checksum = spec && spec.checksum && '-' << spec.checksum[0, 5]
if released_pod?
checksum = spec.checksum && '-' << spec.checksum[0, 5]
"Release/#{name}/#{spec.version}#{checksum}"
else
opts = params.to_a.sort_by(&:first).map { |k, v| "#{k}=#{v}" }.join('-').gsub(/(#{Regexp.escape File::SEPARATOR})+/, '+')
"External/#{name}/#{opts}"
"External/#{name}/#{opts}#{checksum}"
end
end
......
......@@ -7,6 +7,12 @@ module Pod
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@spec.source = { :git => SpecHelper.fixture('banana-lib') }
@request = Downloader::Request.new(:spec => @spec, :released => true)
@stub_download = lambda do |cache, &blk|
cache.define_singleton_method(:download) do |name, target, params, head|
FileUtils.mkdir_p target
Dir.chdir(target) { blk.call }
end
end
end
it 'returns the root' do
......@@ -14,13 +20,37 @@ module Pod
end
describe 'when the download is not cached' do
it 'downloads the source' do
Downloader::Git.any_instance.expects(:download)
Downloader::Git.any_instance.expects(:checkout_options).returns(@spec.source)
@cache.download_pod(@request)
describe 'when downloading a released pod' do
it 'downloads the source' do
Downloader::Git.any_instance.expects(:download)
Downloader::Git.any_instance.expects(:checkout_options).returns(@spec.source)
response = @cache.download_pod(@request)
response.should == Downloader::Response.new(@cache.root + @request.slug, @spec, @spec.source)
end
end
describe 'when downloading an un-released pod' do
before do
@request = Downloader::Request.new(:name => 'BananaLib', :params => @spec.source)
@stub_download.call @cache do
File.open('BananaLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json }
File.open('OrangeLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json.sub(/"name": "BananaLib"/, '"name": "OrangeLib"') }
@spec.source
end
end
it 'downloads the source' do
@cache.expects(:copy_and_clean).twice
response = @cache.download_pod(@request)
response.should == Downloader::Response.new(@cache.root + @request.slug, @spec, @spec.source)
end
end
end
describe 'when the download is cached' do
end
after do
@cache.root.rmtree
end
......
......@@ -9,7 +9,7 @@ module Pod
#--------------------------------------#
describe 'Validation' do
it "validates request initialization" do
it 'validates request initialization' do
options = [
{ :spec => nil, :name => nil },
{ :spec => nil, :released => true },
......
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