ref: refs/heads/dmacvicar_log_viewer
commit 6e031d3415667d30aee034516f596aa398dedde1
Author: Ladislav Slezak
Date: Mon Aug 17 15:09:22 2009 +0200
system plugin - added functional tests
---
.../test/functional/system_controller_test.rb | 116 +++++++++++++++++++-
1 files changed, 115 insertions(+), 1 deletions(-)
diff --git a/plugins/system/test/functional/system_controller_test.rb b/plugins/system/test/functional/system_controller_test.rb
index 3c7843f..a69f0eb 100644
--- a/plugins/system/test/functional/system_controller_test.rb
+++ b/plugins/system/test/functional/system_controller_test.rb
@@ -5,6 +5,120 @@ require 'rubygems'
class SystemControllerTest < ActionController::TestCase
- # TODO FIXME: write the tests
+ class Proxy
+ attr_accessor :result, :permissions, :timeout
+ def find
+ return result
+ end
+ end
+
+ class Action
+ attr_accessor :active
+
+ def initialize
+ @active = false
+ end
+ end
+
+ class Result
+ attr_accessor :reboot, :shutdown
+
+ def fill
+ @reboot = Action.new
+ @shutdown = Action.new
+ end
+
+ def save
+ return true
+ end
+ end
+
+ def setup
+ @request = ActionController::TestRequest.new
+
+ @result = Result.new
+ @result.fill
+
+ @proxy = Proxy.new
+ @proxy.permissions = { :read => true, :write => true }
+ @proxy.result = @result
+
+ YaST::ServiceResource.stubs(:proxy_for).with('org.opensuse.yast.system.system').returns(@proxy)
+
+ @controller = SystemController.new
+ SystemController.any_instance.stubs(:login_required)
+ end
+
+ test "'reboot' not accpeted via GET" do
+ ret = get :reboot
+
+ # redirected to the control panel?
+ assert_response :found
+ assert_redirected_to :controller => :controlpanel, :action => :index
+
+ # error reported?
+ assert !ret.flash[:error].blank?
+ end
+
+ test "'shutdown' not accpeted via GET" do
+ ret = get :shutdown
+
+ # redirected to the control panel?
+ assert_response :found
+ assert_redirected_to :controller => :controlpanel, :action => :index
+
+ # error reported?
+ assert !ret.flash[:error].blank?
+ end
+
+ test "check 'shutdown' result" do
+ ret = put :shutdown
+
+ # redirected to the control panel?
+ assert_response :found
+ assert_redirected_to :controller => :controlpanel, :action => :index
+
+ # no error and a message present?
+ assert ret.flash[:error].blank?
+ assert !ret.flash[:message].blank?
+ end
+
+ test "check 'reboot' result" do
+ ret = put :reboot
+
+ # redirected to the control panel?
+ assert_response :found
+ assert_redirected_to :controller => :controlpanel, :action => :index
+
+ # no error and a message present?
+ assert ret.flash[:error].blank?
+ assert !ret.flash[:message].blank?
+ end
+
+ test "check 'shutdown' failed" do
+ Result.any_instance.stubs(:save).returns(false)
+ ret = put :shutdown
+
+ # redirected to the control panel?
+ assert_response :found
+ assert_redirected_to :controller => :controlpanel, :action => :index
+
+ # error reported?
+ assert !ret.flash[:error].blank?
+ Result.any_instance.stubs(:save).returns(true)
+ end
+
+ test "check 'reboot' failed" do
+ Result.any_instance.stubs(:save).returns(false)
+ ret = put :reboot
+
+ # redirected to the control panel?
+ assert_response :found
+ assert_redirected_to :controller => :controlpanel, :action => :index
+
+ # error reported?
+ assert !ret.flash[:error].blank?
+ Result.any_instance.stubs(:save).returns(true)
+ end
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org