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 !
Hongli Lai (Phusion) (author)
Wed Apr 23 04:05:28 -0700 2008
commit  5bc9ea518e346767e4b69d70044c3dac90bda113
tree    50e3875d3ca7d7a6101d759ada24d787825c44a8
parent  2cbd4debcb83c562a454e239a9b65ad3c19e2bba
passenger / test / application_spawner_spec.rb
100644 81 lines (69 sloc) 1.845 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
require 'support/config'
require 'passenger/application_spawner'
require 'minimal_spawner_spec'
require 'spawn_server_spec'
require 'spawner_privilege_lowering_spec'
require 'spawner_error_handling_spec'
include Passenger
 
# TODO: write unit test which checks whether setting ENV['RAILS_ENV'] in environment.rb is respected (issue #6)
 
describe ApplicationSpawner do
  before :all do
    ENV['RAILS_ENV'] = 'production'
    @test_app = "stub/railsapp"
    Dir["#{@test_app}/log/*"].each do |file|
      File.chmod(0666, file) rescue nil
    end
    File.chmod(0777, "#{@test_app}/log") rescue nil
  end
  
  before :each do
    @spawner = ApplicationSpawner.new(@test_app)
    @spawner.start
    @server = @spawner
  end
  
  after :each do
    @spawner.stop
  end
  
  it_should_behave_like "a minimal spawner"
  it_should_behave_like "a spawn server"
  
  def spawn_application
    @spawner.spawn_application
  end
end
 
describe ApplicationSpawner do
  it_should_behave_like "handling errors in application initialization"
  
  def spawn_application(app_root)
    @spawner = ApplicationSpawner.new(app_root)
    begin
      @spawner.start
      return @spawner.spawn_application
    ensure
      @spawner.stop rescue nil
    end
  end
end
 
if Process.euid == ApplicationSpawner::ROOT_UID
  describe "ApplicationSpawner privilege lowering support" do
    before :all do
      @test_app = "stub/railsapp"
      ENV['RAILS_ENV'] = 'production'
    end
  
    it_should_behave_like "a spawner that supports lowering of privileges"
    
    def spawn_app(options = {})
      options = {
        :lower_privilege => true,
        :lowest_user => CONFIG['lowest_user']
      }.merge(options)
      @spawner = ApplicationSpawner.new(@test_app,
        options[:lower_privilege],
        options[:lowest_user])
      @spawner.start
      begin
        app = @spawner.spawn_application
        yield app
      ensure
        app.close
        @spawner.stop
      end
    end
  end
end