@@ -1,552 +1,552 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 |
# |
|
|
8 | # | |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 |
# |
|
|
13 | # | |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class ApiTest::IssuesTest < ActionController::IntegrationTest |
|
21 | 21 | fixtures :projects, |
|
22 | 22 | :users, |
|
23 | 23 | :roles, |
|
24 | 24 | :members, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :issues, |
|
27 | 27 | :issue_statuses, |
|
28 | 28 | :versions, |
|
29 | 29 | :trackers, |
|
30 | 30 | :projects_trackers, |
|
31 | 31 | :issue_categories, |
|
32 | 32 | :enabled_modules, |
|
33 | 33 | :enumerations, |
|
34 | 34 | :attachments, |
|
35 | 35 | :workflows, |
|
36 | 36 | :custom_fields, |
|
37 | 37 | :custom_values, |
|
38 | 38 | :custom_fields_projects, |
|
39 | 39 | :custom_fields_trackers, |
|
40 | 40 | :time_entries, |
|
41 | 41 | :journals, |
|
42 | 42 | :journal_details, |
|
43 | 43 | :queries, |
|
44 | 44 | :attachments |
|
45 | 45 | |
|
46 | 46 | def setup |
|
47 | 47 | Setting.rest_api_enabled = '1' |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | context "/issues" do |
|
51 | 51 | # Use a private project to make sure auth is really working and not just |
|
52 | 52 | # only showing public issues. |
|
53 | 53 | should_allow_api_authentication(:get, "/projects/private-child/issues.xml") |
|
54 | ||
|
54 | ||
|
55 | 55 | should "contain metadata" do |
|
56 | 56 | get '/issues.xml' |
|
57 | ||
|
57 | ||
|
58 | 58 | assert_tag :tag => 'issues', |
|
59 | 59 | :attributes => { |
|
60 | 60 | :type => 'array', |
|
61 | 61 | :total_count => assigns(:issue_count), |
|
62 | 62 | :limit => 25, |
|
63 | 63 | :offset => 0 |
|
64 | 64 | } |
|
65 | 65 | end |
|
66 | ||
|
66 | ||
|
67 | 67 | context "with offset and limit" do |
|
68 | 68 | should "use the params" do |
|
69 | 69 | get '/issues.xml?offset=2&limit=3' |
|
70 | ||
|
70 | ||
|
71 | 71 | assert_equal 3, assigns(:limit) |
|
72 | 72 | assert_equal 2, assigns(:offset) |
|
73 | 73 | assert_tag :tag => 'issues', :children => {:count => 3, :only => {:tag => 'issue'}} |
|
74 | 74 | end |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | context "with nometa param" do |
|
78 | 78 | should "not contain metadata" do |
|
79 | 79 | get '/issues.xml?nometa=1' |
|
80 | ||
|
80 | ||
|
81 | 81 | assert_tag :tag => 'issues', |
|
82 | 82 | :attributes => { |
|
83 | 83 | :type => 'array', |
|
84 | 84 | :total_count => nil, |
|
85 | 85 | :limit => nil, |
|
86 | 86 | :offset => nil |
|
87 | 87 | } |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | context "with nometa header" do |
|
92 | 92 | should "not contain metadata" do |
|
93 | 93 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} |
|
94 | ||
|
94 | ||
|
95 | 95 | assert_tag :tag => 'issues', |
|
96 | 96 | :attributes => { |
|
97 | 97 | :type => 'array', |
|
98 | 98 | :total_count => nil, |
|
99 | 99 | :limit => nil, |
|
100 | 100 | :offset => nil |
|
101 | 101 | } |
|
102 | 102 | end |
|
103 | 103 | end |
|
104 | ||
|
104 | ||
|
105 | 105 | context "with relations" do |
|
106 | 106 | should "display relations" do |
|
107 | 107 | get '/issues.xml?include=relations' |
|
108 | ||
|
108 | ||
|
109 | 109 | assert_response :success |
|
110 | 110 | assert_equal 'application/xml', @response.content_type |
|
111 | 111 | assert_tag 'relations', |
|
112 | 112 | :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}}, |
|
113 | 113 | :children => {:count => 1}, |
|
114 | 114 | :child => { |
|
115 | 115 | :tag => 'relation', |
|
116 | 116 | :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'} |
|
117 | 117 | } |
|
118 | 118 | assert_tag 'relations', |
|
119 | 119 | :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}}, |
|
120 | 120 | :children => {:count => 0} |
|
121 | 121 | end |
|
122 | 122 | end |
|
123 | ||
|
123 | ||
|
124 | 124 | context "with invalid query params" do |
|
125 | 125 | should "return errors" do |
|
126 | 126 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} |
|
127 | ||
|
127 | ||
|
128 | 128 | assert_response :unprocessable_entity |
|
129 | 129 | assert_equal 'application/xml', @response.content_type |
|
130 | 130 | assert_tag 'errors', :child => {:tag => 'error', :content => "Start date can't be blank"} |
|
131 | 131 | end |
|
132 | 132 | end |
|
133 | 133 | end |
|
134 | 134 | |
|
135 | 135 | context "/index.json" do |
|
136 | 136 | should_allow_api_authentication(:get, "/projects/private-child/issues.json") |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | context "/index.xml with filter" do |
|
140 | 140 | should "show only issues with the status_id" do |
|
141 | 141 | get '/issues.xml?status_id=5' |
|
142 | 142 | assert_tag :tag => 'issues', |
|
143 |
:children => { :count => Issue.visible.count(:conditions => {:status_id => 5}), |
|
|
143 | :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}), | |
|
144 | 144 | :only => { :tag => 'issue' } } |
|
145 | 145 | end |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | context "/index.json with filter" do |
|
149 | 149 | should "show only issues with the status_id" do |
|
150 | 150 | get '/issues.json?status_id=5' |
|
151 | 151 | |
|
152 | 152 | json = ActiveSupport::JSON.decode(response.body) |
|
153 | 153 | status_ids_used = json['issues'].collect {|j| j['status']['id'] } |
|
154 | 154 | assert_equal 3, status_ids_used.length |
|
155 | 155 | assert status_ids_used.all? {|id| id == 5 } |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | end |
|
159 | 159 | |
|
160 | 160 | # Issue 6 is on a private project |
|
161 | 161 | context "/issues/6.xml" do |
|
162 | 162 | should_allow_api_authentication(:get, "/issues/6.xml") |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | context "/issues/6.json" do |
|
166 | 166 | should_allow_api_authentication(:get, "/issues/6.json") |
|
167 | 167 | end |
|
168 | ||
|
168 | ||
|
169 | 169 | context "GET /issues/:id" do |
|
170 | 170 | context "with journals" do |
|
171 | 171 | context ".xml" do |
|
172 | 172 | should "display journals" do |
|
173 | 173 | get '/issues/1.xml?include=journals' |
|
174 | ||
|
174 | ||
|
175 | 175 | assert_tag :tag => 'issue', |
|
176 | 176 | :child => { |
|
177 | 177 | :tag => 'journals', |
|
178 | 178 | :attributes => { :type => 'array' }, |
|
179 | 179 | :child => { |
|
180 | 180 | :tag => 'journal', |
|
181 | 181 | :attributes => { :id => '1'}, |
|
182 | 182 | :child => { |
|
183 | 183 | :tag => 'details', |
|
184 | 184 | :attributes => { :type => 'array' }, |
|
185 | 185 | :child => { |
|
186 | 186 | :tag => 'detail', |
|
187 | 187 | :attributes => { :name => 'status_id' }, |
|
188 | 188 | :child => { |
|
189 | 189 | :tag => 'old_value', |
|
190 | 190 | :content => '1', |
|
191 | 191 | :sibling => { |
|
192 | 192 | :tag => 'new_value', |
|
193 | 193 | :content => '2' |
|
194 | 194 | } |
|
195 | 195 | } |
|
196 | 196 | } |
|
197 | 197 | } |
|
198 | 198 | } |
|
199 | 199 | } |
|
200 | 200 | end |
|
201 | 201 | end |
|
202 | 202 | end |
|
203 | ||
|
203 | ||
|
204 | 204 | context "with custom fields" do |
|
205 | 205 | context ".xml" do |
|
206 | 206 | should "display custom fields" do |
|
207 | 207 | get '/issues/3.xml' |
|
208 | ||
|
209 |
assert_tag :tag => 'issue', |
|
|
208 | ||
|
209 | assert_tag :tag => 'issue', | |
|
210 | 210 | :child => { |
|
211 | 211 | :tag => 'custom_fields', |
|
212 | 212 | :attributes => { :type => 'array' }, |
|
213 | 213 | :child => { |
|
214 | 214 | :tag => 'custom_field', |
|
215 | 215 | :attributes => { :id => '1'}, |
|
216 | 216 | :child => { |
|
217 | 217 | :tag => 'value', |
|
218 | 218 | :content => 'MySQL' |
|
219 | 219 | } |
|
220 | 220 | } |
|
221 | 221 | } |
|
222 | ||
|
222 | ||
|
223 | 223 | assert_nothing_raised do |
|
224 | 224 | Hash.from_xml(response.body).to_xml |
|
225 | 225 | end |
|
226 | 226 | end |
|
227 | 227 | end |
|
228 | 228 | end |
|
229 | ||
|
229 | ||
|
230 | 230 | context "with attachments" do |
|
231 | 231 | context ".xml" do |
|
232 | 232 | should "display attachments" do |
|
233 | 233 | get '/issues/3.xml?include=attachments' |
|
234 | ||
|
234 | ||
|
235 | 235 | assert_tag :tag => 'issue', |
|
236 | 236 | :child => { |
|
237 | 237 | :tag => 'attachments', |
|
238 | 238 | :children => {:count => 5}, |
|
239 | 239 | :child => { |
|
240 | 240 | :tag => 'attachment', |
|
241 | 241 | :child => { |
|
242 | 242 | :tag => 'filename', |
|
243 | 243 | :content => 'source.rb', |
|
244 | 244 | :sibling => { |
|
245 | 245 | :tag => 'content_url', |
|
246 | 246 | :content => 'http://www.example.com/attachments/download/4/source.rb' |
|
247 | 247 | } |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | } |
|
251 | 251 | end |
|
252 | 252 | end |
|
253 | 253 | end |
|
254 | ||
|
254 | ||
|
255 | 255 | context "with subtasks" do |
|
256 | 256 | setup do |
|
257 | 257 | @c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) |
|
258 | 258 | @c2 = Issue.generate!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) |
|
259 | 259 | @c3 = Issue.generate!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :parent_issue_id => @c1.id) |
|
260 | 260 | end |
|
261 | ||
|
261 | ||
|
262 | 262 | context ".xml" do |
|
263 | 263 | should "display children" do |
|
264 | 264 | get '/issues/1.xml?include=children' |
|
265 | ||
|
266 |
assert_tag :tag => 'issue', |
|
|
265 | ||
|
266 | assert_tag :tag => 'issue', | |
|
267 | 267 | :child => { |
|
268 | 268 | :tag => 'children', |
|
269 | 269 | :children => {:count => 2}, |
|
270 | 270 | :child => { |
|
271 | 271 | :tag => 'issue', |
|
272 | 272 | :attributes => {:id => @c1.id.to_s}, |
|
273 | 273 | :child => { |
|
274 | 274 | :tag => 'subject', |
|
275 | 275 | :content => 'child c1', |
|
276 | 276 | :sibling => { |
|
277 | 277 | :tag => 'children', |
|
278 | 278 | :children => {:count => 1}, |
|
279 | 279 | :child => { |
|
280 | 280 | :tag => 'issue', |
|
281 | 281 | :attributes => {:id => @c3.id.to_s} |
|
282 | 282 | } |
|
283 | 283 | } |
|
284 | 284 | } |
|
285 | 285 | } |
|
286 | 286 | } |
|
287 | 287 | end |
|
288 | ||
|
288 | ||
|
289 | 289 | context ".json" do |
|
290 | 290 | should "display children" do |
|
291 | 291 | get '/issues/1.json?include=children' |
|
292 | ||
|
292 | ||
|
293 | 293 | json = ActiveSupport::JSON.decode(response.body) |
|
294 | 294 | assert_equal([ |
|
295 | 295 | { |
|
296 | 296 | 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, |
|
297 | 297 | 'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }] |
|
298 | 298 | }, |
|
299 | 299 | { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } |
|
300 | 300 | ], |
|
301 | 301 | json['issue']['children']) |
|
302 | 302 | end |
|
303 | 303 | end |
|
304 | 304 | end |
|
305 | 305 | end |
|
306 | 306 | end |
|
307 | 307 | |
|
308 | 308 | context "POST /issues.xml" do |
|
309 | 309 | should_allow_api_authentication(:post, |
|
310 | 310 | '/issues.xml', |
|
311 | 311 | {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, |
|
312 | 312 | {:success_code => :created}) |
|
313 | 313 | |
|
314 | 314 | should "create an issue with the attributes" do |
|
315 | 315 | assert_difference('Issue.count') do |
|
316 | 316 | post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') |
|
317 | 317 | end |
|
318 | ||
|
318 | ||
|
319 | 319 | issue = Issue.first(:order => 'id DESC') |
|
320 | 320 | assert_equal 1, issue.project_id |
|
321 | 321 | assert_equal 2, issue.tracker_id |
|
322 | 322 | assert_equal 3, issue.status_id |
|
323 | 323 | assert_equal 'API test', issue.subject |
|
324 | ||
|
324 | ||
|
325 | 325 | assert_response :created |
|
326 | 326 | assert_equal 'application/xml', @response.content_type |
|
327 | 327 | assert_tag 'issue', :child => {:tag => 'id', :content => issue.id.to_s} |
|
328 | 328 | end |
|
329 | 329 | end |
|
330 | ||
|
330 | ||
|
331 | 331 | context "POST /issues.xml with failure" do |
|
332 | 332 | should "have an errors tag" do |
|
333 | 333 | assert_no_difference('Issue.count') do |
|
334 | 334 | post '/issues.xml', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith') |
|
335 | 335 | end |
|
336 | 336 | |
|
337 | 337 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} |
|
338 | 338 | end |
|
339 | 339 | end |
|
340 | 340 | |
|
341 | 341 | context "POST /issues.json" do |
|
342 | 342 | should_allow_api_authentication(:post, |
|
343 | 343 | '/issues.json', |
|
344 | 344 | {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, |
|
345 | 345 | {:success_code => :created}) |
|
346 | 346 | |
|
347 | 347 | should "create an issue with the attributes" do |
|
348 | 348 | assert_difference('Issue.count') do |
|
349 | 349 | post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') |
|
350 | 350 | end |
|
351 | ||
|
351 | ||
|
352 | 352 | issue = Issue.first(:order => 'id DESC') |
|
353 | 353 | assert_equal 1, issue.project_id |
|
354 | 354 | assert_equal 2, issue.tracker_id |
|
355 | 355 | assert_equal 3, issue.status_id |
|
356 | 356 | assert_equal 'API test', issue.subject |
|
357 | 357 | end |
|
358 | ||
|
358 | ||
|
359 | 359 | end |
|
360 | ||
|
360 | ||
|
361 | 361 | context "POST /issues.json with failure" do |
|
362 | 362 | should "have an errors element" do |
|
363 | 363 | assert_no_difference('Issue.count') do |
|
364 | 364 | post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith') |
|
365 | 365 | end |
|
366 | 366 | |
|
367 | 367 | json = ActiveSupport::JSON.decode(response.body) |
|
368 | 368 | assert json['errors'].include?(['subject', "can't be blank"]) |
|
369 | 369 | end |
|
370 | 370 | end |
|
371 | 371 | |
|
372 | 372 | # Issue 6 is on a private project |
|
373 | 373 | context "PUT /issues/6.xml" do |
|
374 | 374 | setup do |
|
375 | 375 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
|
376 | 376 | @headers = { :authorization => credentials('jsmith') } |
|
377 | 377 | end |
|
378 | ||
|
378 | ||
|
379 | 379 | should_allow_api_authentication(:put, |
|
380 | 380 | '/issues/6.xml', |
|
381 | 381 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
382 | 382 | {:success_code => :ok}) |
|
383 | 383 | |
|
384 | 384 | should "not create a new issue" do |
|
385 | 385 | assert_no_difference('Issue.count') do |
|
386 | 386 | put '/issues/6.xml', @parameters, @headers |
|
387 | 387 | end |
|
388 | 388 | end |
|
389 | 389 | |
|
390 | 390 | should "create a new journal" do |
|
391 | 391 | assert_difference('Journal.count') do |
|
392 | 392 | put '/issues/6.xml', @parameters, @headers |
|
393 | 393 | end |
|
394 | 394 | end |
|
395 | 395 | |
|
396 | 396 | should "add the note to the journal" do |
|
397 | 397 | put '/issues/6.xml', @parameters, @headers |
|
398 | ||
|
398 | ||
|
399 | 399 | journal = Journal.last |
|
400 | 400 | assert_equal "A new note", journal.notes |
|
401 | 401 | end |
|
402 | 402 | |
|
403 | 403 | should "update the issue" do |
|
404 | 404 | put '/issues/6.xml', @parameters, @headers |
|
405 | ||
|
405 | ||
|
406 | 406 | issue = Issue.find(6) |
|
407 | 407 | assert_equal "API update", issue.subject |
|
408 | 408 | end |
|
409 | ||
|
409 | ||
|
410 | 410 | end |
|
411 | ||
|
411 | ||
|
412 | 412 | context "PUT /issues/3.xml with custom fields" do |
|
413 | 413 | setup do |
|
414 | 414 | @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} |
|
415 | 415 | @headers = { :authorization => credentials('jsmith') } |
|
416 | 416 | end |
|
417 | ||
|
417 | ||
|
418 | 418 | should "update custom fields" do |
|
419 | 419 | assert_no_difference('Issue.count') do |
|
420 | 420 | put '/issues/3.xml', @parameters, @headers |
|
421 | 421 | end |
|
422 | ||
|
422 | ||
|
423 | 423 | issue = Issue.find(3) |
|
424 | 424 | assert_equal '150', issue.custom_value_for(2).value |
|
425 | 425 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value |
|
426 | 426 | end |
|
427 | 427 | end |
|
428 | ||
|
428 | ||
|
429 | 429 | context "PUT /issues/6.xml with failed update" do |
|
430 | 430 | setup do |
|
431 | 431 | @parameters = {:issue => {:subject => ''}} |
|
432 | 432 | @headers = { :authorization => credentials('jsmith') } |
|
433 | 433 | end |
|
434 | 434 | |
|
435 | 435 | should "not create a new issue" do |
|
436 | 436 | assert_no_difference('Issue.count') do |
|
437 | 437 | put '/issues/6.xml', @parameters, @headers |
|
438 | 438 | end |
|
439 | 439 | end |
|
440 | 440 | |
|
441 | 441 | should "not create a new journal" do |
|
442 | 442 | assert_no_difference('Journal.count') do |
|
443 | 443 | put '/issues/6.xml', @parameters, @headers |
|
444 | 444 | end |
|
445 | 445 | end |
|
446 | 446 | |
|
447 | 447 | should "have an errors tag" do |
|
448 | 448 | put '/issues/6.xml', @parameters, @headers |
|
449 | 449 | |
|
450 | 450 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} |
|
451 | 451 | end |
|
452 | 452 | end |
|
453 | 453 | |
|
454 | 454 | context "PUT /issues/6.json" do |
|
455 | 455 | setup do |
|
456 | 456 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
|
457 | 457 | @headers = { :authorization => credentials('jsmith') } |
|
458 | 458 | end |
|
459 | ||
|
459 | ||
|
460 | 460 | should_allow_api_authentication(:put, |
|
461 | 461 | '/issues/6.json', |
|
462 | 462 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
463 | 463 | {:success_code => :ok}) |
|
464 | 464 | |
|
465 | 465 | should "not create a new issue" do |
|
466 | 466 | assert_no_difference('Issue.count') do |
|
467 | 467 | put '/issues/6.json', @parameters, @headers |
|
468 | 468 | end |
|
469 | 469 | end |
|
470 | 470 | |
|
471 | 471 | should "create a new journal" do |
|
472 | 472 | assert_difference('Journal.count') do |
|
473 | 473 | put '/issues/6.json', @parameters, @headers |
|
474 | 474 | end |
|
475 | 475 | end |
|
476 | 476 | |
|
477 | 477 | should "add the note to the journal" do |
|
478 | 478 | put '/issues/6.json', @parameters, @headers |
|
479 | ||
|
479 | ||
|
480 | 480 | journal = Journal.last |
|
481 | 481 | assert_equal "A new note", journal.notes |
|
482 | 482 | end |
|
483 | 483 | |
|
484 | 484 | should "update the issue" do |
|
485 | 485 | put '/issues/6.json', @parameters, @headers |
|
486 | ||
|
486 | ||
|
487 | 487 | issue = Issue.find(6) |
|
488 | 488 | assert_equal "API update", issue.subject |
|
489 | 489 | end |
|
490 | ||
|
490 | ||
|
491 | 491 | end |
|
492 | ||
|
492 | ||
|
493 | 493 | context "PUT /issues/6.json with failed update" do |
|
494 | 494 | setup do |
|
495 | 495 | @parameters = {:issue => {:subject => ''}} |
|
496 | 496 | @headers = { :authorization => credentials('jsmith') } |
|
497 | 497 | end |
|
498 | 498 | |
|
499 | 499 | should "not create a new issue" do |
|
500 | 500 | assert_no_difference('Issue.count') do |
|
501 | 501 | put '/issues/6.json', @parameters, @headers |
|
502 | 502 | end |
|
503 | 503 | end |
|
504 | 504 | |
|
505 | 505 | should "not create a new journal" do |
|
506 | 506 | assert_no_difference('Journal.count') do |
|
507 | 507 | put '/issues/6.json', @parameters, @headers |
|
508 | 508 | end |
|
509 | 509 | end |
|
510 | 510 | |
|
511 | 511 | should "have an errors attribute" do |
|
512 | 512 | put '/issues/6.json', @parameters, @headers |
|
513 | 513 | |
|
514 | 514 | json = ActiveSupport::JSON.decode(response.body) |
|
515 | 515 | assert json['errors'].include?(['subject', "can't be blank"]) |
|
516 | 516 | end |
|
517 | 517 | end |
|
518 | 518 | |
|
519 | 519 | context "DELETE /issues/1.xml" do |
|
520 | 520 | should_allow_api_authentication(:delete, |
|
521 | 521 | '/issues/6.xml', |
|
522 | 522 | {}, |
|
523 | 523 | {:success_code => :ok}) |
|
524 | 524 | |
|
525 | 525 | should "delete the issue" do |
|
526 | 526 | assert_difference('Issue.count',-1) do |
|
527 | 527 | delete '/issues/6.xml', {}, :authorization => credentials('jsmith') |
|
528 | 528 | end |
|
529 | ||
|
529 | ||
|
530 | 530 | assert_nil Issue.find_by_id(6) |
|
531 | 531 | end |
|
532 | 532 | end |
|
533 | 533 | |
|
534 | 534 | context "DELETE /issues/1.json" do |
|
535 | 535 | should_allow_api_authentication(:delete, |
|
536 | 536 | '/issues/6.json', |
|
537 | 537 | {}, |
|
538 | 538 | {:success_code => :ok}) |
|
539 | 539 | |
|
540 | 540 | should "delete the issue" do |
|
541 | 541 | assert_difference('Issue.count',-1) do |
|
542 | 542 | delete '/issues/6.json', {}, :authorization => credentials('jsmith') |
|
543 | 543 | end |
|
544 | ||
|
544 | ||
|
545 | 545 | assert_nil Issue.find_by_id(6) |
|
546 | 546 | end |
|
547 | 547 | end |
|
548 | 548 | |
|
549 | 549 | def credentials(user, password=nil) |
|
550 | 550 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
|
551 | 551 | end |
|
552 | 552 | end |
General Comments 0
You need to be logged in to leave comments.
Login now