Index: test/integration/users_api_test.rb =================================================================== --- test/integration/users_api_test.rb (revision 0) +++ test/integration/users_api_test.rb (revision 0) @@ -0,0 +1,91 @@ +# Redmine - project management software +# Copyright (C) 2006-2010 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require "#{File.dirname(__FILE__)}/../test_helper" + +class UsersApiTest < ActionController::IntegrationTest + fixtures :users, :roles + + def setup + Setting.rest_api_enabled = '1' + end + + def teardown + Setting.rest_api_enabled = '0' + end + + context "get /users.xml with authorized user" do + setup do + get '/users.xml', nil, :authorization => credentials('admin') + end + + should_respond_with :success + should_respond_with_content_type 'application/xml' + + end + + context "get /users.xml with unauthorized user" do + setup do + get '/users.xml', nil, :authorization => credentials('jsmith') + end + + should_respond_with :forbidden + + end + + context "get /users.xml with name " do + setup do + get '/users.xml?name=jsmith', nil, :authorization => credentials('admin') + end + + + + should_respond_with_content_type 'application/xml' + + should "show only users with the name jsmith " do + + c = ARCondition.new(["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", "jsmith","jsmith","jsmith","jsmith"]) + @user_count = User.count(:conditions => c.conditions) + assert_tag :tag => 'users', :children => { :count => @user_count, :only => {:tag => "user"} } + end + + end + + + context "get /users.xml with status 1 " do + setup do + get '/users.xml?status=1', nil, :authorization => credentials('admin') + end + + + + should_respond_with_content_type 'application/xml' + + should "show only users with the status 1 " do + + c = ARCondition.new(["status = 1"]) + @user_count = User.count(:conditions => c.conditions) + assert_tag :tag => 'users', :children => { :count => @user_count, :only => {:tag => "user"} } + end + + end + + + def credentials(user, password=nil) + ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) + end +end Index: app/controllers/users_controller.rb =================================================================== --- app/controllers/users_controller.rb (revision 3859) +++ app/controllers/users_controller.rb (working copy) @@ -46,7 +46,7 @@ :limit => @user_pages.items_per_page, :offset => @user_pages.current.offset - render :layout => !request.xhr? + render :layout => !request.xhr? end def show @@ -67,8 +67,14 @@ return end end - render :layout => 'base' + respond_to do |format| + format.html { + render :layout => 'base' + } + format.xml + end + rescue ActiveRecord::RecordNotFound render_404 end Index: app/views/users/index.xml.builder =================================================================== --- app/views/users/index.xml.builder (revision 0) +++ app/views/users/index.xml.builder (revision 0) @@ -0,0 +1,12 @@ +xml.instruct! +xml.users :type => 'array' do + @users.each do |user| + xml.user do + xml.id user.id + xml.first user.firstname + xml.last user.lastname + xml.login user.login + xml.mail user.mail + end + end +end Index: config/routes.rb =================================================================== --- config/routes.rb (revision 3859) +++ config/routes.rb (working copy) @@ -171,6 +171,7 @@ map.with_options :controller => 'users' do |users| users.with_options :conditions => {:method => :get} do |user_views| user_views.connect 'users', :action => 'index' + user_views.connect 'users.:format', :action => 'index' user_views.connect 'users/:id', :action => 'show', :id => /\d+/ user_views.connect 'users/new', :action => 'add' user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil