Permalink
Browse files

If the user wants it, we'll add the configuration needed by passenger…

… to an existing conf.
  • Loading branch information...
1 parent 7a99c9e commit e90332d35a3a281857247ff867153a8a85766bd5 @alloy alloy committed Jun 10, 2008
Showing with 23 additions and 46 deletions.
  1. +4 −11 PassengerApplication.rb
  2. +8 −12 PassengerPref.rb
  3. +10 −0 shared_passenger_behaviour.rb
  4. +1 −23 test/pref_pane_passenger_test.rb
@@ -1,7 +1,11 @@
require 'osx/cocoa'
include OSX
+require File.expand_path('../shared_passenger_behaviour', __FILE__)
+
class PassengerApplication < NSObject
+ include SharedPassengerBehaviour
+
CONFIG_PATH = "/etc/apache2/users/passenger_apps"
CONFIG_INSTALLER = File.expand_path('../config_installer.rb', __FILE__)
@@ -55,15 +59,4 @@ def rbSetValue_forKey(value, key)
@dirty = true
(@new_app ? start : restart) unless @host.empty? or @path.empty?
end
-
- private
-
- 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
View
@@ -11,9 +11,15 @@
OSX.require_framework 'PreferencePanes'
+require File.expand_path('../shared_passenger_behaviour', __FILE__)
require File.expand_path('../PassengerApplication', __FILE__)
class PrefPanePassenger < NSPreferencePane
+ include SharedPassengerBehaviour
+
+ USERS_APACHE_CONFIG = "/etc/apache2/users/#{OSX.NSUserName}.conf"
+ PASSENGER_CONFIG_INSTALLER = File.expand_path('../passenger_config_installer.rb', __FILE__)
+
ib_outlet :applicationsController
kvc_accessor :applications
@@ -45,10 +51,6 @@ def restart(sender)
p "restart"
end
- def users_apache_config
- "/etc/apache2/users/#{OSX.NSUserName}.conf"
- end
-
USERS_APACHE_CONFIG_LOAD_PASSENGER = [
'LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so',
'RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server',
@@ -57,7 +59,7 @@ def users_apache_config
]
def is_users_apache_config_setup?
- conf = File.read(users_apache_config)
+ conf = File.read(USERS_APACHE_CONFIG)
USERS_APACHE_CONFIG_LOAD_PASSENGER.all? { |line| conf.include? line }
end
@@ -68,12 +70,6 @@ def user_wants_us_to_setup_config?
end
def setup_users_apache_config!
-
- end
-
- private
-
- def p(obj)
- NSLog(obj.inspect)
+ execute "/usr/bin/env ruby '#{PASSENGER_CONFIG_INSTALLER}' '#{USERS_APACHE_CONFIG}'"
end
end
@@ -0,0 +1,10 @@
+module SharedPassengerBehaviour
+ 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
@@ -58,26 +58,8 @@ def after_setup
end
it "should add the required lines to setup passenger to the users apache config" do
- tmp = File.expand_path('../tmp', __FILE__)
- FileUtils.mkdir_p tmp
-
- conf = File.join(tmp, 'user.conf')
- File.open(conf, 'w') { |f| f << "</Directory>" }
-
+ pref_pane.expects(:execute).with("/usr/bin/env ruby '#{PrefPanePassenger::PASSENGER_CONFIG_INSTALLER}' '#{PrefPanePassenger::USERS_APACHE_CONFIG}'")
pref_pane.setup_users_apache_config!
-
- File.read(conf).should == %{
-</Directory>
-
-LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
-RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
-RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
-RailsEnv development
-
-Include /private/etc/apache2/users/passenger_apps/*.vhost.conf
-}.sub(/^\n/, '')
-
- FileUtils.rm_rf tmp
end
end
@@ -111,8 +93,4 @@ def after_setup
pref_pane.remove(nil)
applicationsController.content.should == [stay_app]
end
-
- it "should return the path to the users apache config" do
- pref_pane.users_apache_config.should == "/etc/apache2/users/#{OSX.NSUserName}.conf"
- end
end

0 comments on commit e90332d

Please sign in to comment.