ref: refs/heads/network commit 1220c411b21b0a2c9d5bdefe6e8bf08ea2039ebf Author: Martin Vidner <martin@vidner.net> Date: Tue Sep 1 15:55:19 2009 +0200 HostnameControllerTest uses PluginBasicTests. Had to move the controller to network/ for that. (?!) --- .../network/app/controllers/hostname_controller.rb | 45 ------------------- .../app/controllers/network/hostname_controller.rb | 46 ++++++++++++++++++++ .../test/functional/hostname_controller_test.rb | 23 +++++----- 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/plugins/network/app/controllers/hostname_controller.rb b/plugins/network/app/controllers/hostname_controller.rb deleted file mode 100644 index bb2db89..0000000 --- a/plugins/network/app/controllers/hostname_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -# = Hostname controller -# Provides access to hostname settings for authenticated users. -# Main goal is checking permissions. -class HostnameController < ApplicationController - - before_filter :login_required - - # Sets hostname settings. Requires write permissions for network YaPI. - def update - unless permission_check( "org.opensuse.yast.modules.yapi.network.write") - render ErrorResult.error(403, 1, "no permission") and return - end - - root = params[:hostname] - if root == nil - render ErrorResult.error(404, 2, "format or internal error") and return - end - - @hostname = Hostname.new(root) - @hostname.save - render :show - end - - # See update - def create - update - end - - # Shows hostname settings. Requires read permission for network YaPI. - def show - - unless permission_check( "org.opensuse.yast.modules.yapi.network.read") - render ErrorResult.error( 403, 1, "no permission" ) and return - end - - @hostname = Hostname.find - - respond_to do |format| - format.html { render :xml => @hostname.to_xml( :root => "hostname", :dasherize => false ) } - format.xml { render :xml => @hostname.to_xml( :root => "hostname", :dasherize => false ) } - format.json { render :json => @hostname.to_json } - end - end - -end diff --git a/plugins/network/app/controllers/network/hostname_controller.rb b/plugins/network/app/controllers/network/hostname_controller.rb new file mode 100644 index 0000000..d25ec82 --- /dev/null +++ b/plugins/network/app/controllers/network/hostname_controller.rb @@ -0,0 +1,46 @@ +# = Hostname controller +# Provides access to hostname settings for authenticated users. +# Main goal is checking permissions. + +class Network::HostnameController < ApplicationController + + before_filter :login_required + + # Sets hostname settings. Requires write permissions for network YaPI. + def update + unless permission_check( "org.opensuse.yast.modules.yapi.network.write") + render ErrorResult.error(403, 1, "no permission") and return + end + + root = params[:hostname] + if root == nil + render ErrorResult.error(404, 2, "format or internal error") and return + end + + @hostname = Hostname.new(root) + @hostname.save + render :show + end + + # See update + def create + update + end + + # Shows hostname settings. Requires read permission for network YaPI. + def show + + unless permission_check( "org.opensuse.yast.modules.yapi.network.read") + render ErrorResult.error( 403, 1, "no permission" ) and return + end + + @hostname = Hostname.find + + respond_to do |format| + format.html { render :xml => @hostname.to_xml( :root => "hostname", :dasherize => false ) } + format.xml { render :xml => @hostname.to_xml( :root => "hostname", :dasherize => false ) } + format.json { render :json => @hostname.to_json } + end + end + +end diff --git a/plugins/network/test/functional/hostname_controller_test.rb b/plugins/network/test/functional/hostname_controller_test.rb index 76d1eba..1f26a95 100644 --- a/plugins/network/test/functional/hostname_controller_test.rb +++ b/plugins/network/test/functional/hostname_controller_test.rb @@ -1,21 +1,22 @@ require File.expand_path(File.dirname(__FILE__) + "/../test_helper") require 'test/unit' -require 'rubygems' require 'hostname' -require "scr" +require 'rubygems' require 'mocha' require File.expand_path( File.join("test","plugin_basic_tests"), RailsParent.parent ) -class HostnameControllerTest < Test::Unit::TestCase +class HostnameControllerTest < ActionController::TestCase + + def setup + @model_class = Hostname + Hostname.stubs(:find).returns(Hostname.new({"name" => "BAD", "domain" => "DOMAIN"})) + @controller = Network::HostnameController.new + @request = ActionController::TestRequest.new + # http://railsforum.com/viewtopic.php?id=1719 + @request.session[:account_id] = 1 # defined in fixtures + end - # this is test only for mocked data - not very useful - # we need to extend it to test both model and controller - # to extract hostname data from all YaPI map - # - def test_show - Hostname.expects(:find).returns({:name=>'linux', :domain=>'suse.cz'}) - Hostname.find - end + include PluginBasicTests end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org