Skip to content

Commit

Permalink
Add additional tests to cover all url redirection cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Rouillard committed Feb 7, 2015
1 parent 7a4da4f commit 63b6148
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions spec/httpi/httpi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
end

describe ".request" do
let(:request) { HTTPI::Request.new('http://example.com') }
let(:request) { HTTPI::Request.new('http://example.com/foo/') }

it "allows custom HTTP methods" do
httpclient.any_instance.expects(:request).with(:custom)
Expand All @@ -238,7 +238,33 @@
response = HTTPI::Response.new(200, {}, 'success')

httpclient.any_instance.expects(:request).twice.with(:custom).returns(redirect, response)
request.expects(:url=).with(redirect_location)
request.expects(:url=).with(URI.parse(redirect_location))

client.request(:custom, request, :httpclient)
end

it 'follows redirects with absolute path' do
request.follow_redirect = true
redirect_location = '/bar/foo'

redirect = HTTPI::Response.new(302, {'location' => redirect_location}, 'Moved')
response = HTTPI::Response.new(200, {}, 'success')

httpclient.any_instance.expects(:request).twice.with(:custom).returns(redirect, response)
request.expects(:url=).with(URI.parse('http://example.com/bar/foo'))

client.request(:custom, request, :httpclient)
end

it 'follows redirects with relative path' do
request.follow_redirect = true
redirect_location = 'bar/foo'

redirect = HTTPI::Response.new(302, {'location' => redirect_location}, 'Moved')
response = HTTPI::Response.new(200, {}, 'success')

httpclient.any_instance.expects(:request).twice.with(:custom).returns(redirect, response)
request.expects(:url=).with(URI.parse('http://example.com/foo/bar/foo'))

client.request(:custom, request, :httpclient)
end
Expand Down

0 comments on commit 63b6148

Please sign in to comment.