@@ -5,12 +5,12 | |||||
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. | |
8 |
# |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 |
# |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
@@ -51,10 +51,10 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
51 | # Use a private project to make sure auth is really working and not just |
|
51 | # Use a private project to make sure auth is really working and not just | |
52 | # only showing public issues. |
|
52 | # only showing public issues. | |
53 | should_allow_api_authentication(:get, "/projects/private-child/issues.xml") |
|
53 | should_allow_api_authentication(:get, "/projects/private-child/issues.xml") | |
54 |
|
54 | |||
55 | should "contain metadata" do |
|
55 | should "contain metadata" do | |
56 | get '/issues.xml' |
|
56 | get '/issues.xml' | |
57 |
|
57 | |||
58 | assert_tag :tag => 'issues', |
|
58 | assert_tag :tag => 'issues', | |
59 | :attributes => { |
|
59 | :attributes => { | |
60 | :type => 'array', |
|
60 | :type => 'array', | |
@@ -63,11 +63,11 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
63 | :offset => 0 |
|
63 | :offset => 0 | |
64 | } |
|
64 | } | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | context "with offset and limit" do |
|
67 | context "with offset and limit" do | |
68 | should "use the params" do |
|
68 | should "use the params" do | |
69 | get '/issues.xml?offset=2&limit=3' |
|
69 | get '/issues.xml?offset=2&limit=3' | |
70 |
|
70 | |||
71 | assert_equal 3, assigns(:limit) |
|
71 | assert_equal 3, assigns(:limit) | |
72 | assert_equal 2, assigns(:offset) |
|
72 | assert_equal 2, assigns(:offset) | |
73 | assert_tag :tag => 'issues', :children => {:count => 3, :only => {:tag => 'issue'}} |
|
73 | assert_tag :tag => 'issues', :children => {:count => 3, :only => {:tag => 'issue'}} | |
@@ -77,7 +77,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
77 | context "with nometa param" do |
|
77 | context "with nometa param" do | |
78 | should "not contain metadata" do |
|
78 | should "not contain metadata" do | |
79 | get '/issues.xml?nometa=1' |
|
79 | get '/issues.xml?nometa=1' | |
80 |
|
80 | |||
81 | assert_tag :tag => 'issues', |
|
81 | assert_tag :tag => 'issues', | |
82 | :attributes => { |
|
82 | :attributes => { | |
83 | :type => 'array', |
|
83 | :type => 'array', | |
@@ -91,7 +91,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
91 | context "with nometa header" do |
|
91 | context "with nometa header" do | |
92 | should "not contain metadata" do |
|
92 | should "not contain metadata" do | |
93 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} |
|
93 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} | |
94 |
|
94 | |||
95 | assert_tag :tag => 'issues', |
|
95 | assert_tag :tag => 'issues', | |
96 | :attributes => { |
|
96 | :attributes => { | |
97 | :type => 'array', |
|
97 | :type => 'array', | |
@@ -101,11 +101,11 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
101 | } |
|
101 | } | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | context "with relations" do |
|
105 | context "with relations" do | |
106 | should "display relations" do |
|
106 | should "display relations" do | |
107 | get '/issues.xml?include=relations' |
|
107 | get '/issues.xml?include=relations' | |
108 |
|
108 | |||
109 | assert_response :success |
|
109 | assert_response :success | |
110 | assert_equal 'application/xml', @response.content_type |
|
110 | assert_equal 'application/xml', @response.content_type | |
111 | assert_tag 'relations', |
|
111 | assert_tag 'relations', | |
@@ -120,11 +120,11 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
120 | :children => {:count => 0} |
|
120 | :children => {:count => 0} | |
121 | end |
|
121 | end | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | context "with invalid query params" do |
|
124 | context "with invalid query params" do | |
125 | should "return errors" do |
|
125 | should "return errors" do | |
126 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} |
|
126 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} | |
127 |
|
127 | |||
128 | assert_response :unprocessable_entity |
|
128 | assert_response :unprocessable_entity | |
129 | assert_equal 'application/xml', @response.content_type |
|
129 | assert_equal 'application/xml', @response.content_type | |
130 | assert_tag 'errors', :child => {:tag => 'error', :content => "Start date can't be blank"} |
|
130 | assert_tag 'errors', :child => {:tag => 'error', :content => "Start date can't be blank"} | |
@@ -140,7 +140,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
140 | should "show only issues with the status_id" do |
|
140 | should "show only issues with the status_id" do | |
141 | get '/issues.xml?status_id=5' |
|
141 | get '/issues.xml?status_id=5' | |
142 | assert_tag :tag => 'issues', |
|
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 | :only => { :tag => 'issue' } } |
|
144 | :only => { :tag => 'issue' } } | |
145 | end |
|
145 | end | |
146 | end |
|
146 | end | |
@@ -165,13 +165,13 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
165 | context "/issues/6.json" do |
|
165 | context "/issues/6.json" do | |
166 | should_allow_api_authentication(:get, "/issues/6.json") |
|
166 | should_allow_api_authentication(:get, "/issues/6.json") | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | context "GET /issues/:id" do |
|
169 | context "GET /issues/:id" do | |
170 | context "with journals" do |
|
170 | context "with journals" do | |
171 | context ".xml" do |
|
171 | context ".xml" do | |
172 | should "display journals" do |
|
172 | should "display journals" do | |
173 | get '/issues/1.xml?include=journals' |
|
173 | get '/issues/1.xml?include=journals' | |
174 |
|
174 | |||
175 | assert_tag :tag => 'issue', |
|
175 | assert_tag :tag => 'issue', | |
176 | :child => { |
|
176 | :child => { | |
177 | :tag => 'journals', |
|
177 | :tag => 'journals', | |
@@ -200,13 +200,13 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 | end |
|
202 | end | |
203 |
|
203 | |||
204 | context "with custom fields" do |
|
204 | context "with custom fields" do | |
205 | context ".xml" do |
|
205 | context ".xml" do | |
206 | should "display custom fields" do |
|
206 | should "display custom fields" do | |
207 | get '/issues/3.xml' |
|
207 | get '/issues/3.xml' | |
208 |
|
208 | |||
209 |
assert_tag :tag => 'issue', |
|
209 | assert_tag :tag => 'issue', | |
210 | :child => { |
|
210 | :child => { | |
211 | :tag => 'custom_fields', |
|
211 | :tag => 'custom_fields', | |
212 | :attributes => { :type => 'array' }, |
|
212 | :attributes => { :type => 'array' }, | |
@@ -219,19 +219,19 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | assert_nothing_raised do |
|
223 | assert_nothing_raised do | |
224 | Hash.from_xml(response.body).to_xml |
|
224 | Hash.from_xml(response.body).to_xml | |
225 | end |
|
225 | end | |
226 | end |
|
226 | end | |
227 | end |
|
227 | end | |
228 | end |
|
228 | end | |
229 |
|
229 | |||
230 | context "with attachments" do |
|
230 | context "with attachments" do | |
231 | context ".xml" do |
|
231 | context ".xml" do | |
232 | should "display attachments" do |
|
232 | should "display attachments" do | |
233 | get '/issues/3.xml?include=attachments' |
|
233 | get '/issues/3.xml?include=attachments' | |
234 |
|
234 | |||
235 | assert_tag :tag => 'issue', |
|
235 | assert_tag :tag => 'issue', | |
236 | :child => { |
|
236 | :child => { | |
237 | :tag => 'attachments', |
|
237 | :tag => 'attachments', | |
@@ -251,19 +251,19 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
251 | end |
|
251 | end | |
252 | end |
|
252 | end | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | context "with subtasks" do |
|
255 | context "with subtasks" do | |
256 | setup do |
|
256 | setup do | |
257 | @c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) |
|
257 | @c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) | |
258 | @c2 = Issue.generate!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) |
|
258 | @c2 = Issue.generate!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) | |
259 | @c3 = Issue.generate!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :parent_issue_id => @c1.id) |
|
259 | @c3 = Issue.generate!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :parent_issue_id => @c1.id) | |
260 | end |
|
260 | end | |
261 |
|
261 | |||
262 | context ".xml" do |
|
262 | context ".xml" do | |
263 | should "display children" do |
|
263 | should "display children" do | |
264 | get '/issues/1.xml?include=children' |
|
264 | get '/issues/1.xml?include=children' | |
265 |
|
265 | |||
266 |
assert_tag :tag => 'issue', |
|
266 | assert_tag :tag => 'issue', | |
267 | :child => { |
|
267 | :child => { | |
268 | :tag => 'children', |
|
268 | :tag => 'children', | |
269 | :children => {:count => 2}, |
|
269 | :children => {:count => 2}, | |
@@ -285,11 +285,11 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
285 | } |
|
285 | } | |
286 | } |
|
286 | } | |
287 | end |
|
287 | end | |
288 |
|
288 | |||
289 | context ".json" do |
|
289 | context ".json" do | |
290 | should "display children" do |
|
290 | should "display children" do | |
291 | get '/issues/1.json?include=children' |
|
291 | get '/issues/1.json?include=children' | |
292 |
|
292 | |||
293 | json = ActiveSupport::JSON.decode(response.body) |
|
293 | json = ActiveSupport::JSON.decode(response.body) | |
294 | assert_equal([ |
|
294 | assert_equal([ | |
295 | { |
|
295 | { | |
@@ -315,19 +315,19 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
315 | assert_difference('Issue.count') do |
|
315 | assert_difference('Issue.count') do | |
316 | post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') |
|
316 | post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') | |
317 | end |
|
317 | end | |
318 |
|
318 | |||
319 | issue = Issue.first(:order => 'id DESC') |
|
319 | issue = Issue.first(:order => 'id DESC') | |
320 | assert_equal 1, issue.project_id |
|
320 | assert_equal 1, issue.project_id | |
321 | assert_equal 2, issue.tracker_id |
|
321 | assert_equal 2, issue.tracker_id | |
322 | assert_equal 3, issue.status_id |
|
322 | assert_equal 3, issue.status_id | |
323 | assert_equal 'API test', issue.subject |
|
323 | assert_equal 'API test', issue.subject | |
324 |
|
324 | |||
325 | assert_response :created |
|
325 | assert_response :created | |
326 | assert_equal 'application/xml', @response.content_type |
|
326 | assert_equal 'application/xml', @response.content_type | |
327 | assert_tag 'issue', :child => {:tag => 'id', :content => issue.id.to_s} |
|
327 | assert_tag 'issue', :child => {:tag => 'id', :content => issue.id.to_s} | |
328 | end |
|
328 | end | |
329 | end |
|
329 | end | |
330 |
|
330 | |||
331 | context "POST /issues.xml with failure" do |
|
331 | context "POST /issues.xml with failure" do | |
332 | should "have an errors tag" do |
|
332 | should "have an errors tag" do | |
333 | assert_no_difference('Issue.count') do |
|
333 | assert_no_difference('Issue.count') do | |
@@ -348,16 +348,16 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
348 | assert_difference('Issue.count') do |
|
348 | assert_difference('Issue.count') do | |
349 | post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') |
|
349 | post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') | |
350 | end |
|
350 | end | |
351 |
|
351 | |||
352 | issue = Issue.first(:order => 'id DESC') |
|
352 | issue = Issue.first(:order => 'id DESC') | |
353 | assert_equal 1, issue.project_id |
|
353 | assert_equal 1, issue.project_id | |
354 | assert_equal 2, issue.tracker_id |
|
354 | assert_equal 2, issue.tracker_id | |
355 | assert_equal 3, issue.status_id |
|
355 | assert_equal 3, issue.status_id | |
356 | assert_equal 'API test', issue.subject |
|
356 | assert_equal 'API test', issue.subject | |
357 | end |
|
357 | end | |
358 |
|
358 | |||
359 | end |
|
359 | end | |
360 |
|
360 | |||
361 | context "POST /issues.json with failure" do |
|
361 | context "POST /issues.json with failure" do | |
362 | should "have an errors element" do |
|
362 | should "have an errors element" do | |
363 | assert_no_difference('Issue.count') do |
|
363 | assert_no_difference('Issue.count') do | |
@@ -375,7 +375,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
375 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
|
375 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
376 | @headers = { :authorization => credentials('jsmith') } |
|
376 | @headers = { :authorization => credentials('jsmith') } | |
377 | end |
|
377 | end | |
378 |
|
378 | |||
379 | should_allow_api_authentication(:put, |
|
379 | should_allow_api_authentication(:put, | |
380 | '/issues/6.xml', |
|
380 | '/issues/6.xml', | |
381 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
381 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
@@ -395,37 +395,37 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
395 |
|
395 | |||
396 | should "add the note to the journal" do |
|
396 | should "add the note to the journal" do | |
397 | put '/issues/6.xml', @parameters, @headers |
|
397 | put '/issues/6.xml', @parameters, @headers | |
398 |
|
398 | |||
399 | journal = Journal.last |
|
399 | journal = Journal.last | |
400 | assert_equal "A new note", journal.notes |
|
400 | assert_equal "A new note", journal.notes | |
401 | end |
|
401 | end | |
402 |
|
402 | |||
403 | should "update the issue" do |
|
403 | should "update the issue" do | |
404 | put '/issues/6.xml', @parameters, @headers |
|
404 | put '/issues/6.xml', @parameters, @headers | |
405 |
|
405 | |||
406 | issue = Issue.find(6) |
|
406 | issue = Issue.find(6) | |
407 | assert_equal "API update", issue.subject |
|
407 | assert_equal "API update", issue.subject | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | end |
|
410 | end | |
411 |
|
411 | |||
412 | context "PUT /issues/3.xml with custom fields" do |
|
412 | context "PUT /issues/3.xml with custom fields" do | |
413 | setup do |
|
413 | setup do | |
414 | @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} |
|
414 | @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} | |
415 | @headers = { :authorization => credentials('jsmith') } |
|
415 | @headers = { :authorization => credentials('jsmith') } | |
416 | end |
|
416 | end | |
417 |
|
417 | |||
418 | should "update custom fields" do |
|
418 | should "update custom fields" do | |
419 | assert_no_difference('Issue.count') do |
|
419 | assert_no_difference('Issue.count') do | |
420 | put '/issues/3.xml', @parameters, @headers |
|
420 | put '/issues/3.xml', @parameters, @headers | |
421 | end |
|
421 | end | |
422 |
|
422 | |||
423 | issue = Issue.find(3) |
|
423 | issue = Issue.find(3) | |
424 | assert_equal '150', issue.custom_value_for(2).value |
|
424 | assert_equal '150', issue.custom_value_for(2).value | |
425 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value |
|
425 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value | |
426 | end |
|
426 | end | |
427 | end |
|
427 | end | |
428 |
|
428 | |||
429 | context "PUT /issues/6.xml with failed update" do |
|
429 | context "PUT /issues/6.xml with failed update" do | |
430 | setup do |
|
430 | setup do | |
431 | @parameters = {:issue => {:subject => ''}} |
|
431 | @parameters = {:issue => {:subject => ''}} | |
@@ -456,7 +456,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
456 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
|
456 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
457 | @headers = { :authorization => credentials('jsmith') } |
|
457 | @headers = { :authorization => credentials('jsmith') } | |
458 | end |
|
458 | end | |
459 |
|
459 | |||
460 | should_allow_api_authentication(:put, |
|
460 | should_allow_api_authentication(:put, | |
461 | '/issues/6.json', |
|
461 | '/issues/6.json', | |
462 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
462 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
@@ -476,20 +476,20 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
476 |
|
476 | |||
477 | should "add the note to the journal" do |
|
477 | should "add the note to the journal" do | |
478 | put '/issues/6.json', @parameters, @headers |
|
478 | put '/issues/6.json', @parameters, @headers | |
479 |
|
479 | |||
480 | journal = Journal.last |
|
480 | journal = Journal.last | |
481 | assert_equal "A new note", journal.notes |
|
481 | assert_equal "A new note", journal.notes | |
482 | end |
|
482 | end | |
483 |
|
483 | |||
484 | should "update the issue" do |
|
484 | should "update the issue" do | |
485 | put '/issues/6.json', @parameters, @headers |
|
485 | put '/issues/6.json', @parameters, @headers | |
486 |
|
486 | |||
487 | issue = Issue.find(6) |
|
487 | issue = Issue.find(6) | |
488 | assert_equal "API update", issue.subject |
|
488 | assert_equal "API update", issue.subject | |
489 | end |
|
489 | end | |
490 |
|
490 | |||
491 | end |
|
491 | end | |
492 |
|
492 | |||
493 | context "PUT /issues/6.json with failed update" do |
|
493 | context "PUT /issues/6.json with failed update" do | |
494 | setup do |
|
494 | setup do | |
495 | @parameters = {:issue => {:subject => ''}} |
|
495 | @parameters = {:issue => {:subject => ''}} | |
@@ -526,7 +526,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
526 | assert_difference('Issue.count',-1) do |
|
526 | assert_difference('Issue.count',-1) do | |
527 | delete '/issues/6.xml', {}, :authorization => credentials('jsmith') |
|
527 | delete '/issues/6.xml', {}, :authorization => credentials('jsmith') | |
528 | end |
|
528 | end | |
529 |
|
529 | |||
530 | assert_nil Issue.find_by_id(6) |
|
530 | assert_nil Issue.find_by_id(6) | |
531 | end |
|
531 | end | |
532 | end |
|
532 | end | |
@@ -541,7 +541,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
541 | assert_difference('Issue.count',-1) do |
|
541 | assert_difference('Issue.count',-1) do | |
542 | delete '/issues/6.json', {}, :authorization => credentials('jsmith') |
|
542 | delete '/issues/6.json', {}, :authorization => credentials('jsmith') | |
543 | end |
|
543 | end | |
544 |
|
544 | |||
545 | assert_nil Issue.find_by_id(6) |
|
545 | assert_nil Issue.find_by_id(6) | |
546 | end |
|
546 | end | |
547 | end |
|
547 | end |
General Comments 0
You need to be logged in to leave comments.
Login now