Mercurial > hg > soundsoftware-site
comparison .svn/pristine/60/60a95a1966b625bd87358ca8fc028478e501f2bb.svn-base @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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 Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base | |
21 fixtures :users, :groups_users | |
22 | |
23 def setup | |
24 Setting.rest_api_enabled = '1' | |
25 end | |
26 | |
27 test "GET /groups.xml should require authentication" do | |
28 get '/groups.xml' | |
29 assert_response 401 | |
30 end | |
31 | |
32 test "GET /groups.xml should return groups" do | |
33 get '/groups.xml', {}, credentials('admin') | |
34 assert_response :success | |
35 assert_equal 'application/xml', response.content_type | |
36 | |
37 assert_select 'groups' do | |
38 assert_select 'group' do | |
39 assert_select 'name', :text => 'A Team' | |
40 assert_select 'id', :text => '10' | |
41 end | |
42 end | |
43 end | |
44 | |
45 test "GET /groups.json should require authentication" do | |
46 get '/groups.json' | |
47 assert_response 401 | |
48 end | |
49 | |
50 test "GET /groups.json should return groups" do | |
51 get '/groups.json', {}, credentials('admin') | |
52 assert_response :success | |
53 assert_equal 'application/json', response.content_type | |
54 | |
55 json = MultiJson.load(response.body) | |
56 groups = json['groups'] | |
57 assert_kind_of Array, groups | |
58 group = groups.detect {|g| g['name'] == 'A Team'} | |
59 assert_not_nil group | |
60 assert_equal({'id' => 10, 'name' => 'A Team'}, group) | |
61 end | |
62 | |
63 test "GET /groups/:id.xml should return the group with its users" do | |
64 get '/groups/10.xml', {}, credentials('admin') | |
65 assert_response :success | |
66 assert_equal 'application/xml', response.content_type | |
67 | |
68 assert_select 'group' do | |
69 assert_select 'name', :text => 'A Team' | |
70 assert_select 'id', :text => '10' | |
71 end | |
72 end | |
73 | |
74 test "GET /groups/:id.xml should include users if requested" do | |
75 get '/groups/10.xml?include=users', {}, credentials('admin') | |
76 assert_response :success | |
77 assert_equal 'application/xml', response.content_type | |
78 | |
79 assert_select 'group' do | |
80 assert_select 'users' do | |
81 assert_select 'user', Group.find(10).users.count | |
82 assert_select 'user[id=8]' | |
83 end | |
84 end | |
85 end | |
86 | |
87 test "GET /groups/:id.xml include memberships if requested" do | |
88 get '/groups/10.xml?include=memberships', {}, credentials('admin') | |
89 assert_response :success | |
90 assert_equal 'application/xml', response.content_type | |
91 | |
92 assert_select 'group' do | |
93 assert_select 'memberships' | |
94 end | |
95 end | |
96 | |
97 test "POST /groups.xml with valid parameters should create the group" do | |
98 assert_difference('Group.count') do | |
99 post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin') | |
100 assert_response :created | |
101 assert_equal 'application/xml', response.content_type | |
102 end | |
103 | |
104 group = Group.order('id DESC').first | |
105 assert_equal 'Test', group.name | |
106 assert_equal [2, 3], group.users.map(&:id).sort | |
107 | |
108 assert_select 'group' do | |
109 assert_select 'name', :text => 'Test' | |
110 end | |
111 end | |
112 | |
113 test "POST /groups.xml with invalid parameters should return errors" do | |
114 assert_no_difference('Group.count') do | |
115 post '/groups.xml', {:group => {:name => ''}}, credentials('admin') | |
116 end | |
117 assert_response :unprocessable_entity | |
118 assert_equal 'application/xml', response.content_type | |
119 | |
120 assert_select 'errors' do | |
121 assert_select 'error', :text => /Name can't be blank/ | |
122 end | |
123 end | |
124 | |
125 test "PUT /groups/:id.xml with valid parameters should update the group" do | |
126 put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin') | |
127 assert_response :ok | |
128 assert_equal '', @response.body | |
129 | |
130 group = Group.find(10) | |
131 assert_equal 'New name', group.name | |
132 assert_equal [2, 3], group.users.map(&:id).sort | |
133 end | |
134 | |
135 test "PUT /groups/:id.xml with invalid parameters should return errors" do | |
136 put '/groups/10.xml', {:group => {:name => ''}}, credentials('admin') | |
137 assert_response :unprocessable_entity | |
138 assert_equal 'application/xml', response.content_type | |
139 | |
140 assert_select 'errors' do | |
141 assert_select 'error', :text => /Name can't be blank/ | |
142 end | |
143 end | |
144 | |
145 test "DELETE /groups/:id.xml should delete the group" do | |
146 assert_difference 'Group.count', -1 do | |
147 delete '/groups/10.xml', {}, credentials('admin') | |
148 assert_response :ok | |
149 assert_equal '', @response.body | |
150 end | |
151 end | |
152 | |
153 test "POST /groups/:id/users.xml should add user to the group" do | |
154 assert_difference 'Group.find(10).users.count' do | |
155 post '/groups/10/users.xml', {:user_id => 5}, credentials('admin') | |
156 assert_response :ok | |
157 assert_equal '', @response.body | |
158 end | |
159 assert_include User.find(5), Group.find(10).users | |
160 end | |
161 | |
162 test "DELETE /groups/:id/users/:user_id.xml should remove user from the group" do | |
163 assert_difference 'Group.find(10).users.count', -1 do | |
164 delete '/groups/10/users/8.xml', {}, credentials('admin') | |
165 assert_response :ok | |
166 assert_equal '', @response.body | |
167 end | |
168 assert_not_include User.find(8), Group.find(10).users | |
169 end | |
170 end |