This diff has been collapsed as it changes many lines, (811 lines changed)
Show them
Hide them
|
|
@@
-48,98
+48,117
class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
|
48
|
Setting.rest_api_enabled = '1'
|
|
48
|
Setting.rest_api_enabled = '1'
|
|
49
|
end
|
|
49
|
end
|
|
50
|
|
|
50
|
|
|
51
|
context "/issues" do
|
|
51
|
# Use a private project to make sure auth is really working and not just
|
|
52
|
# Use a private project to make sure auth is really working and not just
|
|
52
|
# only showing public issues.
|
|
53
|
# only showing public issues.
|
|
53
|
should_allow_api_authentication(:get, "/projects/private-child/issues.xml")
|
|
54
|
should_allow_api_authentication(:get, "/projects/private-child/issues.xml")
|
|
54
|
should_allow_api_authentication(:get, "/projects/private-child/issues.json")
|
|
55
|
|
|
55
|
|
|
56
|
should "contain metadata" do
|
|
56
|
should_allow_api_authentication(:get, "/issues/6.xml")
|
|
57
|
get '/issues.xml'
|
|
57
|
should_allow_api_authentication(:get, "/issues/6.json")
|
|
|
|
|
58
|
|
|
|
|
|
59
|
should_allow_api_authentication(
|
|
|
|
|
60
|
:post,
|
|
|
|
|
61
|
'/issues.xml',
|
|
|
|
|
62
|
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
|
|
|
|
|
63
|
{:success_code => :created}
|
|
|
|
|
64
|
)
|
|
|
|
|
65
|
should_allow_api_authentication(:post,
|
|
|
|
|
66
|
'/issues.json',
|
|
|
|
|
67
|
{:issue => {:project_id => 1, :subject => 'API test',
|
|
|
|
|
68
|
:tracker_id => 2, :status_id => 3}},
|
|
|
|
|
69
|
{:success_code => :created})
|
|
|
|
|
70
|
|
|
|
|
|
71
|
should_allow_api_authentication(:put,
|
|
|
|
|
72
|
'/issues/6.xml',
|
|
|
|
|
73
|
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
|
|
|
|
74
|
{:success_code => :ok})
|
|
|
|
|
75
|
should_allow_api_authentication(:put,
|
|
|
|
|
76
|
'/issues/6.json',
|
|
|
|
|
77
|
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
|
|
|
|
78
|
{:success_code => :ok})
|
|
|
|
|
79
|
|
|
|
|
|
80
|
should_allow_api_authentication(:delete,
|
|
|
|
|
81
|
'/issues/6.xml',
|
|
|
|
|
82
|
{},
|
|
|
|
|
83
|
{:success_code => :ok})
|
|
|
|
|
84
|
should_allow_api_authentication(:delete,
|
|
|
|
|
85
|
'/issues/6.json',
|
|
|
|
|
86
|
{},
|
|
|
|
|
87
|
{:success_code => :ok})
|
|
|
|
|
88
|
|
|
|
|
|
89
|
test "GET /issues.xml should contain metadata" do
|
|
|
|
|
90
|
get '/issues.xml'
|
|
|
|
|
91
|
assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]',
|
|
|
|
|
92
|
assigns(:issue_count).to_s
|
|
|
|
|
93
|
end
|
|
58
|
|
|
94
|
|
|
59
|
assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', assigns(:issue_count).to_s
|
|
95
|
test "GET /issues.xml with nometa param should not contain metadata" do
|
|
60
|
end
|
|
96
|
get '/issues.xml?nometa=1'
|
|
|
|
|
97
|
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
|
|
|
|
98
|
end
|
|
61
|
|
|
99
|
|
|
62
|
context "with offset and limit" do
|
|
100
|
test "GET /issues.xml with nometa header should not contain metadata" do
|
|
63
|
should "use the params" do
|
|
101
|
get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
|
|
64
|
get '/issues.xml?offset=2&limit=3'
|
|
102
|
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
|
|
|
|
103
|
end
|
|
65
|
|
|
104
|
|
|
66
|
assert_equal 3, assigns(:limit)
|
|
105
|
test "GET /issues.xml with offset and limit" do
|
|
67
|
assert_equal 2, assigns(:offset)
|
|
106
|
get '/issues.xml?offset=2&limit=3'
|
|
68
|
assert_select 'issues issue', 3
|
|
|
|
|
69
|
end
|
|
|
|
|
70
|
end
|
|
|
|
|
71
|
|
|
107
|
|
|
72
|
context "with nometa param" do
|
|
108
|
assert_equal 3, assigns(:limit)
|
|
73
|
should "not contain metadata" do
|
|
109
|
assert_equal 2, assigns(:offset)
|
|
74
|
get '/issues.xml?nometa=1'
|
|
110
|
assert_select 'issues issue', 3
|
|
|
|
|
111
|
end
|
|
75
|
|
|
112
|
|
|
76
|
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
|
113
|
test "GET /issues.xml with relations" do
|
|
77
|
end
|
|
114
|
get '/issues.xml?include=relations'
|
|
78
|
end
|
|
|
|
|
79
|
|
|
115
|
|
|
80
|
context "with nometa header" do
|
|
116
|
assert_response :success
|
|
81
|
should "not contain metadata" do
|
|
117
|
assert_equal 'application/xml', @response.content_type
|
|
82
|
get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
|
|
|
|
|
83
|
|
|
118
|
|
|
84
|
assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
|
|
119
|
assert_select 'issue id:content(3)' do
|
|
85
|
end
|
|
120
|
assert_select '~ relations relation', 1
|
|
|
|
|
121
|
assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]'
|
|
86
|
end
|
|
122
|
end
|
|
87
|
|
|
123
|
|
|
88
|
context "with relations" do
|
|
124
|
assert_select 'issue id:content(1)' do
|
|
89
|
should "display relations" do
|
|
125
|
assert_select '~ relations'
|
|
90
|
get '/issues.xml?include=relations'
|
|
126
|
assert_select '~ relations relation', 0
|
|
91
|
|
|
127
|
end
|
|
92
|
assert_response :success
|
|
128
|
end
|
|
93
|
assert_equal 'application/xml', @response.content_type
|
|
|
|
|
94
|
|
|
129
|
|
|
95
|
assert_select 'issue id:content(3)' do
|
|
130
|
test "GET /issues.xml with invalid query params" do
|
|
96
|
assert_select '~ relations relation', 1
|
|
131
|
get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
|
|
97
|
assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]'
|
|
|
|
|
98
|
end
|
|
|
|
|
99
|
|
|
132
|
|
|
100
|
assert_select 'issue id:content(1)' do
|
|
133
|
assert_response :unprocessable_entity
|
|
101
|
assert_select '~ relations'
|
|
134
|
assert_equal 'application/xml', @response.content_type
|
|
102
|
assert_select '~ relations relation', 0
|
|
135
|
assert_select 'errors error', :text => "Start date can't be blank"
|
|
103
|
end
|
|
136
|
end
|
|
104
|
end
|
|
|
|
|
105
|
end
|
|
|
|
|
106
|
|
|
137
|
|
|
107
|
context "with invalid query params" do
|
|
138
|
test "GET /issues.xml with custom field filter" do
|
|
108
|
should "return errors" do
|
|
139
|
get '/issues.xml',
|
|
109
|
get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
|
|
140
|
{:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}}
|
|
110
|
|
|
141
|
|
|
111
|
assert_response :unprocessable_entity
|
|
142
|
expected_ids = Issue.visible.
|
|
112
|
assert_equal 'application/xml', @response.content_type
|
|
143
|
joins(:custom_values).
|
|
113
|
assert_select 'errors error', :text => "Start date can't be blank"
|
|
144
|
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
|
|
114
|
end
|
|
145
|
assert expected_ids.any?
|
|
115
|
end
|
|
|
|
|
116
|
|
|
146
|
|
|
117
|
context "with custom field filter" do
|
|
147
|
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
|
118
|
should "show only issues with the custom field value" do
|
|
148
|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
|
119
|
get '/issues.xml',
|
|
|
|
|
120
|
{:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='},
|
|
|
|
|
121
|
:v => {:cf_1 => ['MySQL']}}
|
|
|
|
|
122
|
expected_ids = Issue.visible.
|
|
|
|
|
123
|
joins(:custom_values).
|
|
|
|
|
124
|
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
|
|
|
|
|
125
|
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
|
|
|
|
126
|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
|
|
|
|
127
|
end
|
|
|
|
|
128
|
end
|
|
|
|
|
129
|
end
|
|
149
|
end
|
|
|
|
|
150
|
end
|
|
130
|
|
|
151
|
|
|
131
|
context "with custom field filter (shorthand method)" do
|
|
152
|
test "GET /issues.xml with custom field filter (shorthand method)" do
|
|
132
|
should "show only issues with the custom field value" do
|
|
153
|
get '/issues.xml', {:cf_1 => 'MySQL'}
|
|
133
|
get '/issues.xml', { :cf_1 => 'MySQL' }
|
|
|
|
|
134
|
|
|
154
|
|
|
135
|
expected_ids = Issue.visible.
|
|
155
|
expected_ids = Issue.visible.
|
|
136
|
joins(:custom_values).
|
|
156
|
joins(:custom_values).
|
|
137
|
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
|
|
157
|
where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
|
|
|
|
|
158
|
assert expected_ids.any?
|
|
138
|
|
|
159
|
|
|
139
|
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
|
160
|
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
|
140
|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
|
161
|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
|
141
|
end
|
|
|
|
|
142
|
end
|
|
|
|
|
143
|
end
|
|
162
|
end
|
|
144
|
end
|
|
163
|
end
|
|
145
|
|
|
164
|
|
|
@@
-171,234
+190,163
class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
|
171
|
assert_select 'issues>issue', :count => 2
|
|
190
|
assert_select 'issues>issue', :count => 2
|
|
172
|
end
|
|
191
|
end
|
|
173
|
|
|
192
|
|
|
174
|
context "/index.json" do
|
|
193
|
test "GET /issues.xml with filter" do
|
|
175
|
should_allow_api_authentication(:get, "/projects/private-child/issues.json")
|
|
194
|
get '/issues.xml?status_id=5'
|
|
176
|
end
|
|
|
|
|
177
|
|
|
195
|
|
|
178
|
context "/index.xml with filter" do
|
|
196
|
expected_ids = Issue.visible.where(:status_id => 5).map(&:id)
|
|
179
|
should "show only issues with the status_id" do
|
|
197
|
assert expected_ids.any?
|
|
180
|
get '/issues.xml?status_id=5'
|
|
|
|
|
181
|
|
|
198
|
|
|
182
|
expected_ids = Issue.visible.where(:status_id => 5).map(&:id)
|
|
199
|
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
|
183
|
|
|
200
|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
|
184
|
assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
|
|
|
|
|
185
|
ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
|
|
|
|
|
186
|
end
|
|
|
|
|
187
|
end
|
|
201
|
end
|
|
188
|
end
|
|
202
|
end
|
|
189
|
|
|
203
|
|
|
190
|
context "/index.json with filter" do
|
|
204
|
test "GET /issues.json with filter" do
|
|
191
|
should "show only issues with the status_id" do
|
|
205
|
get '/issues.json?status_id=5'
|
|
192
|
get '/issues.json?status_id=5'
|
|
|
|
|
193
|
|
|
|
|
|
194
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
195
|
status_ids_used = json['issues'].collect {|j| j['status']['id'] }
|
|
|
|
|
196
|
assert_equal 3, status_ids_used.length
|
|
|
|
|
197
|
assert status_ids_used.all? {|id| id == 5 }
|
|
|
|
|
198
|
end
|
|
|
|
|
199
|
|
|
206
|
|
|
|
|
|
207
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
208
|
status_ids_used = json['issues'].collect {|j| j['status']['id'] }
|
|
|
|
|
209
|
assert_equal 3, status_ids_used.length
|
|
|
|
|
210
|
assert status_ids_used.all? {|id| id == 5 }
|
|
200
|
end
|
|
211
|
end
|
|
201
|
|
|
212
|
|
|
202
|
# Issue 6 is on a private project
|
|
213
|
test "GET /issues/:id.xml with journals" do
|
|
203
|
context "/issues/6.xml" do
|
|
214
|
get '/issues/1.xml?include=journals'
|
|
204
|
should_allow_api_authentication(:get, "/issues/6.xml")
|
|
|
|
|
205
|
end
|
|
|
|
|
206
|
|
|
215
|
|
|
207
|
context "/issues/6.json" do
|
|
216
|
assert_select 'issue journals[type=array]' do
|
|
208
|
should_allow_api_authentication(:get, "/issues/6.json")
|
|
217
|
assert_select 'journal[id="1"]' do
|
|
|
|
|
218
|
assert_select 'details[type=array]' do
|
|
|
|
|
219
|
assert_select 'detail[name=status_id]' do
|
|
|
|
|
220
|
assert_select 'old_value', :text => '1'
|
|
|
|
|
221
|
assert_select 'new_value', :text => '2'
|
|
|
|
|
222
|
end
|
|
|
|
|
223
|
end
|
|
|
|
|
224
|
end
|
|
|
|
|
225
|
end
|
|
209
|
end
|
|
226
|
end
|
|
210
|
|
|
227
|
|
|
211
|
context "GET /issues/:id" do
|
|
228
|
test "GET /issues/:id.xml with custom fields" do
|
|
212
|
context "with journals" do
|
|
229
|
get '/issues/3.xml'
|
|
213
|
context ".xml" do
|
|
|
|
|
214
|
should "display journals" do
|
|
|
|
|
215
|
get '/issues/1.xml?include=journals'
|
|
|
|
|
216
|
|
|
230
|
|
|
217
|
assert_select 'issue journals[type=array]' do
|
|
231
|
assert_select 'issue custom_fields[type=array]' do
|
|
218
|
assert_select 'journal[id="1"]' do
|
|
232
|
assert_select 'custom_field[id="1"]' do
|
|
219
|
assert_select 'details[type=array]' do
|
|
233
|
assert_select 'value', :text => 'MySQL'
|
|
220
|
assert_select 'detail[name=status_id]' do
|
|
|
|
|
221
|
assert_select 'old_value', :text => '1'
|
|
|
|
|
222
|
assert_select 'new_value', :text => '2'
|
|
|
|
|
223
|
end
|
|
|
|
|
224
|
end
|
|
|
|
|
225
|
end
|
|
|
|
|
226
|
end
|
|
|
|
|
227
|
end
|
|
|
|
|
228
|
end
|
|
234
|
end
|
|
229
|
end
|
|
235
|
end
|
|
|
|
|
236
|
assert_nothing_raised do
|
|
|
|
|
237
|
Hash.from_xml(response.body).to_xml
|
|
|
|
|
238
|
end
|
|
|
|
|
239
|
end
|
|
230
|
|
|
240
|
|
|
231
|
context "with custom fields" do
|
|
241
|
test "GET /issues/:id.xml with multi custom fields" do
|
|
232
|
context ".xml" do
|
|
242
|
field = CustomField.find(1)
|
|
233
|
should "display custom fields" do
|
|
243
|
field.update_attribute :multiple, true
|
|
234
|
get '/issues/3.xml'
|
|
244
|
issue = Issue.find(3)
|
|
|
|
|
245
|
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
|
|
|
|
|
246
|
issue.save!
|
|
235
|
|
|
247
|
|
|
236
|
assert_select 'issue custom_fields[type=array]' do
|
|
248
|
get '/issues/3.xml'
|
|
237
|
assert_select 'custom_field[id="1"]' do
|
|
249
|
assert_response :success
|
|
238
|
assert_select 'value', :text => 'MySQL'
|
|
|
|
|
239
|
end
|
|
|
|
|
240
|
end
|
|
|
|
|
241
|
|
|
250
|
|
|
242
|
assert_nothing_raised do
|
|
251
|
assert_select 'issue custom_fields[type=array]' do
|
|
243
|
Hash.from_xml(response.body).to_xml
|
|
252
|
assert_select 'custom_field[id="1"]' do
|
|
244
|
end
|
|
253
|
assert_select 'value[type=array] value', 2
|
|
245
|
end
|
|
|
|
|
246
|
end
|
|
254
|
end
|
|
247
|
end
|
|
255
|
end
|
|
|
|
|
256
|
xml = Hash.from_xml(response.body)
|
|
|
|
|
257
|
custom_fields = xml['issue']['custom_fields']
|
|
|
|
|
258
|
assert_kind_of Array, custom_fields
|
|
|
|
|
259
|
field = custom_fields.detect {|f| f['id'] == '1'}
|
|
|
|
|
260
|
assert_kind_of Hash, field
|
|
|
|
|
261
|
assert_equal ['MySQL', 'Oracle'], field['value'].sort
|
|
|
|
|
262
|
end
|
|
248
|
|
|
263
|
|
|
249
|
context "with multi custom fields" do
|
|
264
|
test "GET /issues/:id.json with multi custom fields" do
|
|
250
|
setup do
|
|
265
|
field = CustomField.find(1)
|
|
251
|
field = CustomField.find(1)
|
|
266
|
field.update_attribute :multiple, true
|
|
252
|
field.update_attribute :multiple, true
|
|
267
|
issue = Issue.find(3)
|
|
253
|
issue = Issue.find(3)
|
|
268
|
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
|
|
254
|
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
|
|
269
|
issue.save!
|
|
255
|
issue.save!
|
|
|
|
|
256
|
end
|
|
|
|
|
257
|
|
|
270
|
|
|
258
|
context ".xml" do
|
|
271
|
get '/issues/3.json'
|
|
259
|
should "display custom fields" do
|
|
272
|
assert_response :success
|
|
260
|
get '/issues/3.xml'
|
|
|
|
|
261
|
assert_response :success
|
|
|
|
|
262
|
|
|
273
|
|
|
263
|
assert_select 'issue custom_fields[type=array]' do
|
|
274
|
json = ActiveSupport::JSON.decode(response.body)
|
|
264
|
assert_select 'custom_field[id="1"]' do
|
|
275
|
custom_fields = json['issue']['custom_fields']
|
|
265
|
assert_select 'value[type=array] value', 2
|
|
276
|
assert_kind_of Array, custom_fields
|
|
266
|
end
|
|
277
|
field = custom_fields.detect {|f| f['id'] == 1}
|
|
267
|
end
|
|
278
|
assert_kind_of Hash, field
|
|
|
|
|
279
|
assert_equal ['MySQL', 'Oracle'], field['value'].sort
|
|
|
|
|
280
|
end
|
|
268
|
|
|
281
|
|
|
269
|
xml = Hash.from_xml(response.body)
|
|
282
|
test "GET /issues/:id.xml with empty value for multi custom field" do
|
|
270
|
custom_fields = xml['issue']['custom_fields']
|
|
283
|
field = CustomField.find(1)
|
|
271
|
assert_kind_of Array, custom_fields
|
|
284
|
field.update_attribute :multiple, true
|
|
272
|
field = custom_fields.detect {|f| f['id'] == '1'}
|
|
285
|
issue = Issue.find(3)
|
|
273
|
assert_kind_of Hash, field
|
|
286
|
issue.custom_field_values = {1 => ['']}
|
|
274
|
assert_equal ['MySQL', 'Oracle'], field['value'].sort
|
|
287
|
issue.save!
|
|
275
|
end
|
|
|
|
|
276
|
end
|
|
|
|
|
277
|
|
|
288
|
|
|
278
|
context ".json" do
|
|
289
|
get '/issues/3.xml'
|
|
279
|
should "display custom fields" do
|
|
|
|
|
280
|
get '/issues/3.json'
|
|
|
|
|
281
|
assert_response :success
|
|
|
|
|
282
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
283
|
custom_fields = json['issue']['custom_fields']
|
|
|
|
|
284
|
assert_kind_of Array, custom_fields
|
|
|
|
|
285
|
field = custom_fields.detect {|f| f['id'] == 1}
|
|
|
|
|
286
|
assert_kind_of Hash, field
|
|
|
|
|
287
|
assert_equal ['MySQL', 'Oracle'], field['value'].sort
|
|
|
|
|
288
|
end
|
|
|
|
|
289
|
end
|
|
|
|
|
290
|
end
|
|
|
|
|
291
|
|
|
290
|
|
|
292
|
context "with empty value for multi custom field" do
|
|
291
|
assert_select 'issue custom_fields[type=array]' do
|
|
293
|
setup do
|
|
292
|
assert_select 'custom_field[id="1"]' do
|
|
294
|
field = CustomField.find(1)
|
|
293
|
assert_select 'value[type=array]:empty'
|
|
295
|
field.update_attribute :multiple, true
|
|
|
|
|
296
|
issue = Issue.find(3)
|
|
|
|
|
297
|
issue.custom_field_values = {1 => ['']}
|
|
|
|
|
298
|
issue.save!
|
|
|
|
|
299
|
end
|
|
294
|
end
|
|
|
|
|
295
|
end
|
|
|
|
|
296
|
xml = Hash.from_xml(response.body)
|
|
|
|
|
297
|
custom_fields = xml['issue']['custom_fields']
|
|
|
|
|
298
|
assert_kind_of Array, custom_fields
|
|
|
|
|
299
|
field = custom_fields.detect {|f| f['id'] == '1'}
|
|
|
|
|
300
|
assert_kind_of Hash, field
|
|
|
|
|
301
|
assert_equal [], field['value']
|
|
|
|
|
302
|
end
|
|
300
|
|
|
303
|
|
|
301
|
context ".xml" do
|
|
304
|
test "GET /issues/:id.json with empty value for multi custom field" do
|
|
302
|
should "display custom fields" do
|
|
305
|
field = CustomField.find(1)
|
|
303
|
get '/issues/3.xml'
|
|
306
|
field.update_attribute :multiple, true
|
|
|
|
|
307
|
issue = Issue.find(3)
|
|
|
|
|
308
|
issue.custom_field_values = {1 => ['']}
|
|
|
|
|
309
|
issue.save!
|
|
304
|
|
|
310
|
|
|
305
|
assert_select 'issue custom_fields[type=array]' do
|
|
311
|
get '/issues/3.json'
|
|
306
|
assert_select 'custom_field[id="1"]' do
|
|
312
|
assert_response :success
|
|
307
|
assert_select 'value[type=array]:empty'
|
|
313
|
json = ActiveSupport::JSON.decode(response.body)
|
|
308
|
end
|
|
314
|
custom_fields = json['issue']['custom_fields']
|
|
309
|
end
|
|
315
|
assert_kind_of Array, custom_fields
|
|
|
|
|
316
|
field = custom_fields.detect {|f| f['id'] == 1}
|
|
|
|
|
317
|
assert_kind_of Hash, field
|
|
|
|
|
318
|
assert_equal [], field['value'].sort
|
|
|
|
|
319
|
end
|
|
310
|
|
|
320
|
|
|
311
|
xml = Hash.from_xml(response.body)
|
|
321
|
test "GET /issues/:id.xml with attachments" do
|
|
312
|
custom_fields = xml['issue']['custom_fields']
|
|
322
|
get '/issues/3.xml?include=attachments'
|
|
313
|
assert_kind_of Array, custom_fields
|
|
|
|
|
314
|
field = custom_fields.detect {|f| f['id'] == '1'}
|
|
|
|
|
315
|
assert_kind_of Hash, field
|
|
|
|
|
316
|
assert_equal [], field['value']
|
|
|
|
|
317
|
end
|
|
|
|
|
318
|
end
|
|
|
|
|
319
|
|
|
323
|
|
|
320
|
context ".json" do
|
|
324
|
assert_select 'issue attachments[type=array]' do
|
|
321
|
should "display custom fields" do
|
|
325
|
assert_select 'attachment', 5
|
|
322
|
get '/issues/3.json'
|
|
326
|
assert_select 'attachment id:content(4)' do
|
|
323
|
assert_response :success
|
|
327
|
assert_select '~ filename', :text => 'source.rb'
|
|
324
|
json = ActiveSupport::JSON.decode(response.body)
|
|
328
|
assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb'
|
|
325
|
custom_fields = json['issue']['custom_fields']
|
|
|
|
|
326
|
assert_kind_of Array, custom_fields
|
|
|
|
|
327
|
field = custom_fields.detect {|f| f['id'] == 1}
|
|
|
|
|
328
|
assert_kind_of Hash, field
|
|
|
|
|
329
|
assert_equal [], field['value'].sort
|
|
|
|
|
330
|
end
|
|
|
|
|
331
|
end
|
|
329
|
end
|
|
332
|
end
|
|
330
|
end
|
|
|
|
|
331
|
end
|
|
333
|
|
|
332
|
|
|
334
|
context "with attachments" do
|
|
333
|
test "GET /issues/:id.xml with subtasks" do
|
|
335
|
context ".xml" do
|
|
334
|
issue = Issue.generate_with_descendants!(:project_id => 1)
|
|
336
|
should "display attachments" do
|
|
335
|
get "/issues/#{issue.id}.xml?include=children"
|
|
337
|
get '/issues/3.xml?include=attachments'
|
|
|
|
|
338
|
|
|
|
|
|
339
|
assert_select 'issue attachments[type=array]' do
|
|
|
|
|
340
|
assert_select 'attachment', 5
|
|
|
|
|
341
|
assert_select 'attachment id:content(4)' do
|
|
|
|
|
342
|
assert_select '~ filename', :text => 'source.rb'
|
|
|
|
|
343
|
assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb'
|
|
|
|
|
344
|
end
|
|
|
|
|
345
|
end
|
|
|
|
|
346
|
end
|
|
|
|
|
347
|
end
|
|
|
|
|
348
|
end
|
|
|
|
|
349
|
|
|
336
|
|
|
350
|
context "with subtasks" do
|
|
337
|
assert_select 'issue children[type=array]' do
|
|
351
|
setup do
|
|
338
|
assert_select 'issue', 2
|
|
352
|
@c1 = Issue.create!(
|
|
339
|
assert_select 'issue children', 1
|
|
353
|
:status_id => 1, :subject => "child c1",
|
|
340
|
end
|
|
354
|
:tracker_id => 1, :project_id => 1, :author_id => 1,
|
|
341
|
end
|
|
355
|
:parent_issue_id => 1
|
|
|
|
|
356
|
)
|
|
|
|
|
357
|
@c2 = Issue.create!(
|
|
|
|
|
358
|
:status_id => 1, :subject => "child c2",
|
|
|
|
|
359
|
:tracker_id => 1, :project_id => 1, :author_id => 1,
|
|
|
|
|
360
|
:parent_issue_id => 1
|
|
|
|
|
361
|
)
|
|
|
|
|
362
|
@c3 = Issue.create!(
|
|
|
|
|
363
|
:status_id => 1, :subject => "child c3",
|
|
|
|
|
364
|
:tracker_id => 1, :project_id => 1, :author_id => 1,
|
|
|
|
|
365
|
:parent_issue_id => @c1.id
|
|
|
|
|
366
|
)
|
|
|
|
|
367
|
end
|
|
|
|
|
368
|
|
|
342
|
|
|
369
|
context ".xml" do
|
|
343
|
test "GET /issues/:id.json with subtasks" do
|
|
370
|
should "display children" do
|
|
344
|
issue = Issue.generate_with_descendants!(:project_id => 1)
|
|
371
|
get '/issues/1.xml?include=children'
|
|
345
|
get "/issues/#{issue.id}.json?include=children"
|
|
372
|
|
|
|
|
|
373
|
assert_select 'issue children[type=array]' do
|
|
|
|
|
374
|
assert_select 'issue', 2
|
|
|
|
|
375
|
assert_select 'issue[id=?]', @c1.id.to_s do
|
|
|
|
|
376
|
assert_select 'subject', :text => 'child c1'
|
|
|
|
|
377
|
assert_select 'children' do
|
|
|
|
|
378
|
assert_select 'issue[id=?]', @c3.id.to_s
|
|
|
|
|
379
|
end
|
|
|
|
|
380
|
end
|
|
|
|
|
381
|
end
|
|
|
|
|
382
|
end
|
|
|
|
|
383
|
|
|
346
|
|
|
384
|
context ".json" do
|
|
347
|
json = ActiveSupport::JSON.decode(response.body)
|
|
385
|
should "display children" do
|
|
348
|
assert_equal 2, json['issue']['children'].size
|
|
386
|
get '/issues/1.json?include=children'
|
|
349
|
assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
|
|
387
|
|
|
|
|
|
388
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
389
|
assert_equal([
|
|
|
|
|
390
|
{
|
|
|
|
|
391
|
'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'},
|
|
|
|
|
392
|
'children' => [{'id' => @c3.id, 'subject' => 'child c3',
|
|
|
|
|
393
|
'tracker' => {'id' => 1, 'name' => 'Bug'} }]
|
|
|
|
|
394
|
},
|
|
|
|
|
395
|
{ 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} }
|
|
|
|
|
396
|
],
|
|
|
|
|
397
|
json['issue']['children'])
|
|
|
|
|
398
|
end
|
|
|
|
|
399
|
end
|
|
|
|
|
400
|
end
|
|
|
|
|
401
|
end
|
|
|
|
|
402
|
end
|
|
350
|
end
|
|
403
|
|
|
351
|
|
|
404
|
def test_show_should_include_issue_attributes
|
|
352
|
def test_show_should_include_issue_attributes
|
|
@@
-421,29
+369,21
class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
|
421
|
end
|
|
369
|
end
|
|
422
|
end
|
|
370
|
end
|
|
423
|
|
|
371
|
|
|
424
|
context "POST /issues.xml" do
|
|
372
|
test "POST /issues.xml should create an issue with the attributes" do
|
|
425
|
should_allow_api_authentication(
|
|
373
|
assert_difference('Issue.count') do
|
|
426
|
:post,
|
|
374
|
post '/issues.xml',
|
|
427
|
'/issues.xml',
|
|
375
|
{:issue => {:project_id => 1, :subject => 'API test',
|
|
428
|
{:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}},
|
|
376
|
:tracker_id => 2, :status_id => 3}}, credentials('jsmith')
|
|
429
|
{:success_code => :created}
|
|
|
|
|
430
|
)
|
|
|
|
|
431
|
should "create an issue with the attributes" do
|
|
|
|
|
432
|
assert_difference('Issue.count') do
|
|
|
|
|
433
|
post '/issues.xml',
|
|
|
|
|
434
|
{:issue => {:project_id => 1, :subject => 'API test',
|
|
|
|
|
435
|
:tracker_id => 2, :status_id => 3}}, credentials('jsmith')
|
|
|
|
|
436
|
end
|
|
|
|
|
437
|
issue = Issue.order('id DESC').first
|
|
|
|
|
438
|
assert_equal 1, issue.project_id
|
|
|
|
|
439
|
assert_equal 2, issue.tracker_id
|
|
|
|
|
440
|
assert_equal 3, issue.status_id
|
|
|
|
|
441
|
assert_equal 'API test', issue.subject
|
|
|
|
|
442
|
|
|
|
|
|
443
|
assert_response :created
|
|
|
|
|
444
|
assert_equal 'application/xml', @response.content_type
|
|
|
|
|
445
|
assert_select 'issue > id', :text => issue.id.to_s
|
|
|
|
|
446
|
end
|
|
377
|
end
|
|
|
|
|
378
|
issue = Issue.order('id DESC').first
|
|
|
|
|
379
|
assert_equal 1, issue.project_id
|
|
|
|
|
380
|
assert_equal 2, issue.tracker_id
|
|
|
|
|
381
|
assert_equal 3, issue.status_id
|
|
|
|
|
382
|
assert_equal 'API test', issue.subject
|
|
|
|
|
383
|
|
|
|
|
|
384
|
assert_response :created
|
|
|
|
|
385
|
assert_equal 'application/xml', @response.content_type
|
|
|
|
|
386
|
assert_select 'issue > id', :text => issue.id.to_s
|
|
447
|
end
|
|
387
|
end
|
|
448
|
|
|
388
|
|
|
449
|
test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
|
|
389
|
test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
|
|
@@
-458,246
+398,139
class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
|
|
458
|
assert_equal [1, 3], issue.watcher_user_ids.sort
|
|
398
|
assert_equal [1, 3], issue.watcher_user_ids.sort
|
|
459
|
end
|
|
399
|
end
|
|
460
|
|
|
400
|
|
|
461
|
context "POST /issues.xml with failure" do
|
|
401
|
test "POST /issues.xml with failure should return errors" do
|
|
462
|
should "have an errors tag" do
|
|
402
|
assert_no_difference('Issue.count') do
|
|
463
|
assert_no_difference('Issue.count') do
|
|
403
|
post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
|
|
464
|
post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
|
|
|
|
|
465
|
end
|
|
|
|
|
466
|
|
|
|
|
|
467
|
assert_select 'errors error', :text => "Subject can't be blank"
|
|
|
|
|
468
|
end
|
|
|
|
|
469
|
end
|
|
|
|
|
470
|
|
|
|
|
|
471
|
context "POST /issues.json" do
|
|
|
|
|
472
|
should_allow_api_authentication(:post,
|
|
|
|
|
473
|
'/issues.json',
|
|
|
|
|
474
|
{:issue => {:project_id => 1, :subject => 'API test',
|
|
|
|
|
475
|
:tracker_id => 2, :status_id => 3}},
|
|
|
|
|
476
|
{:success_code => :created})
|
|
|
|
|
477
|
|
|
|
|
|
478
|
should "create an issue with the attributes" do
|
|
|
|
|
479
|
assert_difference('Issue.count') do
|
|
|
|
|
480
|
post '/issues.json',
|
|
|
|
|
481
|
{:issue => {:project_id => 1, :subject => 'API test',
|
|
|
|
|
482
|
:tracker_id => 2, :status_id => 3}},
|
|
|
|
|
483
|
credentials('jsmith')
|
|
|
|
|
484
|
end
|
|
|
|
|
485
|
|
|
|
|
|
486
|
issue = Issue.order('id DESC').first
|
|
|
|
|
487
|
assert_equal 1, issue.project_id
|
|
|
|
|
488
|
assert_equal 2, issue.tracker_id
|
|
|
|
|
489
|
assert_equal 3, issue.status_id
|
|
|
|
|
490
|
assert_equal 'API test', issue.subject
|
|
|
|
|
491
|
end
|
|
404
|
end
|
|
492
|
|
|
405
|
|
|
|
|
|
406
|
assert_select 'errors error', :text => "Subject can't be blank"
|
|
493
|
end
|
|
407
|
end
|
|
494
|
|
|
408
|
|
|
495
|
context "POST /issues.json with failure" do
|
|
409
|
test "POST /issues.json should create an issue with the attributes" do
|
|
496
|
should "have an errors element" do
|
|
410
|
assert_difference('Issue.count') do
|
|
497
|
assert_no_difference('Issue.count') do
|
|
411
|
post '/issues.json',
|
|
498
|
post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
|
|
412
|
{:issue => {:project_id => 1, :subject => 'API test',
|
|
499
|
end
|
|
413
|
:tracker_id => 2, :status_id => 3}},
|
|
500
|
|
|
414
|
credentials('jsmith')
|
|
501
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
502
|
assert json['errors'].include?("Subject can't be blank")
|
|
|
|
|
503
|
end
|
|
|
|
|
504
|
end
|
|
|
|
|
505
|
|
|
|
|
|
506
|
# Issue 6 is on a private project
|
|
|
|
|
507
|
context "PUT /issues/6.xml" do
|
|
|
|
|
508
|
setup do
|
|
|
|
|
509
|
@parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
|
|
|
|
|
510
|
end
|
|
|
|
|
511
|
|
|
|
|
|
512
|
should_allow_api_authentication(:put,
|
|
|
|
|
513
|
'/issues/6.xml',
|
|
|
|
|
514
|
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
|
|
|
|
515
|
{:success_code => :ok})
|
|
|
|
|
516
|
|
|
|
|
|
517
|
should "not create a new issue" do
|
|
|
|
|
518
|
assert_no_difference('Issue.count') do
|
|
|
|
|
519
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
|
|
|
520
|
end
|
|
|
|
|
521
|
end
|
|
|
|
|
522
|
|
|
|
|
|
523
|
should "create a new journal" do
|
|
|
|
|
524
|
assert_difference('Journal.count') do
|
|
|
|
|
525
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
|
|
|
526
|
end
|
|
|
|
|
527
|
end
|
|
|
|
|
528
|
|
|
|
|
|
529
|
should "add the note to the journal" do
|
|
|
|
|
530
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
|
|
|
531
|
|
|
|
|
|
532
|
journal = Journal.last
|
|
|
|
|
533
|
assert_equal "A new note", journal.notes
|
|
|
|
|
534
|
end
|
|
|
|
|
535
|
|
|
|
|
|
536
|
should "update the issue" do
|
|
|
|
|
537
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
|
|
|
538
|
|
|
|
|
|
539
|
issue = Issue.find(6)
|
|
|
|
|
540
|
assert_equal "API update", issue.subject
|
|
|
|
|
541
|
end
|
|
415
|
end
|
|
542
|
|
|
416
|
|
|
|
|
|
417
|
issue = Issue.order('id DESC').first
|
|
|
|
|
418
|
assert_equal 1, issue.project_id
|
|
|
|
|
419
|
assert_equal 2, issue.tracker_id
|
|
|
|
|
420
|
assert_equal 3, issue.status_id
|
|
|
|
|
421
|
assert_equal 'API test', issue.subject
|
|
543
|
end
|
|
422
|
end
|
|
544
|
|
|
423
|
|
|
545
|
context "PUT /issues/3.xml with custom fields" do
|
|
424
|
test "POST /issues.json with failure should return errors" do
|
|
546
|
setup do
|
|
425
|
assert_no_difference('Issue.count') do
|
|
547
|
@parameters = {
|
|
426
|
post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
|
|
548
|
:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' },
|
|
|
|
|
549
|
{'id' => '2', 'value' => '150'}]}
|
|
|
|
|
550
|
}
|
|
|
|
|
551
|
end
|
|
427
|
end
|
|
552
|
|
|
428
|
|
|
553
|
should "update custom fields" do
|
|
429
|
json = ActiveSupport::JSON.decode(response.body)
|
|
554
|
assert_no_difference('Issue.count') do
|
|
430
|
assert json['errors'].include?("Subject can't be blank")
|
|
555
|
put '/issues/3.xml', @parameters, credentials('jsmith')
|
|
|
|
|
556
|
end
|
|
|
|
|
557
|
|
|
|
|
|
558
|
issue = Issue.find(3)
|
|
|
|
|
559
|
assert_equal '150', issue.custom_value_for(2).value
|
|
|
|
|
560
|
assert_equal 'PostgreSQL', issue.custom_value_for(1).value
|
|
|
|
|
561
|
end
|
|
|
|
|
562
|
end
|
|
431
|
end
|
|
563
|
|
|
432
|
|
|
564
|
context "PUT /issues/3.xml with multi custom fields" do
|
|
433
|
test "PUT /issues/:id.xml" do
|
|
565
|
setup do
|
|
434
|
assert_difference('Journal.count') do
|
|
566
|
field = CustomField.find(1)
|
|
435
|
put '/issues/6.xml',
|
|
567
|
field.update_attribute :multiple, true
|
|
436
|
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
|
568
|
@parameters = {
|
|
437
|
credentials('jsmith')
|
|
569
|
:issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
|
|
|
|
|
570
|
{'id' => '2', 'value' => '150'}]}
|
|
|
|
|
571
|
}
|
|
|
|
|
572
|
end
|
|
438
|
end
|
|
573
|
|
|
439
|
|
|
574
|
should "update custom fields" do
|
|
440
|
issue = Issue.find(6)
|
|
575
|
assert_no_difference('Issue.count') do
|
|
441
|
assert_equal "API update", issue.subject
|
|
576
|
put '/issues/3.xml', @parameters, credentials('jsmith')
|
|
442
|
journal = Journal.last
|
|
577
|
end
|
|
443
|
assert_equal "A new note", journal.notes
|
|
578
|
|
|
|
|
|
579
|
issue = Issue.find(3)
|
|
|
|
|
580
|
assert_equal '150', issue.custom_value_for(2).value
|
|
|
|
|
581
|
assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
|
|
|
|
|
582
|
end
|
|
|
|
|
583
|
end
|
|
444
|
end
|
|
584
|
|
|
445
|
|
|
585
|
context "PUT /issues/3.xml with project change" do
|
|
446
|
test "PUT /issues/:id.xml with custom fields" do
|
|
586
|
setup do
|
|
447
|
put '/issues/3.xml',
|
|
587
|
@parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}}
|
|
448
|
{:issue => {:custom_fields => [
|
|
588
|
end
|
|
449
|
{'id' => '1', 'value' => 'PostgreSQL' },
|
|
589
|
|
|
450
|
{'id' => '2', 'value' => '150'}
|
|
590
|
should "update project" do
|
|
451
|
]}},
|
|
591
|
assert_no_difference('Issue.count') do
|
|
452
|
credentials('jsmith')
|
|
592
|
put '/issues/3.xml', @parameters, credentials('jsmith')
|
|
453
|
|
|
593
|
end
|
|
454
|
issue = Issue.find(3)
|
|
594
|
|
|
455
|
assert_equal '150', issue.custom_value_for(2).value
|
|
595
|
issue = Issue.find(3)
|
|
456
|
assert_equal 'PostgreSQL', issue.custom_value_for(1).value
|
|
596
|
assert_equal 2, issue.project_id
|
|
|
|
|
597
|
assert_equal 'Project changed', issue.subject
|
|
|
|
|
598
|
end
|
|
|
|
|
599
|
end
|
|
457
|
end
|
|
600
|
|
|
458
|
|
|
601
|
context "PUT /issues/6.xml with failed update" do
|
|
459
|
test "PUT /issues/:id.xml with multi custom fields" do
|
|
602
|
setup do
|
|
460
|
field = CustomField.find(1)
|
|
603
|
@parameters = {:issue => {:subject => ''}}
|
|
461
|
field.update_attribute :multiple, true
|
|
604
|
end
|
|
|
|
|
605
|
|
|
|
|
|
606
|
should "not create a new issue" do
|
|
|
|
|
607
|
assert_no_difference('Issue.count') do
|
|
|
|
|
608
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
|
|
|
609
|
end
|
|
|
|
|
610
|
end
|
|
|
|
|
611
|
|
|
|
|
|
612
|
should "not create a new journal" do
|
|
|
|
|
613
|
assert_no_difference('Journal.count') do
|
|
|
|
|
614
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
|
|
|
615
|
end
|
|
|
|
|
616
|
end
|
|
|
|
|
617
|
|
|
462
|
|
|
618
|
should "have an errors tag" do
|
|
463
|
put '/issues/3.xml',
|
|
619
|
put '/issues/6.xml', @parameters, credentials('jsmith')
|
|
464
|
{:issue => {:custom_fields => [
|
|
|
|
|
465
|
{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
|
|
|
|
|
466
|
{'id' => '2', 'value' => '150'}
|
|
|
|
|
467
|
]}},
|
|
|
|
|
468
|
credentials('jsmith')
|
|
620
|
|
|
469
|
|
|
621
|
assert_select 'errors error', :text => "Subject can't be blank"
|
|
470
|
issue = Issue.find(3)
|
|
622
|
end
|
|
471
|
assert_equal '150', issue.custom_value_for(2).value
|
|
|
|
|
472
|
assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
|
|
623
|
end
|
|
473
|
end
|
|
624
|
|
|
474
|
|
|
625
|
context "PUT /issues/6.json" do
|
|
475
|
test "PUT /issues/:id.xml with project change" do
|
|
626
|
setup do
|
|
476
|
put '/issues/3.xml',
|
|
627
|
@parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}}
|
|
477
|
{:issue => {:project_id => 2, :subject => 'Project changed'}},
|
|
628
|
end
|
|
478
|
credentials('jsmith')
|
|
629
|
|
|
|
|
|
630
|
should_allow_api_authentication(:put,
|
|
|
|
|
631
|
'/issues/6.json',
|
|
|
|
|
632
|
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
|
|
|
|
633
|
{:success_code => :ok})
|
|
|
|
|
634
|
|
|
479
|
|
|
635
|
should "update the issue" do
|
|
480
|
issue = Issue.find(3)
|
|
636
|
assert_no_difference('Issue.count') do
|
|
481
|
assert_equal 2, issue.project_id
|
|
637
|
assert_difference('Journal.count') do
|
|
482
|
assert_equal 'Project changed', issue.subject
|
|
638
|
put '/issues/6.json', @parameters, credentials('jsmith')
|
|
483
|
end
|
|
639
|
|
|
484
|
|
|
640
|
assert_response :ok
|
|
485
|
test "PUT /issues/:id.xml with failed update" do
|
|
641
|
assert_equal '', response.body
|
|
486
|
put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')
|
|
642
|
end
|
|
|
|
|
643
|
end
|
|
|
|
|
644
|
|
|
487
|
|
|
645
|
issue = Issue.find(6)
|
|
488
|
assert_response :unprocessable_entity
|
|
646
|
assert_equal "API update", issue.subject
|
|
489
|
assert_select 'errors error', :text => "Subject can't be blank"
|
|
647
|
journal = Journal.last
|
|
|
|
|
648
|
assert_equal "A new note", journal.notes
|
|
|
|
|
649
|
end
|
|
|
|
|
650
|
end
|
|
490
|
end
|
|
651
|
|
|
491
|
|
|
652
|
context "PUT /issues/6.json with failed update" do
|
|
492
|
test "PUT /issues/:id.json" do
|
|
653
|
should "return errors" do
|
|
493
|
assert_difference('Journal.count') do
|
|
654
|
assert_no_difference('Issue.count') do
|
|
494
|
put '/issues/6.json',
|
|
655
|
assert_no_difference('Journal.count') do
|
|
495
|
{:issue => {:subject => 'API update', :notes => 'A new note'}},
|
|
656
|
put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
|
|
496
|
credentials('jsmith')
|
|
657
|
|
|
|
|
|
658
|
assert_response :unprocessable_entity
|
|
|
|
|
659
|
end
|
|
|
|
|
660
|
end
|
|
|
|
|
661
|
|
|
497
|
|
|
662
|
json = ActiveSupport::JSON.decode(response.body)
|
|
498
|
assert_response :ok
|
|
663
|
assert json['errors'].include?("Subject can't be blank")
|
|
499
|
assert_equal '', response.body
|
|
664
|
end
|
|
500
|
end
|
|
|
|
|
501
|
|
|
|
|
|
502
|
issue = Issue.find(6)
|
|
|
|
|
503
|
assert_equal "API update", issue.subject
|
|
|
|
|
504
|
journal = Journal.last
|
|
|
|
|
505
|
assert_equal "A new note", journal.notes
|
|
665
|
end
|
|
506
|
end
|
|
666
|
|
|
507
|
|
|
667
|
context "DELETE /issues/1.xml" do
|
|
508
|
test "PUT /issues/:id.json with failed update" do
|
|
668
|
should_allow_api_authentication(:delete,
|
|
509
|
put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
|
|
669
|
'/issues/6.xml',
|
|
|
|
|
670
|
{},
|
|
|
|
|
671
|
{:success_code => :ok})
|
|
|
|
|
672
|
|
|
510
|
|
|
673
|
should "delete the issue" do
|
|
511
|
assert_response :unprocessable_entity
|
|
674
|
assert_difference('Issue.count', -1) do
|
|
512
|
json = ActiveSupport::JSON.decode(response.body)
|
|
675
|
delete '/issues/6.xml', {}, credentials('jsmith')
|
|
513
|
assert json['errors'].include?("Subject can't be blank")
|
|
|
|
|
514
|
end
|
|
676
|
|
|
515
|
|
|
677
|
assert_response :ok
|
|
516
|
test "DELETE /issues/:id.xml" do
|
|
678
|
assert_equal '', response.body
|
|
517
|
assert_difference('Issue.count', -1) do
|
|
679
|
end
|
|
518
|
delete '/issues/6.xml', {}, credentials('jsmith')
|
|
680
|
|
|
519
|
|
|
681
|
assert_nil Issue.find_by_id(6)
|
|
520
|
assert_response :ok
|
|
|
|
|
521
|
assert_equal '', response.body
|
|
682
|
end
|
|
522
|
end
|
|
|
|
|
523
|
assert_nil Issue.find_by_id(6)
|
|
683
|
end
|
|
524
|
end
|
|
684
|
|
|
525
|
|
|
685
|
context "DELETE /issues/1.json" do
|
|
526
|
test "DELETE /issues/:id.json" do
|
|
686
|
should_allow_api_authentication(:delete,
|
|
527
|
assert_difference('Issue.count', -1) do
|
|
687
|
'/issues/6.json',
|
|
528
|
delete '/issues/6.json', {}, credentials('jsmith')
|
|
688
|
{},
|
|
|
|
|
689
|
{:success_code => :ok})
|
|
|
|
|
690
|
|
|
|
|
|
691
|
should "delete the issue" do
|
|
|
|
|
692
|
assert_difference('Issue.count', -1) do
|
|
|
|
|
693
|
delete '/issues/6.json', {}, credentials('jsmith')
|
|
|
|
|
694
|
|
|
529
|
|
|
695
|
assert_response :ok
|
|
530
|
assert_response :ok
|
|
696
|
assert_equal '', response.body
|
|
531
|
assert_equal '', response.body
|
|
697
|
end
|
|
|
|
|
698
|
|
|
|
|
|
699
|
assert_nil Issue.find_by_id(6)
|
|
|
|
|
700
|
end
|
|
532
|
end
|
|
|
|
|
533
|
assert_nil Issue.find_by_id(6)
|
|
701
|
end
|
|
534
|
end
|
|
702
|
|
|
535
|
|
|
703
|
test "POST /issues/:id/watchers.xml should add watcher" do
|
|
536
|
test "POST /issues/:id/watchers.xml should add watcher" do
|