comparison test/integration/api_test/projects_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
150 {:success_code => :created}) 150 {:success_code => :created})
151 151
152 152
153 should "create a project with the attributes" do 153 should "create a project with the attributes" do
154 assert_difference('Project.count') do 154 assert_difference('Project.count') do
155 post '/projects.xml', @parameters, :authorization => credentials('admin') 155 post '/projects.xml', @parameters, credentials('admin')
156 end 156 end
157 157
158 project = Project.first(:order => 'id DESC') 158 project = Project.first(:order => 'id DESC')
159 assert_equal 'API test', project.name 159 assert_equal 'API test', project.name
160 assert_equal 'api-test', project.identifier 160 assert_equal 'api-test', project.identifier
168 168
169 should "accept enabled_module_names attribute" do 169 should "accept enabled_module_names attribute" do
170 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) 170 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
171 171
172 assert_difference('Project.count') do 172 assert_difference('Project.count') do
173 post '/projects.xml', @parameters, :authorization => credentials('admin') 173 post '/projects.xml', @parameters, credentials('admin')
174 end 174 end
175 175
176 project = Project.first(:order => 'id DESC') 176 project = Project.first(:order => 'id DESC')
177 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort 177 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
178 end 178 end
179 179
180 should "accept tracker_ids attribute" do 180 should "accept tracker_ids attribute" do
181 @parameters[:project].merge!({:tracker_ids => [1, 3]}) 181 @parameters[:project].merge!({:tracker_ids => [1, 3]})
182 182
183 assert_difference('Project.count') do 183 assert_difference('Project.count') do
184 post '/projects.xml', @parameters, :authorization => credentials('admin') 184 post '/projects.xml', @parameters, credentials('admin')
185 end 185 end
186 186
187 project = Project.first(:order => 'id DESC') 187 project = Project.first(:order => 'id DESC')
188 assert_equal [1, 3], project.trackers.map(&:id).sort 188 assert_equal [1, 3], project.trackers.map(&:id).sort
189 end 189 end
196 end 196 end
197 197
198 context ".xml" do 198 context ".xml" do
199 should "return errors" do 199 should "return errors" do
200 assert_no_difference('Project.count') do 200 assert_no_difference('Project.count') do
201 post '/projects.xml', @parameters, :authorization => credentials('admin') 201 post '/projects.xml', @parameters, credentials('admin')
202 end 202 end
203 203
204 assert_response :unprocessable_entity 204 assert_response :unprocessable_entity
205 assert_equal 'application/xml', @response.content_type 205 assert_equal 'application/xml', @response.content_type
206 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"} 206 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
221 {:project => {:name => 'API update'}}, 221 {:project => {:name => 'API update'}},
222 {:success_code => :ok}) 222 {:success_code => :ok})
223 223
224 should "update the project" do 224 should "update the project" do
225 assert_no_difference 'Project.count' do 225 assert_no_difference 'Project.count' do
226 put '/projects/2.xml', @parameters, :authorization => credentials('jsmith') 226 put '/projects/2.xml', @parameters, credentials('jsmith')
227 end 227 end
228 assert_response :ok 228 assert_response :ok
229 assert_equal '', @response.body
229 assert_equal 'application/xml', @response.content_type 230 assert_equal 'application/xml', @response.content_type
230 project = Project.find(2) 231 project = Project.find(2)
231 assert_equal 'API update', project.name 232 assert_equal 'API update', project.name
232 end 233 end
233 234
234 should "accept enabled_module_names attribute" do 235 should "accept enabled_module_names attribute" do
235 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) 236 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
236 237
237 assert_no_difference 'Project.count' do 238 assert_no_difference 'Project.count' do
238 put '/projects/2.xml', @parameters, :authorization => credentials('admin') 239 put '/projects/2.xml', @parameters, credentials('admin')
239 end 240 end
240 assert_response :ok 241 assert_response :ok
242 assert_equal '', @response.body
241 project = Project.find(2) 243 project = Project.find(2)
242 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort 244 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
243 end 245 end
244 246
245 should "accept tracker_ids attribute" do 247 should "accept tracker_ids attribute" do
246 @parameters[:project].merge!({:tracker_ids => [1, 3]}) 248 @parameters[:project].merge!({:tracker_ids => [1, 3]})
247 249
248 assert_no_difference 'Project.count' do 250 assert_no_difference 'Project.count' do
249 put '/projects/2.xml', @parameters, :authorization => credentials('admin') 251 put '/projects/2.xml', @parameters, credentials('admin')
250 end 252 end
251 assert_response :ok 253 assert_response :ok
254 assert_equal '', @response.body
252 project = Project.find(2) 255 project = Project.find(2)
253 assert_equal [1, 3], project.trackers.map(&:id).sort 256 assert_equal [1, 3], project.trackers.map(&:id).sort
254 end 257 end
255 end 258 end
256 end 259 end
261 end 264 end
262 265
263 context ".xml" do 266 context ".xml" do
264 should "return errors" do 267 should "return errors" do
265 assert_no_difference('Project.count') do 268 assert_no_difference('Project.count') do
266 put '/projects/2.xml', @parameters, :authorization => credentials('admin') 269 put '/projects/2.xml', @parameters, credentials('admin')
267 end 270 end
268 271
269 assert_response :unprocessable_entity 272 assert_response :unprocessable_entity
270 assert_equal 'application/xml', @response.content_type 273 assert_equal 'application/xml', @response.content_type
271 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} 274 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
281 {}, 284 {},
282 {:success_code => :ok}) 285 {:success_code => :ok})
283 286
284 should "delete the project" do 287 should "delete the project" do
285 assert_difference('Project.count',-1) do 288 assert_difference('Project.count',-1) do
286 delete '/projects/2.xml', {}, :authorization => credentials('admin') 289 delete '/projects/2.xml', {}, credentials('admin')
287 end 290 end
288 assert_response :ok 291 assert_response :ok
292 assert_equal '', @response.body
289 assert_nil Project.find_by_id(2) 293 assert_nil Project.find_by_id(2)
290 end 294 end
291 end 295 end
292 end 296 end
293
294 def credentials(user, password=nil)
295 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
296 end
297 end 297 end