Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Added code to actually start and restart an application.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jun 9, 2008
1 parent 86f33e9 commit e79b2e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
19 changes: 15 additions & 4 deletions PassengerApplication.rb
Expand Up @@ -26,16 +26,23 @@ def initWithFile(file)
end
end

# def restart(sender)
# p "Restarting Rails application: #{@path}"
# save_config!
# end
def start
p "Starting Rails application (restarting Apache): #{@path}"
execute '/bin/launchctl stop org.apache.httpd'
end

def restart(sender = nil)
p "Restarting Rails application: #{@path}"
save_config! if @dirty
Kernel.system("/usr/bin/touch '#{File.join(@path, 'tmp', 'restart.txt')}'")
end

# def remove!
# p "remove #{self}"
# end

def save_config!
p "Saving configuration: #{config_path}"
execute "/usr/bin/env ruby '#{CONFIG_INSTALLER}' '#{config_path}' '/etc/hosts' '#{@host}' '#{@path}'"
end

Expand All @@ -55,4 +62,8 @@ def execute(command)
script = NSAppleScript.alloc.initWithSource("do shell script \"#{command}\" with administrator privileges")
script.performSelector_withObject("executeAndReturnError:", nil)
end

def p(obj)
NSLog(obj.inspect)
end
end
27 changes: 26 additions & 1 deletion test/passenger_application_test.rb
Expand Up @@ -6,6 +6,7 @@

def after_setup
@instance_to_be_tested = PassengerApplication.alloc.init
passenger_app.stubs(:execute)
end

it "should initialize with empty path & host" do
Expand All @@ -28,6 +29,11 @@ def after_setup
passenger_app.setValue_forKey('het-manfreds-blog.local', 'host')
passenger_app.setValue_forKey('/Users/het-manfred/rails code/blog', 'path')
end

it "should start the application by restarting apache" do
passenger_app.expects(:execute).with('/bin/launchctl stop org.apache.httpd')
passenger_app.start
end
end

describe "PassengerApplication, in general" do
Expand All @@ -36,6 +42,8 @@ def after_setup
def after_setup
@vhost = File.expand_path('../fixtures/blog.vhost.conf', __FILE__)
@instance_to_be_tested = PassengerApplication.alloc.initWithFile(@vhost)

Kernel.stubs(:system)
end

it "should parse the correct host & path from a vhost file" do
Expand Down Expand Up @@ -72,7 +80,7 @@ def after_setup
assigns(:dirty).should.be true
end

it "should not start the application if only one of host or path is entered" do
it "should not restart the application if only one of host or path is entered" do
passenger_app.expects(:restart).times(0)

passenger_app.setValue_forKey('', 'host')
Expand All @@ -83,4 +91,21 @@ def after_setup
passenger_app.expects(:restart).times(1)
passenger_app.setValue_forKey('het-manfreds-blog.local', 'host')
end

it "should save the config before restarting if it was marked dirty" do
passenger_app.expects(:save_config!).times(1)
assigns(:dirty, true)
passenger_app.restart
end

it "should not save the config before restarting if it wasn't marked dirty" do
passenger_app.expects(:save_config!).times(0)
assigns(:dirty, false)
passenger_app.restart
end

it "should restart the application" do
Kernel.expects(:system).with("/usr/bin/touch '/Users/het-manfred/rails code/blog/tmp/restart.txt'")
passenger_app.restart
end
end

0 comments on commit e79b2e2

Please sign in to comment.