Permalink
Browse files

Check if Passenger is installed, if not tell the user to do so.

  • Loading branch information...
1 parent ab1f1b4 commit 1679fa32fd67dfd3bab3cc935bcb84f21e4f7b54 @alloy alloy committed Jun 11, 2008
Showing with 55 additions and 12 deletions.
  1. +13 −0 PassengerPref.rb
  2. +5 −1 shared_passenger_behaviour.rb
  3. +37 −11 test/pref_pane_passenger_test.rb
View
@@ -25,6 +25,8 @@ class PrefPanePassenger < NSPreferencePane
def mainViewDidLoad
@applications = [].to_ns
+ install_passenger! unless passenger_installed?
+
if is_users_apache_config_setup?
Dir.glob(File.join(USERS_APACHE_PASSENGER_APPS_DIR, '*.vhost.conf')).each do |app|
@applicationsController.addObject PassengerApplication.alloc.initWithFile(app)
@@ -44,6 +46,17 @@ def restart(sender)
p "restart"
end
+ def passenger_installed?
+ `/usr/bin/gem list passenger`.include? 'passenger'
+ end
+
+ def install_passenger!
+ apple_script "tell application \"Terminal\"\nactivate\ndo script with command \"sudo gem install passenger && sudo /usr/bin/passenger-install-apache2-module\"\nend tell"
+ alert = OSX::NSAlert.alloc.init
+ alert.informativeText = "Oh noes, the drama! It seems like you haven't installed the Passenger gem yet...\n\nI took the liberty of setting up a terminal for you so that you can install it. Once it's done hit OK to continue."
+ alert.runModal
+ 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',
@@ -5,7 +5,11 @@ module SharedPassengerBehaviour
USERS_APACHE_CONFIG = "/etc/apache2/users/#{OSX.NSUserName}.conf"
def execute(command)
- script = NSAppleScript.alloc.initWithSource("do shell script \"#{command}\" with administrator privileges")
+ apple_script "do shell script \"#{command}\" with administrator privileges"
+ end
+
+ def apple_script(command)
+ script = NSAppleScript.alloc.initWithSource(command)
script.performSelector_withObject("executeAndReturnError:", nil)
end
@@ -8,21 +8,23 @@ def OSX._ignore_ns_override; true; end
def after_setup
ib_outlets :applicationsController => OSX::NSArrayController.alloc.init
+ pref_pane.stubs(:passenger_installed?).returns(true)
end
- it "should add existing applications found in /etc/apache2/users/passenger_apps to the array controller: applicationsController" do
- dir = "/etc/apache2/users/#{OSX.NSUserName}-passenger-apps"
- blog, paste = ["#{dir}/blog.vhost.conf", "#{dir}/paste.vhost.conf"]
- blog_stub, paste_stub = stub("PassengerApplication: blog"), stub("PassengerApplication: paste")
-
- PassengerApplication.any_instance.expects(:initWithFile).with(blog).returns(blog_stub)
- PassengerApplication.any_instance.expects(:initWithFile).with(paste).returns(paste_stub)
-
- pref_pane.stubs(:is_users_apache_config_setup?).returns(true)
- Dir.stubs(:glob).with("#{dir}/*.vhost.conf").returns([blog, paste])
+ it "should check if the passenger gem is installed" do
+ pref_pane.expects(:passenger_installed?).returns(true)
+ pref_pane.expects(:install_passenger!).times(0)
pref_pane.mainViewDidLoad
- applicationsController.content.should == [blog_stub, paste_stub]
+ pref_pane.expects(:passenger_installed?).returns(false)
+ pref_pane.expects(:install_passenger!).times(1)
+ pref_pane.mainViewDidLoad
+ end
+
+ it "should tell the user to first install passenger" do
+ pref_pane.expects(:apple_script).with("tell application \"Terminal\"\nactivate\ndo script with command \"sudo gem install passenger && sudo /usr/bin/passenger-install-apache2-module\"\nend tell")
+ OSX::NSAlert.any_instance.expects(:runModal)
+ pref_pane.install_passenger!
end
it "should check if the users apache config is set up" do
@@ -61,6 +63,21 @@ def after_setup
pref_pane.expects(:execute).with("/usr/bin/env ruby '#{PrefPanePassenger::PASSENGER_CONFIG_INSTALLER}' '#{PrefPanePassenger::USERS_APACHE_CONFIG}'")
pref_pane.setup_users_apache_config!
end
+
+ it "should add existing applications found in /etc/apache2/users/passenger_apps to the array controller: applicationsController" do
+ dir = "/etc/apache2/users/#{OSX.NSUserName}-passenger-apps"
+ blog, paste = ["#{dir}/blog.vhost.conf", "#{dir}/paste.vhost.conf"]
+ blog_stub, paste_stub = stub("PassengerApplication: blog"), stub("PassengerApplication: paste")
+
+ PassengerApplication.any_instance.expects(:initWithFile).with(blog).returns(blog_stub)
+ PassengerApplication.any_instance.expects(:initWithFile).with(paste).returns(paste_stub)
+
+ pref_pane.stubs(:is_users_apache_config_setup?).returns(true)
+ Dir.stubs(:glob).with("#{dir}/*.vhost.conf").returns([blog, paste])
+ pref_pane.mainViewDidLoad
+
+ applicationsController.content.should == [blog_stub, paste_stub]
+ end
end
describe "PrefPanePassenger, in general" do
@@ -69,6 +86,7 @@ def after_setup
def after_setup
ib_outlets :applicationsController => OSX::NSArrayController.alloc.init
pref_pane.stubs(:is_users_apache_config_setup?).returns(true)
+ pref_pane.stubs(:install_passenger!).returns(true)
pref_pane.mainViewDidLoad
end
@@ -107,4 +125,12 @@ def after_setup
pref_pane.browse
end
+
+ it "should be able to check if the passenger gem is installed" do
+ pref_pane.expects(:`).with('/usr/bin/gem list passenger').returns("*** LOCAL GEMS ***\n\npassenger (1.0.5, 1.0.1)\n")
+ pref_pane.passenger_installed?.should.be true
+
+ pref_pane.expects(:`).with('/usr/bin/gem list passenger').returns("*** LOCAL GEMS ***\n\n\n")
+ pref_pane.passenger_installed?.should.be false
+ end
end

0 comments on commit 1679fa3

Please sign in to comment.