annotate .svn/pristine/32/325cbd5f2592da1a1293c4a50be14ad1338348eb.svn-base @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class ApiTest::GroupsTest < ActionController::IntegrationTest
Chris@1296 21 fixtures :users, :groups_users
Chris@1296 22
Chris@1296 23 def setup
Chris@1296 24 Setting.rest_api_enabled = '1'
Chris@1296 25 end
Chris@1296 26
Chris@1296 27 context "GET /groups" do
Chris@1296 28 context ".xml" do
Chris@1296 29 should "require authentication" do
Chris@1296 30 get '/groups.xml'
Chris@1296 31 assert_response 401
Chris@1296 32 end
Chris@1296 33
Chris@1296 34 should "return groups" do
Chris@1296 35 get '/groups.xml', {}, credentials('admin')
Chris@1296 36 assert_response :success
Chris@1296 37 assert_equal 'application/xml', response.content_type
Chris@1296 38
Chris@1296 39 assert_select 'groups' do
Chris@1296 40 assert_select 'group' do
Chris@1296 41 assert_select 'name', :text => 'A Team'
Chris@1296 42 assert_select 'id', :text => '10'
Chris@1296 43 end
Chris@1296 44 end
Chris@1296 45 end
Chris@1296 46 end
Chris@1296 47
Chris@1296 48 context ".json" do
Chris@1296 49 should "require authentication" do
Chris@1296 50 get '/groups.json'
Chris@1296 51 assert_response 401
Chris@1296 52 end
Chris@1296 53
Chris@1296 54 should "return groups" do
Chris@1296 55 get '/groups.json', {}, credentials('admin')
Chris@1296 56 assert_response :success
Chris@1296 57 assert_equal 'application/json', response.content_type
Chris@1296 58
Chris@1296 59 json = MultiJson.load(response.body)
Chris@1296 60 groups = json['groups']
Chris@1296 61 assert_kind_of Array, groups
Chris@1296 62 group = groups.detect {|g| g['name'] == 'A Team'}
Chris@1296 63 assert_not_nil group
Chris@1296 64 assert_equal({'id' => 10, 'name' => 'A Team'}, group)
Chris@1296 65 end
Chris@1296 66 end
Chris@1296 67 end
Chris@1296 68
Chris@1296 69 context "GET /groups/:id" do
Chris@1296 70 context ".xml" do
Chris@1296 71 should "return the group with its users" do
Chris@1296 72 get '/groups/10.xml', {}, credentials('admin')
Chris@1296 73 assert_response :success
Chris@1296 74 assert_equal 'application/xml', response.content_type
Chris@1296 75
Chris@1296 76 assert_select 'group' do
Chris@1296 77 assert_select 'name', :text => 'A Team'
Chris@1296 78 assert_select 'id', :text => '10'
Chris@1296 79 end
Chris@1296 80 end
Chris@1296 81
Chris@1296 82 should "include users if requested" do
Chris@1296 83 get '/groups/10.xml?include=users', {}, credentials('admin')
Chris@1296 84 assert_response :success
Chris@1296 85 assert_equal 'application/xml', response.content_type
Chris@1296 86
Chris@1296 87 assert_select 'group' do
Chris@1296 88 assert_select 'users' do
Chris@1296 89 assert_select 'user', Group.find(10).users.count
Chris@1296 90 assert_select 'user[id=8]'
Chris@1296 91 end
Chris@1296 92 end
Chris@1296 93 end
Chris@1296 94
Chris@1296 95 should "include memberships if requested" do
Chris@1296 96 get '/groups/10.xml?include=memberships', {}, credentials('admin')
Chris@1296 97 assert_response :success
Chris@1296 98 assert_equal 'application/xml', response.content_type
Chris@1296 99
Chris@1296 100 assert_select 'group' do
Chris@1296 101 assert_select 'memberships'
Chris@1296 102 end
Chris@1296 103 end
Chris@1296 104 end
Chris@1296 105 end
Chris@1296 106
Chris@1296 107 context "POST /groups" do
Chris@1296 108 context "with valid parameters" do
Chris@1296 109 context ".xml" do
Chris@1296 110 should "create groups" do
Chris@1296 111 assert_difference('Group.count') do
Chris@1296 112 post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin')
Chris@1296 113 assert_response :created
Chris@1296 114 assert_equal 'application/xml', response.content_type
Chris@1296 115 end
Chris@1296 116
Chris@1296 117 group = Group.order('id DESC').first
Chris@1296 118 assert_equal 'Test', group.name
Chris@1296 119 assert_equal [2, 3], group.users.map(&:id).sort
Chris@1296 120
Chris@1296 121 assert_select 'group' do
Chris@1296 122 assert_select 'name', :text => 'Test'
Chris@1296 123 end
Chris@1296 124 end
Chris@1296 125 end
Chris@1296 126 end
Chris@1296 127
Chris@1296 128 context "with invalid parameters" do
Chris@1296 129 context ".xml" do
Chris@1296 130 should "return errors" do
Chris@1296 131 assert_no_difference('Group.count') do
Chris@1296 132 post '/groups.xml', {:group => {:name => ''}}, credentials('admin')
Chris@1296 133 end
Chris@1296 134 assert_response :unprocessable_entity
Chris@1296 135 assert_equal 'application/xml', response.content_type
Chris@1296 136
Chris@1296 137 assert_select 'errors' do
Chris@1296 138 assert_select 'error', :text => /Name can't be blank/
Chris@1296 139 end
Chris@1296 140 end
Chris@1296 141 end
Chris@1296 142 end
Chris@1296 143 end
Chris@1296 144
Chris@1296 145 context "PUT /groups/:id" do
Chris@1296 146 context "with valid parameters" do
Chris@1296 147 context ".xml" do
Chris@1296 148 should "update the group" do
Chris@1296 149 put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin')
Chris@1296 150 assert_response :ok
Chris@1296 151 assert_equal '', @response.body
Chris@1296 152
Chris@1296 153 group = Group.find(10)
Chris@1296 154 assert_equal 'New name', group.name
Chris@1296 155 assert_equal [2, 3], group.users.map(&:id).sort
Chris@1296 156 end
Chris@1296 157 end
Chris@1296 158 end
Chris@1296 159
Chris@1296 160 context "with invalid parameters" do
Chris@1296 161 context ".xml" do
Chris@1296 162 should "return errors" do
Chris@1296 163 put '/groups/10.xml', {:group => {:name => ''}}, credentials('admin')
Chris@1296 164 assert_response :unprocessable_entity
Chris@1296 165 assert_equal 'application/xml', response.content_type
Chris@1296 166
Chris@1296 167 assert_select 'errors' do
Chris@1296 168 assert_select 'error', :text => /Name can't be blank/
Chris@1296 169 end
Chris@1296 170 end
Chris@1296 171 end
Chris@1296 172 end
Chris@1296 173 end
Chris@1296 174
Chris@1296 175 context "DELETE /groups/:id" do
Chris@1296 176 context ".xml" do
Chris@1296 177 should "delete the group" do
Chris@1296 178 assert_difference 'Group.count', -1 do
Chris@1296 179 delete '/groups/10.xml', {}, credentials('admin')
Chris@1296 180 assert_response :ok
Chris@1296 181 assert_equal '', @response.body
Chris@1296 182 end
Chris@1296 183 end
Chris@1296 184 end
Chris@1296 185 end
Chris@1296 186
Chris@1296 187 context "POST /groups/:id/users" do
Chris@1296 188 context ".xml" do
Chris@1296 189 should "add user to the group" do
Chris@1296 190 assert_difference 'Group.find(10).users.count' do
Chris@1296 191 post '/groups/10/users.xml', {:user_id => 5}, credentials('admin')
Chris@1296 192 assert_response :ok
Chris@1296 193 assert_equal '', @response.body
Chris@1296 194 end
Chris@1296 195 assert_include User.find(5), Group.find(10).users
Chris@1296 196 end
Chris@1296 197 end
Chris@1296 198 end
Chris@1296 199
Chris@1296 200 context "DELETE /groups/:id/users/:user_id" do
Chris@1296 201 context ".xml" do
Chris@1296 202 should "remove user from the group" do
Chris@1296 203 assert_difference 'Group.find(10).users.count', -1 do
Chris@1296 204 delete '/groups/10/users/8.xml', {}, credentials('admin')
Chris@1296 205 assert_response :ok
Chris@1296 206 assert_equal '', @response.body
Chris@1296 207 end
Chris@1296 208 assert_not_include User.find(8), Group.find(10).users
Chris@1296 209 end
Chris@1296 210 end
Chris@1296 211 end
Chris@1296 212 end