@@ -1,704 +1,782 | |||||
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).sort |
|
435 | assert_equal ["V1", "V3"], issue.custom_field_value(field).sort | |
436 | end |
|
436 | end | |
437 |
|
437 | |||
|
438 | test "POST /issues.json with omitted custom field should set default value" do | |||
|
439 | field = IssueCustomField.generate!(:default_value => "Default") | |||
|
440 | ||||
|
441 | issue = new_record(Issue) do | |||
|
442 | post '/issues.json', | |||
|
443 | {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}}, | |||
|
444 | credentials('jsmith') | |||
|
445 | end | |||
|
446 | assert_equal "Default", issue.custom_field_value(field) | |||
|
447 | end | |||
|
448 | ||||
|
449 | test "POST /issues.json with custom field set to blank should not set default value" do | |||
|
450 | field = IssueCustomField.generate!(:default_value => "Default") | |||
|
451 | ||||
|
452 | issue = new_record(Issue) do | |||
|
453 | post '/issues.json', | |||
|
454 | {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}}, | |||
|
455 | credentials('jsmith') | |||
|
456 | end | |||
|
457 | assert_equal "", issue.custom_field_value(field) | |||
|
458 | end | |||
|
459 | ||||
438 | test "POST /issues.json with failure should return errors" do |
|
460 | test "POST /issues.json with failure should return errors" do | |
439 | assert_no_difference('Issue.count') do |
|
461 | assert_no_difference('Issue.count') do | |
440 | post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') |
|
462 | post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') | |
441 | end |
|
463 | end | |
442 |
|
464 | |||
443 | json = ActiveSupport::JSON.decode(response.body) |
|
465 | json = ActiveSupport::JSON.decode(response.body) | |
444 | assert json['errors'].include?("Subject cannot be blank") |
|
466 | assert json['errors'].include?("Subject cannot be blank") | |
445 | end |
|
467 | end | |
446 |
|
468 | |||
447 | test "POST /issues.json with invalid project_id should respond with 422" do |
|
469 | test "POST /issues.json with invalid project_id should respond with 422" do | |
448 | post '/issues.json', {:issue => {:project_id => 999, :subject => "API"}}, credentials('jsmith') |
|
470 | post '/issues.json', {:issue => {:project_id => 999, :subject => "API"}}, credentials('jsmith') | |
449 | assert_response 422 |
|
471 | assert_response 422 | |
450 | end |
|
472 | end | |
451 |
|
473 | |||
452 | test "PUT /issues/:id.xml" do |
|
474 | test "PUT /issues/:id.xml" do | |
453 | assert_difference('Journal.count') do |
|
475 | assert_difference('Journal.count') do | |
454 | put '/issues/6.xml', |
|
476 | put '/issues/6.xml', | |
455 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
477 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
456 | credentials('jsmith') |
|
478 | credentials('jsmith') | |
457 | end |
|
479 | end | |
458 |
|
480 | |||
459 | issue = Issue.find(6) |
|
481 | issue = Issue.find(6) | |
460 | assert_equal "API update", issue.subject |
|
482 | assert_equal "API update", issue.subject | |
461 | journal = Journal.last |
|
483 | journal = Journal.last | |
462 | assert_equal "A new note", journal.notes |
|
484 | assert_equal "A new note", journal.notes | |
463 | end |
|
485 | end | |
464 |
|
486 | |||
465 | test "PUT /issues/:id.xml with custom fields" do |
|
487 | test "PUT /issues/:id.xml with custom fields" do | |
466 | put '/issues/3.xml', |
|
488 | put '/issues/3.xml', | |
467 | {:issue => {:custom_fields => [ |
|
489 | {:issue => {:custom_fields => [ | |
468 | {'id' => '1', 'value' => 'PostgreSQL' }, |
|
490 | {'id' => '1', 'value' => 'PostgreSQL' }, | |
469 | {'id' => '2', 'value' => '150'} |
|
491 | {'id' => '2', 'value' => '150'} | |
470 | ]}}, |
|
492 | ]}}, | |
471 | credentials('jsmith') |
|
493 | credentials('jsmith') | |
472 |
|
494 | |||
473 | issue = Issue.find(3) |
|
495 | issue = Issue.find(3) | |
474 | assert_equal '150', issue.custom_value_for(2).value |
|
496 | assert_equal '150', issue.custom_value_for(2).value | |
475 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value |
|
497 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value | |
476 | end |
|
498 | end | |
477 |
|
499 | |||
478 | test "PUT /issues/:id.xml with multi custom fields" do |
|
500 | test "PUT /issues/:id.xml with multi custom fields" do | |
479 | field = CustomField.find(1) |
|
501 | field = CustomField.find(1) | |
480 | field.update_attribute :multiple, true |
|
502 | field.update_attribute :multiple, true | |
481 |
|
503 | |||
482 | put '/issues/3.xml', |
|
504 | put '/issues/3.xml', | |
483 | {:issue => {:custom_fields => [ |
|
505 | {:issue => {:custom_fields => [ | |
484 | {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, |
|
506 | {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, | |
485 | {'id' => '2', 'value' => '150'} |
|
507 | {'id' => '2', 'value' => '150'} | |
486 | ]}}, |
|
508 | ]}}, | |
487 | credentials('jsmith') |
|
509 | credentials('jsmith') | |
488 |
|
510 | |||
489 | issue = Issue.find(3) |
|
511 | issue = Issue.find(3) | |
490 | assert_equal '150', issue.custom_value_for(2).value |
|
512 | assert_equal '150', issue.custom_value_for(2).value | |
491 | assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort |
|
513 | assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort | |
492 | end |
|
514 | end | |
493 |
|
515 | |||
494 | test "PUT /issues/:id.xml with project change" do |
|
516 | test "PUT /issues/:id.xml with project change" do | |
495 | put '/issues/3.xml', |
|
517 | put '/issues/3.xml', | |
496 | {:issue => {:project_id => 2, :subject => 'Project changed'}}, |
|
518 | {:issue => {:project_id => 2, :subject => 'Project changed'}}, | |
497 | credentials('jsmith') |
|
519 | credentials('jsmith') | |
498 |
|
520 | |||
499 | issue = Issue.find(3) |
|
521 | issue = Issue.find(3) | |
500 | assert_equal 2, issue.project_id |
|
522 | assert_equal 2, issue.project_id | |
501 | assert_equal 'Project changed', issue.subject |
|
523 | assert_equal 'Project changed', issue.subject | |
502 | end |
|
524 | end | |
503 |
|
525 | |||
504 | test "PUT /issues/:id.xml with notes only" do |
|
526 | test "PUT /issues/:id.xml with notes only" do | |
505 | assert_difference('Journal.count') do |
|
527 | assert_difference('Journal.count') do | |
506 | put '/issues/6.xml', |
|
528 | put '/issues/6.xml', | |
507 | {:issue => {:notes => 'Notes only'}}, |
|
529 | {:issue => {:notes => 'Notes only'}}, | |
508 | credentials('jsmith') |
|
530 | credentials('jsmith') | |
509 | end |
|
531 | end | |
510 |
|
532 | |||
511 | journal = Journal.last |
|
533 | journal = Journal.last | |
512 | assert_equal "Notes only", journal.notes |
|
534 | assert_equal "Notes only", journal.notes | |
513 | end |
|
535 | end | |
514 |
|
536 | |||
|
537 | test "PUT /issues/:id.json with omitted custom field should not change blank value to default value" do | |||
|
538 | field = IssueCustomField.generate!(:default_value => "Default") | |||
|
539 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""}) | |||
|
540 | assert_equal "", issue.reload.custom_field_value(field) | |||
|
541 | ||||
|
542 | assert_difference('Journal.count') do | |||
|
543 | put "/issues/#{issue.id}.json", | |||
|
544 | {:issue => {:custom_field_values => {}, :notes => 'API'}}, | |||
|
545 | credentials('jsmith') | |||
|
546 | end | |||
|
547 | ||||
|
548 | assert_equal "", issue.reload.custom_field_value(field) | |||
|
549 | end | |||
|
550 | ||||
|
551 | test "PUT /issues/:id.json with custom field set to blank should not change blank value to default value" do | |||
|
552 | field = IssueCustomField.generate!(:default_value => "Default") | |||
|
553 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""}) | |||
|
554 | assert_equal "", issue.reload.custom_field_value(field) | |||
|
555 | ||||
|
556 | assert_difference('Journal.count') do | |||
|
557 | put "/issues/#{issue.id}.json", | |||
|
558 | {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, | |||
|
559 | credentials('jsmith') | |||
|
560 | end | |||
|
561 | ||||
|
562 | assert_equal "", issue.reload.custom_field_value(field) | |||
|
563 | end | |||
|
564 | ||||
|
565 | test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker does not set default value" do | |||
|
566 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) | |||
|
567 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) | |||
|
568 | ||||
|
569 | assert_difference('Journal.count') do | |||
|
570 | put "/issues/#{issue.id}.json", | |||
|
571 | {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}}, | |||
|
572 | credentials('jsmith') | |||
|
573 | end | |||
|
574 | ||||
|
575 | assert_equal 2, issue.reload.tracker_id | |||
|
576 | assert_nil issue.reload.custom_field_value(field) | |||
|
577 | end | |||
|
578 | ||||
|
579 | test "PUT /issues/:id.json with tracker change and custom field specific to that tracker set to blank should not set default value" do | |||
|
580 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) | |||
|
581 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) | |||
|
582 | ||||
|
583 | assert_difference('Journal.count') do | |||
|
584 | put "/issues/#{issue.id}.json", | |||
|
585 | {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, | |||
|
586 | credentials('jsmith') | |||
|
587 | end | |||
|
588 | ||||
|
589 | assert_equal 2, issue.reload.tracker_id | |||
|
590 | assert_equal "", issue.reload.custom_field_value(field) | |||
|
591 | end | |||
|
592 | ||||
515 | test "PUT /issues/:id.xml with failed update" do |
|
593 | test "PUT /issues/:id.xml with failed update" do | |
516 | put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') |
|
594 | put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') | |
517 |
|
595 | |||
518 | assert_response :unprocessable_entity |
|
596 | assert_response :unprocessable_entity | |
519 | assert_select 'errors error', :text => "Subject cannot be blank" |
|
597 | assert_select 'errors error', :text => "Subject cannot be blank" | |
520 | end |
|
598 | end | |
521 |
|
599 | |||
522 | test "PUT /issues/:id.json" do |
|
600 | test "PUT /issues/:id.json" do | |
523 | assert_difference('Journal.count') do |
|
601 | assert_difference('Journal.count') do | |
524 | put '/issues/6.json', |
|
602 | put '/issues/6.json', | |
525 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
603 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
526 | credentials('jsmith') |
|
604 | credentials('jsmith') | |
527 |
|
605 | |||
528 | assert_response :ok |
|
606 | assert_response :ok | |
529 | assert_equal '', response.body |
|
607 | assert_equal '', response.body | |
530 | end |
|
608 | end | |
531 |
|
609 | |||
532 | issue = Issue.find(6) |
|
610 | issue = Issue.find(6) | |
533 | assert_equal "API update", issue.subject |
|
611 | assert_equal "API update", issue.subject | |
534 | journal = Journal.last |
|
612 | journal = Journal.last | |
535 | assert_equal "A new note", journal.notes |
|
613 | assert_equal "A new note", journal.notes | |
536 | end |
|
614 | end | |
537 |
|
615 | |||
538 | test "PUT /issues/:id.json with failed update" do |
|
616 | test "PUT /issues/:id.json with failed update" do | |
539 | put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') |
|
617 | put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') | |
540 |
|
618 | |||
541 | assert_response :unprocessable_entity |
|
619 | assert_response :unprocessable_entity | |
542 | json = ActiveSupport::JSON.decode(response.body) |
|
620 | json = ActiveSupport::JSON.decode(response.body) | |
543 | assert json['errors'].include?("Subject cannot be blank") |
|
621 | assert json['errors'].include?("Subject cannot be blank") | |
544 | end |
|
622 | end | |
545 |
|
623 | |||
546 | test "DELETE /issues/:id.xml" do |
|
624 | test "DELETE /issues/:id.xml" do | |
547 | assert_difference('Issue.count', -1) do |
|
625 | assert_difference('Issue.count', -1) do | |
548 | delete '/issues/6.xml', {}, credentials('jsmith') |
|
626 | delete '/issues/6.xml', {}, credentials('jsmith') | |
549 |
|
627 | |||
550 | assert_response :ok |
|
628 | assert_response :ok | |
551 | assert_equal '', response.body |
|
629 | assert_equal '', response.body | |
552 | end |
|
630 | end | |
553 | assert_nil Issue.find_by_id(6) |
|
631 | assert_nil Issue.find_by_id(6) | |
554 | end |
|
632 | end | |
555 |
|
633 | |||
556 | test "DELETE /issues/:id.json" do |
|
634 | test "DELETE /issues/:id.json" do | |
557 | assert_difference('Issue.count', -1) do |
|
635 | assert_difference('Issue.count', -1) do | |
558 | delete '/issues/6.json', {}, credentials('jsmith') |
|
636 | delete '/issues/6.json', {}, credentials('jsmith') | |
559 |
|
637 | |||
560 | assert_response :ok |
|
638 | assert_response :ok | |
561 | assert_equal '', response.body |
|
639 | assert_equal '', response.body | |
562 | end |
|
640 | end | |
563 | assert_nil Issue.find_by_id(6) |
|
641 | assert_nil Issue.find_by_id(6) | |
564 | end |
|
642 | end | |
565 |
|
643 | |||
566 | test "POST /issues/:id/watchers.xml should add watcher" do |
|
644 | test "POST /issues/:id/watchers.xml should add watcher" do | |
567 | assert_difference 'Watcher.count' do |
|
645 | assert_difference 'Watcher.count' do | |
568 | post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith') |
|
646 | post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith') | |
569 |
|
647 | |||
570 | assert_response :ok |
|
648 | assert_response :ok | |
571 | assert_equal '', response.body |
|
649 | assert_equal '', response.body | |
572 | end |
|
650 | end | |
573 | watcher = Watcher.order('id desc').first |
|
651 | watcher = Watcher.order('id desc').first | |
574 | assert_equal Issue.find(1), watcher.watchable |
|
652 | assert_equal Issue.find(1), watcher.watchable | |
575 | assert_equal User.find(3), watcher.user |
|
653 | assert_equal User.find(3), watcher.user | |
576 | end |
|
654 | end | |
577 |
|
655 | |||
578 | test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do |
|
656 | test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do | |
579 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) |
|
657 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) | |
580 |
|
658 | |||
581 | assert_difference 'Watcher.count', -1 do |
|
659 | assert_difference 'Watcher.count', -1 do | |
582 | delete '/issues/1/watchers/3.xml', {}, credentials('jsmith') |
|
660 | delete '/issues/1/watchers/3.xml', {}, credentials('jsmith') | |
583 |
|
661 | |||
584 | assert_response :ok |
|
662 | assert_response :ok | |
585 | assert_equal '', response.body |
|
663 | assert_equal '', response.body | |
586 | end |
|
664 | end | |
587 | assert_equal false, Issue.find(1).watched_by?(User.find(3)) |
|
665 | assert_equal false, Issue.find(1).watched_by?(User.find(3)) | |
588 | end |
|
666 | end | |
589 |
|
667 | |||
590 | def test_create_issue_with_uploaded_file |
|
668 | def test_create_issue_with_uploaded_file | |
591 | token = xml_upload('test_create_with_upload', credentials('jsmith')) |
|
669 | token = xml_upload('test_create_with_upload', credentials('jsmith')) | |
592 | attachment = Attachment.find_by_token(token) |
|
670 | attachment = Attachment.find_by_token(token) | |
593 |
|
671 | |||
594 | # create the issue with the upload's token |
|
672 | # create the issue with the upload's token | |
595 | assert_difference 'Issue.count' do |
|
673 | assert_difference 'Issue.count' do | |
596 | post '/issues.xml', |
|
674 | post '/issues.xml', | |
597 | {:issue => {:project_id => 1, :subject => 'Uploaded file', |
|
675 | {:issue => {:project_id => 1, :subject => 'Uploaded file', | |
598 | :uploads => [{:token => token, :filename => 'test.txt', |
|
676 | :uploads => [{:token => token, :filename => 'test.txt', | |
599 | :content_type => 'text/plain'}]}}, |
|
677 | :content_type => 'text/plain'}]}}, | |
600 | credentials('jsmith') |
|
678 | credentials('jsmith') | |
601 | assert_response :created |
|
679 | assert_response :created | |
602 | end |
|
680 | end | |
603 | issue = Issue.order('id DESC').first |
|
681 | issue = Issue.order('id DESC').first | |
604 | assert_equal 1, issue.attachments.count |
|
682 | assert_equal 1, issue.attachments.count | |
605 | assert_equal attachment, issue.attachments.first |
|
683 | assert_equal attachment, issue.attachments.first | |
606 |
|
684 | |||
607 | attachment.reload |
|
685 | attachment.reload | |
608 | assert_equal 'test.txt', attachment.filename |
|
686 | assert_equal 'test.txt', attachment.filename | |
609 | assert_equal 'text/plain', attachment.content_type |
|
687 | assert_equal 'text/plain', attachment.content_type | |
610 | assert_equal 'test_create_with_upload'.size, attachment.filesize |
|
688 | assert_equal 'test_create_with_upload'.size, attachment.filesize | |
611 | assert_equal 2, attachment.author_id |
|
689 | assert_equal 2, attachment.author_id | |
612 |
|
690 | |||
613 | # get the issue with its attachments |
|
691 | # get the issue with its attachments | |
614 | get "/issues/#{issue.id}.xml", :include => 'attachments' |
|
692 | get "/issues/#{issue.id}.xml", :include => 'attachments' | |
615 | assert_response :success |
|
693 | assert_response :success | |
616 | xml = Hash.from_xml(response.body) |
|
694 | xml = Hash.from_xml(response.body) | |
617 | attachments = xml['issue']['attachments'] |
|
695 | attachments = xml['issue']['attachments'] | |
618 | assert_kind_of Array, attachments |
|
696 | assert_kind_of Array, attachments | |
619 | assert_equal 1, attachments.size |
|
697 | assert_equal 1, attachments.size | |
620 | url = attachments.first['content_url'] |
|
698 | url = attachments.first['content_url'] | |
621 | assert_not_nil url |
|
699 | assert_not_nil url | |
622 |
|
700 | |||
623 | # download the attachment |
|
701 | # download the attachment | |
624 | get url |
|
702 | get url | |
625 | assert_response :success |
|
703 | assert_response :success | |
626 | assert_equal 'test_create_with_upload', response.body |
|
704 | assert_equal 'test_create_with_upload', response.body | |
627 | end |
|
705 | end | |
628 |
|
706 | |||
629 | def test_create_issue_with_multiple_uploaded_files_as_xml |
|
707 | def test_create_issue_with_multiple_uploaded_files_as_xml | |
630 | token1 = xml_upload('File content 1', credentials('jsmith')) |
|
708 | token1 = xml_upload('File content 1', credentials('jsmith')) | |
631 | token2 = xml_upload('File content 2', credentials('jsmith')) |
|
709 | token2 = xml_upload('File content 2', credentials('jsmith')) | |
632 |
|
710 | |||
633 | payload = <<-XML |
|
711 | payload = <<-XML | |
634 | <?xml version="1.0" encoding="UTF-8" ?> |
|
712 | <?xml version="1.0" encoding="UTF-8" ?> | |
635 | <issue> |
|
713 | <issue> | |
636 | <project_id>1</project_id> |
|
714 | <project_id>1</project_id> | |
637 | <tracker_id>1</tracker_id> |
|
715 | <tracker_id>1</tracker_id> | |
638 | <subject>Issue with multiple attachments</subject> |
|
716 | <subject>Issue with multiple attachments</subject> | |
639 | <uploads type="array"> |
|
717 | <uploads type="array"> | |
640 | <upload> |
|
718 | <upload> | |
641 | <token>#{token1}</token> |
|
719 | <token>#{token1}</token> | |
642 | <filename>test1.txt</filename> |
|
720 | <filename>test1.txt</filename> | |
643 | </upload> |
|
721 | </upload> | |
644 | <upload> |
|
722 | <upload> | |
645 | <token>#{token2}</token> |
|
723 | <token>#{token2}</token> | |
646 | <filename>test1.txt</filename> |
|
724 | <filename>test1.txt</filename> | |
647 | </upload> |
|
725 | </upload> | |
648 | </uploads> |
|
726 | </uploads> | |
649 | </issue> |
|
727 | </issue> | |
650 | XML |
|
728 | XML | |
651 |
|
729 | |||
652 | assert_difference 'Issue.count' do |
|
730 | assert_difference 'Issue.count' do | |
653 | post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) |
|
731 | post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) | |
654 | assert_response :created |
|
732 | assert_response :created | |
655 | end |
|
733 | end | |
656 | issue = Issue.order('id DESC').first |
|
734 | issue = Issue.order('id DESC').first | |
657 | assert_equal 2, issue.attachments.count |
|
735 | assert_equal 2, issue.attachments.count | |
658 | end |
|
736 | end | |
659 |
|
737 | |||
660 | def test_create_issue_with_multiple_uploaded_files_as_json |
|
738 | def test_create_issue_with_multiple_uploaded_files_as_json | |
661 | token1 = json_upload('File content 1', credentials('jsmith')) |
|
739 | token1 = json_upload('File content 1', credentials('jsmith')) | |
662 | token2 = json_upload('File content 2', credentials('jsmith')) |
|
740 | token2 = json_upload('File content 2', credentials('jsmith')) | |
663 |
|
741 | |||
664 | payload = <<-JSON |
|
742 | payload = <<-JSON | |
665 | { |
|
743 | { | |
666 | "issue": { |
|
744 | "issue": { | |
667 | "project_id": "1", |
|
745 | "project_id": "1", | |
668 | "tracker_id": "1", |
|
746 | "tracker_id": "1", | |
669 | "subject": "Issue with multiple attachments", |
|
747 | "subject": "Issue with multiple attachments", | |
670 | "uploads": [ |
|
748 | "uploads": [ | |
671 | {"token": "#{token1}", "filename": "test1.txt"}, |
|
749 | {"token": "#{token1}", "filename": "test1.txt"}, | |
672 | {"token": "#{token2}", "filename": "test2.txt"} |
|
750 | {"token": "#{token2}", "filename": "test2.txt"} | |
673 | ] |
|
751 | ] | |
674 | } |
|
752 | } | |
675 | } |
|
753 | } | |
676 | JSON |
|
754 | JSON | |
677 |
|
755 | |||
678 | assert_difference 'Issue.count' do |
|
756 | assert_difference 'Issue.count' do | |
679 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
757 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) | |
680 | assert_response :created |
|
758 | assert_response :created | |
681 | end |
|
759 | end | |
682 | issue = Issue.order('id DESC').first |
|
760 | issue = Issue.order('id DESC').first | |
683 | assert_equal 2, issue.attachments.count |
|
761 | assert_equal 2, issue.attachments.count | |
684 | end |
|
762 | end | |
685 |
|
763 | |||
686 | def test_update_issue_with_uploaded_file |
|
764 | def test_update_issue_with_uploaded_file | |
687 | token = xml_upload('test_upload_with_upload', credentials('jsmith')) |
|
765 | token = xml_upload('test_upload_with_upload', credentials('jsmith')) | |
688 | attachment = Attachment.find_by_token(token) |
|
766 | attachment = Attachment.find_by_token(token) | |
689 |
|
767 | |||
690 | # update the issue with the upload's token |
|
768 | # update the issue with the upload's token | |
691 | assert_difference 'Journal.count' do |
|
769 | assert_difference 'Journal.count' do | |
692 | put '/issues/1.xml', |
|
770 | put '/issues/1.xml', | |
693 | {:issue => {:notes => 'Attachment added', |
|
771 | {:issue => {:notes => 'Attachment added', | |
694 | :uploads => [{:token => token, :filename => 'test.txt', |
|
772 | :uploads => [{:token => token, :filename => 'test.txt', | |
695 | :content_type => 'text/plain'}]}}, |
|
773 | :content_type => 'text/plain'}]}}, | |
696 | credentials('jsmith') |
|
774 | credentials('jsmith') | |
697 | assert_response :ok |
|
775 | assert_response :ok | |
698 | assert_equal '', @response.body |
|
776 | assert_equal '', @response.body | |
699 | end |
|
777 | end | |
700 |
|
778 | |||
701 | issue = Issue.find(1) |
|
779 | issue = Issue.find(1) | |
702 | assert_include attachment, issue.attachments |
|
780 | assert_include attachment, issue.attachments | |
703 | end |
|
781 | end | |
704 | end |
|
782 | end |
@@ -1,264 +1,271 | |||||
1 | module ObjectHelpers |
|
1 | module ObjectHelpers | |
2 | def User.generate!(attributes={}) |
|
2 | def User.generate!(attributes={}) | |
3 | @generated_user_login ||= 'user0' |
|
3 | @generated_user_login ||= 'user0' | |
4 | @generated_user_login.succ! |
|
4 | @generated_user_login.succ! | |
5 | user = User.new(attributes) |
|
5 | user = User.new(attributes) | |
6 | user.login = @generated_user_login.dup if user.login.blank? |
|
6 | user.login = @generated_user_login.dup if user.login.blank? | |
7 | user.mail = "#{@generated_user_login}@example.com" if user.mail.blank? |
|
7 | user.mail = "#{@generated_user_login}@example.com" if user.mail.blank? | |
8 | user.firstname = "Bob" if user.firstname.blank? |
|
8 | user.firstname = "Bob" if user.firstname.blank? | |
9 | user.lastname = "Doe" if user.lastname.blank? |
|
9 | user.lastname = "Doe" if user.lastname.blank? | |
10 | yield user if block_given? |
|
10 | yield user if block_given? | |
11 | user.save! |
|
11 | user.save! | |
12 | user |
|
12 | user | |
13 | end |
|
13 | end | |
14 |
|
14 | |||
15 | def User.add_to_project(user, project, roles=nil) |
|
15 | def User.add_to_project(user, project, roles=nil) | |
16 | roles = Role.find(1) if roles.nil? |
|
16 | roles = Role.find(1) if roles.nil? | |
17 | roles = [roles] if roles.is_a?(Role) |
|
17 | roles = [roles] if roles.is_a?(Role) | |
18 | Member.create!(:principal => user, :project => project, :roles => roles) |
|
18 | Member.create!(:principal => user, :project => project, :roles => roles) | |
19 | end |
|
19 | end | |
20 |
|
20 | |||
21 | def Group.generate!(attributes={}) |
|
21 | def Group.generate!(attributes={}) | |
22 | @generated_group_name ||= 'Group 0' |
|
22 | @generated_group_name ||= 'Group 0' | |
23 | @generated_group_name.succ! |
|
23 | @generated_group_name.succ! | |
24 | group = Group.new(attributes) |
|
24 | group = Group.new(attributes) | |
25 | group.name = @generated_group_name.dup if group.name.blank? |
|
25 | group.name = @generated_group_name.dup if group.name.blank? | |
26 | yield group if block_given? |
|
26 | yield group if block_given? | |
27 | group.save! |
|
27 | group.save! | |
28 | group |
|
28 | group | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def Project.generate!(attributes={}) |
|
31 | def Project.generate!(attributes={}) | |
32 | @generated_project_identifier ||= 'project-0000' |
|
32 | @generated_project_identifier ||= 'project-0000' | |
33 | @generated_project_identifier.succ! |
|
33 | @generated_project_identifier.succ! | |
34 | project = Project.new(attributes) |
|
34 | project = Project.new(attributes) | |
35 | project.name = @generated_project_identifier.dup if project.name.blank? |
|
35 | project.name = @generated_project_identifier.dup if project.name.blank? | |
36 | project.identifier = @generated_project_identifier.dup if project.identifier.blank? |
|
36 | project.identifier = @generated_project_identifier.dup if project.identifier.blank? | |
37 | yield project if block_given? |
|
37 | yield project if block_given? | |
38 | project.save! |
|
38 | project.save! | |
39 | project |
|
39 | project | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def Project.generate_with_parent!(*args) |
|
42 | def Project.generate_with_parent!(*args) | |
43 | attributes = args.last.is_a?(Hash) ? args.pop : {} |
|
43 | attributes = args.last.is_a?(Hash) ? args.pop : {} | |
44 | parent = args.size > 0 ? args.first : Project.generate! |
|
44 | parent = args.size > 0 ? args.first : Project.generate! | |
45 |
|
45 | |||
46 | project = Project.generate!(attributes) do |p| |
|
46 | project = Project.generate!(attributes) do |p| | |
47 | p.parent = parent |
|
47 | p.parent = parent | |
48 | end |
|
48 | end | |
49 | parent.reload if parent |
|
49 | parent.reload if parent | |
50 | project |
|
50 | project | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def IssueStatus.generate!(attributes={}) |
|
53 | def IssueStatus.generate!(attributes={}) | |
54 | @generated_status_name ||= 'Status 0' |
|
54 | @generated_status_name ||= 'Status 0' | |
55 | @generated_status_name.succ! |
|
55 | @generated_status_name.succ! | |
56 | status = IssueStatus.new(attributes) |
|
56 | status = IssueStatus.new(attributes) | |
57 | status.name = @generated_status_name.dup if status.name.blank? |
|
57 | status.name = @generated_status_name.dup if status.name.blank? | |
58 | yield status if block_given? |
|
58 | yield status if block_given? | |
59 | status.save! |
|
59 | status.save! | |
60 | status |
|
60 | status | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def Tracker.generate!(attributes={}) |
|
63 | def Tracker.generate!(attributes={}) | |
64 | @generated_tracker_name ||= 'Tracker 0' |
|
64 | @generated_tracker_name ||= 'Tracker 0' | |
65 | @generated_tracker_name.succ! |
|
65 | @generated_tracker_name.succ! | |
66 | tracker = Tracker.new(attributes) |
|
66 | tracker = Tracker.new(attributes) | |
67 | tracker.name = @generated_tracker_name.dup if tracker.name.blank? |
|
67 | tracker.name = @generated_tracker_name.dup if tracker.name.blank? | |
68 | tracker.default_status ||= IssueStatus.order('position').first || IssueStatus.generate! |
|
68 | tracker.default_status ||= IssueStatus.order('position').first || IssueStatus.generate! | |
69 | yield tracker if block_given? |
|
69 | yield tracker if block_given? | |
70 | tracker.save! |
|
70 | tracker.save! | |
71 | tracker |
|
71 | tracker | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def Role.generate!(attributes={}) |
|
74 | def Role.generate!(attributes={}) | |
75 | @generated_role_name ||= 'Role 0' |
|
75 | @generated_role_name ||= 'Role 0' | |
76 | @generated_role_name.succ! |
|
76 | @generated_role_name.succ! | |
77 | role = Role.new(attributes) |
|
77 | role = Role.new(attributes) | |
78 | role.name = @generated_role_name.dup if role.name.blank? |
|
78 | role.name = @generated_role_name.dup if role.name.blank? | |
79 | yield role if block_given? |
|
79 | yield role if block_given? | |
80 | role.save! |
|
80 | role.save! | |
81 | role |
|
81 | role | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | # Generates an unsaved Issue |
|
84 | # Generates an unsaved Issue | |
85 | def Issue.generate(attributes={}) |
|
85 | def Issue.generate(attributes={}) | |
86 | issue = Issue.new(attributes) |
|
86 | issue = Issue.new(attributes) | |
87 | issue.project ||= Project.find(1) |
|
87 | issue.project ||= Project.find(1) | |
88 | issue.tracker ||= issue.project.trackers.first |
|
88 | issue.tracker ||= issue.project.trackers.first | |
89 | issue.subject = 'Generated' if issue.subject.blank? |
|
89 | issue.subject = 'Generated' if issue.subject.blank? | |
90 | issue.author ||= User.find(2) |
|
90 | issue.author ||= User.find(2) | |
91 | yield issue if block_given? |
|
91 | yield issue if block_given? | |
92 | issue |
|
92 | issue | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | # Generates a saved Issue |
|
95 | # Generates a saved Issue | |
96 | def Issue.generate!(attributes={}, &block) |
|
96 | def Issue.generate!(attributes={}, &block) | |
97 | issue = Issue.generate(attributes, &block) |
|
97 | issue = Issue.generate(attributes, &block) | |
98 | issue.save! |
|
98 | issue.save! | |
99 | issue |
|
99 | issue | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | # Generates an issue with 2 children and a grandchild |
|
102 | # Generates an issue with 2 children and a grandchild | |
103 | def Issue.generate_with_descendants!(attributes={}) |
|
103 | def Issue.generate_with_descendants!(attributes={}) | |
104 | issue = Issue.generate!(attributes) |
|
104 | issue = Issue.generate!(attributes) | |
105 | child = Issue.generate!(:project => issue.project, :subject => 'Child1', :parent_issue_id => issue.id) |
|
105 | child = Issue.generate!(:project => issue.project, :subject => 'Child1', :parent_issue_id => issue.id) | |
106 | Issue.generate!(:project => issue.project, :subject => 'Child2', :parent_issue_id => issue.id) |
|
106 | Issue.generate!(:project => issue.project, :subject => 'Child2', :parent_issue_id => issue.id) | |
107 | Issue.generate!(:project => issue.project, :subject => 'Child11', :parent_issue_id => child.id) |
|
107 | Issue.generate!(:project => issue.project, :subject => 'Child11', :parent_issue_id => child.id) | |
108 | issue.reload |
|
108 | issue.reload | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def Issue.generate_with_child!(attributes={}) |
|
111 | def Issue.generate_with_child!(attributes={}) | |
112 | issue = Issue.generate!(attributes) |
|
112 | issue = Issue.generate!(attributes) | |
113 | Issue.generate!(:parent_issue_id => issue.id) |
|
113 | Issue.generate!(:parent_issue_id => issue.id) | |
114 | issue.reload |
|
114 | issue.reload | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def Journal.generate!(attributes={}) |
|
117 | def Journal.generate!(attributes={}) | |
118 | journal = Journal.new(attributes) |
|
118 | journal = Journal.new(attributes) | |
119 | journal.user ||= User.first |
|
119 | journal.user ||= User.first | |
120 | journal.journalized ||= Issue.first |
|
120 | journal.journalized ||= Issue.first | |
121 | yield journal if block_given? |
|
121 | yield journal if block_given? | |
122 | journal.save! |
|
122 | journal.save! | |
123 | journal |
|
123 | journal | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def Version.generate!(attributes={}) |
|
126 | def Version.generate!(attributes={}) | |
127 | @generated_version_name ||= 'Version 0' |
|
127 | @generated_version_name ||= 'Version 0' | |
128 | @generated_version_name.succ! |
|
128 | @generated_version_name.succ! | |
129 | version = Version.new(attributes) |
|
129 | version = Version.new(attributes) | |
130 | version.name = @generated_version_name.dup if version.name.blank? |
|
130 | version.name = @generated_version_name.dup if version.name.blank? | |
131 | version.project ||= Project.find(1) |
|
131 | version.project ||= Project.find(1) | |
132 | yield version if block_given? |
|
132 | yield version if block_given? | |
133 | version.save! |
|
133 | version.save! | |
134 | version |
|
134 | version | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def TimeEntry.generate!(attributes={}) |
|
137 | def TimeEntry.generate!(attributes={}) | |
138 | entry = TimeEntry.new(attributes) |
|
138 | entry = TimeEntry.new(attributes) | |
139 | entry.user ||= User.find(2) |
|
139 | entry.user ||= User.find(2) | |
140 | entry.issue ||= Issue.find(1) unless entry.project |
|
140 | entry.issue ||= Issue.find(1) unless entry.project | |
141 | entry.project ||= entry.issue.project |
|
141 | entry.project ||= entry.issue.project | |
142 | entry.activity ||= TimeEntryActivity.first |
|
142 | entry.activity ||= TimeEntryActivity.first | |
143 | entry.spent_on ||= Date.today |
|
143 | entry.spent_on ||= Date.today | |
144 | entry.hours ||= 1.0 |
|
144 | entry.hours ||= 1.0 | |
145 | entry.save! |
|
145 | entry.save! | |
146 | entry |
|
146 | entry | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def AuthSource.generate!(attributes={}) |
|
149 | def AuthSource.generate!(attributes={}) | |
150 | @generated_auth_source_name ||= 'Auth 0' |
|
150 | @generated_auth_source_name ||= 'Auth 0' | |
151 | @generated_auth_source_name.succ! |
|
151 | @generated_auth_source_name.succ! | |
152 | source = AuthSource.new(attributes) |
|
152 | source = AuthSource.new(attributes) | |
153 | source.name = @generated_auth_source_name.dup if source.name.blank? |
|
153 | source.name = @generated_auth_source_name.dup if source.name.blank? | |
154 | yield source if block_given? |
|
154 | yield source if block_given? | |
155 | source.save! |
|
155 | source.save! | |
156 | source |
|
156 | source | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def Board.generate!(attributes={}) |
|
159 | def Board.generate!(attributes={}) | |
160 | @generated_board_name ||= 'Forum 0' |
|
160 | @generated_board_name ||= 'Forum 0' | |
161 | @generated_board_name.succ! |
|
161 | @generated_board_name.succ! | |
162 | board = Board.new(attributes) |
|
162 | board = Board.new(attributes) | |
163 | board.name = @generated_board_name.dup if board.name.blank? |
|
163 | board.name = @generated_board_name.dup if board.name.blank? | |
164 | board.description = @generated_board_name.dup if board.description.blank? |
|
164 | board.description = @generated_board_name.dup if board.description.blank? | |
165 | yield board if block_given? |
|
165 | yield board if block_given? | |
166 | board.save! |
|
166 | board.save! | |
167 | board |
|
167 | board | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | def Attachment.generate!(attributes={}) |
|
170 | def Attachment.generate!(attributes={}) | |
171 | @generated_filename ||= 'testfile0' |
|
171 | @generated_filename ||= 'testfile0' | |
172 | @generated_filename.succ! |
|
172 | @generated_filename.succ! | |
173 | attributes = attributes.dup |
|
173 | attributes = attributes.dup | |
174 | attachment = Attachment.new(attributes) |
|
174 | attachment = Attachment.new(attributes) | |
175 | attachment.container ||= Issue.find(1) |
|
175 | attachment.container ||= Issue.find(1) | |
176 | attachment.author ||= User.find(2) |
|
176 | attachment.author ||= User.find(2) | |
177 | attachment.filename = @generated_filename.dup if attachment.filename.blank? |
|
177 | attachment.filename = @generated_filename.dup if attachment.filename.blank? | |
178 | attachment.save! |
|
178 | attachment.save! | |
179 | attachment |
|
179 | attachment | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | def CustomField.generate!(attributes={}) |
|
182 | def CustomField.generate!(attributes={}) | |
183 | @generated_custom_field_name ||= 'Custom field 0' |
|
183 | @generated_custom_field_name ||= 'Custom field 0' | |
184 | @generated_custom_field_name.succ! |
|
184 | @generated_custom_field_name.succ! | |
185 | field = new(attributes) |
|
185 | field = new(attributes) | |
186 | field.name = @generated_custom_field_name.dup if field.name.blank? |
|
186 | field.name = @generated_custom_field_name.dup if field.name.blank? | |
187 | field.field_format = 'string' if field.field_format.blank? |
|
187 | field.field_format = 'string' if field.field_format.blank? | |
188 | yield field if block_given? |
|
188 | yield field if block_given? | |
189 | field.save! |
|
189 | field.save! | |
190 | field |
|
190 | field | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
|
193 | def IssueCustomField.generate!(attributes={}) | |||
|
194 | super do |field| | |||
|
195 | field.is_for_all = true unless attributes.key?(:is_for_all) | |||
|
196 | field.tracker_ids = Tracker.all.ids unless attributes.key?(:tracker_ids) || attributes.key?(:trackers) | |||
|
197 | end | |||
|
198 | end | |||
|
199 | ||||
193 | def Changeset.generate!(attributes={}) |
|
200 | def Changeset.generate!(attributes={}) | |
194 | @generated_changeset_rev ||= '123456' |
|
201 | @generated_changeset_rev ||= '123456' | |
195 | @generated_changeset_rev.succ! |
|
202 | @generated_changeset_rev.succ! | |
196 | changeset = new(attributes) |
|
203 | changeset = new(attributes) | |
197 | changeset.repository ||= Project.find(1).repository |
|
204 | changeset.repository ||= Project.find(1).repository | |
198 | changeset.revision ||= @generated_changeset_rev |
|
205 | changeset.revision ||= @generated_changeset_rev | |
199 | changeset.committed_on ||= Time.now |
|
206 | changeset.committed_on ||= Time.now | |
200 | yield changeset if block_given? |
|
207 | yield changeset if block_given? | |
201 | changeset.save! |
|
208 | changeset.save! | |
202 | changeset |
|
209 | changeset | |
203 | end |
|
210 | end | |
204 |
|
211 | |||
205 | def Query.generate!(attributes={}) |
|
212 | def Query.generate!(attributes={}) | |
206 | query = new(attributes) |
|
213 | query = new(attributes) | |
207 | query.name = "Generated query" if query.name.blank? |
|
214 | query.name = "Generated query" if query.name.blank? | |
208 | query.user ||= User.find(1) |
|
215 | query.user ||= User.find(1) | |
209 | query.save! |
|
216 | query.save! | |
210 | query |
|
217 | query | |
211 | end |
|
218 | end | |
212 |
|
219 | |||
213 | def generate_import(fixture_name='import_issues.csv') |
|
220 | def generate_import(fixture_name='import_issues.csv') | |
214 | import = IssueImport.new |
|
221 | import = IssueImport.new | |
215 | import.user_id = 2 |
|
222 | import.user_id = 2 | |
216 | import.file = uploaded_test_file(fixture_name, 'text/csv') |
|
223 | import.file = uploaded_test_file(fixture_name, 'text/csv') | |
217 | import.save! |
|
224 | import.save! | |
218 | import |
|
225 | import | |
219 | end |
|
226 | end | |
220 |
|
227 | |||
221 | def generate_import_with_mapping(fixture_name='import_issues.csv') |
|
228 | def generate_import_with_mapping(fixture_name='import_issues.csv') | |
222 | import = generate_import(fixture_name) |
|
229 | import = generate_import(fixture_name) | |
223 |
|
230 | |||
224 | import.settings = { |
|
231 | import.settings = { | |
225 | 'separator' => ";", 'wrapper' => '"', 'encoding' => "UTF-8", |
|
232 | 'separator' => ";", 'wrapper' => '"', 'encoding' => "UTF-8", | |
226 | 'mapping' => {'project_id' => '1', 'tracker_id' => '2', 'subject' => '1'} |
|
233 | 'mapping' => {'project_id' => '1', 'tracker_id' => '2', 'subject' => '1'} | |
227 | } |
|
234 | } | |
228 | import.save! |
|
235 | import.save! | |
229 | import |
|
236 | import | |
230 | end |
|
237 | end | |
231 | end |
|
238 | end | |
232 |
|
239 | |||
233 | module TrackerObjectHelpers |
|
240 | module TrackerObjectHelpers | |
234 | def generate_transitions!(*args) |
|
241 | def generate_transitions!(*args) | |
235 | options = args.last.is_a?(Hash) ? args.pop : {} |
|
242 | options = args.last.is_a?(Hash) ? args.pop : {} | |
236 | if args.size == 1 |
|
243 | if args.size == 1 | |
237 | args << args.first |
|
244 | args << args.first | |
238 | end |
|
245 | end | |
239 | if options[:clear] |
|
246 | if options[:clear] | |
240 | WorkflowTransition.where(:tracker_id => id).delete_all |
|
247 | WorkflowTransition.where(:tracker_id => id).delete_all | |
241 | end |
|
248 | end | |
242 | args.each_cons(2) do |old_status_id, new_status_id| |
|
249 | args.each_cons(2) do |old_status_id, new_status_id| | |
243 | WorkflowTransition.create!( |
|
250 | WorkflowTransition.create!( | |
244 | :tracker => self, |
|
251 | :tracker => self, | |
245 | :role_id => (options[:role_id] || 1), |
|
252 | :role_id => (options[:role_id] || 1), | |
246 | :old_status_id => old_status_id, |
|
253 | :old_status_id => old_status_id, | |
247 | :new_status_id => new_status_id |
|
254 | :new_status_id => new_status_id | |
248 | ) |
|
255 | ) | |
249 | end |
|
256 | end | |
250 | end |
|
257 | end | |
251 | end |
|
258 | end | |
252 | Tracker.send :include, TrackerObjectHelpers |
|
259 | Tracker.send :include, TrackerObjectHelpers | |
253 |
|
260 | |||
254 | module IssueObjectHelpers |
|
261 | module IssueObjectHelpers | |
255 | def close! |
|
262 | def close! | |
256 | self.status = IssueStatus.where(:is_closed => true).first |
|
263 | self.status = IssueStatus.where(:is_closed => true).first | |
257 | save! |
|
264 | save! | |
258 | end |
|
265 | end | |
259 |
|
266 | |||
260 | def generate_child!(attributes={}) |
|
267 | def generate_child!(attributes={}) | |
261 | Issue.generate!(attributes.merge(:parent_issue_id => self.id)) |
|
268 | Issue.generate!(attributes.merge(:parent_issue_id => self.id)) | |
262 | end |
|
269 | end | |
263 | end |
|
270 | end | |
264 | Issue.send :include, IssueObjectHelpers |
|
271 | Issue.send :include, IssueObjectHelpers |
General Comments 0
You need to be logged in to leave comments.
Login now