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