##// END OF EJS Templates
remove trailing white-spaces from test/integration/api_test/issues_test.rb....
Toshi MARUYAMA -
r6825:d51cc908fe66
parent child
Show More
@@ -1,552 +1,552
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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.
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.
17
17
18 require File.expand_path('../../../test_helper', __FILE__)
18 require File.expand_path('../../../test_helper', __FILE__)
19
19
20 class ApiTest::IssuesTest < ActionController::IntegrationTest
20 class ApiTest::IssuesTest < ActionController::IntegrationTest
21 fixtures :projects,
21 fixtures :projects,
22 :users,
22 :users,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :issues,
26 :issues,
27 :issue_statuses,
27 :issue_statuses,
28 :versions,
28 :versions,
29 :trackers,
29 :trackers,
30 :projects_trackers,
30 :projects_trackers,
31 :issue_categories,
31 :issue_categories,
32 :enabled_modules,
32 :enabled_modules,
33 :enumerations,
33 :enumerations,
34 :attachments,
34 :attachments,
35 :workflows,
35 :workflows,
36 :custom_fields,
36 :custom_fields,
37 :custom_values,
37 :custom_values,
38 :custom_fields_projects,
38 :custom_fields_projects,
39 :custom_fields_trackers,
39 :custom_fields_trackers,
40 :time_entries,
40 :time_entries,
41 :journals,
41 :journals,
42 :journal_details,
42 :journal_details,
43 :queries,
43 :queries,
44 :attachments
44 :attachments
45
45
46 def setup
46 def setup
47 Setting.rest_api_enabled = '1'
47 Setting.rest_api_enabled = '1'
48 end
48 end
49
49
50 context "/issues" do
50 context "/issues" do
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',
61 :total_count => assigns(:issue_count),
61 :total_count => assigns(:issue_count),
62 :limit => 25,
62 :limit => 25,
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'}}
74 end
74 end
75 end
75 end
76
76
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',
84 :total_count => nil,
84 :total_count => nil,
85 :limit => nil,
85 :limit => nil,
86 :offset => nil
86 :offset => nil
87 }
87 }
88 end
88 end
89 end
89 end
90
90
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',
98 :total_count => nil,
98 :total_count => nil,
99 :limit => nil,
99 :limit => nil,
100 :offset => nil
100 :offset => nil
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',
112 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}},
112 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}},
113 :children => {:count => 1},
113 :children => {:count => 1},
114 :child => {
114 :child => {
115 :tag => 'relation',
115 :tag => 'relation',
116 :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'}
116 :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'}
117 }
117 }
118 assert_tag 'relations',
118 assert_tag 'relations',
119 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}},
119 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}},
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"}
131 end
131 end
132 end
132 end
133 end
133 end
134
134
135 context "/index.json" do
135 context "/index.json" do
136 should_allow_api_authentication(:get, "/projects/private-child/issues.json")
136 should_allow_api_authentication(:get, "/projects/private-child/issues.json")
137 end
137 end
138
138
139 context "/index.xml with filter" do
139 context "/index.xml with filter" do
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
147
147
148 context "/index.json with filter" do
148 context "/index.json with filter" do
149 should "show only issues with the status_id" do
149 should "show only issues with the status_id" do
150 get '/issues.json?status_id=5'
150 get '/issues.json?status_id=5'
151
151
152 json = ActiveSupport::JSON.decode(response.body)
152 json = ActiveSupport::JSON.decode(response.body)
153 status_ids_used = json['issues'].collect {|j| j['status']['id'] }
153 status_ids_used = json['issues'].collect {|j| j['status']['id'] }
154 assert_equal 3, status_ids_used.length
154 assert_equal 3, status_ids_used.length
155 assert status_ids_used.all? {|id| id == 5 }
155 assert status_ids_used.all? {|id| id == 5 }
156 end
156 end
157
157
158 end
158 end
159
159
160 # Issue 6 is on a private project
160 # Issue 6 is on a private project
161 context "/issues/6.xml" do
161 context "/issues/6.xml" do
162 should_allow_api_authentication(:get, "/issues/6.xml")
162 should_allow_api_authentication(:get, "/issues/6.xml")
163 end
163 end
164
164
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',
178 :attributes => { :type => 'array' },
178 :attributes => { :type => 'array' },
179 :child => {
179 :child => {
180 :tag => 'journal',
180 :tag => 'journal',
181 :attributes => { :id => '1'},
181 :attributes => { :id => '1'},
182 :child => {
182 :child => {
183 :tag => 'details',
183 :tag => 'details',
184 :attributes => { :type => 'array' },
184 :attributes => { :type => 'array' },
185 :child => {
185 :child => {
186 :tag => 'detail',
186 :tag => 'detail',
187 :attributes => { :name => 'status_id' },
187 :attributes => { :name => 'status_id' },
188 :child => {
188 :child => {
189 :tag => 'old_value',
189 :tag => 'old_value',
190 :content => '1',
190 :content => '1',
191 :sibling => {
191 :sibling => {
192 :tag => 'new_value',
192 :tag => 'new_value',
193 :content => '2'
193 :content => '2'
194 }
194 }
195 }
195 }
196 }
196 }
197 }
197 }
198 }
198 }
199 }
199 }
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' },
213 :child => {
213 :child => {
214 :tag => 'custom_field',
214 :tag => 'custom_field',
215 :attributes => { :id => '1'},
215 :attributes => { :id => '1'},
216 :child => {
216 :child => {
217 :tag => 'value',
217 :tag => 'value',
218 :content => 'MySQL'
218 :content => 'MySQL'
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',
238 :children => {:count => 5},
238 :children => {:count => 5},
239 :child => {
239 :child => {
240 :tag => 'attachment',
240 :tag => 'attachment',
241 :child => {
241 :child => {
242 :tag => 'filename',
242 :tag => 'filename',
243 :content => 'source.rb',
243 :content => 'source.rb',
244 :sibling => {
244 :sibling => {
245 :tag => 'content_url',
245 :tag => 'content_url',
246 :content => 'http://www.example.com/attachments/download/4/source.rb'
246 :content => 'http://www.example.com/attachments/download/4/source.rb'
247 }
247 }
248 }
248 }
249 }
249 }
250 }
250 }
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},
270 :child => {
270 :child => {
271 :tag => 'issue',
271 :tag => 'issue',
272 :attributes => {:id => @c1.id.to_s},
272 :attributes => {:id => @c1.id.to_s},
273 :child => {
273 :child => {
274 :tag => 'subject',
274 :tag => 'subject',
275 :content => 'child c1',
275 :content => 'child c1',
276 :sibling => {
276 :sibling => {
277 :tag => 'children',
277 :tag => 'children',
278 :children => {:count => 1},
278 :children => {:count => 1},
279 :child => {
279 :child => {
280 :tag => 'issue',
280 :tag => 'issue',
281 :attributes => {:id => @c3.id.to_s}
281 :attributes => {:id => @c3.id.to_s}
282 }
282 }
283 }
283 }
284 }
284 }
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 {
296 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'},
296 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'},
297 'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }]
297 'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }]
298 },
298 },
299 { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} }
299 { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} }
300 ],
300 ],
301 json['issue']['children'])
301 json['issue']['children'])
302 end
302 end
303 end
303 end
304 end
304 end
305 end
305 end
306 end
306 end
307
307
308 context "POST /issues.xml" do
308 context "POST /issues.xml" do
309 should_allow_api_authentication(:post,
309 should_allow_api_authentication(:post,
310 '/issues.xml',
310 '/issues.xml',
311 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
311 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
312 {:success_code => :created})
312 {:success_code => :created})
313
313
314 should "create an issue with the attributes" do
314 should "create an issue with the attributes" do
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
334 post '/issues.xml', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith')
334 post '/issues.xml', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith')
335 end
335 end
336
336
337 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
337 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
338 end
338 end
339 end
339 end
340
340
341 context "POST /issues.json" do
341 context "POST /issues.json" do
342 should_allow_api_authentication(:post,
342 should_allow_api_authentication(:post,
343 '/issues.json',
343 '/issues.json',
344 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
344 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
345 {:success_code => :created})
345 {:success_code => :created})
346
346
347 should "create an issue with the attributes" do
347 should "create an issue with the attributes" do
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
364 post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith')
364 post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith')
365 end
365 end
366
366
367 json = ActiveSupport::JSON.decode(response.body)
367 json = ActiveSupport::JSON.decode(response.body)
368 assert json['errors'].include?(['subject', "can't be blank"])
368 assert json['errors'].include?(['subject', "can't be blank"])
369 end
369 end
370 end
370 end
371
371
372 # Issue 6 is on a private project
372 # Issue 6 is on a private project
373 context "PUT /issues/6.xml" do
373 context "PUT /issues/6.xml" do
374 setup do
374 setup do
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'}},
382 {:success_code => :ok})
382 {:success_code => :ok})
383
383
384 should "not create a new issue" do
384 should "not create a new issue" do
385 assert_no_difference('Issue.count') do
385 assert_no_difference('Issue.count') do
386 put '/issues/6.xml', @parameters, @headers
386 put '/issues/6.xml', @parameters, @headers
387 end
387 end
388 end
388 end
389
389
390 should "create a new journal" do
390 should "create a new journal" do
391 assert_difference('Journal.count') do
391 assert_difference('Journal.count') do
392 put '/issues/6.xml', @parameters, @headers
392 put '/issues/6.xml', @parameters, @headers
393 end
393 end
394 end
394 end
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 => ''}}
432 @headers = { :authorization => credentials('jsmith') }
432 @headers = { :authorization => credentials('jsmith') }
433 end
433 end
434
434
435 should "not create a new issue" do
435 should "not create a new issue" do
436 assert_no_difference('Issue.count') do
436 assert_no_difference('Issue.count') do
437 put '/issues/6.xml', @parameters, @headers
437 put '/issues/6.xml', @parameters, @headers
438 end
438 end
439 end
439 end
440
440
441 should "not create a new journal" do
441 should "not create a new journal" do
442 assert_no_difference('Journal.count') do
442 assert_no_difference('Journal.count') do
443 put '/issues/6.xml', @parameters, @headers
443 put '/issues/6.xml', @parameters, @headers
444 end
444 end
445 end
445 end
446
446
447 should "have an errors tag" do
447 should "have an errors tag" do
448 put '/issues/6.xml', @parameters, @headers
448 put '/issues/6.xml', @parameters, @headers
449
449
450 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
450 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
451 end
451 end
452 end
452 end
453
453
454 context "PUT /issues/6.json" do
454 context "PUT /issues/6.json" do
455 setup do
455 setup do
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'}},
463 {:success_code => :ok})
463 {:success_code => :ok})
464
464
465 should "not create a new issue" do
465 should "not create a new issue" do
466 assert_no_difference('Issue.count') do
466 assert_no_difference('Issue.count') do
467 put '/issues/6.json', @parameters, @headers
467 put '/issues/6.json', @parameters, @headers
468 end
468 end
469 end
469 end
470
470
471 should "create a new journal" do
471 should "create a new journal" do
472 assert_difference('Journal.count') do
472 assert_difference('Journal.count') do
473 put '/issues/6.json', @parameters, @headers
473 put '/issues/6.json', @parameters, @headers
474 end
474 end
475 end
475 end
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 => ''}}
496 @headers = { :authorization => credentials('jsmith') }
496 @headers = { :authorization => credentials('jsmith') }
497 end
497 end
498
498
499 should "not create a new issue" do
499 should "not create a new issue" do
500 assert_no_difference('Issue.count') do
500 assert_no_difference('Issue.count') do
501 put '/issues/6.json', @parameters, @headers
501 put '/issues/6.json', @parameters, @headers
502 end
502 end
503 end
503 end
504
504
505 should "not create a new journal" do
505 should "not create a new journal" do
506 assert_no_difference('Journal.count') do
506 assert_no_difference('Journal.count') do
507 put '/issues/6.json', @parameters, @headers
507 put '/issues/6.json', @parameters, @headers
508 end
508 end
509 end
509 end
510
510
511 should "have an errors attribute" do
511 should "have an errors attribute" do
512 put '/issues/6.json', @parameters, @headers
512 put '/issues/6.json', @parameters, @headers
513
513
514 json = ActiveSupport::JSON.decode(response.body)
514 json = ActiveSupport::JSON.decode(response.body)
515 assert json['errors'].include?(['subject', "can't be blank"])
515 assert json['errors'].include?(['subject', "can't be blank"])
516 end
516 end
517 end
517 end
518
518
519 context "DELETE /issues/1.xml" do
519 context "DELETE /issues/1.xml" do
520 should_allow_api_authentication(:delete,
520 should_allow_api_authentication(:delete,
521 '/issues/6.xml',
521 '/issues/6.xml',
522 {},
522 {},
523 {:success_code => :ok})
523 {:success_code => :ok})
524
524
525 should "delete the issue" do
525 should "delete the issue" do
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
533
533
534 context "DELETE /issues/1.json" do
534 context "DELETE /issues/1.json" do
535 should_allow_api_authentication(:delete,
535 should_allow_api_authentication(:delete,
536 '/issues/6.json',
536 '/issues/6.json',
537 {},
537 {},
538 {:success_code => :ok})
538 {:success_code => :ok})
539
539
540 should "delete the issue" do
540 should "delete the issue" do
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
548
548
549 def credentials(user, password=nil)
549 def credentials(user, password=nil)
550 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
550 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
551 end
551 end
552 end
552 end
General Comments 0
You need to be logged in to leave comments. Login now