comparison test/integration/api_test/roles_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
15 # along with this program; if not, write to the Free Software 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../../test_helper', __FILE__) 18 require File.expand_path('../../../test_helper', __FILE__)
19 19
20 class ApiTest::RolesTest < ActionController::IntegrationTest 20 class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
21 fixtures :roles 21 fixtures :roles
22 22
23 def setup 23 def setup
24 Setting.rest_api_enabled = '1' 24 Setting.rest_api_enabled = '1'
25 end 25 end
26 26
27 context "/roles" do 27 test "GET /roles.xml should return the roles" do
28 context "GET" do 28 get '/roles.xml'
29 context "xml" do
30 should "return the roles" do
31 get '/roles.xml'
32 29
33 assert_response :success 30 assert_response :success
34 assert_equal 'application/xml', @response.content_type 31 assert_equal 'application/xml', @response.content_type
35 assert_equal 3, assigns(:roles).size 32 assert_equal 3, assigns(:roles).size
36 33
37 assert_tag :tag => 'roles', 34 assert_tag :tag => 'roles',
38 :attributes => {:type => 'array'}, 35 :attributes => {:type => 'array'},
39 :child => { 36 :child => {
40 :tag => 'role', 37 :tag => 'role',
41 :child => { 38 :child => {
42 :tag => 'id', 39 :tag => 'id',
43 :content => '2', 40 :content => '2',
44 :sibling => { 41 :sibling => {
45 :tag => 'name', 42 :tag => 'name',
46 :content => 'Developer' 43 :content => 'Developer'
47 } 44 }
48 } 45 }
49 } 46 }
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 47 end
69 48
70 context "/roles/:id" do 49 test "GET /roles.json should return the roles" do
71 context "GET" do 50 get '/roles.json'
72 context "xml" do
73 should "return the role" do
74 get '/roles/1.xml'
75 51
76 assert_response :success 52 assert_response :success
77 assert_equal 'application/xml', @response.content_type 53 assert_equal 'application/json', @response.content_type
54 assert_equal 3, assigns(:roles).size
78 55
79 assert_select 'role' do 56 json = ActiveSupport::JSON.decode(response.body)
80 assert_select 'name', :text => 'Manager' 57 assert_kind_of Hash, json
81 assert_select 'role permissions[type=array]' do 58 assert_kind_of Array, json['roles']
82 assert_select 'permission', Role.find(1).permissions.size 59 assert_include({'id' => 2, 'name' => 'Developer'}, json['roles'])
83 assert_select 'permission', :text => 'view_issues' 60 end
84 end 61
85 end 62 test "GET /roles/:id.xml should return the role" do
86 end 63 get '/roles/1.xml'
64
65 assert_response :success
66 assert_equal 'application/xml', @response.content_type
67
68 assert_select 'role' do
69 assert_select 'name', :text => 'Manager'
70 assert_select 'role permissions[type=array]' do
71 assert_select 'permission', Role.find(1).permissions.size
72 assert_select 'permission', :text => 'view_issues'
87 end 73 end
88 end 74 end
89 end 75 end
90 end 76 end