##// END OF EJS Templates
Merged r14084, r14086 and r14087 from trunk to 3.0-stable (#19368)...
Toshi MARUYAMA -
r13718:c271be6d81c4
parent child
Show More
@@ -1,42 +1,63
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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::CustomFieldsAttributeTest < Redmine::ApiTest::Base
20 class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
21 fixtures :users
21 fixtures :users
22
22
23 def test_integer_custom_fields_should_accept_strings
23 def test_integer_custom_fields_should_accept_strings
24 field = GroupCustomField.generate!(:field_format => 'int')
24 field = GroupCustomField.generate!(:field_format => 'int')
25
25
26 post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}),
26 post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}),
27 {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
27 {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
28 assert_response :created
28 assert_response :created
29 group = Group.order('id DESC').first
29 group = Group.order('id DESC').first
30 assert_equal "52", group.custom_field_value(field)
30 assert_equal "52", group.custom_field_value(field)
31 end
31 end
32
32
33 def test_integer_custom_fields_should_accept_integers
33 def test_integer_custom_fields_should_accept_integers
34 field = GroupCustomField.generate!(:field_format => 'int')
34 field = GroupCustomField.generate!(:field_format => 'int')
35
35
36 post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}),
36 post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}),
37 {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
37 {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
38 assert_response :created
38 assert_response :created
39 group = Group.order('id DESC').first
39 group = Group.order('id DESC').first
40 assert_equal "52", group.custom_field_value(field)
40 assert_equal "52", group.custom_field_value(field)
41 end
41 end
42
43 def test_multivalued_custom_fields_should_accept_an_array
44 field = GroupCustomField.generate!(
45 :field_format => 'list',
46 :multiple => true,
47 :possible_values => ["V1", "V2", "V3"],
48 :default_value => "V2"
49 )
50
51 payload = <<-JSON
52 {"group": {"name":"Foooo",
53 "custom_field_values":{"#{field.id}":["V1","V3"]}
54 }
55 }
56 JSON
57
58 post '/groups.json', payload, {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
59 assert_response :created
60 group = Group.order('id DESC').first
61 assert_equal ["V1", "V3"], group.custom_field_value(field).sort
62 end
42 end
63 end
@@ -1,688 +1,688
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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 get '/issues/1.xml?include=journals'
172 get '/issues/1.xml?include=journals'
173
173
174 assert_select 'issue journals[type=array]' do
174 assert_select 'issue journals[type=array]' do
175 assert_select 'journal[id="1"]' do
175 assert_select 'journal[id="1"]' do
176 assert_select 'details[type=array]' do
176 assert_select 'details[type=array]' do
177 assert_select 'detail[name=status_id]' do
177 assert_select 'detail[name=status_id]' do
178 assert_select 'old_value', :text => '1'
178 assert_select 'old_value', :text => '1'
179 assert_select 'new_value', :text => '2'
179 assert_select 'new_value', :text => '2'
180 end
180 end
181 end
181 end
182 end
182 end
183 end
183 end
184 end
184 end
185
185
186 test "GET /issues/:id.xml with journals should format timestamps in ISO 8601" do
186 test "GET /issues/:id.xml with journals should format timestamps in ISO 8601" do
187 get '/issues/1.xml?include=journals'
187 get '/issues/1.xml?include=journals'
188
188
189 iso_date = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
189 iso_date = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
190 assert_select 'issue>created_on', :text => iso_date
190 assert_select 'issue>created_on', :text => iso_date
191 assert_select 'issue>updated_on', :text => iso_date
191 assert_select 'issue>updated_on', :text => iso_date
192 assert_select 'issue journal>created_on', :text => iso_date
192 assert_select 'issue journal>created_on', :text => iso_date
193 end
193 end
194
194
195 test "GET /issues/:id.xml with custom fields" do
195 test "GET /issues/:id.xml with custom fields" do
196 get '/issues/3.xml'
196 get '/issues/3.xml'
197
197
198 assert_select 'issue custom_fields[type=array]' do
198 assert_select 'issue custom_fields[type=array]' do
199 assert_select 'custom_field[id="1"]' do
199 assert_select 'custom_field[id="1"]' do
200 assert_select 'value', :text => 'MySQL'
200 assert_select 'value', :text => 'MySQL'
201 end
201 end
202 end
202 end
203 assert_nothing_raised do
203 assert_nothing_raised do
204 Hash.from_xml(response.body).to_xml
204 Hash.from_xml(response.body).to_xml
205 end
205 end
206 end
206 end
207
207
208 test "GET /issues/:id.xml with multi custom fields" do
208 test "GET /issues/:id.xml with multi custom fields" do
209 field = CustomField.find(1)
209 field = CustomField.find(1)
210 field.update_attribute :multiple, true
210 field.update_attribute :multiple, true
211 issue = Issue.find(3)
211 issue = Issue.find(3)
212 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
212 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
213 issue.save!
213 issue.save!
214
214
215 get '/issues/3.xml'
215 get '/issues/3.xml'
216 assert_response :success
216 assert_response :success
217
217
218 assert_select 'issue custom_fields[type=array]' do
218 assert_select 'issue custom_fields[type=array]' do
219 assert_select 'custom_field[id="1"]' do
219 assert_select 'custom_field[id="1"]' do
220 assert_select 'value[type=array] value', 2
220 assert_select 'value[type=array] value', 2
221 end
221 end
222 end
222 end
223 xml = Hash.from_xml(response.body)
223 xml = Hash.from_xml(response.body)
224 custom_fields = xml['issue']['custom_fields']
224 custom_fields = xml['issue']['custom_fields']
225 assert_kind_of Array, custom_fields
225 assert_kind_of Array, custom_fields
226 field = custom_fields.detect {|f| f['id'] == '1'}
226 field = custom_fields.detect {|f| f['id'] == '1'}
227 assert_kind_of Hash, field
227 assert_kind_of Hash, field
228 assert_equal ['MySQL', 'Oracle'], field['value'].sort
228 assert_equal ['MySQL', 'Oracle'], field['value'].sort
229 end
229 end
230
230
231 test "GET /issues/:id.json with multi custom fields" do
231 test "GET /issues/:id.json with multi custom fields" do
232 field = CustomField.find(1)
232 field = CustomField.find(1)
233 field.update_attribute :multiple, true
233 field.update_attribute :multiple, true
234 issue = Issue.find(3)
234 issue = Issue.find(3)
235 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
235 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
236 issue.save!
236 issue.save!
237
237
238 get '/issues/3.json'
238 get '/issues/3.json'
239 assert_response :success
239 assert_response :success
240
240
241 json = ActiveSupport::JSON.decode(response.body)
241 json = ActiveSupport::JSON.decode(response.body)
242 custom_fields = json['issue']['custom_fields']
242 custom_fields = json['issue']['custom_fields']
243 assert_kind_of Array, custom_fields
243 assert_kind_of Array, custom_fields
244 field = custom_fields.detect {|f| f['id'] == 1}
244 field = custom_fields.detect {|f| f['id'] == 1}
245 assert_kind_of Hash, field
245 assert_kind_of Hash, field
246 assert_equal ['MySQL', 'Oracle'], field['value'].sort
246 assert_equal ['MySQL', 'Oracle'], field['value'].sort
247 end
247 end
248
248
249 test "GET /issues/:id.xml with empty value for multi custom field" do
249 test "GET /issues/:id.xml with empty value for multi custom field" do
250 field = CustomField.find(1)
250 field = CustomField.find(1)
251 field.update_attribute :multiple, true
251 field.update_attribute :multiple, true
252 issue = Issue.find(3)
252 issue = Issue.find(3)
253 issue.custom_field_values = {1 => ['']}
253 issue.custom_field_values = {1 => ['']}
254 issue.save!
254 issue.save!
255
255
256 get '/issues/3.xml'
256 get '/issues/3.xml'
257
257
258 assert_select 'issue custom_fields[type=array]' do
258 assert_select 'issue custom_fields[type=array]' do
259 assert_select 'custom_field[id="1"]' do
259 assert_select 'custom_field[id="1"]' do
260 assert_select 'value[type=array]:empty'
260 assert_select 'value[type=array]:empty'
261 end
261 end
262 end
262 end
263 xml = Hash.from_xml(response.body)
263 xml = Hash.from_xml(response.body)
264 custom_fields = xml['issue']['custom_fields']
264 custom_fields = xml['issue']['custom_fields']
265 assert_kind_of Array, custom_fields
265 assert_kind_of Array, custom_fields
266 field = custom_fields.detect {|f| f['id'] == '1'}
266 field = custom_fields.detect {|f| f['id'] == '1'}
267 assert_kind_of Hash, field
267 assert_kind_of Hash, field
268 assert_equal [], field['value']
268 assert_equal [], field['value']
269 end
269 end
270
270
271 test "GET /issues/:id.json with empty value for multi custom field" do
271 test "GET /issues/:id.json with empty value for multi custom field" do
272 field = CustomField.find(1)
272 field = CustomField.find(1)
273 field.update_attribute :multiple, true
273 field.update_attribute :multiple, true
274 issue = Issue.find(3)
274 issue = Issue.find(3)
275 issue.custom_field_values = {1 => ['']}
275 issue.custom_field_values = {1 => ['']}
276 issue.save!
276 issue.save!
277
277
278 get '/issues/3.json'
278 get '/issues/3.json'
279 assert_response :success
279 assert_response :success
280 json = ActiveSupport::JSON.decode(response.body)
280 json = ActiveSupport::JSON.decode(response.body)
281 custom_fields = json['issue']['custom_fields']
281 custom_fields = json['issue']['custom_fields']
282 assert_kind_of Array, custom_fields
282 assert_kind_of Array, custom_fields
283 field = custom_fields.detect {|f| f['id'] == 1}
283 field = custom_fields.detect {|f| f['id'] == 1}
284 assert_kind_of Hash, field
284 assert_kind_of Hash, field
285 assert_equal [], field['value'].sort
285 assert_equal [], field['value'].sort
286 end
286 end
287
287
288 test "GET /issues/:id.xml with attachments" do
288 test "GET /issues/:id.xml with attachments" do
289 get '/issues/3.xml?include=attachments'
289 get '/issues/3.xml?include=attachments'
290
290
291 assert_select 'issue attachments[type=array]' do
291 assert_select 'issue attachments[type=array]' do
292 assert_select 'attachment', 4
292 assert_select 'attachment', 4
293 assert_select 'attachment id', :text => '1' do
293 assert_select 'attachment id', :text => '1' do
294 assert_select '~ filename', :text => 'error281.txt'
294 assert_select '~ filename', :text => 'error281.txt'
295 assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/1/error281.txt'
295 assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/1/error281.txt'
296 end
296 end
297 end
297 end
298 end
298 end
299
299
300 test "GET /issues/:id.xml with subtasks" do
300 test "GET /issues/:id.xml with subtasks" do
301 issue = Issue.generate_with_descendants!(:project_id => 1)
301 issue = Issue.generate_with_descendants!(:project_id => 1)
302 get "/issues/#{issue.id}.xml?include=children"
302 get "/issues/#{issue.id}.xml?include=children"
303
303
304 assert_select 'issue id', :text => issue.id.to_s do
304 assert_select 'issue id', :text => issue.id.to_s do
305 assert_select '~ children[type=array] > issue', 2
305 assert_select '~ children[type=array] > issue', 2
306 assert_select '~ children[type=array] > issue > children', 1
306 assert_select '~ children[type=array] > issue > children', 1
307 end
307 end
308 end
308 end
309
309
310 test "GET /issues/:id.json with subtasks" do
310 test "GET /issues/:id.json with subtasks" do
311 issue = Issue.generate_with_descendants!(:project_id => 1)
311 issue = Issue.generate_with_descendants!(:project_id => 1)
312 get "/issues/#{issue.id}.json?include=children"
312 get "/issues/#{issue.id}.json?include=children"
313
313
314 json = ActiveSupport::JSON.decode(response.body)
314 json = ActiveSupport::JSON.decode(response.body)
315 assert_equal 2, json['issue']['children'].size
315 assert_equal 2, json['issue']['children'].size
316 assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
316 assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
317 end
317 end
318
318
319 def test_show_should_include_issue_attributes
319 def test_show_should_include_issue_attributes
320 get '/issues/1.xml'
320 get '/issues/1.xml'
321 assert_select 'issue>is_private', :text => 'false'
321 assert_select 'issue>is_private', :text => 'false'
322 end
322 end
323
323
324 test "GET /issues/:id.xml?include=watchers should include watchers" do
324 test "GET /issues/:id.xml?include=watchers should include watchers" do
325 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
325 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
326
326
327 get '/issues/1.xml?include=watchers', {}, credentials('jsmith')
327 get '/issues/1.xml?include=watchers', {}, credentials('jsmith')
328
328
329 assert_response :ok
329 assert_response :ok
330 assert_equal 'application/xml', response.content_type
330 assert_equal 'application/xml', response.content_type
331 assert_select 'issue' do
331 assert_select 'issue' do
332 assert_select 'watchers', Issue.find(1).watchers.count
332 assert_select 'watchers', Issue.find(1).watchers.count
333 assert_select 'watchers' do
333 assert_select 'watchers' do
334 assert_select 'user[id="3"]'
334 assert_select 'user[id="3"]'
335 end
335 end
336 end
336 end
337 end
337 end
338
338
339 test "POST /issues.xml should create an issue with the attributes" do
339 test "POST /issues.xml should create an issue with the attributes" do
340
340
341 payload = <<-XML
341 payload = <<-XML
342 <?xml version="1.0" encoding="UTF-8" ?>
342 <?xml version="1.0" encoding="UTF-8" ?>
343 <issue>
343 <issue>
344 <project_id>1</project_id>
344 <project_id>1</project_id>
345 <tracker_id>2</tracker_id>
345 <tracker_id>2</tracker_id>
346 <status_id>3</status_id>
346 <status_id>3</status_id>
347 <subject>API test</subject>
347 <subject>API test</subject>
348 </issue>
348 </issue>
349 XML
349 XML
350
350
351 assert_difference('Issue.count') do
351 assert_difference('Issue.count') do
352 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
352 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
353 end
353 end
354 issue = Issue.order('id DESC').first
354 issue = Issue.order('id DESC').first
355 assert_equal 1, issue.project_id
355 assert_equal 1, issue.project_id
356 assert_equal 2, issue.tracker_id
356 assert_equal 2, issue.tracker_id
357 assert_equal 3, issue.status_id
357 assert_equal 3, issue.status_id
358 assert_equal 'API test', issue.subject
358 assert_equal 'API test', issue.subject
359
359
360 assert_response :created
360 assert_response :created
361 assert_equal 'application/xml', @response.content_type
361 assert_equal 'application/xml', @response.content_type
362 assert_select 'issue > id', :text => issue.id.to_s
362 assert_select 'issue > id', :text => issue.id.to_s
363 end
363 end
364
364
365 test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
365 test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
366 assert_difference('Issue.count') do
366 assert_difference('Issue.count') do
367 post '/issues.xml',
367 post '/issues.xml',
368 {:issue => {:project_id => 1, :subject => 'Watchers',
368 {:issue => {:project_id => 1, :subject => 'Watchers',
369 :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith')
369 :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith')
370 assert_response :created
370 assert_response :created
371 end
371 end
372 issue = Issue.order('id desc').first
372 issue = Issue.order('id desc').first
373 assert_equal 2, issue.watchers.size
373 assert_equal 2, issue.watchers.size
374 assert_equal [1, 3], issue.watcher_user_ids.sort
374 assert_equal [1, 3], issue.watcher_user_ids.sort
375 end
375 end
376
376
377 test "POST /issues.xml with failure should return errors" do
377 test "POST /issues.xml with failure should return errors" do
378 assert_no_difference('Issue.count') do
378 assert_no_difference('Issue.count') do
379 post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
379 post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
380 end
380 end
381
381
382 assert_select 'errors error', :text => "Subject cannot be blank"
382 assert_select 'errors error', :text => "Subject cannot be blank"
383 end
383 end
384
384
385 test "POST /issues.json should create an issue with the attributes" do
385 test "POST /issues.json should create an issue with the attributes" do
386
386
387 payload = <<-JSON
387 payload = <<-JSON
388 {
388 {
389 "issue": {
389 "issue": {
390 "project_id": "1",
390 "project_id": "1",
391 "tracker_id": "2",
391 "tracker_id": "2",
392 "status_id": "3",
392 "status_id": "3",
393 "subject": "API test"
393 "subject": "API test"
394 }
394 }
395 }
395 }
396 JSON
396 JSON
397
397
398 assert_difference('Issue.count') do
398 assert_difference('Issue.count') do
399 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
399 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
400 end
400 end
401
401
402 issue = Issue.order('id DESC').first
402 issue = Issue.order('id DESC').first
403 assert_equal 1, issue.project_id
403 assert_equal 1, issue.project_id
404 assert_equal 2, issue.tracker_id
404 assert_equal 2, issue.tracker_id
405 assert_equal 3, issue.status_id
405 assert_equal 3, issue.status_id
406 assert_equal 'API test', issue.subject
406 assert_equal 'API test', issue.subject
407 end
407 end
408
408
409 test "POST /issues.json without tracker_id should accept custom fields" do
409 test "POST /issues.json without tracker_id should accept custom fields" do
410 field = IssueCustomField.generate!(
410 field = IssueCustomField.generate!(
411 :field_format => 'list',
411 :field_format => 'list',
412 :multiple => true,
412 :multiple => true,
413 :possible_values => ["V1", "V2", "V3"],
413 :possible_values => ["V1", "V2", "V3"],
414 :default_value => "V2",
414 :default_value => "V2",
415 :is_for_all => true,
415 :is_for_all => true,
416 :trackers => Tracker.all.to_a
416 :trackers => Tracker.all.to_a
417 )
417 )
418
418
419 payload = <<-JSON
419 payload = <<-JSON
420 {
420 {
421 "issue": {
421 "issue": {
422 "project_id": "1",
422 "project_id": "1",
423 "subject": "Multivalued custom field",
423 "subject": "Multivalued custom field",
424 "custom_field_values":{"#{field.id}":["V1","V3"]}
424 "custom_field_values":{"#{field.id}":["V1","V3"]}
425 }
425 }
426 }
426 }
427 JSON
427 JSON
428
428
429 assert_difference('Issue.count') do
429 assert_difference('Issue.count') do
430 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
430 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
431 end
431 end
432
432
433 assert_response :created
433 assert_response :created
434 issue = Issue.order('id DESC').first
434 issue = Issue.order('id DESC').first
435 assert_equal ["V1", "V3"], issue.custom_field_value(field)
435 assert_equal ["V1", "V3"], issue.custom_field_value(field).sort
436 end
436 end
437
437
438 test "POST /issues.json with failure should return errors" do
438 test "POST /issues.json with failure should return errors" do
439 assert_no_difference('Issue.count') do
439 assert_no_difference('Issue.count') do
440 post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
440 post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
441 end
441 end
442
442
443 json = ActiveSupport::JSON.decode(response.body)
443 json = ActiveSupport::JSON.decode(response.body)
444 assert json['errors'].include?("Subject cannot be blank")
444 assert json['errors'].include?("Subject cannot be blank")
445 end
445 end
446
446
447 test "PUT /issues/:id.xml" do
447 test "PUT /issues/:id.xml" do
448 assert_difference('Journal.count') do
448 assert_difference('Journal.count') do
449 put '/issues/6.xml',
449 put '/issues/6.xml',
450 {:issue => {:subject => 'API update', :notes => 'A new note'}},
450 {:issue => {:subject => 'API update', :notes => 'A new note'}},
451 credentials('jsmith')
451 credentials('jsmith')
452 end
452 end
453
453
454 issue = Issue.find(6)
454 issue = Issue.find(6)
455 assert_equal "API update", issue.subject
455 assert_equal "API update", issue.subject
456 journal = Journal.last
456 journal = Journal.last
457 assert_equal "A new note", journal.notes
457 assert_equal "A new note", journal.notes
458 end
458 end
459
459
460 test "PUT /issues/:id.xml with custom fields" do
460 test "PUT /issues/:id.xml with custom fields" do
461 put '/issues/3.xml',
461 put '/issues/3.xml',
462 {:issue => {:custom_fields => [
462 {:issue => {:custom_fields => [
463 {'id' => '1', 'value' => 'PostgreSQL' },
463 {'id' => '1', 'value' => 'PostgreSQL' },
464 {'id' => '2', 'value' => '150'}
464 {'id' => '2', 'value' => '150'}
465 ]}},
465 ]}},
466 credentials('jsmith')
466 credentials('jsmith')
467
467
468 issue = Issue.find(3)
468 issue = Issue.find(3)
469 assert_equal '150', issue.custom_value_for(2).value
469 assert_equal '150', issue.custom_value_for(2).value
470 assert_equal 'PostgreSQL', issue.custom_value_for(1).value
470 assert_equal 'PostgreSQL', issue.custom_value_for(1).value
471 end
471 end
472
472
473 test "PUT /issues/:id.xml with multi custom fields" do
473 test "PUT /issues/:id.xml with multi custom fields" do
474 field = CustomField.find(1)
474 field = CustomField.find(1)
475 field.update_attribute :multiple, true
475 field.update_attribute :multiple, true
476
476
477 put '/issues/3.xml',
477 put '/issues/3.xml',
478 {:issue => {:custom_fields => [
478 {:issue => {:custom_fields => [
479 {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
479 {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
480 {'id' => '2', 'value' => '150'}
480 {'id' => '2', 'value' => '150'}
481 ]}},
481 ]}},
482 credentials('jsmith')
482 credentials('jsmith')
483
483
484 issue = Issue.find(3)
484 issue = Issue.find(3)
485 assert_equal '150', issue.custom_value_for(2).value
485 assert_equal '150', issue.custom_value_for(2).value
486 assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
486 assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
487 end
487 end
488
488
489 test "PUT /issues/:id.xml with project change" do
489 test "PUT /issues/:id.xml with project change" do
490 put '/issues/3.xml',
490 put '/issues/3.xml',
491 {:issue => {:project_id => 2, :subject => 'Project changed'}},
491 {:issue => {:project_id => 2, :subject => 'Project changed'}},
492 credentials('jsmith')
492 credentials('jsmith')
493
493
494 issue = Issue.find(3)
494 issue = Issue.find(3)
495 assert_equal 2, issue.project_id
495 assert_equal 2, issue.project_id
496 assert_equal 'Project changed', issue.subject
496 assert_equal 'Project changed', issue.subject
497 end
497 end
498
498
499 test "PUT /issues/:id.xml with failed update" do
499 test "PUT /issues/:id.xml with failed update" do
500 put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')
500 put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')
501
501
502 assert_response :unprocessable_entity
502 assert_response :unprocessable_entity
503 assert_select 'errors error', :text => "Subject cannot be blank"
503 assert_select 'errors error', :text => "Subject cannot be blank"
504 end
504 end
505
505
506 test "PUT /issues/:id.json" do
506 test "PUT /issues/:id.json" do
507 assert_difference('Journal.count') do
507 assert_difference('Journal.count') do
508 put '/issues/6.json',
508 put '/issues/6.json',
509 {:issue => {:subject => 'API update', :notes => 'A new note'}},
509 {:issue => {:subject => 'API update', :notes => 'A new note'}},
510 credentials('jsmith')
510 credentials('jsmith')
511
511
512 assert_response :ok
512 assert_response :ok
513 assert_equal '', response.body
513 assert_equal '', response.body
514 end
514 end
515
515
516 issue = Issue.find(6)
516 issue = Issue.find(6)
517 assert_equal "API update", issue.subject
517 assert_equal "API update", issue.subject
518 journal = Journal.last
518 journal = Journal.last
519 assert_equal "A new note", journal.notes
519 assert_equal "A new note", journal.notes
520 end
520 end
521
521
522 test "PUT /issues/:id.json with failed update" do
522 test "PUT /issues/:id.json with failed update" do
523 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
523 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
524
524
525 assert_response :unprocessable_entity
525 assert_response :unprocessable_entity
526 json = ActiveSupport::JSON.decode(response.body)
526 json = ActiveSupport::JSON.decode(response.body)
527 assert json['errors'].include?("Subject cannot be blank")
527 assert json['errors'].include?("Subject cannot be blank")
528 end
528 end
529
529
530 test "DELETE /issues/:id.xml" do
530 test "DELETE /issues/:id.xml" do
531 assert_difference('Issue.count', -1) do
531 assert_difference('Issue.count', -1) do
532 delete '/issues/6.xml', {}, credentials('jsmith')
532 delete '/issues/6.xml', {}, credentials('jsmith')
533
533
534 assert_response :ok
534 assert_response :ok
535 assert_equal '', response.body
535 assert_equal '', response.body
536 end
536 end
537 assert_nil Issue.find_by_id(6)
537 assert_nil Issue.find_by_id(6)
538 end
538 end
539
539
540 test "DELETE /issues/:id.json" do
540 test "DELETE /issues/:id.json" do
541 assert_difference('Issue.count', -1) do
541 assert_difference('Issue.count', -1) do
542 delete '/issues/6.json', {}, credentials('jsmith')
542 delete '/issues/6.json', {}, credentials('jsmith')
543
543
544 assert_response :ok
544 assert_response :ok
545 assert_equal '', response.body
545 assert_equal '', response.body
546 end
546 end
547 assert_nil Issue.find_by_id(6)
547 assert_nil Issue.find_by_id(6)
548 end
548 end
549
549
550 test "POST /issues/:id/watchers.xml should add watcher" do
550 test "POST /issues/:id/watchers.xml should add watcher" do
551 assert_difference 'Watcher.count' do
551 assert_difference 'Watcher.count' do
552 post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith')
552 post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith')
553
553
554 assert_response :ok
554 assert_response :ok
555 assert_equal '', response.body
555 assert_equal '', response.body
556 end
556 end
557 watcher = Watcher.order('id desc').first
557 watcher = Watcher.order('id desc').first
558 assert_equal Issue.find(1), watcher.watchable
558 assert_equal Issue.find(1), watcher.watchable
559 assert_equal User.find(3), watcher.user
559 assert_equal User.find(3), watcher.user
560 end
560 end
561
561
562 test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do
562 test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do
563 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
563 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
564
564
565 assert_difference 'Watcher.count', -1 do
565 assert_difference 'Watcher.count', -1 do
566 delete '/issues/1/watchers/3.xml', {}, credentials('jsmith')
566 delete '/issues/1/watchers/3.xml', {}, credentials('jsmith')
567
567
568 assert_response :ok
568 assert_response :ok
569 assert_equal '', response.body
569 assert_equal '', response.body
570 end
570 end
571 assert_equal false, Issue.find(1).watched_by?(User.find(3))
571 assert_equal false, Issue.find(1).watched_by?(User.find(3))
572 end
572 end
573
573
574 def test_create_issue_with_uploaded_file
574 def test_create_issue_with_uploaded_file
575 token = xml_upload('test_create_with_upload', credentials('jsmith'))
575 token = xml_upload('test_create_with_upload', credentials('jsmith'))
576 attachment = Attachment.find_by_token(token)
576 attachment = Attachment.find_by_token(token)
577
577
578 # create the issue with the upload's token
578 # create the issue with the upload's token
579 assert_difference 'Issue.count' do
579 assert_difference 'Issue.count' do
580 post '/issues.xml',
580 post '/issues.xml',
581 {:issue => {:project_id => 1, :subject => 'Uploaded file',
581 {:issue => {:project_id => 1, :subject => 'Uploaded file',
582 :uploads => [{:token => token, :filename => 'test.txt',
582 :uploads => [{:token => token, :filename => 'test.txt',
583 :content_type => 'text/plain'}]}},
583 :content_type => 'text/plain'}]}},
584 credentials('jsmith')
584 credentials('jsmith')
585 assert_response :created
585 assert_response :created
586 end
586 end
587 issue = Issue.order('id DESC').first
587 issue = Issue.order('id DESC').first
588 assert_equal 1, issue.attachments.count
588 assert_equal 1, issue.attachments.count
589 assert_equal attachment, issue.attachments.first
589 assert_equal attachment, issue.attachments.first
590
590
591 attachment.reload
591 attachment.reload
592 assert_equal 'test.txt', attachment.filename
592 assert_equal 'test.txt', attachment.filename
593 assert_equal 'text/plain', attachment.content_type
593 assert_equal 'text/plain', attachment.content_type
594 assert_equal 'test_create_with_upload'.size, attachment.filesize
594 assert_equal 'test_create_with_upload'.size, attachment.filesize
595 assert_equal 2, attachment.author_id
595 assert_equal 2, attachment.author_id
596
596
597 # get the issue with its attachments
597 # get the issue with its attachments
598 get "/issues/#{issue.id}.xml", :include => 'attachments'
598 get "/issues/#{issue.id}.xml", :include => 'attachments'
599 assert_response :success
599 assert_response :success
600 xml = Hash.from_xml(response.body)
600 xml = Hash.from_xml(response.body)
601 attachments = xml['issue']['attachments']
601 attachments = xml['issue']['attachments']
602 assert_kind_of Array, attachments
602 assert_kind_of Array, attachments
603 assert_equal 1, attachments.size
603 assert_equal 1, attachments.size
604 url = attachments.first['content_url']
604 url = attachments.first['content_url']
605 assert_not_nil url
605 assert_not_nil url
606
606
607 # download the attachment
607 # download the attachment
608 get url
608 get url
609 assert_response :success
609 assert_response :success
610 assert_equal 'test_create_with_upload', response.body
610 assert_equal 'test_create_with_upload', response.body
611 end
611 end
612
612
613 def test_create_issue_with_multiple_uploaded_files_as_xml
613 def test_create_issue_with_multiple_uploaded_files_as_xml
614 token1 = xml_upload('File content 1', credentials('jsmith'))
614 token1 = xml_upload('File content 1', credentials('jsmith'))
615 token2 = xml_upload('File content 2', credentials('jsmith'))
615 token2 = xml_upload('File content 2', credentials('jsmith'))
616
616
617 payload = <<-XML
617 payload = <<-XML
618 <?xml version="1.0" encoding="UTF-8" ?>
618 <?xml version="1.0" encoding="UTF-8" ?>
619 <issue>
619 <issue>
620 <project_id>1</project_id>
620 <project_id>1</project_id>
621 <tracker_id>1</tracker_id>
621 <tracker_id>1</tracker_id>
622 <subject>Issue with multiple attachments</subject>
622 <subject>Issue with multiple attachments</subject>
623 <uploads type="array">
623 <uploads type="array">
624 <upload>
624 <upload>
625 <token>#{token1}</token>
625 <token>#{token1}</token>
626 <filename>test1.txt</filename>
626 <filename>test1.txt</filename>
627 </upload>
627 </upload>
628 <upload>
628 <upload>
629 <token>#{token2}</token>
629 <token>#{token2}</token>
630 <filename>test1.txt</filename>
630 <filename>test1.txt</filename>
631 </upload>
631 </upload>
632 </uploads>
632 </uploads>
633 </issue>
633 </issue>
634 XML
634 XML
635
635
636 assert_difference 'Issue.count' do
636 assert_difference 'Issue.count' do
637 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
637 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
638 assert_response :created
638 assert_response :created
639 end
639 end
640 issue = Issue.order('id DESC').first
640 issue = Issue.order('id DESC').first
641 assert_equal 2, issue.attachments.count
641 assert_equal 2, issue.attachments.count
642 end
642 end
643
643
644 def test_create_issue_with_multiple_uploaded_files_as_json
644 def test_create_issue_with_multiple_uploaded_files_as_json
645 token1 = json_upload('File content 1', credentials('jsmith'))
645 token1 = json_upload('File content 1', credentials('jsmith'))
646 token2 = json_upload('File content 2', credentials('jsmith'))
646 token2 = json_upload('File content 2', credentials('jsmith'))
647
647
648 payload = <<-JSON
648 payload = <<-JSON
649 {
649 {
650 "issue": {
650 "issue": {
651 "project_id": "1",
651 "project_id": "1",
652 "tracker_id": "1",
652 "tracker_id": "1",
653 "subject": "Issue with multiple attachments",
653 "subject": "Issue with multiple attachments",
654 "uploads": [
654 "uploads": [
655 {"token": "#{token1}", "filename": "test1.txt"},
655 {"token": "#{token1}", "filename": "test1.txt"},
656 {"token": "#{token2}", "filename": "test2.txt"}
656 {"token": "#{token2}", "filename": "test2.txt"}
657 ]
657 ]
658 }
658 }
659 }
659 }
660 JSON
660 JSON
661
661
662 assert_difference 'Issue.count' do
662 assert_difference 'Issue.count' do
663 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
663 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
664 assert_response :created
664 assert_response :created
665 end
665 end
666 issue = Issue.order('id DESC').first
666 issue = Issue.order('id DESC').first
667 assert_equal 2, issue.attachments.count
667 assert_equal 2, issue.attachments.count
668 end
668 end
669
669
670 def test_update_issue_with_uploaded_file
670 def test_update_issue_with_uploaded_file
671 token = xml_upload('test_upload_with_upload', credentials('jsmith'))
671 token = xml_upload('test_upload_with_upload', credentials('jsmith'))
672 attachment = Attachment.find_by_token(token)
672 attachment = Attachment.find_by_token(token)
673
673
674 # update the issue with the upload's token
674 # update the issue with the upload's token
675 assert_difference 'Journal.count' do
675 assert_difference 'Journal.count' do
676 put '/issues/1.xml',
676 put '/issues/1.xml',
677 {:issue => {:notes => 'Attachment added',
677 {:issue => {:notes => 'Attachment added',
678 :uploads => [{:token => token, :filename => 'test.txt',
678 :uploads => [{:token => token, :filename => 'test.txt',
679 :content_type => 'text/plain'}]}},
679 :content_type => 'text/plain'}]}},
680 credentials('jsmith')
680 credentials('jsmith')
681 assert_response :ok
681 assert_response :ok
682 assert_equal '', @response.body
682 assert_equal '', @response.body
683 end
683 end
684
684
685 issue = Issue.find(1)
685 issue = Issue.find(1)
686 assert_include attachment, issue.attachments
686 assert_include attachment, issue.attachments
687 end
687 end
688 end
688 end
General Comments 0
You need to be logged in to leave comments. Login now