public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Click here to lend your support to: thin and make a donation at www.pledgie.com !
thin / spec / rack / rails_adapter_spec.rb
100644 93 lines (68 sloc) 2.628 kb
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
require File.dirname(__FILE__) + '/../spec_helper'
require 'rack/mock'
 
begin
  gem 'rails', '= 2.0.2' # We could freeze Rails in the rails_app dir to remove this
 
  describe Rack::Adapter::Rails do
    before do
      @rails_app_path = File.dirname(__FILE__) + '/../rails_app'
      @request = Rack::MockRequest.new(Rack::Adapter::Rails.new(:root => @rails_app_path))
    end
  
    it "should handle simple GET request" do
      res = @request.get("/simple", :lint => true)
 
      res.should be_ok
      res["Content-Type"].should include("text/html")
 
      res.body.should include('Simple#index')
    end
 
    it "should handle POST parameters" do
      data = "foo=bar"
      res = @request.post("/simple/post_form", :input => data, 'CONTENT_LENGTH' => data.size)
 
      res.should be_ok
      res["Content-Type"].should include("text/html")
      res["Content-Length"].should_not be_nil
    
      res.body.should include('foo: bar')
    end
  
    it "should serve static files" do
      res = @request.get("/index.html")
 
      res.should be_ok
      res["Content-Type"].should include("text/html")
    end
    
    it "should serve root with index.html if present" do
      res = @request.get("/")
 
      res.should be_ok
      res["Content-Length"].to_i.should == File.size(@rails_app_path + '/public/index.html')
    end
    
    it "should serve page cache if present" do
      res = @request.get("/simple/cached?value=cached")
 
      res.should be_ok
      res.body.should == 'cached'
      
      res = @request.get("/simple/cached?value=notcached")
      
      res.should be_ok
      res.body.should == 'cached'
    end
    
    it "handles multiple cookies" do
      res = @request.get('/simple/set_cookie?name=a&value=1')
    
      res.should be_ok
      res.original_headers['Set-Cookie'].should include('a=1; path=/', '_rails_app_session')
    end
    
    after do
      FileUtils.rm_rf @rails_app_path + '/public/simple'
    end
  end
  
  describe Rack::Adapter::Rails, 'with prefix' do
    before do
      @rails_app_path = File.dirname(__FILE__) + '/../rails_app'
      @prefix = '/nowhere'
      @request = Rack::MockRequest.new(
        Rack::URLMap.new(
          @prefix => Rack::Adapter::Rails.new(:root => @rails_app_path, :prefix => @prefix)))
    end
  
    it "should handle simple GET request" do
      res = @request.get("#{@prefix}/simple", :lint => true)
 
      res.should be_ok
      res["Content-Type"].should include("text/html")
 
      res.body.should include('Simple#index')
    end
  end
 
rescue Gem::LoadError
  warn 'Rails 2.0.2 is required to run the Rails adapter specs'
end