##// END OF EJS Templates
Adds API response to /trackers to get the list of all available trackers (#7181)....
Jean-Philippe Lang -
r7757:053adaef52d7
parent child
Show More
@@ -0,0 +1,8
1 api.array :trackers do
2 @trackers.each do |tracker|
3 api.tracker do
4 api.id tracker.id
5 api.name tracker.name
6 end
7 end
8 end
@@ -0,0 +1,51
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../test_helper', __FILE__)
19
20 class ApiTest::TrackersTest < ActionController::IntegrationTest
21 fixtures :trackers
22
23 def setup
24 Setting.rest_api_enabled = '1'
25 end
26
27 context "/trackers" do
28 context "GET" do
29
30 should "return trackers" do
31 get '/trackers.xml'
32
33 assert_response :success
34 assert_equal 'application/xml', @response.content_type
35 assert_tag :tag => 'trackers',
36 :attributes => {:type => 'array'},
37 :child => {
38 :tag => 'tracker',
39 :child => {
40 :tag => 'id',
41 :content => '2',
42 :sibling => {
43 :tag => 'name',
44 :content => 'Feature request'
45 }
46 }
47 }
48 end
49 end
50 end
51 end
@@ -314,6 +314,19 class ApplicationController < ActionController::Base
314 format.json { head @status }
314 format.json { head @status }
315 end
315 end
316 end
316 end
317
318 # Filter for actions that provide an API response
319 # but have no HTML representation for non admin users
320 def require_admin_or_api_request
321 return true if api_request?
322 if User.current.admin?
323 true
324 elsif User.current.logged?
325 render_error(:status => 406)
326 else
327 deny_access
328 end
329 end
317
330
318 # Picks which layout to use based on the request
331 # Picks which layout to use based on the request
319 #
332 #
@@ -18,13 +18,22
18 class TrackersController < ApplicationController
18 class TrackersController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin
21 before_filter :require_admin, :except => :index
22 before_filter :require_admin_or_api_request, :only => :index
23 accept_api_auth :index
22
24
23 verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
25 verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
24
26
25 def index
27 def index
26 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
28 respond_to do |format|
27 render :action => "index", :layout => false if request.xhr?
29 format.html {
30 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
31 render :action => "index", :layout => false if request.xhr?
32 }
33 format.api {
34 @trackers = Tracker.all
35 }
36 end
28 end
37 end
29
38
30 def new
39 def new
@@ -227,6 +227,7 ActionController::Routing::Routes.draw do |map|
227 map.resources :groups
227 map.resources :groups
228
228
229 #left old routes at the bottom for backwards compat
229 #left old routes at the bottom for backwards compat
230 map.connect 'trackers.:format', :controller => 'trackers', :action => 'index'
230 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
231 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
231 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
232 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
232 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
233 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
@@ -37,6 +37,18 class TrackersControllerTest < ActionController::TestCase
37 assert_response :success
37 assert_response :success
38 assert_template 'index'
38 assert_template 'index'
39 end
39 end
40
41 def test_index_by_anonymous_should_redirect_to_login_form
42 @request.session[:user_id] = nil
43 get :index
44 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftrackers'
45 end
46
47 def test_index_by_user_should_respond_with_406
48 @request.session[:user_id] = 2
49 get :index
50 assert_response 406
51 end
40
52
41 def test_get_new
53 def test_get_new
42 get :new
54 get :new
General Comments 0
You need to be logged in to leave comments. Login now