diff --git a/CHANGELOG.md b/CHANGELOG.md index 2351a13..7001eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/cocoapods-downloader.rb b/lib/cocoapods-downloader.rb index 08d7ee0..7895fc0 100644 --- a/lib/cocoapods-downloader.rb +++ b/lib/cocoapods-downloader.rb @@ -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 diff --git a/lib/cocoapods-downloader/http.rb b/lib/cocoapods-downloader/http.rb index 90139c0..4d21ff0 100644 --- a/lib/cocoapods-downloader/http.rb +++ b/lib/cocoapods-downloader/http.rb @@ -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 diff --git a/spec/cocoapods-downloaders_spec.rb b/spec/cocoapods-downloaders_spec.rb index 492aa25..9bc05d3 100644 --- a/spec/cocoapods-downloaders_spec.rb +++ b/spec/cocoapods-downloaders_spec.rb @@ -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 @@ -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 diff --git a/spec/http_spec.rb b/spec/http_spec.rb index 0938213..3c79f56 100644 --- a/spec/http_spec.rb +++ b/spec/http_spec.rb @@ -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' @@ -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) @@ -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