Skip to content

Commit

Permalink
Merge pull request #40 from mbishop-fiksu/master
Browse files Browse the repository at this point in the history
The downloader is no longer confused by params in the URL.
  • Loading branch information
kylef committed Nov 11, 2014
2 parents 5a36760 + 5c2e682 commit dd0eddd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## Master

## 0.7.2
* Fixed fetching from 'dumb' git remotes that don't support shallow clones.
[Michael Bishop](https://github.com/mbishop-fiksu)
[#40](https://github.com/CocoaPods/cocoapods-downloader/pull/40)

###### Enhancements

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ begin
rescue LoadError
$stderr.puts "\033[0;31m" \
'[!] Some Rake tasks haven been disabled because the environment' \
' couldnt be loaded. Be sure to run `rake bootstrap` first.' \
' couldn\'t be loaded. Be sure to run `rake bootstrap` first.' \
"\e[0m"
$stderr.puts e.message
$stderr.puts e.backtrace
Expand Down
11 changes: 6 additions & 5 deletions lib/cocoapods-downloader/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ def should_flatten?
end

def type_with_url(url)
if url =~ /.zip$/
path = URI.parse(url).path
if path =~ /.zip$/
:zip
elsif url =~ /.(tgz|tar\.gz)$/
elsif path =~ /.(tgz|tar\.gz)$/
:tgz
elsif url =~ /.tar$/
elsif path =~ /.tar$/
:tar
elsif url =~ /.(tbz|tar\.bz2)$/
elsif path =~ /.(tbz|tar\.bz2)$/
:tbz
elsif url =~ /.(txz|tar\.xz)$/
elsif path =~ /.(txz|tar\.xz)$/
:txz
else
nil
Expand Down
28 changes: 17 additions & 11 deletions spec/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ module Downloader
tmp_folder('lib/file.txt').read.strip.should =~ /This is a fixture/
end

it 'ignores any params in the url' do
options = { :http => "#{@fixtures_url}/lib.zip?param=value" }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :zip
end

it 'should download file and unzip it when the target folder name contains quotes or spaces' do
options = { :http => "#{@fixtures_url}/lib.zip" }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
Expand Down Expand Up @@ -103,69 +109,69 @@ module Downloader
#-------------------------------------------------------------------------#

it 'detects zip files' do
options = { :http => 'https://file.zip' }
options = { :http => 'https://foo/file.zip' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :zip
end

it 'detects tar files' do
options = { :http => 'https://file.tar' }
options = { :http => 'https://foo/file.tar' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :tar
end

it 'detects tgz files' do
options = { :http => 'https://file.tgz' }
options = { :http => 'https://foo/file.tgz' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :tgz
end

it 'detects tbz files' do
options = { :http => 'https://file.tbz' }
options = { :http => 'https://foo/file.tbz' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :tbz
end

it 'detects txz files' do
options = { :http => 'https://file.txz' }
options = { :http => 'https://foo/file.txz' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :txz
end

it 'allows to specify the file type in the sources' do
options = { :http => 'https://file', :type => :zip }
options = { :http => 'https://foo/file', :type => :zip }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :zip
end

it 'should download file and extract it with proper type' do
options = { :http => 'https://file.zip' }
options = { :http => 'https://foo/file.zip' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.expects(:download_file).with(anything)
downloader.expects(:extract_with_type).with(anything, :zip).at_least_once
downloader.download
end

it 'should raise error when an unsupported file type is detected' do
options = { :http => 'https://file.rar' }
options = { :http => 'https://foo/file.rar' }
downloader = Downloader.for_target(tmp_folder, options)
lambda { downloader.download }.should.raise Http::UnsupportedFileTypeError
end

it 'should raise error when an unsupported file type is specified in the options' do
options = { :http => 'https://file', :type => :rar }
options = { :http => 'https://foo/file', :type => :rar }
downloader = Downloader.for_target(tmp_folder, options)
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' }
options = { :http => 'https://foo/file', :type => 'zip' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.send(:type).should == :zip
end

it 'returns whether it does not supports the download of the head' do
options = { :http => 'https://file', :type => 'zip' }
options = { :http => 'https://foo/file', :type => 'zip' }
downloader = Downloader.for_target(tmp_folder('checkout'), options)
downloader.head_supported?.should.be.false
end
Expand Down

0 comments on commit dd0eddd

Please sign in to comment.