Skip to content

Commit

Permalink
Be robust agains string keys
Browse files Browse the repository at this point in the history
Closes #25
  • Loading branch information
fabiopelosin committed May 20, 2014
1 parent c1e2527 commit 22aef18
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Master

* Robustness against string keys.
[Fabio Pelosin](https://github.com/irrationalfab)
[#25](https://github.com/CocoaPods/cocoapods-downloader/issues/25)

## 0.6.0

###### Enhancements
Expand Down
2 changes: 2 additions & 0 deletions lib/cocoapods-downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def self.strategy_from_options(options)
# global options for the Downloader cache?
#
def self.for_target(target_path, options)
options = Hash[options.map{ |k, v| [k.to_sym, v] }]

if target_path.nil?
raise DownloaderError, 'No target path provided.'
end
Expand Down
6 changes: 5 additions & 1 deletion lib/cocoapods-downloader/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def download_head!
end

def type
options[:type] || type_with_url(url)
if options[:type]
options[:type].to_sym
else
type_with_url(url)
end
end

# @note The archive is flattened if it contains only one folder and its
Expand Down
10 changes: 10 additions & 0 deletions spec/cocoapods-downloaders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Downloader
end

describe '::for_target' do

it 'returns the Git downloader' do
concrete = @subject.for_target(tmp_folder, :git => 'url')
concrete.class.should == @subject::Git
Expand Down Expand Up @@ -69,6 +70,15 @@ module Downloader
concrete = @subject.for_target(tmp_folder, :git => 'url')
concrete.url.should == 'url'
end


it 'converts the keys of the options to symbols' do
options = {'http' => 'url', 'type' => 'zip'}
concrete = @subject.for_target(tmp_folder, options)
concrete.class.should == @subject::Http
concrete.options.should == {:type=>"zip"}
end

end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Downloader
Dir.glob(tmp_folder + '*').count.should == 8 + 1 + 1
end

# TODO: slow 90.6 s
it 'moves unpacked contents to parent dir when archive contains only a folder (#727)' do
downloader = Downloader.for_target(tmp_folder,
:http => 'http://www.openssl.org/source/openssl-1.0.0a.tar.gz'
Expand All @@ -61,12 +62,14 @@ module Downloader
lambda { downloader.download }.should.raise DownloaderError
end

# TODO: slow 109.7 s
it 'should verify that the downloaded file matches a sha1 hash' do
options = { :http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.zip', :sha1 => 'fb62ffebfaa5b722fc50f09458aacf617a5b0177' }
downloader = Downloader.for_target(tmp_folder, options)
lambda { downloader.download }.should.not.raise DownloaderError
end

# TODO: slow 88.1 s
it 'should fail if the sha1 hash does not match' do
options = { :http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.zip', :sha1 => 'invalid_sha1_hash' }
downloader = Downloader.for_target(tmp_folder, options)
Expand Down Expand Up @@ -143,6 +146,11 @@ module Downloader
lambda { downloader.download }.should.raise Http::UnsupportedFileTypeError
end

it 'detects the file type if specified with a string' do
options = { :http => 'https://file', :type => 'zip' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :zip
end
end
end
end

0 comments on commit 22aef18

Please sign in to comment.