/
ie_redirect_fix_spec.rb
60 lines (48 loc) · 1.87 KB
/
ie_redirect_fix_spec.rb
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
require 'spec_helper'
describe Rack::IeRedirectFix do
let(:app) do
Rack::IeRedirectFix.new(lambda{|env| rack_response })
end
let(:response){ get 'http://other-example.com/' }
subject{ response }
context "given a non-redirect" do
let(:status) { 200 }
let(:headers){ { "Content-Type" => 'text/plain' } }
let(:body) { "hi" }
let(:rack_response){ [status, headers, [body]] }
its(:status){ should == status }
its(:body) { should == body }
it "should leave the headers alone" do
headers.each do |name, value|
response.headers[name].should == value
end
end
end
context "given a to our app" do
let(:location) { 'http://other-example.com/some/path' }
let(:rack_response){ [302, { "Content-Type" => 'text/plain', 'Location' => location }, ["Some body"]] }
let(:expected_location){ 'https://other-example.com/some/path' }
let(:expected_body) { %Q{<html><body>You are being <a href="#{expected_location}">redirected</a>.</body></html>} }
it "should set the location to an SSL version of that URL" do
response.headers['Location'].should == expected_location
end
it "should set the appropriate content length" do
response.headers['Content-Length'].should == expected_body.size.to_s
end
its(:status){ should == 302 }
its(:body) { should == expected_body }
end
context "given a redirect an external URL" do
let(:location) { 'http://google.com/some/path.html' }
let(:headers) { { "Content-Type" => 'text/plain', 'Location' => location } }
let(:body) { "Redirecting to somewhere" }
let(:rack_response){ [302, headers, [body]] }
its(:status){ should == 302 }
its(:body) { should == body }
it "should leave the headers alone" do
headers.each do |name, value|
response.headers[name].should == value
end
end
end
end