annotate .svn/pristine/9b/9beda19e37ba519663a5fe247e7821709eb07ca9.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::UsersTest < Redmine::ApiTest::Base
Chris@1494 21 fixtures :users, :members, :member_roles, :roles, :projects
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 should_allow_api_authentication(:get, "/users.xml")
Chris@1494 28 should_allow_api_authentication(:get, "/users.json")
Chris@1494 29 should_allow_api_authentication(:post,
Chris@1494 30 '/users.xml',
Chris@1494 31 {:user => {
Chris@1494 32 :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
Chris@1494 33 :mail => 'foo@example.net', :password => 'secret123'
Chris@1494 34 }},
Chris@1494 35 {:success_code => :created})
Chris@1494 36 should_allow_api_authentication(:post,
Chris@1494 37 '/users.json',
Chris@1494 38 {:user => {
Chris@1494 39 :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
Chris@1494 40 :mail => 'foo@example.net'
Chris@1494 41 }},
Chris@1494 42 {:success_code => :created})
Chris@1494 43 should_allow_api_authentication(:put,
Chris@1494 44 '/users/2.xml',
Chris@1494 45 {:user => {
Chris@1494 46 :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
Chris@1494 47 :mail => 'jsmith@somenet.foo'
Chris@1494 48 }},
Chris@1494 49 {:success_code => :ok})
Chris@1494 50 should_allow_api_authentication(:put,
Chris@1494 51 '/users/2.json',
Chris@1494 52 {:user => {
Chris@1494 53 :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
Chris@1494 54 :mail => 'jsmith@somenet.foo'
Chris@1494 55 }},
Chris@1494 56 {:success_code => :ok})
Chris@1494 57 should_allow_api_authentication(:delete,
Chris@1494 58 '/users/2.xml',
Chris@1494 59 {},
Chris@1494 60 {:success_code => :ok})
Chris@1494 61 should_allow_api_authentication(:delete,
Chris@1494 62 '/users/2.xml',
Chris@1494 63 {},
Chris@1494 64 {:success_code => :ok})
Chris@1494 65
Chris@1494 66 test "GET /users/:id.xml should return the user" do
Chris@1494 67 get '/users/2.xml'
Chris@1494 68
Chris@1494 69 assert_response :success
Chris@1494 70 assert_tag :tag => 'user',
Chris@1494 71 :child => {:tag => 'id', :content => '2'}
Chris@1494 72 end
Chris@1494 73
Chris@1494 74 test "GET /users/:id.json should return the user" do
Chris@1494 75 get '/users/2.json'
Chris@1494 76
Chris@1494 77 assert_response :success
Chris@1494 78 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 79 assert_kind_of Hash, json
Chris@1494 80 assert_kind_of Hash, json['user']
Chris@1494 81 assert_equal 2, json['user']['id']
Chris@1494 82 end
Chris@1494 83
Chris@1494 84 test "GET /users/:id.xml with include=memberships should include memberships" do
Chris@1494 85 get '/users/2.xml?include=memberships'
Chris@1494 86
Chris@1494 87 assert_response :success
Chris@1494 88 assert_tag :tag => 'memberships',
Chris@1494 89 :parent => {:tag => 'user'},
Chris@1494 90 :children => {:count => 1}
Chris@1494 91 end
Chris@1494 92
Chris@1494 93 test "GET /users/:id.json with include=memberships should include memberships" do
Chris@1494 94 get '/users/2.json?include=memberships'
Chris@1494 95
Chris@1494 96 assert_response :success
Chris@1494 97 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 98 assert_kind_of Array, json['user']['memberships']
Chris@1494 99 assert_equal [{
Chris@1494 100 "id"=>1,
Chris@1494 101 "project"=>{"name"=>"eCookbook", "id"=>1},
Chris@1494 102 "roles"=>[{"name"=>"Manager", "id"=>1}]
Chris@1494 103 }], json['user']['memberships']
Chris@1494 104 end
Chris@1494 105
Chris@1494 106 test "GET /users/current.xml should require authentication" do
Chris@1494 107 get '/users/current.xml'
Chris@1494 108
Chris@1494 109 assert_response 401
Chris@1494 110 end
Chris@1494 111
Chris@1494 112 test "GET /users/current.xml should return current user" do
Chris@1494 113 get '/users/current.xml', {}, credentials('jsmith')
Chris@1494 114
Chris@1494 115 assert_tag :tag => 'user',
Chris@1494 116 :child => {:tag => 'id', :content => '2'}
Chris@1494 117 end
Chris@1494 118
Chris@1494 119 test "GET /users/:id should not return login for other user" do
Chris@1494 120 get '/users/3.xml', {}, credentials('jsmith')
Chris@1494 121 assert_response :success
Chris@1494 122 assert_no_tag 'user', :child => {:tag => 'login'}
Chris@1494 123 end
Chris@1494 124
Chris@1494 125 test "GET /users/:id should return login for current user" do
Chris@1494 126 get '/users/2.xml', {}, credentials('jsmith')
Chris@1494 127 assert_response :success
Chris@1494 128 assert_tag 'user', :child => {:tag => 'login', :content => 'jsmith'}
Chris@1494 129 end
Chris@1494 130
Chris@1494 131 test "GET /users/:id should not return api_key for other user" do
Chris@1494 132 get '/users/3.xml', {}, credentials('jsmith')
Chris@1494 133 assert_response :success
Chris@1494 134 assert_no_tag 'user', :child => {:tag => 'api_key'}
Chris@1494 135 end
Chris@1494 136
Chris@1494 137 test "GET /users/:id should return api_key for current user" do
Chris@1494 138 get '/users/2.xml', {}, credentials('jsmith')
Chris@1494 139 assert_response :success
Chris@1494 140 assert_tag 'user', :child => {:tag => 'api_key', :content => User.find(2).api_key}
Chris@1494 141 end
Chris@1494 142
Chris@1494 143 test "GET /users/:id should not return status for standard user" do
Chris@1494 144 get '/users/3.xml', {}, credentials('jsmith')
Chris@1494 145 assert_response :success
Chris@1494 146 assert_no_tag 'user', :child => {:tag => 'status'}
Chris@1494 147 end
Chris@1494 148
Chris@1494 149 test "GET /users/:id should return status for administrators" do
Chris@1494 150 get '/users/2.xml', {}, credentials('admin')
Chris@1494 151 assert_response :success
Chris@1494 152 assert_tag 'user', :child => {:tag => 'status', :content => User.find(1).status.to_s}
Chris@1494 153 end
Chris@1494 154
Chris@1494 155 test "POST /users.xml with valid parameters should create the user" do
Chris@1494 156 assert_difference('User.count') do
Chris@1494 157 post '/users.xml', {
Chris@1494 158 :user => {
Chris@1494 159 :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
Chris@1494 160 :mail => 'foo@example.net', :password => 'secret123',
Chris@1494 161 :mail_notification => 'only_assigned'}
Chris@1494 162 },
Chris@1494 163 credentials('admin')
Chris@1494 164 end
Chris@1494 165
Chris@1494 166 user = User.first(:order => 'id DESC')
Chris@1494 167 assert_equal 'foo', user.login
Chris@1494 168 assert_equal 'Firstname', user.firstname
Chris@1494 169 assert_equal 'Lastname', user.lastname
Chris@1494 170 assert_equal 'foo@example.net', user.mail
Chris@1494 171 assert_equal 'only_assigned', user.mail_notification
Chris@1494 172 assert !user.admin?
Chris@1494 173 assert user.check_password?('secret123')
Chris@1494 174
Chris@1494 175 assert_response :created
Chris@1494 176 assert_equal 'application/xml', @response.content_type
Chris@1494 177 assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s}
Chris@1494 178 end
Chris@1494 179
Chris@1494 180 test "POST /users.json with valid parameters should create the user" do
Chris@1494 181 assert_difference('User.count') do
Chris@1494 182 post '/users.json', {
Chris@1494 183 :user => {
Chris@1494 184 :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
Chris@1494 185 :mail => 'foo@example.net', :password => 'secret123',
Chris@1494 186 :mail_notification => 'only_assigned'}
Chris@1494 187 },
Chris@1494 188 credentials('admin')
Chris@1494 189 end
Chris@1494 190
Chris@1494 191 user = User.first(:order => 'id DESC')
Chris@1494 192 assert_equal 'foo', user.login
Chris@1494 193 assert_equal 'Firstname', user.firstname
Chris@1494 194 assert_equal 'Lastname', user.lastname
Chris@1494 195 assert_equal 'foo@example.net', user.mail
Chris@1494 196 assert !user.admin?
Chris@1494 197
Chris@1494 198 assert_response :created
Chris@1494 199 assert_equal 'application/json', @response.content_type
Chris@1494 200 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 201 assert_kind_of Hash, json
Chris@1494 202 assert_kind_of Hash, json['user']
Chris@1494 203 assert_equal user.id, json['user']['id']
Chris@1494 204 end
Chris@1494 205
Chris@1494 206 test "POST /users.xml with with invalid parameters should return errors" do
Chris@1494 207 assert_no_difference('User.count') do
Chris@1494 208 post '/users.xml', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
Chris@1494 209 end
Chris@1494 210
Chris@1494 211 assert_response :unprocessable_entity
Chris@1494 212 assert_equal 'application/xml', @response.content_type
Chris@1494 213 assert_tag 'errors', :child => {
Chris@1494 214 :tag => 'error',
Chris@1494 215 :content => "First name can't be blank"
Chris@1494 216 }
Chris@1494 217 end
Chris@1494 218
Chris@1494 219 test "POST /users.json with with invalid parameters should return errors" do
Chris@1494 220 assert_no_difference('User.count') do
Chris@1494 221 post '/users.json', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
Chris@1494 222 end
Chris@1494 223
Chris@1494 224 assert_response :unprocessable_entity
Chris@1494 225 assert_equal 'application/json', @response.content_type
Chris@1494 226 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 227 assert_kind_of Hash, json
Chris@1494 228 assert json.has_key?('errors')
Chris@1494 229 assert_kind_of Array, json['errors']
Chris@1494 230 end
Chris@1494 231
Chris@1494 232 test "PUT /users/:id.xml with valid parameters should update the user" do
Chris@1494 233 assert_no_difference('User.count') do
Chris@1494 234 put '/users/2.xml', {
Chris@1494 235 :user => {
Chris@1494 236 :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
Chris@1494 237 :mail => 'jsmith@somenet.foo'}
Chris@1494 238 },
Chris@1494 239 credentials('admin')
Chris@1494 240 end
Chris@1494 241
Chris@1494 242 user = User.find(2)
Chris@1494 243 assert_equal 'jsmith', user.login
Chris@1494 244 assert_equal 'John', user.firstname
Chris@1494 245 assert_equal 'Renamed', user.lastname
Chris@1494 246 assert_equal 'jsmith@somenet.foo', user.mail
Chris@1494 247 assert !user.admin?
Chris@1494 248
Chris@1494 249 assert_response :ok
Chris@1494 250 assert_equal '', @response.body
Chris@1494 251 end
Chris@1494 252
Chris@1494 253 test "PUT /users/:id.json with valid parameters should update the user" do
Chris@1494 254 assert_no_difference('User.count') do
Chris@1494 255 put '/users/2.json', {
Chris@1494 256 :user => {
Chris@1494 257 :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
Chris@1494 258 :mail => 'jsmith@somenet.foo'}
Chris@1494 259 },
Chris@1494 260 credentials('admin')
Chris@1494 261 end
Chris@1494 262
Chris@1494 263 user = User.find(2)
Chris@1494 264 assert_equal 'jsmith', user.login
Chris@1494 265 assert_equal 'John', user.firstname
Chris@1494 266 assert_equal 'Renamed', user.lastname
Chris@1494 267 assert_equal 'jsmith@somenet.foo', user.mail
Chris@1494 268 assert !user.admin?
Chris@1494 269
Chris@1494 270 assert_response :ok
Chris@1494 271 assert_equal '', @response.body
Chris@1494 272 end
Chris@1494 273
Chris@1494 274 test "PUT /users/:id.xml with invalid parameters" do
Chris@1494 275 assert_no_difference('User.count') do
Chris@1494 276 put '/users/2.xml', {
Chris@1494 277 :user => {
Chris@1494 278 :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
Chris@1494 279 :mail => 'foo'}
Chris@1494 280 },
Chris@1494 281 credentials('admin')
Chris@1494 282 end
Chris@1494 283
Chris@1494 284 assert_response :unprocessable_entity
Chris@1494 285 assert_equal 'application/xml', @response.content_type
Chris@1494 286 assert_tag 'errors', :child => {
Chris@1494 287 :tag => 'error',
Chris@1494 288 :content => "First name can't be blank"
Chris@1494 289 }
Chris@1494 290 end
Chris@1494 291
Chris@1494 292 test "PUT /users/:id.json with invalid parameters" do
Chris@1494 293 assert_no_difference('User.count') do
Chris@1494 294 put '/users/2.json', {
Chris@1494 295 :user => {
Chris@1494 296 :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
Chris@1494 297 :mail => 'foo'}
Chris@1494 298 },
Chris@1494 299 credentials('admin')
Chris@1494 300 end
Chris@1494 301
Chris@1494 302 assert_response :unprocessable_entity
Chris@1494 303 assert_equal 'application/json', @response.content_type
Chris@1494 304 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 305 assert_kind_of Hash, json
Chris@1494 306 assert json.has_key?('errors')
Chris@1494 307 assert_kind_of Array, json['errors']
Chris@1494 308 end
Chris@1494 309
Chris@1494 310 test "DELETE /users/:id.xml should delete the user" do
Chris@1494 311 assert_difference('User.count', -1) do
Chris@1494 312 delete '/users/2.xml', {}, credentials('admin')
Chris@1494 313 end
Chris@1494 314
Chris@1494 315 assert_response :ok
Chris@1494 316 assert_equal '', @response.body
Chris@1494 317 end
Chris@1494 318
Chris@1494 319 test "DELETE /users/:id.json should delete the user" do
Chris@1494 320 assert_difference('User.count', -1) do
Chris@1494 321 delete '/users/2.json', {}, credentials('admin')
Chris@1494 322 end
Chris@1494 323
Chris@1494 324 assert_response :ok
Chris@1494 325 assert_equal '', @response.body
Chris@1494 326 end
Chris@1494 327 end