From 63b6148ff1aa8d7c5509f0c74665101c75de57fc Mon Sep 17 00:00:00 2001 From: Yann Rouillard Date: Sat, 7 Feb 2015 20:24:58 +0100 Subject: [PATCH] Add additional tests to cover all url redirection cases --- spec/httpi/httpi_spec.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/spec/httpi/httpi_spec.rb b/spec/httpi/httpi_spec.rb index cd87059..780e0e2 100644 --- a/spec/httpi/httpi_spec.rb +++ b/spec/httpi/httpi_spec.rb @@ -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) @@ -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