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