Skip to content
Browse files

At least show an alert that something went wrong if execution fails.

  • Loading branch information...
1 parent 00a8f36 commit 18dc1433217bd90d67cdd1dfb674e9e89198d597 @alloy alloy committed Jun 20, 2008
Showing with 42 additions and 4 deletions.
  1. +0 −1 TODO
  2. +14 −1 shared_passenger_behaviour.rb
  3. +28 −2 test/shared_passenger_behaviour_test.rb
View
1 TODO
@@ -1,2 +1 @@
-- When false is returned by executeCommand_withArgs show an alert telling the user to check his console.
- Check paths in help file.
View
15 shared_passenger_behaviour.rb
@@ -4,7 +4,20 @@ module SharedPassengerBehaviour
PASSENGER_APPS_DIR = "/private/etc/apache2/passenger_pane_vhosts"
def execute(command, *args)
- OSX::SecurityHelper.sharedInstance.executeCommand_withArgs(command, args)
+ if OSX::SecurityHelper.sharedInstance.executeCommand_withArgs(command, args) == 0
+ alert = OSX::NSAlert.alloc.init
+ alert.messageText = 'Something went wrong while trying to save your changes'
+ alert.informativeText = "Please check your console.log for further info and file a bug report if it is a bug at:\nhttp://fingertips.lighthouseapp.com/projects/13022"
+ alert.objc_send(
+ :beginSheetModalForWindow, PrefPanePassenger.sharedInstance.mainView.window,
+ :modalDelegate, nil,
+ :didEndSelector, nil,
+ :contextInfo, nil
+ )
+ false
+ else
+ true
+ end
end
module_function :execute
View
30 test/shared_passenger_behaviour_test.rb
@@ -1,11 +1,37 @@
require File.expand_path('../test_helper', __FILE__)
require 'shared_passenger_behaviour'
+class PrefPanePassenger
+ class << self
+ attr_accessor :sharedInstance
+ end
+end
+
describe "SharedPassengerBehaviour" do
include SharedPassengerBehaviour
it "should forward commands to be executed with privileges to the SecurityHelper" do
- OSX::SecurityHelper.sharedInstance.expects(:executeCommand_withArgs).with('/some/command', ['arg1', 'arg2'])
- execute '/some/command', 'arg1', 'arg2'
+ OSX::SecurityHelper.sharedInstance.expects(:executeCommand_withArgs).with('/some/command', ['arg1', 'arg2']).returns(1)
+ execute('/some/command', 'arg1', 'arg2').should.be true
+ end
+
+ it "should show an alert if something went wrong while executing the given command" do
+ pref_stub = stub('PrefPanePassenger')
+ PrefPanePassenger.sharedInstance = pref_stub
+ mainView_stub = stub('MainView')
+ pref_stub.stubs(:mainView).returns(mainView_stub)
+ window_stub = stub('Window')
+ mainView_stub.stubs(:window).returns(window_stub)
+
+ OSX::SecurityHelper.sharedInstance.stubs(:executeCommand_withArgs).returns(0)
+
+ OSX::NSAlert.any_instance.expects(:objc_send).with(
+ :beginSheetModalForWindow, window_stub,
+ :modalDelegate, nil,
+ :didEndSelector, nil,
+ :contextInfo, nil
+ ).times(1)
+
+ execute('/some/command', 'arg1', 'arg2').should.be false
end
end

0 comments on commit 18dc143

Please sign in to comment.
Something went wrong with that request. Please try again.