To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 57 / 57b02f2ab6d4376e071c17d4651c0cbfba20e65a.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.69 KB)

1 1296:038ba2d95de8 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2012  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::RolesTest < ActionController::IntegrationTest
21
  fixtures :roles
22
23
  def setup
24
    Setting.rest_api_enabled = '1'
25
  end
26
27
  context "/roles" do
28
    context "GET" do
29
      context "xml" do
30
        should "return the roles" do
31
          get '/roles.xml'
32
33
          assert_response :success
34
          assert_equal 'application/xml', @response.content_type
35
          assert_equal 3, assigns(:roles).size
36
37
          assert_tag :tag => 'roles',
38
            :attributes => {:type => 'array'},
39
            :child => {
40
              :tag => 'role',
41
              :child => {
42
                :tag => 'id',
43
                :content => '2',
44
                :sibling => {
45
                  :tag => 'name',
46
                  :content => 'Developer'
47
                }
48
              }
49
            }
50
        end
51
      end
52
53
      context "json" do
54
        should "return the roles" do
55
          get '/roles.json'
56
57
          assert_response :success
58
          assert_equal 'application/json', @response.content_type
59
          assert_equal 3, assigns(:roles).size
60
61
          json = ActiveSupport::JSON.decode(response.body)
62
          assert_kind_of Hash, json
63
          assert_kind_of Array, json['roles']
64
          assert_include({'id' => 2, 'name' => 'Developer'}, json['roles'])
65
        end
66
      end
67
    end
68
  end
69
70
  context "/roles/:id" do
71
    context "GET" do
72
      context "xml" do
73
        should "return the role" do
74
          get '/roles/1.xml'
75
76
          assert_response :success
77
          assert_equal 'application/xml', @response.content_type
78
79
          assert_select 'role' do
80
            assert_select 'name', :text => 'Manager'
81
            assert_select 'role permissions[type=array]' do
82
              assert_select 'permission', Role.find(1).permissions.size
83
              assert_select 'permission', :text => 'view_issues'
84
            end
85
          end
86
        end
87
      end
88
    end
89
  end
90
end