1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
require 'spec_helper'
describe HTTP::Redirector do
def simple_response(status, body = '', headers = {})
HTTP::Response.new(status, '1.1', headers, body)
end
def redirect_response(location, status)
simple_response status, '', 'Location' => location
end
let(:max_hops) { 5 }
subject(:redirector) { described_class.new max_hops }
context 'following 300 redirect' do
let(:orig_request) { HTTP::Request.new :post, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 300 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be orig_request.verb
simple_response 200
end
end
end
context 'following 301 redirect' do
let(:orig_request) { HTTP::Request.new :post, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 301 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be orig_request.verb
simple_response 200
end
end
end
context 'following 302 redirect' do
let(:orig_request) { HTTP::Request.new :post, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 302 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be orig_request.verb
simple_response 200
end
end
end
context 'following 303 redirect' do
context 'upon POST request' do
let(:orig_request) { HTTP::Request.new :post, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 303 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be :get
simple_response 200
end
end
end
context 'upon HEAD request' do
let(:orig_request) { HTTP::Request.new :head, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 303 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be :get
simple_response 200
end
end
end
end
context 'following 307 redirect' do
let(:orig_request) { HTTP::Request.new :post, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 307 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be orig_request.verb
simple_response 200
end
end
end
context 'following 308 redirect' do
let(:orig_request) { HTTP::Request.new :post, 'http://www.example.com/' }
let(:orig_response) { redirect_response 'http://example.com/', 308 }
it 'follows without changing verb' do
redirector.perform(orig_request, orig_response) do |request|
expect(request.verb).to be orig_request.verb
simple_response 200
end
end
end
end
|