ref: refs/heads/master
commit d8fcbaf2d7c14e1a677b2747d8e2f7ea66296365
Author: Josef Reidinger
Date: Tue Jul 7 09:34:07 2009 +0200
add functionals test for time plugin
---
.../time/app/controllers/systemtimes_controller.rb | 6 +-
.../test/functional/systemtimes_controller_test.rb | 78 ++++++++++++--------
2 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/plugins/time/app/controllers/systemtimes_controller.rb b/plugins/time/app/controllers/systemtimes_controller.rb
index 0ccbc97..14951ba 100644
--- a/plugins/time/app/controllers/systemtimes_controller.rb
+++ b/plugins/time/app/controllers/systemtimes_controller.rb
@@ -35,9 +35,9 @@ class SystemtimesController < ApplicationController
def show
-# unless permission_check( "org.opensuse.yast.modules.yapi.time.read")
-# render ErrorResult.error( 403, 1, "no permission" ) and return
-# end
+ unless permission_check( "org.opensuse.yast.modules.yapi.time.read")
+ render ErrorResult.error( 403, 1, "no permission" ) and return
+ end
@systemtime = Systemtime.new
@systemtime.read
diff --git a/plugins/time/test/functional/systemtimes_controller_test.rb b/plugins/time/test/functional/systemtimes_controller_test.rb
index 528cd94..10419c4 100644
--- a/plugins/time/test/functional/systemtimes_controller_test.rb
+++ b/plugins/time/test/functional/systemtimes_controller_test.rb
@@ -12,63 +12,79 @@ class SystemtimesControllerTest < ActionController::TestCase
@request = ActionController::TestRequest.new
# http://railsforum.com/viewtopic.php?id=1719
@request.session[:account_id] = 1 # defined in fixtures
- Scr.any_instance.stubs(:initialize)
- Scr.any_instance.stubs(:execute).with(["/sbin/yast2", "timezone", "list"]).returns({:stderr=>"\nRegion: Africa\nAfrica/Abidjan (Abidjan)\nAfrica/Accra (Accra)\nAfrica/Addis_Ababa (Addis Ababa)\nAfrica/Algiers (Algiers)\nAfrica/Asmara (Asmara)\nAfrica/Bamako (Bamako)\nAfrica/Bangui (Bangui)\nAfrica/Banjul (Banjul)\nAfrica/Bissau (Bissau)\nAfrica/Blantyre (Blantyre)\nAfrica/Brazzaville (Brazzaville)\nAfrica/Bujumbura (Bujumbura)\nAfrica/Cairo (Cairo)\nAfrica/Casablanca (Casablanca)\nAfrica/Ceuta (Ceuta)\nAfrica/Conakry (Conakry)\n", :exit=>0, :stdout=>""})
- Scr.any_instance.stubs(:execute).with(["/bin/date"]).returns({:stderr=>"", :exit=>0, :stdout=>"Fri May 29 10:37:28 CEST 2009\n"})
- Scr.any_instance.stubs(:read).with(".sysconfig.clock.TIMEZONE").returns("Europe/Berlin")
- Scr.any_instance.stubs(:read).with(".sysconfig.clock.HWCLOCK").returns("-u")
end
test "access show" do
+ Systemtime.any_instance.stubs(:read)
get :show
assert_response :success
end
- test "access show xml" do
+ def test_access_denied
+ #mock model to test only controller
+ Systemtime.any_instance.stubs(:read)
+ @controller.stubs(:permission_check).returns(false);
+ get :show
+ assert_response :forbidden
+ end
+
+
+ def test_access_show_xml
+ Systemtime.any_instance.stubs(:read)
mime = Mime::XML
@request.accept = mime.to_s
get :show, :format => :xml
assert_equal mime.to_s, @response.content_type
end
- test "access show json" do
+ def test_access_show_json
+ Systemtime.any_instance.stubs(:read)
mime = Mime::JSON
@request.accept = mime.to_s
get :show, :format => :json
assert_equal mime.to_s, @response.content_type
end
- test "access show with a SCR call which returns an error" do
- Scr.any_instance.stubs(:execute).with(["/bin/date"]).returns({:stderr=>"", :exit=>1, :stdout=>"Fri May 29 10:37:28 CEST 2009\n"})
- get :show
- assert_response 404
+ Data = {:time => {
+ :timezone => "Europe/Prague",
+ :utcstatus => "true"
+ }}
+
+ def test_update
+ Systemtime.any_instance.stubs(:save)
+ put :update, Data
+ check_update_result
end
- test "access show with a SCR call which returns nil" do
- Scr.any_instance.stubs(:read).with(".sysconfig.clock.HWCLOCK").returns(nil)
- get :show
- assert_response 404
+ def test_create
+ Systemtime.any_instance.stubs(:save)
+ put :create, Data
+ check_update_result
end
- test "writing values back" do
- Scr.any_instance.stubs(:execute).with(["/sbin/hwclock", "--set", "-u", "--date=\"05/29/09 04:49:00\""], ["TZ=Europe/Berlin"]).returns()
- Scr.any_instance.stubs(:execute).with(['/sbin/hwclock', '--hctosys', '-u']).returns()
- Scr.any_instance.stubs(:write).with(".sysconfig.clock.TIMEZONE","Europe/Berlin").returns()
- Scr.any_instance.stubs(:write).with(".sysconfig.clock.HWCLOCK","-u").returns()
- current_time = Time.parse("Fri May 29 04:49:00 UTC 2009").strftime("%H:%M:%S")
- date = Time.parse("Fri May 29 04:49:00 UTC 2009").strftime("%m/%d/%y")
- post :create, :time=>{"timezone"=>"Europe/Berlin", "is_utc"=>true, "currenttime"=>current_time, "date"=>date, "validtimezones"=>[]}
+ def check_update_result
assert_response :success
+ time = assigns(:systemtime)
+ assert time
+ assert_equal Data[:time][:timezone], time.timezone
+ assert_equal Data[:time][:utcstatus], time.utcstatus
+ assert_nil time.datetime
end
- test "writing values back with not existing parameters" do
- post :create
- assert_response 404
+ def test_update_noparams
+ Language.any_instance.stubs(:save)
+ put :update
+ assert_response :missing
end
- test "writing values back with wrong parameters" do
- post :create, :time=>{}
- assert_response 404
- end
+ def test_update_noperm
+ #ensure that nothink is saved
+ Language.any_instance.expects(:save).never
+
+ @controller.stubs(:permission_check).returns(false);
-end
+ put :update, Data
+
+ assert_response :forbidden
+ end
+end
\ No newline at end of file
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org