|
af63af25
»
|
macournoyer |
2008-03-13 |
* Guess which adapter to us... |
1 |
require File.dirname(__FILE__) + '/../spec_helper' |
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
2 |
require 'rack/mock' |
| |
3 |
|
| |
4 |
begin |
| |
5 |
gem 'rails', '= 2.0.2' # We could freeze Rails in the rails_app dir to remove this |
| |
6 |
|
|
d0e2e14d
»
|
macournoyer |
2008-01-13 |
Add prefix option to thin s... |
7 |
describe Rack::Adapter::Rails do |
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
8 |
before do |
|
af63af25
»
|
macournoyer |
2008-03-13 |
* Guess which adapter to us... |
9 |
@rails_app_path = File.dirname(__FILE__) + '/../rails_app' |
|
6b31acff
»
|
macournoyer |
2008-01-06 |
Add URL rewriting to Rails ... |
10 |
@request = Rack::MockRequest.new(Rack::Adapter::Rails.new(:root => @rails_app_path)) |
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
11 |
end |
| |
12 |
|
| |
13 |
it "should handle simple GET request" do |
| |
14 |
res = @request.get("/simple", :lint => true) |
| |
15 |
|
| |
16 |
res.should be_ok |
| |
17 |
res["Content-Type"].should include("text/html") |
| |
18 |
|
| |
19 |
res.body.should include('Simple#index') |
| |
20 |
end |
| |
21 |
|
| |
22 |
it "should handle POST parameters" do |
| |
23 |
data = "foo=bar" |
| |
24 |
res = @request.post("/simple/post_form", :input => data, 'CONTENT_LENGTH' => data.size) |
| |
25 |
|
| |
26 |
res.should be_ok |
| |
27 |
res["Content-Type"].should include("text/html") |
| |
28 |
res["Content-Length"].should_not be_nil |
| |
29 |
|
| |
30 |
res.body.should include('foo: bar') |
| |
31 |
end |
| |
32 |
|
| |
33 |
it "should serve static files" do |
| |
34 |
res = @request.get("/index.html") |
| |
35 |
|
| |
36 |
res.should be_ok |
| |
37 |
res["Content-Type"].should include("text/html") |
| |
38 |
end |
| |
39 |
|
|
6b31acff
»
|
macournoyer |
2008-01-06 |
Add URL rewriting to Rails ... |
40 |
it "should serve root with index.html if present" do |
| |
41 |
res = @request.get("/") |
| |
42 |
|
| |
43 |
res.should be_ok |
| |
44 |
res["Content-Length"].to_i.should == File.size(@rails_app_path + '/public/index.html') |
| |
45 |
end |
| |
46 |
|
| |
47 |
it "should serve page cache if present" do |
| |
48 |
res = @request.get("/simple/cached?value=cached") |
| |
49 |
|
| |
50 |
res.should be_ok |
| |
51 |
res.body.should == 'cached' |
| |
52 |
|
| |
53 |
res = @request.get("/simple/cached?value=notcached") |
| |
54 |
|
| |
55 |
res.should be_ok |
| |
56 |
res.body.should == 'cached' |
| |
57 |
end |
| |
58 |
|
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
59 |
it "handles multiple cookies" do |
| |
60 |
res = @request.get('/simple/set_cookie?name=a&value=1') |
| |
61 |
|
|
6b31acff
»
|
macournoyer |
2008-01-06 |
Add URL rewriting to Rails ... |
62 |
res.should be_ok |
| |
63 |
res.original_headers['Set-Cookie'].should include('a=1; path=/', '_rails_app_session') |
| |
64 |
end |
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
65 |
|
|
6b31acff
»
|
macournoyer |
2008-01-06 |
Add URL rewriting to Rails ... |
66 |
after do |
| |
67 |
FileUtils.rm_rf @rails_app_path + '/public/simple' |
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
68 |
end |
| |
69 |
end |
|
d0e2e14d
»
|
macournoyer |
2008-01-13 |
Add prefix option to thin s... |
70 |
|
| |
71 |
describe Rack::Adapter::Rails, 'with prefix' do |
| |
72 |
before do |
|
af63af25
»
|
macournoyer |
2008-03-13 |
* Guess which adapter to us... |
73 |
@rails_app_path = File.dirname(__FILE__) + '/../rails_app' |
|
d0e2e14d
»
|
macournoyer |
2008-01-13 |
Add prefix option to thin s... |
74 |
@prefix = '/nowhere' |
| |
75 |
@request = Rack::MockRequest.new( |
| |
76 |
Rack::URLMap.new( |
| |
77 |
@prefix => Rack::Adapter::Rails.new(:root => @rails_app_path, :prefix => @prefix))) |
| |
78 |
end |
| |
79 |
|
| |
80 |
it "should handle simple GET request" do |
| |
81 |
res = @request.get("#{@prefix}/simple", :lint => true) |
| |
82 |
|
| |
83 |
res.should be_ok |
| |
84 |
res["Content-Type"].should include("text/html") |
| |
85 |
|
| |
86 |
res.body.should include('Simple#index') |
| |
87 |
end |
| |
88 |
end |
|
0fc43e84
»
|
macournoyer |
2008-01-06 |
Add Rails app for testing a... |
89 |
|
| |
90 |
rescue Gem::LoadError |
| |
91 |
warn 'Rails 2.0.2 is required to run the Rails adapter specs' |
| |
92 |
end |