public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Write integration tests for Rack support.
Hongli Lai (Phusion) (author)
Fri May 09 05:27:59 -0700 2008
commit  32b1bd0ec64c3910d856fc3dcff0b4ff2c74bd25
tree    e7d2a03b0ed038739cad47e51b36f1d3e0f70bf5
parent  cf18aaf3ebf14ad89da6f3e315ddbccbb7e693ac
...
281
282
283
284
 
285
286
287
...
281
282
283
 
284
285
286
287
0
@@ -281,7 +281,7 @@ $ cd /webapps/rack_example
0
 $ some_awesome_editor config.ru
0
 ...type in some source code...
0
 $ cat config.ru
0
-app = Proc.new do |env|
0
+app = lambda do |env|
0
     return [200, { "Content-Type" => "text/html" }, "hello <b>world</b>"]
0
 end
0
 run app
...
29
30
31
 
32
33
34
...
29
30
31
32
33
34
35
0
@@ -29,6 +29,7 @@ class RackSpawner
0
         a.close
0
         channel = MessageChannel.new(b)
0
         ENV['RACK_ENV'] = environment
0
+ Dir.chdir(app_root)
0
         app = load_rack_app(app_root)
0
         
0
         reader, writer = IO.pipe
...
138
139
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
142
143
...
355
356
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
359
360
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
0
@@ -138,6 +138,44 @@ shared_examples_for "MyCook(tm) beta" do
0
   end
0
 end
0
 
0
+shared_examples_for "HelloWorld Rack application" do
0
+ it "is possible to fetch static assets" do
0
+ get('/rack.jpg').should == public_file('rack.jpg')
0
+ end
0
+
0
+ it "is possible to GET a regular Rack page" do
0
+ get('/').should =~ /hello/
0
+ end
0
+
0
+ it "supports restarting via restart.txt" do
0
+ get('/').should =~ /hello/
0
+ File.write("#{@stub.app_root}/config.ru", %q{
0
+ app = lambda do |env|
0
+ [200, { "Content-Type" => "text/html" }, "changed"]
0
+ end
0
+ run app
0
+ })
0
+ File.new("#{@stub.app_root}/tmp/restart.txt", "w").close
0
+ get('/').should == "changed"
0
+ File.exist?("#{@stub.app_root}/tmp/restart.txt").should == false
0
+ end
0
+
0
+ if Process.uid == 0
0
+ it "runs as an unprivileged user" do
0
+ pending do
0
+ File.prepend("#{@stub.app_root}/config.ru", %q{
0
+ File.new('foo.txt', 'w').close
0
+ })
0
+ File.new("#{@stub.app_root}/tmp/restart.txt", "w").close
0
+ get('/')
0
+ stat = File.stat("#{@stub.app_root}/foo.txt")
0
+ stat.uid.should_not == 0
0
+ stat.gid.should_not == 0
0
+ end
0
+ end
0
+ end
0
+end
0
+
0
 describe "mod_passenger running in Apache 2" do
0
   include TestHelper
0
   
0
@@ -355,6 +393,21 @@ describe "mod_passenger running in Apache 2" do
0
     end
0
   end
0
   
0
+ describe "Rack support" do
0
+ before :all do
0
+ @stub = setup_stub('rack')
0
+ @apache2.add_vhost('passenger.test', File.expand_path(@stub.app_root) + "/public")
0
+ @apache2.start
0
+ @server = "http://passenger.test:#{@apache2.port}"
0
+ end
0
+
0
+ after :all do
0
+ @stub.destroy
0
+ end
0
+
0
+ it_should_behave_like "HelloWorld Rack application"
0
+ end
0
+
0
   ##### Helper methods #####
0
   
0
   def get(uri)
...
2
3
4
5
 
6
7
8
...
11
12
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
15
16
...
23
24
25
26
27
28
29
30
31
32
...
35
36
37
38
 
39
40
41
...
2
3
4
 
5
6
7
8
...
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
...
44
45
46
 
 
 
 
47
48
49
...
52
53
54
 
55
56
57
58
0
@@ -2,7 +2,7 @@ require 'fileutils'
0
 
0
 module TestHelper
0
   STUB_TEMP_DIR = 'tmp.stub'
0
-
0
+
0
   class Stub
0
     attr_reader :app_root
0
     
0
@@ -11,6 +11,27 @@ module TestHelper
0
       @app_root = app_root
0
     end
0
     
0
+ def destroy
0
+ FileUtils.rm_rf(@app_root)
0
+ end
0
+ end
0
+
0
+ def setup_stub(name, dir = STUB_TEMP_DIR)
0
+ FileUtils.rm_rf(dir)
0
+ FileUtils.mkdir_p(dir)
0
+ FileUtils.cp_r("stub/#{name}/.", dir)
0
+ system("chmod", "-R", "a+rw", dir)
0
+ return Stub.new(name, dir)
0
+ end
0
+
0
+ def use_stub(name, dir = STUB_TEMP_DIR)
0
+ stub = setup_stub(name, dir)
0
+ yield stub
0
+ ensure
0
+ stub.destroy
0
+ end
0
+
0
+ class RailsStub < Stub
0
     def environment_rb
0
       return "#{@app_root}/config/environment.rb"
0
     end
0
@@ -23,10 +44,6 @@ module TestHelper
0
     def dont_use_vendor_rails
0
       FileUtils.rm_rf("#{@app_root}/vendor/rails")
0
     end
0
-
0
- def destroy
0
- FileUtils.rm_rf(@app_root)
0
- end
0
   end
0
   
0
   def setup_rails_stub(name, dir = STUB_TEMP_DIR)
0
@@ -35,7 +52,7 @@ module TestHelper
0
     FileUtils.cp_r("stub/rails_apps/#{name}/.", dir)
0
     FileUtils.mkdir_p("#{dir}/log")
0
     system("chmod", "-R", "a+rw", dir)
0
- return Stub.new(name, dir)
0
+ return RailsStub.new(name, dir)
0
   end
0
   
0
   def teardown_rails_stub

Comments

    No one has commented yet.