@@ -1,79 +1,80 | |||
|
1 | 1 | api.issue do |
|
2 | 2 | api.id @issue.id |
|
3 | 3 | api.project(:id => @issue.project_id, :name => @issue.project.name) unless @issue.project.nil? |
|
4 | 4 | api.tracker(:id => @issue.tracker_id, :name => @issue.tracker.name) unless @issue.tracker.nil? |
|
5 | 5 | api.status(:id => @issue.status_id, :name => @issue.status.name) unless @issue.status.nil? |
|
6 | 6 | api.priority(:id => @issue.priority_id, :name => @issue.priority.name) unless @issue.priority.nil? |
|
7 | 7 | api.author(:id => @issue.author_id, :name => @issue.author.name) unless @issue.author.nil? |
|
8 | 8 | api.assigned_to(:id => @issue.assigned_to_id, :name => @issue.assigned_to.name) unless @issue.assigned_to.nil? |
|
9 | 9 | api.category(:id => @issue.category_id, :name => @issue.category.name) unless @issue.category.nil? |
|
10 | 10 | api.fixed_version(:id => @issue.fixed_version_id, :name => @issue.fixed_version.name) unless @issue.fixed_version.nil? |
|
11 | 11 | api.parent(:id => @issue.parent_id) unless @issue.parent.nil? |
|
12 | 12 | |
|
13 | 13 | api.subject @issue.subject |
|
14 | 14 | api.description @issue.description |
|
15 | 15 | api.start_date @issue.start_date |
|
16 | 16 | api.due_date @issue.due_date |
|
17 | 17 | api.done_ratio @issue.done_ratio |
|
18 | 18 | api.is_private @issue.is_private |
|
19 | 19 | api.estimated_hours @issue.estimated_hours |
|
20 | 20 | api.total_estimated_hours @issue.total_estimated_hours |
|
21 | 21 | if User.current.allowed_to?(:view_time_entries, @project) |
|
22 | 22 | api.spent_hours(@issue.spent_hours) |
|
23 | 23 | api.total_spent_hours(@issue.total_spent_hours) |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | render_api_custom_values @issue.visible_custom_field_values, api |
|
27 | 27 | |
|
28 | 28 | api.created_on @issue.created_on |
|
29 | 29 | api.updated_on @issue.updated_on |
|
30 | 30 | api.closed_on @issue.closed_on |
|
31 | 31 | |
|
32 | 32 | render_api_issue_children(@issue, api) if include_in_api_response?('children') |
|
33 | 33 | |
|
34 | 34 | api.array :attachments do |
|
35 | 35 | @issue.attachments.each do |attachment| |
|
36 | 36 | render_api_attachment(attachment, api) |
|
37 | 37 | end |
|
38 | 38 | end if include_in_api_response?('attachments') |
|
39 | 39 | |
|
40 | 40 | api.array :relations do |
|
41 | 41 | @relations.each do |relation| |
|
42 | 42 | api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay) |
|
43 | 43 | end |
|
44 | 44 | end if include_in_api_response?('relations') && @relations.present? |
|
45 | 45 | |
|
46 | 46 | api.array :changesets do |
|
47 | 47 | @changesets.each do |changeset| |
|
48 | 48 | api.changeset :revision => changeset.revision do |
|
49 | 49 | api.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil? |
|
50 | 50 | api.comments changeset.comments |
|
51 | 51 | api.committed_on changeset.committed_on |
|
52 | 52 | end |
|
53 | 53 | end |
|
54 | 54 | end if include_in_api_response?('changesets') |
|
55 | 55 | |
|
56 | 56 | api.array :journals do |
|
57 | 57 | @journals.each do |journal| |
|
58 | 58 | api.journal :id => journal.id do |
|
59 | 59 | api.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil? |
|
60 | 60 | api.notes journal.notes |
|
61 | 61 | api.created_on journal.created_on |
|
62 | api.private_notes journal.private_notes | |
|
62 | 63 | api.array :details do |
|
63 | 64 | journal.visible_details.each do |detail| |
|
64 | 65 | api.detail :property => detail.property, :name => detail.prop_key do |
|
65 | 66 | api.old_value detail.old_value |
|
66 | 67 | api.new_value detail.value |
|
67 | 68 | end |
|
68 | 69 | end |
|
69 | 70 | end |
|
70 | 71 | end |
|
71 | 72 | end |
|
72 | 73 | end if include_in_api_response?('journals') |
|
73 | 74 | |
|
74 | 75 | api.array :watchers do |
|
75 | 76 | @issue.watcher_users.each do |user| |
|
76 | 77 | api.user :id => user.id, :name => user.name |
|
77 | 78 | end |
|
78 | 79 | end if include_in_api_response?('watchers') && User.current.allowed_to?(:view_issue_watchers, @issue.project) |
|
79 | 80 | end |
@@ -1,860 +1,867 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 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 Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base |
|
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 | :issue_relations, |
|
29 | 29 | :versions, |
|
30 | 30 | :trackers, |
|
31 | 31 | :projects_trackers, |
|
32 | 32 | :issue_categories, |
|
33 | 33 | :enabled_modules, |
|
34 | 34 | :enumerations, |
|
35 | 35 | :attachments, |
|
36 | 36 | :workflows, |
|
37 | 37 | :custom_fields, |
|
38 | 38 | :custom_values, |
|
39 | 39 | :custom_fields_projects, |
|
40 | 40 | :custom_fields_trackers, |
|
41 | 41 | :time_entries, |
|
42 | 42 | :journals, |
|
43 | 43 | :journal_details, |
|
44 | 44 | :queries, |
|
45 | 45 | :attachments |
|
46 | 46 | |
|
47 | 47 | test "GET /issues.xml should contain metadata" do |
|
48 | 48 | get '/issues.xml' |
|
49 | 49 | assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', |
|
50 | 50 | assigns(:issue_count).to_s |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | test "GET /issues.xml with nometa param should not contain metadata" do |
|
54 | 54 | get '/issues.xml?nometa=1' |
|
55 | 55 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | test "GET /issues.xml with nometa header should not contain metadata" do |
|
59 | 59 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} |
|
60 | 60 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | test "GET /issues.xml with offset and limit" do |
|
64 | 64 | get '/issues.xml?offset=2&limit=3' |
|
65 | 65 | |
|
66 | 66 | assert_equal 3, assigns(:limit) |
|
67 | 67 | assert_equal 2, assigns(:offset) |
|
68 | 68 | assert_select 'issues issue', 3 |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | test "GET /issues.xml with relations" do |
|
72 | 72 | get '/issues.xml?include=relations' |
|
73 | 73 | |
|
74 | 74 | assert_response :success |
|
75 | 75 | assert_equal 'application/xml', @response.content_type |
|
76 | 76 | |
|
77 | 77 | assert_select 'issue id', :text => '3' do |
|
78 | 78 | assert_select '~ relations relation', 1 |
|
79 | 79 | assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]' |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | assert_select 'issue id', :text => '1' do |
|
83 | 83 | assert_select '~ relations' |
|
84 | 84 | assert_select '~ relations relation', 0 |
|
85 | 85 | end |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | test "GET /issues.xml with invalid query params" do |
|
89 | 89 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} |
|
90 | 90 | |
|
91 | 91 | assert_response :unprocessable_entity |
|
92 | 92 | assert_equal 'application/xml', @response.content_type |
|
93 | 93 | assert_select 'errors error', :text => "Start date cannot be blank" |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | test "GET /issues.xml with custom field filter" do |
|
97 | 97 | get '/issues.xml', |
|
98 | 98 | {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} |
|
99 | 99 | |
|
100 | 100 | expected_ids = Issue.visible. |
|
101 | 101 | joins(:custom_values). |
|
102 | 102 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) |
|
103 | 103 | assert expected_ids.any? |
|
104 | 104 | |
|
105 | 105 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
|
106 | 106 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | test "GET /issues.xml with custom field filter (shorthand method)" do |
|
111 | 111 | get '/issues.xml', {:cf_1 => 'MySQL'} |
|
112 | 112 | |
|
113 | 113 | expected_ids = Issue.visible. |
|
114 | 114 | joins(:custom_values). |
|
115 | 115 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) |
|
116 | 116 | assert expected_ids.any? |
|
117 | 117 | |
|
118 | 118 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
|
119 | 119 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
|
120 | 120 | end |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | def test_index_should_include_issue_attributes |
|
124 | 124 | get '/issues.xml' |
|
125 | 125 | assert_select 'issues>issue>is_private', :text => 'false' |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def test_index_should_allow_timestamp_filtering |
|
129 | 129 | Issue.delete_all |
|
130 | 130 | Issue.generate!(:subject => '1').update_column(:updated_on, Time.parse("2014-01-02T10:25:00Z")) |
|
131 | 131 | Issue.generate!(:subject => '2').update_column(:updated_on, Time.parse("2014-01-02T12:13:00Z")) |
|
132 | 132 | |
|
133 | 133 | get '/issues.xml', |
|
134 | 134 | {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='}, |
|
135 | 135 | :v => {:updated_on => ['2014-01-02T12:00:00Z']}} |
|
136 | 136 | assert_select 'issues>issue', :count => 1 |
|
137 | 137 | assert_select 'issues>issue>subject', :text => '1' |
|
138 | 138 | |
|
139 | 139 | get '/issues.xml', |
|
140 | 140 | {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, |
|
141 | 141 | :v => {:updated_on => ['2014-01-02T12:00:00Z']}} |
|
142 | 142 | assert_select 'issues>issue', :count => 1 |
|
143 | 143 | assert_select 'issues>issue>subject', :text => '2' |
|
144 | 144 | |
|
145 | 145 | get '/issues.xml', |
|
146 | 146 | {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, |
|
147 | 147 | :v => {:updated_on => ['2014-01-02T08:00:00Z']}} |
|
148 | 148 | assert_select 'issues>issue', :count => 2 |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | test "GET /issues.xml with filter" do |
|
152 | 152 | get '/issues.xml?status_id=5' |
|
153 | 153 | |
|
154 | 154 | expected_ids = Issue.visible.where(:status_id => 5).map(&:id) |
|
155 | 155 | assert expected_ids.any? |
|
156 | 156 | |
|
157 | 157 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
|
158 | 158 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | test "GET /issues.json with filter" do |
|
163 | 163 | get '/issues.json?status_id=5' |
|
164 | 164 | |
|
165 | 165 | json = ActiveSupport::JSON.decode(response.body) |
|
166 | 166 | status_ids_used = json['issues'].collect {|j| j['status']['id'] } |
|
167 | 167 | assert_equal 3, status_ids_used.length |
|
168 | 168 | assert status_ids_used.all? {|id| id == 5 } |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | test "GET /issues/:id.xml with journals" do |
|
172 | get '/issues/1.xml?include=journals' | |
|
172 | Journal.find(2).update_attribute(:private_notes, true) | |
|
173 | ||
|
174 | get '/issues/1.xml?include=journals', {}, credentials('jsmith') | |
|
173 | 175 | |
|
174 | 176 | assert_select 'issue journals[type=array]' do |
|
175 | 177 | assert_select 'journal[id="1"]' do |
|
178 | assert_select 'private_notes', :text => 'false' | |
|
176 | 179 | assert_select 'details[type=array]' do |
|
177 | 180 | assert_select 'detail[name=status_id]' do |
|
178 | 181 | assert_select 'old_value', :text => '1' |
|
179 | 182 | assert_select 'new_value', :text => '2' |
|
180 | 183 | end |
|
181 | 184 | end |
|
182 | 185 | end |
|
186 | assert_select 'journal[id="2"]' do | |
|
187 | assert_select 'private_notes', :text => 'true' | |
|
188 | assert_select 'details[type=array]' | |
|
189 | end | |
|
183 | 190 | end |
|
184 | 191 | end |
|
185 | 192 | |
|
186 | 193 | test "GET /issues/:id.xml with journals should format timestamps in ISO 8601" do |
|
187 | 194 | get '/issues/1.xml?include=journals' |
|
188 | 195 | |
|
189 | 196 | iso_date = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/ |
|
190 | 197 | assert_select 'issue>created_on', :text => iso_date |
|
191 | 198 | assert_select 'issue>updated_on', :text => iso_date |
|
192 | 199 | assert_select 'issue journal>created_on', :text => iso_date |
|
193 | 200 | end |
|
194 | 201 | |
|
195 | 202 | test "GET /issues/:id.xml with custom fields" do |
|
196 | 203 | get '/issues/3.xml' |
|
197 | 204 | |
|
198 | 205 | assert_select 'issue custom_fields[type=array]' do |
|
199 | 206 | assert_select 'custom_field[id="1"]' do |
|
200 | 207 | assert_select 'value', :text => 'MySQL' |
|
201 | 208 | end |
|
202 | 209 | end |
|
203 | 210 | assert_nothing_raised do |
|
204 | 211 | Hash.from_xml(response.body).to_xml |
|
205 | 212 | end |
|
206 | 213 | end |
|
207 | 214 | |
|
208 | 215 | test "GET /issues/:id.xml with multi custom fields" do |
|
209 | 216 | field = CustomField.find(1) |
|
210 | 217 | field.update_attribute :multiple, true |
|
211 | 218 | issue = Issue.find(3) |
|
212 | 219 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
213 | 220 | issue.save! |
|
214 | 221 | |
|
215 | 222 | get '/issues/3.xml' |
|
216 | 223 | assert_response :success |
|
217 | 224 | |
|
218 | 225 | assert_select 'issue custom_fields[type=array]' do |
|
219 | 226 | assert_select 'custom_field[id="1"]' do |
|
220 | 227 | assert_select 'value[type=array] value', 2 |
|
221 | 228 | end |
|
222 | 229 | end |
|
223 | 230 | xml = Hash.from_xml(response.body) |
|
224 | 231 | custom_fields = xml['issue']['custom_fields'] |
|
225 | 232 | assert_kind_of Array, custom_fields |
|
226 | 233 | field = custom_fields.detect {|f| f['id'] == '1'} |
|
227 | 234 | assert_kind_of Hash, field |
|
228 | 235 | assert_equal ['MySQL', 'Oracle'], field['value'].sort |
|
229 | 236 | end |
|
230 | 237 | |
|
231 | 238 | test "GET /issues/:id.json with multi custom fields" do |
|
232 | 239 | field = CustomField.find(1) |
|
233 | 240 | field.update_attribute :multiple, true |
|
234 | 241 | issue = Issue.find(3) |
|
235 | 242 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
236 | 243 | issue.save! |
|
237 | 244 | |
|
238 | 245 | get '/issues/3.json' |
|
239 | 246 | assert_response :success |
|
240 | 247 | |
|
241 | 248 | json = ActiveSupport::JSON.decode(response.body) |
|
242 | 249 | custom_fields = json['issue']['custom_fields'] |
|
243 | 250 | assert_kind_of Array, custom_fields |
|
244 | 251 | field = custom_fields.detect {|f| f['id'] == 1} |
|
245 | 252 | assert_kind_of Hash, field |
|
246 | 253 | assert_equal ['MySQL', 'Oracle'], field['value'].sort |
|
247 | 254 | end |
|
248 | 255 | |
|
249 | 256 | test "GET /issues/:id.xml with empty value for multi custom field" do |
|
250 | 257 | field = CustomField.find(1) |
|
251 | 258 | field.update_attribute :multiple, true |
|
252 | 259 | issue = Issue.find(3) |
|
253 | 260 | issue.custom_field_values = {1 => ['']} |
|
254 | 261 | issue.save! |
|
255 | 262 | |
|
256 | 263 | get '/issues/3.xml' |
|
257 | 264 | |
|
258 | 265 | assert_select 'issue custom_fields[type=array]' do |
|
259 | 266 | assert_select 'custom_field[id="1"]' do |
|
260 | 267 | assert_select 'value[type=array]:empty' |
|
261 | 268 | end |
|
262 | 269 | end |
|
263 | 270 | xml = Hash.from_xml(response.body) |
|
264 | 271 | custom_fields = xml['issue']['custom_fields'] |
|
265 | 272 | assert_kind_of Array, custom_fields |
|
266 | 273 | field = custom_fields.detect {|f| f['id'] == '1'} |
|
267 | 274 | assert_kind_of Hash, field |
|
268 | 275 | assert_equal [], field['value'] |
|
269 | 276 | end |
|
270 | 277 | |
|
271 | 278 | test "GET /issues/:id.json with empty value for multi custom field" do |
|
272 | 279 | field = CustomField.find(1) |
|
273 | 280 | field.update_attribute :multiple, true |
|
274 | 281 | issue = Issue.find(3) |
|
275 | 282 | issue.custom_field_values = {1 => ['']} |
|
276 | 283 | issue.save! |
|
277 | 284 | |
|
278 | 285 | get '/issues/3.json' |
|
279 | 286 | assert_response :success |
|
280 | 287 | json = ActiveSupport::JSON.decode(response.body) |
|
281 | 288 | custom_fields = json['issue']['custom_fields'] |
|
282 | 289 | assert_kind_of Array, custom_fields |
|
283 | 290 | field = custom_fields.detect {|f| f['id'] == 1} |
|
284 | 291 | assert_kind_of Hash, field |
|
285 | 292 | assert_equal [], field['value'].sort |
|
286 | 293 | end |
|
287 | 294 | |
|
288 | 295 | test "GET /issues/:id.xml with attachments" do |
|
289 | 296 | get '/issues/3.xml?include=attachments' |
|
290 | 297 | |
|
291 | 298 | assert_select 'issue attachments[type=array]' do |
|
292 | 299 | assert_select 'attachment', 4 |
|
293 | 300 | assert_select 'attachment id', :text => '1' do |
|
294 | 301 | assert_select '~ filename', :text => 'error281.txt' |
|
295 | 302 | assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/1/error281.txt' |
|
296 | 303 | end |
|
297 | 304 | end |
|
298 | 305 | end |
|
299 | 306 | |
|
300 | 307 | test "GET /issues/:id.xml with subtasks" do |
|
301 | 308 | issue = Issue.generate_with_descendants!(:project_id => 1) |
|
302 | 309 | get "/issues/#{issue.id}.xml?include=children" |
|
303 | 310 | |
|
304 | 311 | assert_select 'issue id', :text => issue.id.to_s do |
|
305 | 312 | assert_select '~ children[type=array] > issue', 2 |
|
306 | 313 | assert_select '~ children[type=array] > issue > children', 1 |
|
307 | 314 | end |
|
308 | 315 | end |
|
309 | 316 | |
|
310 | 317 | test "GET /issues/:id.json with subtasks" do |
|
311 | 318 | issue = Issue.generate_with_descendants!(:project_id => 1) |
|
312 | 319 | get "/issues/#{issue.id}.json?include=children" |
|
313 | 320 | |
|
314 | 321 | json = ActiveSupport::JSON.decode(response.body) |
|
315 | 322 | assert_equal 2, json['issue']['children'].size |
|
316 | 323 | assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size |
|
317 | 324 | end |
|
318 | 325 | |
|
319 | 326 | def test_show_should_include_issue_attributes |
|
320 | 327 | get '/issues/1.xml' |
|
321 | 328 | assert_select 'issue>is_private', :text => 'false' |
|
322 | 329 | end |
|
323 | 330 | |
|
324 | 331 | test "GET /issues/:id.xml?include=watchers should include watchers" do |
|
325 | 332 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) |
|
326 | 333 | |
|
327 | 334 | get '/issues/1.xml?include=watchers', {}, credentials('jsmith') |
|
328 | 335 | |
|
329 | 336 | assert_response :ok |
|
330 | 337 | assert_equal 'application/xml', response.content_type |
|
331 | 338 | assert_select 'issue' do |
|
332 | 339 | assert_select 'watchers', Issue.find(1).watchers.count |
|
333 | 340 | assert_select 'watchers' do |
|
334 | 341 | assert_select 'user[id="3"]' |
|
335 | 342 | end |
|
336 | 343 | end |
|
337 | 344 | end |
|
338 | 345 | |
|
339 | 346 | test "GET /issues/:id.xml should not disclose associated changesets from projects the user has no access to" do |
|
340 | 347 | project = Project.generate!(:is_public => false) |
|
341 | 348 | repository = Repository::Subversion.create!(:project => project, :url => "svn://localhost") |
|
342 | 349 | Issue.find(1).changesets << Changeset.generate!(:repository => repository) |
|
343 | 350 | assert Issue.find(1).changesets.any? |
|
344 | 351 | |
|
345 | 352 | get '/issues/1.xml?include=changesets', {}, credentials('jsmith') |
|
346 | 353 | |
|
347 | 354 | # the user jsmith has no permission to view the associated changeset |
|
348 | 355 | assert_select 'issue changesets[type=array]' do |
|
349 | 356 | assert_select 'changeset', 0 |
|
350 | 357 | end |
|
351 | 358 | end |
|
352 | 359 | |
|
353 | 360 | test "GET /issues/:id.xml should contains total_estimated_hours and total_spent_hours" do |
|
354 | 361 | parent = Issue.find(3) |
|
355 | 362 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
356 | 363 | TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today, |
|
357 | 364 | :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id) |
|
358 | 365 | get '/issues/3.xml' |
|
359 | 366 | |
|
360 | 367 | assert_equal 'application/xml', response.content_type |
|
361 | 368 | assert_select 'issue' do |
|
362 | 369 | assert_select 'estimated_hours', parent.estimated_hours.to_s |
|
363 | 370 | assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s |
|
364 | 371 | assert_select 'spent_hours', parent.spent_hours.to_s |
|
365 | 372 | assert_select 'total_spent_hours', (parent.spent_hours.to_f + 2.5).to_s |
|
366 | 373 | end |
|
367 | 374 | end |
|
368 | 375 | |
|
369 | 376 | test "GET /issues/:id.xml should contains total_estimated_hours, and should not contains spent_hours and total_spent_hours when permission does not exists" do |
|
370 | 377 | parent = Issue.find(3) |
|
371 | 378 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
372 | 379 | # remove permission! |
|
373 | 380 | Role.anonymous.remove_permission! :view_time_entries |
|
374 | 381 | #Role.all.each { |role| role.remove_permission! :view_time_entries } |
|
375 | 382 | get '/issues/3.xml' |
|
376 | 383 | |
|
377 | 384 | assert_equal 'application/xml', response.content_type |
|
378 | 385 | assert_select 'issue' do |
|
379 | 386 | assert_select 'estimated_hours', parent.estimated_hours.to_s |
|
380 | 387 | assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s |
|
381 | 388 | assert_select 'spent_hours', false |
|
382 | 389 | assert_select 'total_spent_hours', false |
|
383 | 390 | end |
|
384 | 391 | end |
|
385 | 392 | |
|
386 | 393 | test "GET /issues/:id.json should contains total_estimated_hours and total_spent_hours" do |
|
387 | 394 | parent = Issue.find(3) |
|
388 | 395 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
389 | 396 | TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today, |
|
390 | 397 | :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id) |
|
391 | 398 | get '/issues/3.json' |
|
392 | 399 | |
|
393 | 400 | assert_equal 'application/json', response.content_type |
|
394 | 401 | json = ActiveSupport::JSON.decode(response.body) |
|
395 | 402 | assert_equal parent.estimated_hours, json['issue']['estimated_hours'] |
|
396 | 403 | assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours'] |
|
397 | 404 | assert_equal parent.spent_hours, json['issue']['spent_hours'] |
|
398 | 405 | assert_equal (parent.spent_hours.to_f + 2.5), json['issue']['total_spent_hours'] |
|
399 | 406 | end |
|
400 | 407 | |
|
401 | 408 | test "GET /issues/:id.json should contains total_estimated_hours, and should not contains spent_hours and total_spent_hours when permission does not exists" do |
|
402 | 409 | parent = Issue.find(3) |
|
403 | 410 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
404 | 411 | # remove permission! |
|
405 | 412 | Role.anonymous.remove_permission! :view_time_entries |
|
406 | 413 | #Role.all.each { |role| role.remove_permission! :view_time_entries } |
|
407 | 414 | get '/issues/3.json' |
|
408 | 415 | |
|
409 | 416 | assert_equal 'application/json', response.content_type |
|
410 | 417 | json = ActiveSupport::JSON.decode(response.body) |
|
411 | 418 | assert_equal parent.estimated_hours, json['issue']['estimated_hours'] |
|
412 | 419 | assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours'] |
|
413 | 420 | assert_equal nil, json['issue']['spent_hours'] |
|
414 | 421 | assert_equal nil, json['issue']['total_spent_hours'] |
|
415 | 422 | end |
|
416 | 423 | |
|
417 | 424 | test "POST /issues.xml should create an issue with the attributes" do |
|
418 | 425 | |
|
419 | 426 | payload = <<-XML |
|
420 | 427 | <?xml version="1.0" encoding="UTF-8" ?> |
|
421 | 428 | <issue> |
|
422 | 429 | <project_id>1</project_id> |
|
423 | 430 | <tracker_id>2</tracker_id> |
|
424 | 431 | <status_id>3</status_id> |
|
425 | 432 | <subject>API test</subject> |
|
426 | 433 | </issue> |
|
427 | 434 | XML |
|
428 | 435 | |
|
429 | 436 | assert_difference('Issue.count') do |
|
430 | 437 | post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) |
|
431 | 438 | end |
|
432 | 439 | issue = Issue.order('id DESC').first |
|
433 | 440 | assert_equal 1, issue.project_id |
|
434 | 441 | assert_equal 2, issue.tracker_id |
|
435 | 442 | assert_equal 3, issue.status_id |
|
436 | 443 | assert_equal 'API test', issue.subject |
|
437 | 444 | |
|
438 | 445 | assert_response :created |
|
439 | 446 | assert_equal 'application/xml', @response.content_type |
|
440 | 447 | assert_select 'issue > id', :text => issue.id.to_s |
|
441 | 448 | end |
|
442 | 449 | |
|
443 | 450 | test "POST /issues.xml with watcher_user_ids should create issue with watchers" do |
|
444 | 451 | assert_difference('Issue.count') do |
|
445 | 452 | post '/issues.xml', |
|
446 | 453 | {:issue => {:project_id => 1, :subject => 'Watchers', |
|
447 | 454 | :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith') |
|
448 | 455 | assert_response :created |
|
449 | 456 | end |
|
450 | 457 | issue = Issue.order('id desc').first |
|
451 | 458 | assert_equal 2, issue.watchers.size |
|
452 | 459 | assert_equal [1, 3], issue.watcher_user_ids.sort |
|
453 | 460 | end |
|
454 | 461 | |
|
455 | 462 | test "POST /issues.xml with failure should return errors" do |
|
456 | 463 | assert_no_difference('Issue.count') do |
|
457 | 464 | post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') |
|
458 | 465 | end |
|
459 | 466 | |
|
460 | 467 | assert_select 'errors error', :text => "Subject cannot be blank" |
|
461 | 468 | end |
|
462 | 469 | |
|
463 | 470 | test "POST /issues.json should create an issue with the attributes" do |
|
464 | 471 | |
|
465 | 472 | payload = <<-JSON |
|
466 | 473 | { |
|
467 | 474 | "issue": { |
|
468 | 475 | "project_id": "1", |
|
469 | 476 | "tracker_id": "2", |
|
470 | 477 | "status_id": "3", |
|
471 | 478 | "subject": "API test" |
|
472 | 479 | } |
|
473 | 480 | } |
|
474 | 481 | JSON |
|
475 | 482 | |
|
476 | 483 | assert_difference('Issue.count') do |
|
477 | 484 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
478 | 485 | end |
|
479 | 486 | |
|
480 | 487 | issue = Issue.order('id DESC').first |
|
481 | 488 | assert_equal 1, issue.project_id |
|
482 | 489 | assert_equal 2, issue.tracker_id |
|
483 | 490 | assert_equal 3, issue.status_id |
|
484 | 491 | assert_equal 'API test', issue.subject |
|
485 | 492 | end |
|
486 | 493 | |
|
487 | 494 | test "POST /issues.json without tracker_id should accept custom fields" do |
|
488 | 495 | field = IssueCustomField.generate!( |
|
489 | 496 | :field_format => 'list', |
|
490 | 497 | :multiple => true, |
|
491 | 498 | :possible_values => ["V1", "V2", "V3"], |
|
492 | 499 | :default_value => "V2", |
|
493 | 500 | :is_for_all => true, |
|
494 | 501 | :trackers => Tracker.all.to_a |
|
495 | 502 | ) |
|
496 | 503 | |
|
497 | 504 | payload = <<-JSON |
|
498 | 505 | { |
|
499 | 506 | "issue": { |
|
500 | 507 | "project_id": "1", |
|
501 | 508 | "subject": "Multivalued custom field", |
|
502 | 509 | "custom_field_values":{"#{field.id}":["V1","V3"]} |
|
503 | 510 | } |
|
504 | 511 | } |
|
505 | 512 | JSON |
|
506 | 513 | |
|
507 | 514 | assert_difference('Issue.count') do |
|
508 | 515 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
509 | 516 | end |
|
510 | 517 | |
|
511 | 518 | assert_response :created |
|
512 | 519 | issue = Issue.order('id DESC').first |
|
513 | 520 | assert_equal ["V1", "V3"], issue.custom_field_value(field).sort |
|
514 | 521 | end |
|
515 | 522 | |
|
516 | 523 | test "POST /issues.json with omitted custom field should set default value" do |
|
517 | 524 | field = IssueCustomField.generate!(:default_value => "Default") |
|
518 | 525 | |
|
519 | 526 | issue = new_record(Issue) do |
|
520 | 527 | post '/issues.json', |
|
521 | 528 | {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}}, |
|
522 | 529 | credentials('jsmith') |
|
523 | 530 | end |
|
524 | 531 | assert_equal "Default", issue.custom_field_value(field) |
|
525 | 532 | end |
|
526 | 533 | |
|
527 | 534 | test "POST /issues.json with custom field set to blank should not set default value" do |
|
528 | 535 | field = IssueCustomField.generate!(:default_value => "Default") |
|
529 | 536 | |
|
530 | 537 | issue = new_record(Issue) do |
|
531 | 538 | post '/issues.json', |
|
532 | 539 | {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}}, |
|
533 | 540 | credentials('jsmith') |
|
534 | 541 | end |
|
535 | 542 | assert_equal "", issue.custom_field_value(field) |
|
536 | 543 | end |
|
537 | 544 | |
|
538 | 545 | test "POST /issues.json with failure should return errors" do |
|
539 | 546 | assert_no_difference('Issue.count') do |
|
540 | 547 | post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') |
|
541 | 548 | end |
|
542 | 549 | |
|
543 | 550 | json = ActiveSupport::JSON.decode(response.body) |
|
544 | 551 | assert json['errors'].include?("Subject cannot be blank") |
|
545 | 552 | end |
|
546 | 553 | |
|
547 | 554 | test "POST /issues.json with invalid project_id should respond with 422" do |
|
548 | 555 | post '/issues.json', {:issue => {:project_id => 999, :subject => "API"}}, credentials('jsmith') |
|
549 | 556 | assert_response 422 |
|
550 | 557 | end |
|
551 | 558 | |
|
552 | 559 | test "PUT /issues/:id.xml" do |
|
553 | 560 | assert_difference('Journal.count') do |
|
554 | 561 | put '/issues/6.xml', |
|
555 | 562 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
556 | 563 | credentials('jsmith') |
|
557 | 564 | end |
|
558 | 565 | |
|
559 | 566 | issue = Issue.find(6) |
|
560 | 567 | assert_equal "API update", issue.subject |
|
561 | 568 | journal = Journal.last |
|
562 | 569 | assert_equal "A new note", journal.notes |
|
563 | 570 | end |
|
564 | 571 | |
|
565 | 572 | test "PUT /issues/:id.xml with custom fields" do |
|
566 | 573 | put '/issues/3.xml', |
|
567 | 574 | {:issue => {:custom_fields => [ |
|
568 | 575 | {'id' => '1', 'value' => 'PostgreSQL' }, |
|
569 | 576 | {'id' => '2', 'value' => '150'} |
|
570 | 577 | ]}}, |
|
571 | 578 | credentials('jsmith') |
|
572 | 579 | |
|
573 | 580 | issue = Issue.find(3) |
|
574 | 581 | assert_equal '150', issue.custom_value_for(2).value |
|
575 | 582 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value |
|
576 | 583 | end |
|
577 | 584 | |
|
578 | 585 | test "PUT /issues/:id.xml with multi custom fields" do |
|
579 | 586 | field = CustomField.find(1) |
|
580 | 587 | field.update_attribute :multiple, true |
|
581 | 588 | |
|
582 | 589 | put '/issues/3.xml', |
|
583 | 590 | {:issue => {:custom_fields => [ |
|
584 | 591 | {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, |
|
585 | 592 | {'id' => '2', 'value' => '150'} |
|
586 | 593 | ]}}, |
|
587 | 594 | credentials('jsmith') |
|
588 | 595 | |
|
589 | 596 | issue = Issue.find(3) |
|
590 | 597 | assert_equal '150', issue.custom_value_for(2).value |
|
591 | 598 | assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort |
|
592 | 599 | end |
|
593 | 600 | |
|
594 | 601 | test "PUT /issues/:id.xml with project change" do |
|
595 | 602 | put '/issues/3.xml', |
|
596 | 603 | {:issue => {:project_id => 2, :subject => 'Project changed'}}, |
|
597 | 604 | credentials('jsmith') |
|
598 | 605 | |
|
599 | 606 | issue = Issue.find(3) |
|
600 | 607 | assert_equal 2, issue.project_id |
|
601 | 608 | assert_equal 'Project changed', issue.subject |
|
602 | 609 | end |
|
603 | 610 | |
|
604 | 611 | test "PUT /issues/:id.xml with notes only" do |
|
605 | 612 | assert_difference('Journal.count') do |
|
606 | 613 | put '/issues/6.xml', |
|
607 | 614 | {:issue => {:notes => 'Notes only'}}, |
|
608 | 615 | credentials('jsmith') |
|
609 | 616 | end |
|
610 | 617 | |
|
611 | 618 | journal = Journal.last |
|
612 | 619 | assert_equal "Notes only", journal.notes |
|
613 | 620 | end |
|
614 | 621 | |
|
615 | 622 | test "PUT /issues/:id.json with omitted custom field should not change blank value to default value" do |
|
616 | 623 | field = IssueCustomField.generate!(:default_value => "Default") |
|
617 | 624 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""}) |
|
618 | 625 | assert_equal "", issue.reload.custom_field_value(field) |
|
619 | 626 | |
|
620 | 627 | assert_difference('Journal.count') do |
|
621 | 628 | put "/issues/#{issue.id}.json", |
|
622 | 629 | {:issue => {:custom_field_values => {}, :notes => 'API'}}, |
|
623 | 630 | credentials('jsmith') |
|
624 | 631 | end |
|
625 | 632 | |
|
626 | 633 | assert_equal "", issue.reload.custom_field_value(field) |
|
627 | 634 | end |
|
628 | 635 | |
|
629 | 636 | test "PUT /issues/:id.json with custom field set to blank should not change blank value to default value" do |
|
630 | 637 | field = IssueCustomField.generate!(:default_value => "Default") |
|
631 | 638 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""}) |
|
632 | 639 | assert_equal "", issue.reload.custom_field_value(field) |
|
633 | 640 | |
|
634 | 641 | assert_difference('Journal.count') do |
|
635 | 642 | put "/issues/#{issue.id}.json", |
|
636 | 643 | {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, |
|
637 | 644 | credentials('jsmith') |
|
638 | 645 | end |
|
639 | 646 | |
|
640 | 647 | assert_equal "", issue.reload.custom_field_value(field) |
|
641 | 648 | end |
|
642 | 649 | |
|
643 | 650 | test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker should set default value" do |
|
644 | 651 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) |
|
645 | 652 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) |
|
646 | 653 | |
|
647 | 654 | assert_difference('Journal.count') do |
|
648 | 655 | put "/issues/#{issue.id}.json", |
|
649 | 656 | {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}}, |
|
650 | 657 | credentials('jsmith') |
|
651 | 658 | end |
|
652 | 659 | |
|
653 | 660 | assert_equal 2, issue.reload.tracker_id |
|
654 | 661 | assert_equal "Default", issue.reload.custom_field_value(field) |
|
655 | 662 | end |
|
656 | 663 | |
|
657 | 664 | test "PUT /issues/:id.json with tracker change and custom field specific to that tracker set to blank should not set default value" do |
|
658 | 665 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) |
|
659 | 666 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) |
|
660 | 667 | |
|
661 | 668 | assert_difference('Journal.count') do |
|
662 | 669 | put "/issues/#{issue.id}.json", |
|
663 | 670 | {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, |
|
664 | 671 | credentials('jsmith') |
|
665 | 672 | end |
|
666 | 673 | |
|
667 | 674 | assert_equal 2, issue.reload.tracker_id |
|
668 | 675 | assert_equal "", issue.reload.custom_field_value(field) |
|
669 | 676 | end |
|
670 | 677 | |
|
671 | 678 | test "PUT /issues/:id.xml with failed update" do |
|
672 | 679 | put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') |
|
673 | 680 | |
|
674 | 681 | assert_response :unprocessable_entity |
|
675 | 682 | assert_select 'errors error', :text => "Subject cannot be blank" |
|
676 | 683 | end |
|
677 | 684 | |
|
678 | 685 | test "PUT /issues/:id.json" do |
|
679 | 686 | assert_difference('Journal.count') do |
|
680 | 687 | put '/issues/6.json', |
|
681 | 688 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
682 | 689 | credentials('jsmith') |
|
683 | 690 | |
|
684 | 691 | assert_response :ok |
|
685 | 692 | assert_equal '', response.body |
|
686 | 693 | end |
|
687 | 694 | |
|
688 | 695 | issue = Issue.find(6) |
|
689 | 696 | assert_equal "API update", issue.subject |
|
690 | 697 | journal = Journal.last |
|
691 | 698 | assert_equal "A new note", journal.notes |
|
692 | 699 | end |
|
693 | 700 | |
|
694 | 701 | test "PUT /issues/:id.json with failed update" do |
|
695 | 702 | put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') |
|
696 | 703 | |
|
697 | 704 | assert_response :unprocessable_entity |
|
698 | 705 | json = ActiveSupport::JSON.decode(response.body) |
|
699 | 706 | assert json['errors'].include?("Subject cannot be blank") |
|
700 | 707 | end |
|
701 | 708 | |
|
702 | 709 | test "DELETE /issues/:id.xml" do |
|
703 | 710 | assert_difference('Issue.count', -1) do |
|
704 | 711 | delete '/issues/6.xml', {}, credentials('jsmith') |
|
705 | 712 | |
|
706 | 713 | assert_response :ok |
|
707 | 714 | assert_equal '', response.body |
|
708 | 715 | end |
|
709 | 716 | assert_nil Issue.find_by_id(6) |
|
710 | 717 | end |
|
711 | 718 | |
|
712 | 719 | test "DELETE /issues/:id.json" do |
|
713 | 720 | assert_difference('Issue.count', -1) do |
|
714 | 721 | delete '/issues/6.json', {}, credentials('jsmith') |
|
715 | 722 | |
|
716 | 723 | assert_response :ok |
|
717 | 724 | assert_equal '', response.body |
|
718 | 725 | end |
|
719 | 726 | assert_nil Issue.find_by_id(6) |
|
720 | 727 | end |
|
721 | 728 | |
|
722 | 729 | test "POST /issues/:id/watchers.xml should add watcher" do |
|
723 | 730 | assert_difference 'Watcher.count' do |
|
724 | 731 | post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith') |
|
725 | 732 | |
|
726 | 733 | assert_response :ok |
|
727 | 734 | assert_equal '', response.body |
|
728 | 735 | end |
|
729 | 736 | watcher = Watcher.order('id desc').first |
|
730 | 737 | assert_equal Issue.find(1), watcher.watchable |
|
731 | 738 | assert_equal User.find(3), watcher.user |
|
732 | 739 | end |
|
733 | 740 | |
|
734 | 741 | test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do |
|
735 | 742 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) |
|
736 | 743 | |
|
737 | 744 | assert_difference 'Watcher.count', -1 do |
|
738 | 745 | delete '/issues/1/watchers/3.xml', {}, credentials('jsmith') |
|
739 | 746 | |
|
740 | 747 | assert_response :ok |
|
741 | 748 | assert_equal '', response.body |
|
742 | 749 | end |
|
743 | 750 | assert_equal false, Issue.find(1).watched_by?(User.find(3)) |
|
744 | 751 | end |
|
745 | 752 | |
|
746 | 753 | def test_create_issue_with_uploaded_file |
|
747 | 754 | token = xml_upload('test_create_with_upload', credentials('jsmith')) |
|
748 | 755 | attachment = Attachment.find_by_token(token) |
|
749 | 756 | |
|
750 | 757 | # create the issue with the upload's token |
|
751 | 758 | assert_difference 'Issue.count' do |
|
752 | 759 | post '/issues.xml', |
|
753 | 760 | {:issue => {:project_id => 1, :subject => 'Uploaded file', |
|
754 | 761 | :uploads => [{:token => token, :filename => 'test.txt', |
|
755 | 762 | :content_type => 'text/plain'}]}}, |
|
756 | 763 | credentials('jsmith') |
|
757 | 764 | assert_response :created |
|
758 | 765 | end |
|
759 | 766 | issue = Issue.order('id DESC').first |
|
760 | 767 | assert_equal 1, issue.attachments.count |
|
761 | 768 | assert_equal attachment, issue.attachments.first |
|
762 | 769 | |
|
763 | 770 | attachment.reload |
|
764 | 771 | assert_equal 'test.txt', attachment.filename |
|
765 | 772 | assert_equal 'text/plain', attachment.content_type |
|
766 | 773 | assert_equal 'test_create_with_upload'.size, attachment.filesize |
|
767 | 774 | assert_equal 2, attachment.author_id |
|
768 | 775 | |
|
769 | 776 | # get the issue with its attachments |
|
770 | 777 | get "/issues/#{issue.id}.xml", :include => 'attachments' |
|
771 | 778 | assert_response :success |
|
772 | 779 | xml = Hash.from_xml(response.body) |
|
773 | 780 | attachments = xml['issue']['attachments'] |
|
774 | 781 | assert_kind_of Array, attachments |
|
775 | 782 | assert_equal 1, attachments.size |
|
776 | 783 | url = attachments.first['content_url'] |
|
777 | 784 | assert_not_nil url |
|
778 | 785 | |
|
779 | 786 | # download the attachment |
|
780 | 787 | get url |
|
781 | 788 | assert_response :success |
|
782 | 789 | assert_equal 'test_create_with_upload', response.body |
|
783 | 790 | end |
|
784 | 791 | |
|
785 | 792 | def test_create_issue_with_multiple_uploaded_files_as_xml |
|
786 | 793 | token1 = xml_upload('File content 1', credentials('jsmith')) |
|
787 | 794 | token2 = xml_upload('File content 2', credentials('jsmith')) |
|
788 | 795 | |
|
789 | 796 | payload = <<-XML |
|
790 | 797 | <?xml version="1.0" encoding="UTF-8" ?> |
|
791 | 798 | <issue> |
|
792 | 799 | <project_id>1</project_id> |
|
793 | 800 | <tracker_id>1</tracker_id> |
|
794 | 801 | <subject>Issue with multiple attachments</subject> |
|
795 | 802 | <uploads type="array"> |
|
796 | 803 | <upload> |
|
797 | 804 | <token>#{token1}</token> |
|
798 | 805 | <filename>test1.txt</filename> |
|
799 | 806 | </upload> |
|
800 | 807 | <upload> |
|
801 | 808 | <token>#{token2}</token> |
|
802 | 809 | <filename>test1.txt</filename> |
|
803 | 810 | </upload> |
|
804 | 811 | </uploads> |
|
805 | 812 | </issue> |
|
806 | 813 | XML |
|
807 | 814 | |
|
808 | 815 | assert_difference 'Issue.count' do |
|
809 | 816 | post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) |
|
810 | 817 | assert_response :created |
|
811 | 818 | end |
|
812 | 819 | issue = Issue.order('id DESC').first |
|
813 | 820 | assert_equal 2, issue.attachments.count |
|
814 | 821 | end |
|
815 | 822 | |
|
816 | 823 | def test_create_issue_with_multiple_uploaded_files_as_json |
|
817 | 824 | token1 = json_upload('File content 1', credentials('jsmith')) |
|
818 | 825 | token2 = json_upload('File content 2', credentials('jsmith')) |
|
819 | 826 | |
|
820 | 827 | payload = <<-JSON |
|
821 | 828 | { |
|
822 | 829 | "issue": { |
|
823 | 830 | "project_id": "1", |
|
824 | 831 | "tracker_id": "1", |
|
825 | 832 | "subject": "Issue with multiple attachments", |
|
826 | 833 | "uploads": [ |
|
827 | 834 | {"token": "#{token1}", "filename": "test1.txt"}, |
|
828 | 835 | {"token": "#{token2}", "filename": "test2.txt"} |
|
829 | 836 | ] |
|
830 | 837 | } |
|
831 | 838 | } |
|
832 | 839 | JSON |
|
833 | 840 | |
|
834 | 841 | assert_difference 'Issue.count' do |
|
835 | 842 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
836 | 843 | assert_response :created |
|
837 | 844 | end |
|
838 | 845 | issue = Issue.order('id DESC').first |
|
839 | 846 | assert_equal 2, issue.attachments.count |
|
840 | 847 | end |
|
841 | 848 | |
|
842 | 849 | def test_update_issue_with_uploaded_file |
|
843 | 850 | token = xml_upload('test_upload_with_upload', credentials('jsmith')) |
|
844 | 851 | attachment = Attachment.find_by_token(token) |
|
845 | 852 | |
|
846 | 853 | # update the issue with the upload's token |
|
847 | 854 | assert_difference 'Journal.count' do |
|
848 | 855 | put '/issues/1.xml', |
|
849 | 856 | {:issue => {:notes => 'Attachment added', |
|
850 | 857 | :uploads => [{:token => token, :filename => 'test.txt', |
|
851 | 858 | :content_type => 'text/plain'}]}}, |
|
852 | 859 | credentials('jsmith') |
|
853 | 860 | assert_response :ok |
|
854 | 861 | assert_equal '', @response.body |
|
855 | 862 | end |
|
856 | 863 | |
|
857 | 864 | issue = Issue.find(1) |
|
858 | 865 | assert_include attachment, issue.attachments |
|
859 | 866 | end |
|
860 | 867 | end |
General Comments 0
You need to be logged in to leave comments.
Login now