annotate test/integration/api_test/groups_test.rb @ 1524:82fac3dcf466 redmine-2.5-integration

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