Permalink
Browse files

bump faraday_middleware to 0.9. Add FollowRedirects middleware

  • Loading branch information...
1 parent 7fd1a4e commit c85c83b8cd90527c715ffd532657d6df00a38482 @joeyw joeyw committed Nov 29, 2012
@@ -43,8 +43,7 @@ def archive_link(repo, options={})
repo_ref = options.delete :ref
format = (options.delete :format) || 'tarball'
url = "repos/#{Repository.new repo}/#{format}/#{repo_ref}"
- headers = request(:get, url, options).headers
- return headers['location']
+ request(:head, url, options).env[:url].to_s
end
end
end
@@ -29,6 +29,7 @@ def connection(options={})
builder.request :json
builder.use Faraday::Response::RaiseOctokitError
+ builder.use FaradayMiddleware::FollowRedirects
builder.use FaradayMiddleware::Mashify
builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
View
@@ -61,7 +61,7 @@ def request(method, path, options={})
end
options.merge!(:per_page => per_page) if per_page
request.url(path, options)
- when :delete
+ when :delete, :head
request.url(path, options)
when :patch, :post, :put
request.path = path
View
@@ -4,7 +4,7 @@ require File.expand_path('../lib/octokit/version', __FILE__)
Gem::Specification.new do |spec|
spec.add_dependency 'addressable', '~> 2.2'
spec.add_dependency 'faraday', '~> 0.8'
- spec.add_dependency 'faraday_middleware', '~> 0.8'
+ spec.add_dependency 'faraday_middleware', '~> 0.9'
spec.add_dependency 'hashie', '~> 1.2'
spec.add_dependency 'multi_json', '~> 1.3'
spec.add_development_dependency 'json', '~> 1.7'
View
@@ -43,6 +43,10 @@ def stub_get(url)
stub_request(:get, github_url(url))
end
+def stub_head(url)
+ stub_request(:head, github_url(url))
+end
+
def stub_patch(url)
stub_request(:patch, github_url(url))
end
@@ -36,9 +36,12 @@
describe ".archive_link" do
it "returns the headers of the request" do
- stub_get("/repos/pengwynn/octokit/tarball/master").
+ stub_head("/repos/pengwynn/octokit/tarball/master").
to_return(:status => 302, :body => '', :headers =>
{ 'location' => "https://nodeload.github.com/repos/pengwynn/octokit/tarball/"})
+ stub_head("https://nodeload.github.com/repos/pengwynn/octokit/tarball/").
+ to_return(:status => 200)
+
archive_link = @client.archive_link('pengwynn/octokit', :ref => "master")
expect(archive_link).to eq("https://nodeload.github.com/repos/pengwynn/octokit/tarball/")
end

0 comments on commit c85c83b

Please sign in to comment.