Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 67 lines (55 sloc) 2.421 kb
543c8b8 @cee-dub Require the right file.
cee-dub authored
1 require 'test/spec'
fe510ef @cee-dub Add Rack::CSSHTTPRequest middleware
cee-dub authored
2 require 'rack/mock'
3
5983335 @cee-dub Skip Rack::CSSHTTPRequest tests if there's a LoadError when requiring…
cee-dub authored
4 begin
5 require 'csshttprequest'
6 require 'rack/contrib/csshttprequest'
7
8 context "Rack::CSSHTTPRequest" do
9
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
10 before(:each) do
11 @test_body = '{"bar":"foo"}'
12 @test_headers = {'Content-Type' => 'text/plain'}
13 @encoded_body = CSSHTTPRequest.encode(@test_body)
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
14 @app = lambda { |env| [200, @test_headers, [@test_body]] }
5983335 @cee-dub Skip Rack::CSSHTTPRequest tests if there's a LoadError when requiring…
cee-dub authored
15 end
16
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
17 specify "env['csshttprequest.chr'] should be set to true when \
18 PATH_INFO ends with '.chr'" do
19 request = Rack::MockRequest.env_for("/blah.chr", :lint => true, :fatal => true)
20 Rack::CSSHTTPRequest.new(@app).call(request)
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
21 request['csshttprequest.chr'].should.equal true
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
22 end
23
24 specify "env['csshttprequest.chr'] should be set to true when \
25 request parameter _format == 'chr'" do
26 request = Rack::MockRequest.env_for("/?_format=chr", :lint => true, :fatal => true)
27 Rack::CSSHTTPRequest.new(@app).call(request)
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
28 request['csshttprequest.chr'].should.equal true
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
29 end
30
31 specify "should not change the headers or response when !env['csshttprequest.chr']" do
32 request = Rack::MockRequest.env_for("/", :lint => true, :fatal => true)
33 status, headers, response = Rack::CSSHTTPRequest.new(@app).call(request)
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
34 headers.should.equal @test_headers
35 response.join.should.equal @test_body
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
36 end
37
38 context "when env['csshttprequest.chr']" do
39 before(:each) do
40 @request = Rack::MockRequest.env_for("/",
41 'csshttprequest.chr' => true, :lint => true, :fatal => true)
42 end
43
44 specify "should modify the content length to the correct value" do
45 headers = Rack::CSSHTTPRequest.new(@app).call(@request)[1]
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
46 headers['Content-Length'].should.equal @encoded_body.length.to_s
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
47 end
48
49 specify "should modify the content type to the correct value" do
50 headers = Rack::CSSHTTPRequest.new(@app).call(@request)[1]
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
51 headers['Content-Type'].should.equal 'text/css'
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
52 end
53
54 specify "should not modify any other headers" do
55 headers = Rack::CSSHTTPRequest.new(@app).call(@request)[1]
0fd04ee @rtomayko Fix all Ruby 1.9 + Rack 1.0 incompatibilities
rtomayko authored
56 headers.should.equal @test_headers.merge({
01fcdeb @cee-dub Enable toggling of CSSHTTPRequest encoding based on #chr_request? met…
cee-dub authored
57 'Content-Type' => 'text/css',
58 'Content-Length' => @encoded_body.length.to_s
59 })
60 end
5983335 @cee-dub Skip Rack::CSSHTTPRequest tests if there's a LoadError when requiring…
cee-dub authored
61 end
62
fe510ef @cee-dub Add Rack::CSSHTTPRequest middleware
cee-dub authored
63 end
5983335 @cee-dub Skip Rack::CSSHTTPRequest tests if there's a LoadError when requiring…
cee-dub authored
64 rescue LoadError => boom
65 STDERR.puts "WARN: Skipping Rack::CSSHTTPRequest tests (nbio-csshttprequest not installed)"
fe510ef @cee-dub Add Rack::CSSHTTPRequest middleware
cee-dub authored
66 end
Something went wrong with that request. Please try again.