[yast-commit] <rest-service> jr-basemodel : Ntp plugin now use rest-service ancestor
ref: refs/heads/jr-basemodel commit ccf3a31ffe1abe0c5a0da47a01992ebfba25224b Author: Josef Reidinger <jreidinger@suse.cz> Date: Fri Dec 11 12:58:32 2009 +0100 Ntp plugin now use rest-service ancestor --- plugins/ntp/app/controllers/ntp_controller.rb | 14 +++----------- plugins/ntp/app/models/ntp.rb | 13 ++++++++----- plugins/ntp/test/functional/ntp_controller_test.rb | 6 +++--- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/plugins/ntp/app/controllers/ntp_controller.rb b/plugins/ntp/app/controllers/ntp_controller.rb index 8af3666..f274cfe 100644 --- a/plugins/ntp/app/controllers/ntp_controller.rb +++ b/plugins/ntp/app/controllers/ntp_controller.rb @@ -1,4 +1,3 @@ - class NtpController < ApplicationController before_filter :login_required @@ -7,8 +6,8 @@ class NtpController < ApplicationController ntp = Ntp.find respond_to do |format| - format.xml { render :xml => ntp.actions.to_xml(:root => :actions)} - format.json { render :json => ntp.actions.to_json } + format.xml { render :xml => ntp.to_xml} + format.json { render :json => ntp.to_json } end end @@ -18,14 +17,7 @@ class NtpController < ApplicationController raise InvalidParameters.new :ntp => "Missing" end - @ntp = Ntp.find - - if root["synchronize"] - yapi_perm_check "ntp.synchronize" - @ntp.actions[:synchronize] = true - end - - @ntp.save + Ntp.new(root).save show end diff --git a/plugins/ntp/app/models/ntp.rb b/plugins/ntp/app/models/ntp.rb index c57115f..ee89f8d 100644 --- a/plugins/ntp/app/models/ntp.rb +++ b/plugins/ntp/app/models/ntp.rb @@ -1,10 +1,15 @@ -class Ntp +class Ntp < BaseModel::Base attr_accessor :actions + validates_inclusion_of :'actions[:synchronize]', :in => [ true, false ], :allow_nil => true + + before_save { yapi_perm_check "ntp.synchronize" if actions[:synchronize] } + public - def initialize + def initialize(args={}) @actions = { :synchronize => false } + super args end def self.find @@ -12,9 +17,7 @@ class Ntp end def save - if @actions[:synchronize] - synchronize - end + synchronize if @actions[:synchronize] end private diff --git a/plugins/ntp/test/functional/ntp_controller_test.rb b/plugins/ntp/test/functional/ntp_controller_test.rb index 9709de5..364f845 100644 --- a/plugins/ntp/test/functional/ntp_controller_test.rb +++ b/plugins/ntp/test/functional/ntp_controller_test.rb @@ -19,18 +19,18 @@ class SystemControllerTest < ActionController::TestCase ret = get :show assert_response :success response = Hash.from_xml(ret.body) - assert response["actions"]["synchronize"] == false + assert response["ntp"]["actions"]["synchronize"] == false end def test_update YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.returns("OK") - post :update, {"ntp"=>{"synchronize"=>true}} + post :update, {"ntp"=>{"actions" => {"synchronize"=>true}}} assert_response :success end def test_update_failed YastService.stubs(:Call).with("YaPI::NTP::Synchronize").once.returns("Failed") - post :update, {"ntp"=>{"synchronize"=>true}} + post :update, {"ntp"=>{"actions" => {"synchronize"=>true}}} assert_response 503 end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Josef Reidinger