ref: refs/heads/network
commit ed1c335cccf5812017f5a4d290b2fb0f3913e708
Author: Josef Reidinger
Date: Thu Aug 20 11:59:58 2009 +0200
fix problems in time module
---
.../time/app/controllers/systemtimes_controller.rb | 6 ++--
plugins/time/app/models/systemtime.rb | 6 ++--
.../test/functional/systemtimes_controller_test.rb | 26 ++++++++++----------
webservice/test/plugin_basic_tests.rb | 16 ++++--------
4 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/plugins/time/app/controllers/systemtimes_controller.rb b/plugins/time/app/controllers/systemtimes_controller.rb
index c49a91c..8e26276 100644
--- a/plugins/time/app/controllers/systemtimes_controller.rb
+++ b/plugins/time/app/controllers/systemtimes_controller.rb
@@ -44,9 +44,9 @@ class SystemtimesController < ApplicationController
@systemtime = Systemtime.find
respond_to do |format|
- format.html { @systemtime.to_xml( :root => "systemtime", :dasherize => false ) }
- format.xml { @systemtime.to_xml( :root => "systemtime", :dasherize => false ) }
- format.json { @systemtime.to_json( :root => "systemtime", :dasherize => false ) }
+ format.html { render :xml => @systemtime.to_xml( :root => "systemtime", :dasherize => false ) }
+ format.xml { render :xml => @systemtime.to_xml( :root => "systemtime", :dasherize => false ) }
+ format.json { render :json => @systemtime.to_json( :root => "systemtime", :dasherize => false ) }
end
end
diff --git a/plugins/time/app/models/systemtime.rb b/plugins/time/app/models/systemtime.rb
index 9a97a20..f14ad69 100644
--- a/plugins/time/app/models/systemtime.rb
+++ b/plugins/time/app/models/systemtime.rb
@@ -78,17 +78,17 @@ class Systemtime
def save
settings = {}
if @timezone and !@timezone.empty?
- settings["timezone"] = @timezone
+ settings[:timezone] = @timezone
end
if @utcstatus and !@utcstatus.empty?
- settings["utcstatus"] = @utcstatus
+ settings[:utcstatus] = @utcstatus
end
need_rescue = false
if (@date and !@date.empty?) and
(@time and !@time.empty?)
date = @date.split("/")
datetime = "#{date[2]}-#{date[0]}-#{date[1]} - "+@time
- settings["currenttime"] = datetime
+ settings[:currenttime] = datetime
need_rescue = true
end
begin
diff --git a/plugins/time/test/functional/systemtimes_controller_test.rb b/plugins/time/test/functional/systemtimes_controller_test.rb
index 4f0ffac..1d5d105 100644
--- a/plugins/time/test/functional/systemtimes_controller_test.rb
+++ b/plugins/time/test/functional/systemtimes_controller_test.rb
@@ -17,7 +17,7 @@ class SystemtimesControllerTest < ActionController::TestCase
def setup
@model_class = Systemtime
- Systemtime.stubs(:find).returns([Systemtime.new, Systemtime.new])
+ Systemtime.stubs(:find).returns(Systemtime.new)
@controller = SystemtimesController.new
@request = ActionController::TestRequest.new
@@ -29,24 +29,24 @@ class SystemtimesControllerTest < ActionController::TestCase
include PluginBasicTests
def test_update
- Systemtime.any_instance.stubs(:save)
+ mock_save
put :update, DATA
- check_update_result
+ assert_response :success
end
def test_create
- Systemtime.any_instance.stubs(:save)
+ mock_save
put :create, DATA
- check_update_result
+ assert_response :success
end
- 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.date
- assert_nil time.time
+ def mock_save
+ YastService.stubs(:Call).with {
+ |params,settings|
+ params == "YaPI::TIME::Write" and
+ settings[:timezone] == DATA[:time][:timezone] and
+ settings[:utcstatus] == DATA[:time][:utcstatus] and
+ ! settings.include?(:currenttime)
+ }
end
end
diff --git a/webservice/test/plugin_basic_tests.rb b/webservice/test/plugin_basic_tests.rb
index d16dd34..0d7ad8f 100644
--- a/webservice/test/plugin_basic_tests.rb
+++ b/webservice/test/plugin_basic_tests.rb
@@ -42,23 +42,17 @@
# end
module PluginBasicTests
- def test_access_index
- #mock model to test only controller
- @model_class.any_instance.stubs(:find)
- get :show
- assert_response :success
- end
def test_access_denied
#mock model to test only controller
- @model_class.any_instance.stubs(:find)
+ @model_class.stubs(:find)
@controller.stubs(:permission_check).returns(false);
get :show
assert_response :forbidden
end
def test_access_show_xml
- @model_class.any_instance.stubs(:find)
+ @model_class.stubs(:find)
mime = Mime::XML
@request.accept = mime.to_s
get :show, :format => :xml
@@ -66,7 +60,7 @@ module PluginBasicTests
end
def test_access_show_json
- @model_class.any_instance.stubs(:find)
+ @model_class.stubs(:find)
mime = Mime::JSON
@request.accept = mime.to_s
get :show, :format => :json
@@ -74,14 +68,14 @@ module PluginBasicTests
end
def test_update_noparams
- @model_class.any_instance.stubs(:save)
+ @model_class.stubs(:save)
put :update
assert_response :missing
end
def test_update_noperm
#ensure that nothing is saved
- @model_class.any_instance.expects(:save).never
+ @model_class.expects(:save).never
@controller.stubs(:permission_check).returns(false);
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org