##// END OF EJS Templates
Adds tests for when showing/deleting an invalid issue....
Jean-Philippe Lang -
r10710:46fe61d51e8b
parent child
Show More
@@ -1,3822 +1,3835
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 IssuesControllerTest < ActionController::TestCase
20 class IssuesControllerTest < ActionController::TestCase
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 :versions,
28 :versions,
29 :trackers,
29 :trackers,
30 :projects_trackers,
30 :projects_trackers,
31 :issue_categories,
31 :issue_categories,
32 :enabled_modules,
32 :enabled_modules,
33 :enumerations,
33 :enumerations,
34 :attachments,
34 :attachments,
35 :workflows,
35 :workflows,
36 :custom_fields,
36 :custom_fields,
37 :custom_values,
37 :custom_values,
38 :custom_fields_projects,
38 :custom_fields_projects,
39 :custom_fields_trackers,
39 :custom_fields_trackers,
40 :time_entries,
40 :time_entries,
41 :journals,
41 :journals,
42 :journal_details,
42 :journal_details,
43 :queries,
43 :queries,
44 :repositories,
44 :repositories,
45 :changesets
45 :changesets
46
46
47 include Redmine::I18n
47 include Redmine::I18n
48
48
49 def setup
49 def setup
50 User.current = nil
50 User.current = nil
51 end
51 end
52
52
53 def test_index
53 def test_index
54 with_settings :default_language => "en" do
54 with_settings :default_language => "en" do
55 get :index
55 get :index
56 assert_response :success
56 assert_response :success
57 assert_template 'index'
57 assert_template 'index'
58 assert_not_nil assigns(:issues)
58 assert_not_nil assigns(:issues)
59 assert_nil assigns(:project)
59 assert_nil assigns(:project)
60
60
61 # links to visible issues
61 # links to visible issues
62 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
62 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
64 # private projects hidden
64 # private projects hidden
65 assert_select 'a[href=/issues/6]', 0
65 assert_select 'a[href=/issues/6]', 0
66 assert_select 'a[href=/issues/4]', 0
66 assert_select 'a[href=/issues/4]', 0
67 # project column
67 # project column
68 assert_select 'th', :text => /Project/
68 assert_select 'th', :text => /Project/
69 end
69 end
70 end
70 end
71
71
72 def test_index_should_not_list_issues_when_module_disabled
72 def test_index_should_not_list_issues_when_module_disabled
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 get :index
74 get :index
75 assert_response :success
75 assert_response :success
76 assert_template 'index'
76 assert_template 'index'
77 assert_not_nil assigns(:issues)
77 assert_not_nil assigns(:issues)
78 assert_nil assigns(:project)
78 assert_nil assigns(:project)
79
79
80 assert_select 'a[href=/issues/1]', 0
80 assert_select 'a[href=/issues/1]', 0
81 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
81 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
82 end
82 end
83
83
84 def test_index_should_list_visible_issues_only
84 def test_index_should_list_visible_issues_only
85 get :index, :per_page => 100
85 get :index, :per_page => 100
86 assert_response :success
86 assert_response :success
87 assert_not_nil assigns(:issues)
87 assert_not_nil assigns(:issues)
88 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
88 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
89 end
89 end
90
90
91 def test_index_with_project
91 def test_index_with_project
92 Setting.display_subprojects_issues = 0
92 Setting.display_subprojects_issues = 0
93 get :index, :project_id => 1
93 get :index, :project_id => 1
94 assert_response :success
94 assert_response :success
95 assert_template 'index'
95 assert_template 'index'
96 assert_not_nil assigns(:issues)
96 assert_not_nil assigns(:issues)
97
97
98 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
98 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
99 assert_select 'a[href=/issues/5]', 0
99 assert_select 'a[href=/issues/5]', 0
100 end
100 end
101
101
102 def test_index_with_project_and_subprojects
102 def test_index_with_project_and_subprojects
103 Setting.display_subprojects_issues = 1
103 Setting.display_subprojects_issues = 1
104 get :index, :project_id => 1
104 get :index, :project_id => 1
105 assert_response :success
105 assert_response :success
106 assert_template 'index'
106 assert_template 'index'
107 assert_not_nil assigns(:issues)
107 assert_not_nil assigns(:issues)
108
108
109 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
109 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
111 assert_select 'a[href=/issues/6]', 0
111 assert_select 'a[href=/issues/6]', 0
112 end
112 end
113
113
114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
115 @request.session[:user_id] = 2
115 @request.session[:user_id] = 2
116 Setting.display_subprojects_issues = 1
116 Setting.display_subprojects_issues = 1
117 get :index, :project_id => 1
117 get :index, :project_id => 1
118 assert_response :success
118 assert_response :success
119 assert_template 'index'
119 assert_template 'index'
120 assert_not_nil assigns(:issues)
120 assert_not_nil assigns(:issues)
121
121
122 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
122 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
125 end
125 end
126
126
127 def test_index_with_project_and_default_filter
127 def test_index_with_project_and_default_filter
128 get :index, :project_id => 1, :set_filter => 1
128 get :index, :project_id => 1, :set_filter => 1
129 assert_response :success
129 assert_response :success
130 assert_template 'index'
130 assert_template 'index'
131 assert_not_nil assigns(:issues)
131 assert_not_nil assigns(:issues)
132
132
133 query = assigns(:query)
133 query = assigns(:query)
134 assert_not_nil query
134 assert_not_nil query
135 # default filter
135 # default filter
136 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
136 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
137 end
137 end
138
138
139 def test_index_with_project_and_filter
139 def test_index_with_project_and_filter
140 get :index, :project_id => 1, :set_filter => 1,
140 get :index, :project_id => 1, :set_filter => 1,
141 :f => ['tracker_id'],
141 :f => ['tracker_id'],
142 :op => {'tracker_id' => '='},
142 :op => {'tracker_id' => '='},
143 :v => {'tracker_id' => ['1']}
143 :v => {'tracker_id' => ['1']}
144 assert_response :success
144 assert_response :success
145 assert_template 'index'
145 assert_template 'index'
146 assert_not_nil assigns(:issues)
146 assert_not_nil assigns(:issues)
147
147
148 query = assigns(:query)
148 query = assigns(:query)
149 assert_not_nil query
149 assert_not_nil query
150 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
150 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
151 end
151 end
152
152
153 def test_index_with_short_filters
153 def test_index_with_short_filters
154 to_test = {
154 to_test = {
155 'status_id' => {
155 'status_id' => {
156 'o' => { :op => 'o', :values => [''] },
156 'o' => { :op => 'o', :values => [''] },
157 'c' => { :op => 'c', :values => [''] },
157 'c' => { :op => 'c', :values => [''] },
158 '7' => { :op => '=', :values => ['7'] },
158 '7' => { :op => '=', :values => ['7'] },
159 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
159 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
160 '=7' => { :op => '=', :values => ['7'] },
160 '=7' => { :op => '=', :values => ['7'] },
161 '!3' => { :op => '!', :values => ['3'] },
161 '!3' => { :op => '!', :values => ['3'] },
162 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
162 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
163 'subject' => {
163 'subject' => {
164 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
164 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
165 'o' => { :op => '=', :values => ['o'] },
165 'o' => { :op => '=', :values => ['o'] },
166 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
166 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
167 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
167 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
168 'tracker_id' => {
168 'tracker_id' => {
169 '3' => { :op => '=', :values => ['3'] },
169 '3' => { :op => '=', :values => ['3'] },
170 '=3' => { :op => '=', :values => ['3'] }},
170 '=3' => { :op => '=', :values => ['3'] }},
171 'start_date' => {
171 'start_date' => {
172 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
172 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
173 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
173 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
174 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
174 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
175 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
175 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
176 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
176 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
177 '<t+2' => { :op => '<t+', :values => ['2'] },
177 '<t+2' => { :op => '<t+', :values => ['2'] },
178 '>t+2' => { :op => '>t+', :values => ['2'] },
178 '>t+2' => { :op => '>t+', :values => ['2'] },
179 't+2' => { :op => 't+', :values => ['2'] },
179 't+2' => { :op => 't+', :values => ['2'] },
180 't' => { :op => 't', :values => [''] },
180 't' => { :op => 't', :values => [''] },
181 'w' => { :op => 'w', :values => [''] },
181 'w' => { :op => 'w', :values => [''] },
182 '>t-2' => { :op => '>t-', :values => ['2'] },
182 '>t-2' => { :op => '>t-', :values => ['2'] },
183 '<t-2' => { :op => '<t-', :values => ['2'] },
183 '<t-2' => { :op => '<t-', :values => ['2'] },
184 't-2' => { :op => 't-', :values => ['2'] }},
184 't-2' => { :op => 't-', :values => ['2'] }},
185 'created_on' => {
185 'created_on' => {
186 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
186 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
187 '<t-2' => { :op => '<t-', :values => ['2'] },
187 '<t-2' => { :op => '<t-', :values => ['2'] },
188 '>t-2' => { :op => '>t-', :values => ['2'] },
188 '>t-2' => { :op => '>t-', :values => ['2'] },
189 't-2' => { :op => 't-', :values => ['2'] }},
189 't-2' => { :op => 't-', :values => ['2'] }},
190 'cf_1' => {
190 'cf_1' => {
191 'c' => { :op => '=', :values => ['c'] },
191 'c' => { :op => '=', :values => ['c'] },
192 '!c' => { :op => '!', :values => ['c'] },
192 '!c' => { :op => '!', :values => ['c'] },
193 '!*' => { :op => '!*', :values => [''] },
193 '!*' => { :op => '!*', :values => [''] },
194 '*' => { :op => '*', :values => [''] }},
194 '*' => { :op => '*', :values => [''] }},
195 'estimated_hours' => {
195 'estimated_hours' => {
196 '=13.4' => { :op => '=', :values => ['13.4'] },
196 '=13.4' => { :op => '=', :values => ['13.4'] },
197 '>=45' => { :op => '>=', :values => ['45'] },
197 '>=45' => { :op => '>=', :values => ['45'] },
198 '<=125' => { :op => '<=', :values => ['125'] },
198 '<=125' => { :op => '<=', :values => ['125'] },
199 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
199 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
200 '!*' => { :op => '!*', :values => [''] },
200 '!*' => { :op => '!*', :values => [''] },
201 '*' => { :op => '*', :values => [''] }}
201 '*' => { :op => '*', :values => [''] }}
202 }
202 }
203
203
204 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
204 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
205
205
206 to_test.each do |field, expression_and_expected|
206 to_test.each do |field, expression_and_expected|
207 expression_and_expected.each do |filter_expression, expected|
207 expression_and_expected.each do |filter_expression, expected|
208
208
209 get :index, :set_filter => 1, field => filter_expression
209 get :index, :set_filter => 1, field => filter_expression
210
210
211 assert_response :success
211 assert_response :success
212 assert_template 'index'
212 assert_template 'index'
213 assert_not_nil assigns(:issues)
213 assert_not_nil assigns(:issues)
214
214
215 query = assigns(:query)
215 query = assigns(:query)
216 assert_not_nil query
216 assert_not_nil query
217 assert query.has_filter?(field)
217 assert query.has_filter?(field)
218 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
218 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
219 end
219 end
220 end
220 end
221 end
221 end
222
222
223 def test_index_with_project_and_empty_filters
223 def test_index_with_project_and_empty_filters
224 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
224 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
225 assert_response :success
225 assert_response :success
226 assert_template 'index'
226 assert_template 'index'
227 assert_not_nil assigns(:issues)
227 assert_not_nil assigns(:issues)
228
228
229 query = assigns(:query)
229 query = assigns(:query)
230 assert_not_nil query
230 assert_not_nil query
231 # no filter
231 # no filter
232 assert_equal({}, query.filters)
232 assert_equal({}, query.filters)
233 end
233 end
234
234
235 def test_index_with_project_custom_field_filter
235 def test_index_with_project_custom_field_filter
236 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
236 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
237 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
237 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
238 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
238 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
239 filter_name = "project.cf_#{field.id}"
239 filter_name = "project.cf_#{field.id}"
240 @request.session[:user_id] = 1
240 @request.session[:user_id] = 1
241
241
242 get :index, :set_filter => 1,
242 get :index, :set_filter => 1,
243 :f => [filter_name],
243 :f => [filter_name],
244 :op => {filter_name => '='},
244 :op => {filter_name => '='},
245 :v => {filter_name => ['Foo']}
245 :v => {filter_name => ['Foo']}
246 assert_response :success
246 assert_response :success
247 assert_template 'index'
247 assert_template 'index'
248 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
248 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
249 end
249 end
250
250
251 def test_index_with_query
251 def test_index_with_query
252 get :index, :project_id => 1, :query_id => 5
252 get :index, :project_id => 1, :query_id => 5
253 assert_response :success
253 assert_response :success
254 assert_template 'index'
254 assert_template 'index'
255 assert_not_nil assigns(:issues)
255 assert_not_nil assigns(:issues)
256 assert_nil assigns(:issue_count_by_group)
256 assert_nil assigns(:issue_count_by_group)
257 end
257 end
258
258
259 def test_index_with_query_grouped_by_tracker
259 def test_index_with_query_grouped_by_tracker
260 get :index, :project_id => 1, :query_id => 6
260 get :index, :project_id => 1, :query_id => 6
261 assert_response :success
261 assert_response :success
262 assert_template 'index'
262 assert_template 'index'
263 assert_not_nil assigns(:issues)
263 assert_not_nil assigns(:issues)
264 assert_not_nil assigns(:issue_count_by_group)
264 assert_not_nil assigns(:issue_count_by_group)
265 end
265 end
266
266
267 def test_index_with_query_grouped_by_list_custom_field
267 def test_index_with_query_grouped_by_list_custom_field
268 get :index, :project_id => 1, :query_id => 9
268 get :index, :project_id => 1, :query_id => 9
269 assert_response :success
269 assert_response :success
270 assert_template 'index'
270 assert_template 'index'
271 assert_not_nil assigns(:issues)
271 assert_not_nil assigns(:issues)
272 assert_not_nil assigns(:issue_count_by_group)
272 assert_not_nil assigns(:issue_count_by_group)
273 end
273 end
274
274
275 def test_index_with_query_grouped_by_user_custom_field
275 def test_index_with_query_grouped_by_user_custom_field
276 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
276 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
277 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
277 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
278 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
278 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
279 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
279 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
280 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
280 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
281
281
282 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
282 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
283 assert_response :success
283 assert_response :success
284
284
285 assert_select 'tr.group', 3
285 assert_select 'tr.group', 3
286 assert_select 'tr.group' do
286 assert_select 'tr.group' do
287 assert_select 'a', :text => 'John Smith'
287 assert_select 'a', :text => 'John Smith'
288 assert_select 'span.count', :text => '1'
288 assert_select 'span.count', :text => '1'
289 end
289 end
290 assert_select 'tr.group' do
290 assert_select 'tr.group' do
291 assert_select 'a', :text => 'Dave Lopper'
291 assert_select 'a', :text => 'Dave Lopper'
292 assert_select 'span.count', :text => '2'
292 assert_select 'span.count', :text => '2'
293 end
293 end
294 end
294 end
295
295
296 def test_index_with_query_grouped_by_tracker
296 def test_index_with_query_grouped_by_tracker
297 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
297 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
298
298
299 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
299 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
300 assert_response :success
300 assert_response :success
301
301
302 trackers = assigns(:issues).map(&:tracker).uniq
302 trackers = assigns(:issues).map(&:tracker).uniq
303 assert_equal [1, 2, 3], trackers.map(&:id)
303 assert_equal [1, 2, 3], trackers.map(&:id)
304 end
304 end
305
305
306 def test_index_with_query_grouped_by_tracker_in_reverse_order
306 def test_index_with_query_grouped_by_tracker_in_reverse_order
307 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
307 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
308
308
309 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
309 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
310 assert_response :success
310 assert_response :success
311
311
312 trackers = assigns(:issues).map(&:tracker).uniq
312 trackers = assigns(:issues).map(&:tracker).uniq
313 assert_equal [3, 2, 1], trackers.map(&:id)
313 assert_equal [3, 2, 1], trackers.map(&:id)
314 end
314 end
315
315
316 def test_index_with_query_id_and_project_id_should_set_session_query
316 def test_index_with_query_id_and_project_id_should_set_session_query
317 get :index, :project_id => 1, :query_id => 4
317 get :index, :project_id => 1, :query_id => 4
318 assert_response :success
318 assert_response :success
319 assert_kind_of Hash, session[:query]
319 assert_kind_of Hash, session[:query]
320 assert_equal 4, session[:query][:id]
320 assert_equal 4, session[:query][:id]
321 assert_equal 1, session[:query][:project_id]
321 assert_equal 1, session[:query][:project_id]
322 end
322 end
323
323
324 def test_index_with_invalid_query_id_should_respond_404
324 def test_index_with_invalid_query_id_should_respond_404
325 get :index, :project_id => 1, :query_id => 999
325 get :index, :project_id => 1, :query_id => 999
326 assert_response 404
326 assert_response 404
327 end
327 end
328
328
329 def test_index_with_cross_project_query_in_session_should_show_project_issues
329 def test_index_with_cross_project_query_in_session_should_show_project_issues
330 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
330 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
331 @request.session[:query] = {:id => q.id, :project_id => 1}
331 @request.session[:query] = {:id => q.id, :project_id => 1}
332
332
333 with_settings :display_subprojects_issues => '0' do
333 with_settings :display_subprojects_issues => '0' do
334 get :index, :project_id => 1
334 get :index, :project_id => 1
335 end
335 end
336 assert_response :success
336 assert_response :success
337 assert_not_nil assigns(:query)
337 assert_not_nil assigns(:query)
338 assert_equal q.id, assigns(:query).id
338 assert_equal q.id, assigns(:query).id
339 assert_equal 1, assigns(:query).project_id
339 assert_equal 1, assigns(:query).project_id
340 assert_equal [1], assigns(:issues).map(&:project_id).uniq
340 assert_equal [1], assigns(:issues).map(&:project_id).uniq
341 end
341 end
342
342
343 def test_private_query_should_not_be_available_to_other_users
343 def test_private_query_should_not_be_available_to_other_users
344 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
344 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
345 @request.session[:user_id] = 3
345 @request.session[:user_id] = 3
346
346
347 get :index, :query_id => q.id
347 get :index, :query_id => q.id
348 assert_response 403
348 assert_response 403
349 end
349 end
350
350
351 def test_private_query_should_be_available_to_its_user
351 def test_private_query_should_be_available_to_its_user
352 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
352 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
353 @request.session[:user_id] = 2
353 @request.session[:user_id] = 2
354
354
355 get :index, :query_id => q.id
355 get :index, :query_id => q.id
356 assert_response :success
356 assert_response :success
357 end
357 end
358
358
359 def test_public_query_should_be_available_to_other_users
359 def test_public_query_should_be_available_to_other_users
360 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
360 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
361 @request.session[:user_id] = 3
361 @request.session[:user_id] = 3
362
362
363 get :index, :query_id => q.id
363 get :index, :query_id => q.id
364 assert_response :success
364 assert_response :success
365 end
365 end
366
366
367 def test_index_should_omit_page_param_in_export_links
367 def test_index_should_omit_page_param_in_export_links
368 get :index, :page => 2
368 get :index, :page => 2
369 assert_response :success
369 assert_response :success
370 assert_select 'a.atom[href=/issues.atom]'
370 assert_select 'a.atom[href=/issues.atom]'
371 assert_select 'a.csv[href=/issues.csv]'
371 assert_select 'a.csv[href=/issues.csv]'
372 assert_select 'a.pdf[href=/issues.pdf]'
372 assert_select 'a.pdf[href=/issues.pdf]'
373 assert_select 'form#csv-export-form[action=/issues.csv]'
373 assert_select 'form#csv-export-form[action=/issues.csv]'
374 end
374 end
375
375
376 def test_index_csv
376 def test_index_csv
377 get :index, :format => 'csv'
377 get :index, :format => 'csv'
378 assert_response :success
378 assert_response :success
379 assert_not_nil assigns(:issues)
379 assert_not_nil assigns(:issues)
380 assert_equal 'text/csv; header=present', @response.content_type
380 assert_equal 'text/csv; header=present', @response.content_type
381 assert @response.body.starts_with?("#,")
381 assert @response.body.starts_with?("#,")
382 lines = @response.body.chomp.split("\n")
382 lines = @response.body.chomp.split("\n")
383 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
383 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
384 end
384 end
385
385
386 def test_index_csv_with_project
386 def test_index_csv_with_project
387 get :index, :project_id => 1, :format => 'csv'
387 get :index, :project_id => 1, :format => 'csv'
388 assert_response :success
388 assert_response :success
389 assert_not_nil assigns(:issues)
389 assert_not_nil assigns(:issues)
390 assert_equal 'text/csv; header=present', @response.content_type
390 assert_equal 'text/csv; header=present', @response.content_type
391 end
391 end
392
392
393 def test_index_csv_with_description
393 def test_index_csv_with_description
394 get :index, :format => 'csv', :description => '1'
394 get :index, :format => 'csv', :description => '1'
395 assert_response :success
395 assert_response :success
396 assert_not_nil assigns(:issues)
396 assert_not_nil assigns(:issues)
397 assert_equal 'text/csv; header=present', @response.content_type
397 assert_equal 'text/csv; header=present', @response.content_type
398 assert @response.body.starts_with?("#,")
398 assert @response.body.starts_with?("#,")
399 lines = @response.body.chomp.split("\n")
399 lines = @response.body.chomp.split("\n")
400 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
400 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
401 end
401 end
402
402
403 def test_index_csv_with_spent_time_column
403 def test_index_csv_with_spent_time_column
404 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
404 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
405 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
405 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
406
406
407 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
407 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
408 assert_response :success
408 assert_response :success
409 assert_equal 'text/csv; header=present', @response.content_type
409 assert_equal 'text/csv; header=present', @response.content_type
410 lines = @response.body.chomp.split("\n")
410 lines = @response.body.chomp.split("\n")
411 assert_include "#{issue.id},#{issue.subject},7.33", lines
411 assert_include "#{issue.id},#{issue.subject},7.33", lines
412 end
412 end
413
413
414 def test_index_csv_with_all_columns
414 def test_index_csv_with_all_columns
415 get :index, :format => 'csv', :columns => 'all'
415 get :index, :format => 'csv', :columns => 'all'
416 assert_response :success
416 assert_response :success
417 assert_not_nil assigns(:issues)
417 assert_not_nil assigns(:issues)
418 assert_equal 'text/csv; header=present', @response.content_type
418 assert_equal 'text/csv; header=present', @response.content_type
419 assert @response.body.starts_with?("#,")
419 assert @response.body.starts_with?("#,")
420 lines = @response.body.chomp.split("\n")
420 lines = @response.body.chomp.split("\n")
421 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
421 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
422 end
422 end
423
423
424 def test_index_csv_with_multi_column_field
424 def test_index_csv_with_multi_column_field
425 CustomField.find(1).update_attribute :multiple, true
425 CustomField.find(1).update_attribute :multiple, true
426 issue = Issue.find(1)
426 issue = Issue.find(1)
427 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
427 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
428 issue.save!
428 issue.save!
429
429
430 get :index, :format => 'csv', :columns => 'all'
430 get :index, :format => 'csv', :columns => 'all'
431 assert_response :success
431 assert_response :success
432 lines = @response.body.chomp.split("\n")
432 lines = @response.body.chomp.split("\n")
433 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
433 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
434 end
434 end
435
435
436 def test_index_csv_big_5
436 def test_index_csv_big_5
437 with_settings :default_language => "zh-TW" do
437 with_settings :default_language => "zh-TW" do
438 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
438 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
439 str_big5 = "\xa4@\xa4\xeb"
439 str_big5 = "\xa4@\xa4\xeb"
440 if str_utf8.respond_to?(:force_encoding)
440 if str_utf8.respond_to?(:force_encoding)
441 str_utf8.force_encoding('UTF-8')
441 str_utf8.force_encoding('UTF-8')
442 str_big5.force_encoding('Big5')
442 str_big5.force_encoding('Big5')
443 end
443 end
444 issue = Issue.generate!(:subject => str_utf8)
444 issue = Issue.generate!(:subject => str_utf8)
445
445
446 get :index, :project_id => 1,
446 get :index, :project_id => 1,
447 :f => ['subject'],
447 :f => ['subject'],
448 :op => '=', :values => [str_utf8],
448 :op => '=', :values => [str_utf8],
449 :format => 'csv'
449 :format => 'csv'
450 assert_equal 'text/csv; header=present', @response.content_type
450 assert_equal 'text/csv; header=present', @response.content_type
451 lines = @response.body.chomp.split("\n")
451 lines = @response.body.chomp.split("\n")
452 s1 = "\xaa\xac\xbaA"
452 s1 = "\xaa\xac\xbaA"
453 if str_utf8.respond_to?(:force_encoding)
453 if str_utf8.respond_to?(:force_encoding)
454 s1.force_encoding('Big5')
454 s1.force_encoding('Big5')
455 end
455 end
456 assert lines[0].include?(s1)
456 assert lines[0].include?(s1)
457 assert lines[1].include?(str_big5)
457 assert lines[1].include?(str_big5)
458 end
458 end
459 end
459 end
460
460
461 def test_index_csv_cannot_convert_should_be_replaced_big_5
461 def test_index_csv_cannot_convert_should_be_replaced_big_5
462 with_settings :default_language => "zh-TW" do
462 with_settings :default_language => "zh-TW" do
463 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
463 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
464 if str_utf8.respond_to?(:force_encoding)
464 if str_utf8.respond_to?(:force_encoding)
465 str_utf8.force_encoding('UTF-8')
465 str_utf8.force_encoding('UTF-8')
466 end
466 end
467 issue = Issue.generate!(:subject => str_utf8)
467 issue = Issue.generate!(:subject => str_utf8)
468
468
469 get :index, :project_id => 1,
469 get :index, :project_id => 1,
470 :f => ['subject'],
470 :f => ['subject'],
471 :op => '=', :values => [str_utf8],
471 :op => '=', :values => [str_utf8],
472 :c => ['status', 'subject'],
472 :c => ['status', 'subject'],
473 :format => 'csv',
473 :format => 'csv',
474 :set_filter => 1
474 :set_filter => 1
475 assert_equal 'text/csv; header=present', @response.content_type
475 assert_equal 'text/csv; header=present', @response.content_type
476 lines = @response.body.chomp.split("\n")
476 lines = @response.body.chomp.split("\n")
477 s1 = "\xaa\xac\xbaA" # status
477 s1 = "\xaa\xac\xbaA" # status
478 if str_utf8.respond_to?(:force_encoding)
478 if str_utf8.respond_to?(:force_encoding)
479 s1.force_encoding('Big5')
479 s1.force_encoding('Big5')
480 end
480 end
481 assert lines[0].include?(s1)
481 assert lines[0].include?(s1)
482 s2 = lines[1].split(",")[2]
482 s2 = lines[1].split(",")[2]
483 if s1.respond_to?(:force_encoding)
483 if s1.respond_to?(:force_encoding)
484 s3 = "\xa5H?" # subject
484 s3 = "\xa5H?" # subject
485 s3.force_encoding('Big5')
485 s3.force_encoding('Big5')
486 assert_equal s3, s2
486 assert_equal s3, s2
487 elsif RUBY_PLATFORM == 'java'
487 elsif RUBY_PLATFORM == 'java'
488 assert_equal "??", s2
488 assert_equal "??", s2
489 else
489 else
490 assert_equal "\xa5H???", s2
490 assert_equal "\xa5H???", s2
491 end
491 end
492 end
492 end
493 end
493 end
494
494
495 def test_index_csv_tw
495 def test_index_csv_tw
496 with_settings :default_language => "zh-TW" do
496 with_settings :default_language => "zh-TW" do
497 str1 = "test_index_csv_tw"
497 str1 = "test_index_csv_tw"
498 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
498 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
499
499
500 get :index, :project_id => 1,
500 get :index, :project_id => 1,
501 :f => ['subject'],
501 :f => ['subject'],
502 :op => '=', :values => [str1],
502 :op => '=', :values => [str1],
503 :c => ['estimated_hours', 'subject'],
503 :c => ['estimated_hours', 'subject'],
504 :format => 'csv',
504 :format => 'csv',
505 :set_filter => 1
505 :set_filter => 1
506 assert_equal 'text/csv; header=present', @response.content_type
506 assert_equal 'text/csv; header=present', @response.content_type
507 lines = @response.body.chomp.split("\n")
507 lines = @response.body.chomp.split("\n")
508 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
508 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
509 end
509 end
510 end
510 end
511
511
512 def test_index_csv_fr
512 def test_index_csv_fr
513 with_settings :default_language => "fr" do
513 with_settings :default_language => "fr" do
514 str1 = "test_index_csv_fr"
514 str1 = "test_index_csv_fr"
515 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
515 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
516
516
517 get :index, :project_id => 1,
517 get :index, :project_id => 1,
518 :f => ['subject'],
518 :f => ['subject'],
519 :op => '=', :values => [str1],
519 :op => '=', :values => [str1],
520 :c => ['estimated_hours', 'subject'],
520 :c => ['estimated_hours', 'subject'],
521 :format => 'csv',
521 :format => 'csv',
522 :set_filter => 1
522 :set_filter => 1
523 assert_equal 'text/csv; header=present', @response.content_type
523 assert_equal 'text/csv; header=present', @response.content_type
524 lines = @response.body.chomp.split("\n")
524 lines = @response.body.chomp.split("\n")
525 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
525 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
526 end
526 end
527 end
527 end
528
528
529 def test_index_pdf
529 def test_index_pdf
530 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
530 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
531 with_settings :default_language => lang do
531 with_settings :default_language => lang do
532
532
533 get :index
533 get :index
534 assert_response :success
534 assert_response :success
535 assert_template 'index'
535 assert_template 'index'
536
536
537 if lang == "ja"
537 if lang == "ja"
538 if RUBY_PLATFORM != 'java'
538 if RUBY_PLATFORM != 'java'
539 assert_equal "CP932", l(:general_pdf_encoding)
539 assert_equal "CP932", l(:general_pdf_encoding)
540 end
540 end
541 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
541 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
542 next
542 next
543 end
543 end
544 end
544 end
545
545
546 get :index, :format => 'pdf'
546 get :index, :format => 'pdf'
547 assert_response :success
547 assert_response :success
548 assert_not_nil assigns(:issues)
548 assert_not_nil assigns(:issues)
549 assert_equal 'application/pdf', @response.content_type
549 assert_equal 'application/pdf', @response.content_type
550
550
551 get :index, :project_id => 1, :format => 'pdf'
551 get :index, :project_id => 1, :format => 'pdf'
552 assert_response :success
552 assert_response :success
553 assert_not_nil assigns(:issues)
553 assert_not_nil assigns(:issues)
554 assert_equal 'application/pdf', @response.content_type
554 assert_equal 'application/pdf', @response.content_type
555
555
556 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
556 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
557 assert_response :success
557 assert_response :success
558 assert_not_nil assigns(:issues)
558 assert_not_nil assigns(:issues)
559 assert_equal 'application/pdf', @response.content_type
559 assert_equal 'application/pdf', @response.content_type
560 end
560 end
561 end
561 end
562 end
562 end
563
563
564 def test_index_pdf_with_query_grouped_by_list_custom_field
564 def test_index_pdf_with_query_grouped_by_list_custom_field
565 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
565 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
566 assert_response :success
566 assert_response :success
567 assert_not_nil assigns(:issues)
567 assert_not_nil assigns(:issues)
568 assert_not_nil assigns(:issue_count_by_group)
568 assert_not_nil assigns(:issue_count_by_group)
569 assert_equal 'application/pdf', @response.content_type
569 assert_equal 'application/pdf', @response.content_type
570 end
570 end
571
571
572 def test_index_atom
572 def test_index_atom
573 get :index, :project_id => 'ecookbook', :format => 'atom'
573 get :index, :project_id => 'ecookbook', :format => 'atom'
574 assert_response :success
574 assert_response :success
575 assert_template 'common/feed'
575 assert_template 'common/feed'
576 assert_equal 'application/atom+xml', response.content_type
576 assert_equal 'application/atom+xml', response.content_type
577
577
578 assert_select 'feed' do
578 assert_select 'feed' do
579 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
579 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
580 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
580 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
581 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
581 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
582 end
582 end
583 end
583 end
584
584
585 def test_index_sort
585 def test_index_sort
586 get :index, :sort => 'tracker,id:desc'
586 get :index, :sort => 'tracker,id:desc'
587 assert_response :success
587 assert_response :success
588
588
589 sort_params = @request.session['issues_index_sort']
589 sort_params = @request.session['issues_index_sort']
590 assert sort_params.is_a?(String)
590 assert sort_params.is_a?(String)
591 assert_equal 'tracker,id:desc', sort_params
591 assert_equal 'tracker,id:desc', sort_params
592
592
593 issues = assigns(:issues)
593 issues = assigns(:issues)
594 assert_not_nil issues
594 assert_not_nil issues
595 assert !issues.empty?
595 assert !issues.empty?
596 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
596 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
597 end
597 end
598
598
599 def test_index_sort_by_field_not_included_in_columns
599 def test_index_sort_by_field_not_included_in_columns
600 Setting.issue_list_default_columns = %w(subject author)
600 Setting.issue_list_default_columns = %w(subject author)
601 get :index, :sort => 'tracker'
601 get :index, :sort => 'tracker'
602 end
602 end
603
603
604 def test_index_sort_by_assigned_to
604 def test_index_sort_by_assigned_to
605 get :index, :sort => 'assigned_to'
605 get :index, :sort => 'assigned_to'
606 assert_response :success
606 assert_response :success
607 assignees = assigns(:issues).collect(&:assigned_to).compact
607 assignees = assigns(:issues).collect(&:assigned_to).compact
608 assert_equal assignees.sort, assignees
608 assert_equal assignees.sort, assignees
609 end
609 end
610
610
611 def test_index_sort_by_assigned_to_desc
611 def test_index_sort_by_assigned_to_desc
612 get :index, :sort => 'assigned_to:desc'
612 get :index, :sort => 'assigned_to:desc'
613 assert_response :success
613 assert_response :success
614 assignees = assigns(:issues).collect(&:assigned_to).compact
614 assignees = assigns(:issues).collect(&:assigned_to).compact
615 assert_equal assignees.sort.reverse, assignees
615 assert_equal assignees.sort.reverse, assignees
616 end
616 end
617
617
618 def test_index_group_by_assigned_to
618 def test_index_group_by_assigned_to
619 get :index, :group_by => 'assigned_to', :sort => 'priority'
619 get :index, :group_by => 'assigned_to', :sort => 'priority'
620 assert_response :success
620 assert_response :success
621 end
621 end
622
622
623 def test_index_sort_by_author
623 def test_index_sort_by_author
624 get :index, :sort => 'author'
624 get :index, :sort => 'author'
625 assert_response :success
625 assert_response :success
626 authors = assigns(:issues).collect(&:author)
626 authors = assigns(:issues).collect(&:author)
627 assert_equal authors.sort, authors
627 assert_equal authors.sort, authors
628 end
628 end
629
629
630 def test_index_sort_by_author_desc
630 def test_index_sort_by_author_desc
631 get :index, :sort => 'author:desc'
631 get :index, :sort => 'author:desc'
632 assert_response :success
632 assert_response :success
633 authors = assigns(:issues).collect(&:author)
633 authors = assigns(:issues).collect(&:author)
634 assert_equal authors.sort.reverse, authors
634 assert_equal authors.sort.reverse, authors
635 end
635 end
636
636
637 def test_index_group_by_author
637 def test_index_group_by_author
638 get :index, :group_by => 'author', :sort => 'priority'
638 get :index, :group_by => 'author', :sort => 'priority'
639 assert_response :success
639 assert_response :success
640 end
640 end
641
641
642 def test_index_sort_by_spent_hours
642 def test_index_sort_by_spent_hours
643 get :index, :sort => 'spent_hours:desc'
643 get :index, :sort => 'spent_hours:desc'
644 assert_response :success
644 assert_response :success
645 hours = assigns(:issues).collect(&:spent_hours)
645 hours = assigns(:issues).collect(&:spent_hours)
646 assert_equal hours.sort.reverse, hours
646 assert_equal hours.sort.reverse, hours
647 end
647 end
648
648
649 def test_index_sort_by_user_custom_field
649 def test_index_sort_by_user_custom_field
650 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
650 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
651 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
651 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
652 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
652 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
653 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
653 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
654 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
654 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
655
655
656 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
656 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
657 assert_response :success
657 assert_response :success
658
658
659 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
659 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
660 end
660 end
661
661
662 def test_index_with_columns
662 def test_index_with_columns
663 columns = ['tracker', 'subject', 'assigned_to']
663 columns = ['tracker', 'subject', 'assigned_to']
664 get :index, :set_filter => 1, :c => columns
664 get :index, :set_filter => 1, :c => columns
665 assert_response :success
665 assert_response :success
666
666
667 # query should use specified columns
667 # query should use specified columns
668 query = assigns(:query)
668 query = assigns(:query)
669 assert_kind_of Query, query
669 assert_kind_of Query, query
670 assert_equal columns, query.column_names.map(&:to_s)
670 assert_equal columns, query.column_names.map(&:to_s)
671
671
672 # columns should be stored in session
672 # columns should be stored in session
673 assert_kind_of Hash, session[:query]
673 assert_kind_of Hash, session[:query]
674 assert_kind_of Array, session[:query][:column_names]
674 assert_kind_of Array, session[:query][:column_names]
675 assert_equal columns, session[:query][:column_names].map(&:to_s)
675 assert_equal columns, session[:query][:column_names].map(&:to_s)
676
676
677 # ensure only these columns are kept in the selected columns list
677 # ensure only these columns are kept in the selected columns list
678 assert_select 'select#selected_columns option' do
678 assert_select 'select#selected_columns option' do
679 assert_select 'option', 3
679 assert_select 'option', 3
680 assert_select 'option[value=tracker]'
680 assert_select 'option[value=tracker]'
681 assert_select 'option[value=project]', 0
681 assert_select 'option[value=project]', 0
682 end
682 end
683 end
683 end
684
684
685 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
685 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
686 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
686 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
687 get :index, :set_filter => 1
687 get :index, :set_filter => 1
688
688
689 # query should use specified columns
689 # query should use specified columns
690 query = assigns(:query)
690 query = assigns(:query)
691 assert_kind_of Query, query
691 assert_kind_of Query, query
692 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
692 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
693 end
693 end
694
694
695 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
695 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
696 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
696 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
697 columns = ['tracker', 'subject', 'assigned_to']
697 columns = ['tracker', 'subject', 'assigned_to']
698 get :index, :set_filter => 1, :c => columns
698 get :index, :set_filter => 1, :c => columns
699
699
700 # query should use specified columns
700 # query should use specified columns
701 query = assigns(:query)
701 query = assigns(:query)
702 assert_kind_of Query, query
702 assert_kind_of Query, query
703 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
703 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
704 end
704 end
705
705
706 def test_index_with_custom_field_column
706 def test_index_with_custom_field_column
707 columns = %w(tracker subject cf_2)
707 columns = %w(tracker subject cf_2)
708 get :index, :set_filter => 1, :c => columns
708 get :index, :set_filter => 1, :c => columns
709 assert_response :success
709 assert_response :success
710
710
711 # query should use specified columns
711 # query should use specified columns
712 query = assigns(:query)
712 query = assigns(:query)
713 assert_kind_of Query, query
713 assert_kind_of Query, query
714 assert_equal columns, query.column_names.map(&:to_s)
714 assert_equal columns, query.column_names.map(&:to_s)
715
715
716 assert_select 'table.issues td.cf_2.string'
716 assert_select 'table.issues td.cf_2.string'
717 end
717 end
718
718
719 def test_index_with_multi_custom_field_column
719 def test_index_with_multi_custom_field_column
720 field = CustomField.find(1)
720 field = CustomField.find(1)
721 field.update_attribute :multiple, true
721 field.update_attribute :multiple, true
722 issue = Issue.find(1)
722 issue = Issue.find(1)
723 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
723 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
724 issue.save!
724 issue.save!
725
725
726 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
726 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
727 assert_response :success
727 assert_response :success
728
728
729 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
729 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
730 end
730 end
731
731
732 def test_index_with_multi_user_custom_field_column
732 def test_index_with_multi_user_custom_field_column
733 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
733 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
734 :tracker_ids => [1], :is_for_all => true)
734 :tracker_ids => [1], :is_for_all => true)
735 issue = Issue.find(1)
735 issue = Issue.find(1)
736 issue.custom_field_values = {field.id => ['2', '3']}
736 issue.custom_field_values = {field.id => ['2', '3']}
737 issue.save!
737 issue.save!
738
738
739 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
739 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
740 assert_response :success
740 assert_response :success
741
741
742 assert_select "table.issues td.cf_#{field.id}" do
742 assert_select "table.issues td.cf_#{field.id}" do
743 assert_select 'a', 2
743 assert_select 'a', 2
744 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
744 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
745 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
745 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
746 end
746 end
747 end
747 end
748
748
749 def test_index_with_date_column
749 def test_index_with_date_column
750 with_settings :date_format => '%d/%m/%Y' do
750 with_settings :date_format => '%d/%m/%Y' do
751 Issue.find(1).update_attribute :start_date, '1987-08-24'
751 Issue.find(1).update_attribute :start_date, '1987-08-24'
752
752
753 get :index, :set_filter => 1, :c => %w(start_date)
753 get :index, :set_filter => 1, :c => %w(start_date)
754
754
755 assert_select "table.issues td.start_date", :text => '24/08/1987'
755 assert_select "table.issues td.start_date", :text => '24/08/1987'
756 end
756 end
757 end
757 end
758
758
759 def test_index_with_done_ratio_column
759 def test_index_with_done_ratio_column
760 Issue.find(1).update_attribute :done_ratio, 40
760 Issue.find(1).update_attribute :done_ratio, 40
761
761
762 get :index, :set_filter => 1, :c => %w(done_ratio)
762 get :index, :set_filter => 1, :c => %w(done_ratio)
763
763
764 assert_select 'table.issues td.done_ratio' do
764 assert_select 'table.issues td.done_ratio' do
765 assert_select 'table.progress' do
765 assert_select 'table.progress' do
766 assert_select 'td.closed[style=?]', 'width: 40%;'
766 assert_select 'td.closed[style=?]', 'width: 40%;'
767 end
767 end
768 end
768 end
769 end
769 end
770
770
771 def test_index_with_spent_hours_column
771 def test_index_with_spent_hours_column
772 get :index, :set_filter => 1, :c => %w(subject spent_hours)
772 get :index, :set_filter => 1, :c => %w(subject spent_hours)
773
773
774 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
774 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
775 end
775 end
776
776
777 def test_index_should_not_show_spent_hours_column_without_permission
777 def test_index_should_not_show_spent_hours_column_without_permission
778 Role.anonymous.remove_permission! :view_time_entries
778 Role.anonymous.remove_permission! :view_time_entries
779 get :index, :set_filter => 1, :c => %w(subject spent_hours)
779 get :index, :set_filter => 1, :c => %w(subject spent_hours)
780
780
781 assert_select 'td.spent_hours', 0
781 assert_select 'td.spent_hours', 0
782 end
782 end
783
783
784 def test_index_with_fixed_version_column
784 def test_index_with_fixed_version_column
785 get :index, :set_filter => 1, :c => %w(fixed_version)
785 get :index, :set_filter => 1, :c => %w(fixed_version)
786
786
787 assert_select 'table.issues td.fixed_version' do
787 assert_select 'table.issues td.fixed_version' do
788 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
788 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
789 end
789 end
790 end
790 end
791
791
792 def test_index_with_relations_column
792 def test_index_with_relations_column
793 IssueRelation.delete_all
793 IssueRelation.delete_all
794 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
794 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
795 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
795 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
796 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
796 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
797 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
797 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
798
798
799 get :index, :set_filter => 1, :c => %w(subject relations)
799 get :index, :set_filter => 1, :c => %w(subject relations)
800 assert_response :success
800 assert_response :success
801 assert_select "tr#issue-1 td.relations" do
801 assert_select "tr#issue-1 td.relations" do
802 assert_select "span", 3
802 assert_select "span", 3
803 assert_select "span", :text => "Related to #7"
803 assert_select "span", :text => "Related to #7"
804 assert_select "span", :text => "Related to #8"
804 assert_select "span", :text => "Related to #8"
805 assert_select "span", :text => "Blocks #11"
805 assert_select "span", :text => "Blocks #11"
806 end
806 end
807 assert_select "tr#issue-2 td.relations" do
807 assert_select "tr#issue-2 td.relations" do
808 assert_select "span", 1
808 assert_select "span", 1
809 assert_select "span", :text => "Blocked by #12"
809 assert_select "span", :text => "Blocked by #12"
810 end
810 end
811 assert_select "tr#issue-3 td.relations" do
811 assert_select "tr#issue-3 td.relations" do
812 assert_select "span", 0
812 assert_select "span", 0
813 end
813 end
814
814
815 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
815 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
816 assert_response :success
816 assert_response :success
817 assert_equal 'text/csv; header=present', response.content_type
817 assert_equal 'text/csv; header=present', response.content_type
818 lines = response.body.chomp.split("\n")
818 lines = response.body.chomp.split("\n")
819 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
819 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
820 assert_include '2,Blocked by #12', lines
820 assert_include '2,Blocked by #12', lines
821 assert_include '3,""', lines
821 assert_include '3,""', lines
822
822
823 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
823 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
824 assert_response :success
824 assert_response :success
825 assert_equal 'application/pdf', response.content_type
825 assert_equal 'application/pdf', response.content_type
826 end
826 end
827
827
828 def test_index_send_html_if_query_is_invalid
828 def test_index_send_html_if_query_is_invalid
829 get :index, :f => ['start_date'], :op => {:start_date => '='}
829 get :index, :f => ['start_date'], :op => {:start_date => '='}
830 assert_equal 'text/html', @response.content_type
830 assert_equal 'text/html', @response.content_type
831 assert_template 'index'
831 assert_template 'index'
832 end
832 end
833
833
834 def test_index_send_nothing_if_query_is_invalid
834 def test_index_send_nothing_if_query_is_invalid
835 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
835 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
836 assert_equal 'text/csv', @response.content_type
836 assert_equal 'text/csv', @response.content_type
837 assert @response.body.blank?
837 assert @response.body.blank?
838 end
838 end
839
839
840 def test_show_by_anonymous
840 def test_show_by_anonymous
841 get :show, :id => 1
841 get :show, :id => 1
842 assert_response :success
842 assert_response :success
843 assert_template 'show'
843 assert_template 'show'
844 assert_equal Issue.find(1), assigns(:issue)
844 assert_equal Issue.find(1), assigns(:issue)
845
845
846 assert_select 'div.issue div.description', :text => /Unable to print recipes/
846 assert_select 'div.issue div.description', :text => /Unable to print recipes/
847
847
848 # anonymous role is allowed to add a note
848 # anonymous role is allowed to add a note
849 assert_select 'form#issue-form' do
849 assert_select 'form#issue-form' do
850 assert_select 'fieldset' do
850 assert_select 'fieldset' do
851 assert_select 'legend', :text => 'Notes'
851 assert_select 'legend', :text => 'Notes'
852 assert_select 'textarea[name=?]', 'issue[notes]'
852 assert_select 'textarea[name=?]', 'issue[notes]'
853 end
853 end
854 end
854 end
855
855
856 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
856 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
857 end
857 end
858
858
859 def test_show_by_manager
859 def test_show_by_manager
860 @request.session[:user_id] = 2
860 @request.session[:user_id] = 2
861 get :show, :id => 1
861 get :show, :id => 1
862 assert_response :success
862 assert_response :success
863
863
864 assert_select 'a', :text => /Quote/
864 assert_select 'a', :text => /Quote/
865
865
866 assert_select 'form#issue-form' do
866 assert_select 'form#issue-form' do
867 assert_select 'fieldset' do
867 assert_select 'fieldset' do
868 assert_select 'legend', :text => 'Change properties'
868 assert_select 'legend', :text => 'Change properties'
869 assert_select 'input[name=?]', 'issue[subject]'
869 assert_select 'input[name=?]', 'issue[subject]'
870 end
870 end
871 assert_select 'fieldset' do
871 assert_select 'fieldset' do
872 assert_select 'legend', :text => 'Log time'
872 assert_select 'legend', :text => 'Log time'
873 assert_select 'input[name=?]', 'time_entry[hours]'
873 assert_select 'input[name=?]', 'time_entry[hours]'
874 end
874 end
875 assert_select 'fieldset' do
875 assert_select 'fieldset' do
876 assert_select 'legend', :text => 'Notes'
876 assert_select 'legend', :text => 'Notes'
877 assert_select 'textarea[name=?]', 'issue[notes]'
877 assert_select 'textarea[name=?]', 'issue[notes]'
878 end
878 end
879 end
879 end
880 end
880 end
881
881
882 def test_show_should_display_update_form
882 def test_show_should_display_update_form
883 @request.session[:user_id] = 2
883 @request.session[:user_id] = 2
884 get :show, :id => 1
884 get :show, :id => 1
885 assert_response :success
885 assert_response :success
886
886
887 assert_tag 'form', :attributes => {:id => 'issue-form'}
887 assert_tag 'form', :attributes => {:id => 'issue-form'}
888 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
888 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
889 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
889 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
890 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
890 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
891 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
891 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
892 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
892 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
893 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
893 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
894 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
894 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
895 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
895 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
896 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
896 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
897 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
897 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
898 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
898 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
899 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
899 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
900 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
900 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
901 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
901 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
902 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
902 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
903 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
903 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
904 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
904 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
905 end
905 end
906
906
907 def test_show_should_display_update_form_with_minimal_permissions
907 def test_show_should_display_update_form_with_minimal_permissions
908 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
908 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
909 WorkflowTransition.delete_all :role_id => 1
909 WorkflowTransition.delete_all :role_id => 1
910
910
911 @request.session[:user_id] = 2
911 @request.session[:user_id] = 2
912 get :show, :id => 1
912 get :show, :id => 1
913 assert_response :success
913 assert_response :success
914
914
915 assert_tag 'form', :attributes => {:id => 'issue-form'}
915 assert_tag 'form', :attributes => {:id => 'issue-form'}
916 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
916 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
917 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
917 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
918 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
918 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
919 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
919 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
920 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
920 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
921 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
921 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
922 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
922 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
923 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
923 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
924 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
924 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
925 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
925 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
926 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
926 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
927 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
927 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
928 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
928 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
929 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
929 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
930 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
930 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
931 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
931 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
932 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
932 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
933 end
933 end
934
934
935 def test_show_should_display_update_form_with_workflow_permissions
935 def test_show_should_display_update_form_with_workflow_permissions
936 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
936 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
937
937
938 @request.session[:user_id] = 2
938 @request.session[:user_id] = 2
939 get :show, :id => 1
939 get :show, :id => 1
940 assert_response :success
940 assert_response :success
941
941
942 assert_tag 'form', :attributes => {:id => 'issue-form'}
942 assert_tag 'form', :attributes => {:id => 'issue-form'}
943 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
943 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
944 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
944 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
945 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
945 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
946 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
946 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
947 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
947 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
948 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
948 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
949 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
949 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
950 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
950 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
951 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
951 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
952 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
952 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
953 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
953 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
954 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
954 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
955 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
955 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
956 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
956 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
957 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
957 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
958 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
958 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
959 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
959 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
960 end
960 end
961
961
962 def test_show_should_not_display_update_form_without_permissions
962 def test_show_should_not_display_update_form_without_permissions
963 Role.find(1).update_attribute :permissions, [:view_issues]
963 Role.find(1).update_attribute :permissions, [:view_issues]
964
964
965 @request.session[:user_id] = 2
965 @request.session[:user_id] = 2
966 get :show, :id => 1
966 get :show, :id => 1
967 assert_response :success
967 assert_response :success
968
968
969 assert_select 'form#issue-form', 0
969 assert_select 'form#issue-form', 0
970 end
970 end
971
971
972 def test_update_form_should_not_display_inactive_enumerations
972 def test_update_form_should_not_display_inactive_enumerations
973 assert !IssuePriority.find(15).active?
973 assert !IssuePriority.find(15).active?
974
974
975 @request.session[:user_id] = 2
975 @request.session[:user_id] = 2
976 get :show, :id => 1
976 get :show, :id => 1
977 assert_response :success
977 assert_response :success
978
978
979 assert_select 'form#issue-form' do
979 assert_select 'form#issue-form' do
980 assert_select 'select[name=?]', 'issue[priority_id]' do
980 assert_select 'select[name=?]', 'issue[priority_id]' do
981 assert_select 'option[value=4]'
981 assert_select 'option[value=4]'
982 assert_select 'option[value=15]', 0
982 assert_select 'option[value=15]', 0
983 end
983 end
984 end
984 end
985 end
985 end
986
986
987 def test_update_form_should_allow_attachment_upload
987 def test_update_form_should_allow_attachment_upload
988 @request.session[:user_id] = 2
988 @request.session[:user_id] = 2
989 get :show, :id => 1
989 get :show, :id => 1
990
990
991 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
991 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
992 assert_select 'input[type=file][name=?]', 'attachments[1][file]'
992 assert_select 'input[type=file][name=?]', 'attachments[1][file]'
993 end
993 end
994 end
994 end
995
995
996 def test_show_should_deny_anonymous_access_without_permission
996 def test_show_should_deny_anonymous_access_without_permission
997 Role.anonymous.remove_permission!(:view_issues)
997 Role.anonymous.remove_permission!(:view_issues)
998 get :show, :id => 1
998 get :show, :id => 1
999 assert_response :redirect
999 assert_response :redirect
1000 end
1000 end
1001
1001
1002 def test_show_should_deny_anonymous_access_to_private_issue
1002 def test_show_should_deny_anonymous_access_to_private_issue
1003 Issue.update_all(["is_private = ?", true], "id = 1")
1003 Issue.update_all(["is_private = ?", true], "id = 1")
1004 get :show, :id => 1
1004 get :show, :id => 1
1005 assert_response :redirect
1005 assert_response :redirect
1006 end
1006 end
1007
1007
1008 def test_show_should_deny_non_member_access_without_permission
1008 def test_show_should_deny_non_member_access_without_permission
1009 Role.non_member.remove_permission!(:view_issues)
1009 Role.non_member.remove_permission!(:view_issues)
1010 @request.session[:user_id] = 9
1010 @request.session[:user_id] = 9
1011 get :show, :id => 1
1011 get :show, :id => 1
1012 assert_response 403
1012 assert_response 403
1013 end
1013 end
1014
1014
1015 def test_show_should_deny_non_member_access_to_private_issue
1015 def test_show_should_deny_non_member_access_to_private_issue
1016 Issue.update_all(["is_private = ?", true], "id = 1")
1016 Issue.update_all(["is_private = ?", true], "id = 1")
1017 @request.session[:user_id] = 9
1017 @request.session[:user_id] = 9
1018 get :show, :id => 1
1018 get :show, :id => 1
1019 assert_response 403
1019 assert_response 403
1020 end
1020 end
1021
1021
1022 def test_show_should_deny_member_access_without_permission
1022 def test_show_should_deny_member_access_without_permission
1023 Role.find(1).remove_permission!(:view_issues)
1023 Role.find(1).remove_permission!(:view_issues)
1024 @request.session[:user_id] = 2
1024 @request.session[:user_id] = 2
1025 get :show, :id => 1
1025 get :show, :id => 1
1026 assert_response 403
1026 assert_response 403
1027 end
1027 end
1028
1028
1029 def test_show_should_deny_member_access_to_private_issue_without_permission
1029 def test_show_should_deny_member_access_to_private_issue_without_permission
1030 Issue.update_all(["is_private = ?", true], "id = 1")
1030 Issue.update_all(["is_private = ?", true], "id = 1")
1031 @request.session[:user_id] = 3
1031 @request.session[:user_id] = 3
1032 get :show, :id => 1
1032 get :show, :id => 1
1033 assert_response 403
1033 assert_response 403
1034 end
1034 end
1035
1035
1036 def test_show_should_allow_author_access_to_private_issue
1036 def test_show_should_allow_author_access_to_private_issue
1037 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
1037 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
1038 @request.session[:user_id] = 3
1038 @request.session[:user_id] = 3
1039 get :show, :id => 1
1039 get :show, :id => 1
1040 assert_response :success
1040 assert_response :success
1041 end
1041 end
1042
1042
1043 def test_show_should_allow_assignee_access_to_private_issue
1043 def test_show_should_allow_assignee_access_to_private_issue
1044 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
1044 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
1045 @request.session[:user_id] = 3
1045 @request.session[:user_id] = 3
1046 get :show, :id => 1
1046 get :show, :id => 1
1047 assert_response :success
1047 assert_response :success
1048 end
1048 end
1049
1049
1050 def test_show_should_allow_member_access_to_private_issue_with_permission
1050 def test_show_should_allow_member_access_to_private_issue_with_permission
1051 Issue.update_all(["is_private = ?", true], "id = 1")
1051 Issue.update_all(["is_private = ?", true], "id = 1")
1052 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1052 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1053 @request.session[:user_id] = 3
1053 @request.session[:user_id] = 3
1054 get :show, :id => 1
1054 get :show, :id => 1
1055 assert_response :success
1055 assert_response :success
1056 end
1056 end
1057
1057
1058 def test_show_should_not_disclose_relations_to_invisible_issues
1058 def test_show_should_not_disclose_relations_to_invisible_issues
1059 Setting.cross_project_issue_relations = '1'
1059 Setting.cross_project_issue_relations = '1'
1060 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1060 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1061 # Relation to a private project issue
1061 # Relation to a private project issue
1062 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1062 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1063
1063
1064 get :show, :id => 1
1064 get :show, :id => 1
1065 assert_response :success
1065 assert_response :success
1066
1066
1067 assert_select 'div#relations' do
1067 assert_select 'div#relations' do
1068 assert_select 'a', :text => /#2$/
1068 assert_select 'a', :text => /#2$/
1069 assert_select 'a', :text => /#4$/, :count => 0
1069 assert_select 'a', :text => /#4$/, :count => 0
1070 end
1070 end
1071 end
1071 end
1072
1072
1073 def test_show_should_list_subtasks
1073 def test_show_should_list_subtasks
1074 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1074 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1075
1075
1076 get :show, :id => 1
1076 get :show, :id => 1
1077 assert_response :success
1077 assert_response :success
1078
1078
1079 assert_select 'div#issue_tree' do
1079 assert_select 'div#issue_tree' do
1080 assert_select 'td.subject', :text => /Child Issue/
1080 assert_select 'td.subject', :text => /Child Issue/
1081 end
1081 end
1082 end
1082 end
1083
1083
1084 def test_show_should_list_parents
1084 def test_show_should_list_parents
1085 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1085 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1086
1086
1087 get :show, :id => issue.id
1087 get :show, :id => issue.id
1088 assert_response :success
1088 assert_response :success
1089
1089
1090 assert_select 'div.subject' do
1090 assert_select 'div.subject' do
1091 assert_select 'h3', 'Child Issue'
1091 assert_select 'h3', 'Child Issue'
1092 assert_select 'a[href=/issues/1]'
1092 assert_select 'a[href=/issues/1]'
1093 end
1093 end
1094 end
1094 end
1095
1095
1096 def test_show_should_not_display_prev_next_links_without_query_in_session
1096 def test_show_should_not_display_prev_next_links_without_query_in_session
1097 get :show, :id => 1
1097 get :show, :id => 1
1098 assert_response :success
1098 assert_response :success
1099 assert_nil assigns(:prev_issue_id)
1099 assert_nil assigns(:prev_issue_id)
1100 assert_nil assigns(:next_issue_id)
1100 assert_nil assigns(:next_issue_id)
1101
1101
1102 assert_select 'div.next-prev-links', 0
1102 assert_select 'div.next-prev-links', 0
1103 end
1103 end
1104
1104
1105 def test_show_should_display_prev_next_links_with_query_in_session
1105 def test_show_should_display_prev_next_links_with_query_in_session
1106 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1106 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1107 @request.session['issues_index_sort'] = 'id'
1107 @request.session['issues_index_sort'] = 'id'
1108
1108
1109 with_settings :display_subprojects_issues => '0' do
1109 with_settings :display_subprojects_issues => '0' do
1110 get :show, :id => 3
1110 get :show, :id => 3
1111 end
1111 end
1112
1112
1113 assert_response :success
1113 assert_response :success
1114 # Previous and next issues for all projects
1114 # Previous and next issues for all projects
1115 assert_equal 2, assigns(:prev_issue_id)
1115 assert_equal 2, assigns(:prev_issue_id)
1116 assert_equal 5, assigns(:next_issue_id)
1116 assert_equal 5, assigns(:next_issue_id)
1117
1117
1118 count = Issue.open.visible.count
1118 count = Issue.open.visible.count
1119
1119
1120 assert_select 'div.next-prev-links' do
1120 assert_select 'div.next-prev-links' do
1121 assert_select 'a[href=/issues/2]', :text => /Previous/
1121 assert_select 'a[href=/issues/2]', :text => /Previous/
1122 assert_select 'a[href=/issues/5]', :text => /Next/
1122 assert_select 'a[href=/issues/5]', :text => /Next/
1123 assert_select 'span.position', :text => "3 of #{count}"
1123 assert_select 'span.position', :text => "3 of #{count}"
1124 end
1124 end
1125 end
1125 end
1126
1126
1127 def test_show_should_display_prev_next_links_with_saved_query_in_session
1127 def test_show_should_display_prev_next_links_with_saved_query_in_session
1128 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1128 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1129 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1129 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1130 :sort_criteria => [['id', 'asc']])
1130 :sort_criteria => [['id', 'asc']])
1131 @request.session[:query] = {:id => query.id, :project_id => nil}
1131 @request.session[:query] = {:id => query.id, :project_id => nil}
1132
1132
1133 get :show, :id => 11
1133 get :show, :id => 11
1134
1134
1135 assert_response :success
1135 assert_response :success
1136 assert_equal query, assigns(:query)
1136 assert_equal query, assigns(:query)
1137 # Previous and next issues for all projects
1137 # Previous and next issues for all projects
1138 assert_equal 8, assigns(:prev_issue_id)
1138 assert_equal 8, assigns(:prev_issue_id)
1139 assert_equal 12, assigns(:next_issue_id)
1139 assert_equal 12, assigns(:next_issue_id)
1140
1140
1141 assert_select 'div.next-prev-links' do
1141 assert_select 'div.next-prev-links' do
1142 assert_select 'a[href=/issues/8]', :text => /Previous/
1142 assert_select 'a[href=/issues/8]', :text => /Previous/
1143 assert_select 'a[href=/issues/12]', :text => /Next/
1143 assert_select 'a[href=/issues/12]', :text => /Next/
1144 end
1144 end
1145 end
1145 end
1146
1146
1147 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1147 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1148 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1148 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1149
1149
1150 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1150 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1151 @request.session['issues_index_sort'] = assoc_sort
1151 @request.session['issues_index_sort'] = assoc_sort
1152
1152
1153 get :show, :id => 3
1153 get :show, :id => 3
1154 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1154 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1155
1155
1156 assert_select 'div.next-prev-links' do
1156 assert_select 'div.next-prev-links' do
1157 assert_select 'a', :text => /(Previous|Next)/
1157 assert_select 'a', :text => /(Previous|Next)/
1158 end
1158 end
1159 end
1159 end
1160 end
1160 end
1161
1161
1162 def test_show_should_display_prev_next_links_with_project_query_in_session
1162 def test_show_should_display_prev_next_links_with_project_query_in_session
1163 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1163 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1164 @request.session['issues_index_sort'] = 'id'
1164 @request.session['issues_index_sort'] = 'id'
1165
1165
1166 with_settings :display_subprojects_issues => '0' do
1166 with_settings :display_subprojects_issues => '0' do
1167 get :show, :id => 3
1167 get :show, :id => 3
1168 end
1168 end
1169
1169
1170 assert_response :success
1170 assert_response :success
1171 # Previous and next issues inside project
1171 # Previous and next issues inside project
1172 assert_equal 2, assigns(:prev_issue_id)
1172 assert_equal 2, assigns(:prev_issue_id)
1173 assert_equal 7, assigns(:next_issue_id)
1173 assert_equal 7, assigns(:next_issue_id)
1174
1174
1175 assert_select 'div.next-prev-links' do
1175 assert_select 'div.next-prev-links' do
1176 assert_select 'a[href=/issues/2]', :text => /Previous/
1176 assert_select 'a[href=/issues/2]', :text => /Previous/
1177 assert_select 'a[href=/issues/7]', :text => /Next/
1177 assert_select 'a[href=/issues/7]', :text => /Next/
1178 end
1178 end
1179 end
1179 end
1180
1180
1181 def test_show_should_not_display_prev_link_for_first_issue
1181 def test_show_should_not_display_prev_link_for_first_issue
1182 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1182 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1183 @request.session['issues_index_sort'] = 'id'
1183 @request.session['issues_index_sort'] = 'id'
1184
1184
1185 with_settings :display_subprojects_issues => '0' do
1185 with_settings :display_subprojects_issues => '0' do
1186 get :show, :id => 1
1186 get :show, :id => 1
1187 end
1187 end
1188
1188
1189 assert_response :success
1189 assert_response :success
1190 assert_nil assigns(:prev_issue_id)
1190 assert_nil assigns(:prev_issue_id)
1191 assert_equal 2, assigns(:next_issue_id)
1191 assert_equal 2, assigns(:next_issue_id)
1192
1192
1193 assert_select 'div.next-prev-links' do
1193 assert_select 'div.next-prev-links' do
1194 assert_select 'a', :text => /Previous/, :count => 0
1194 assert_select 'a', :text => /Previous/, :count => 0
1195 assert_select 'a[href=/issues/2]', :text => /Next/
1195 assert_select 'a[href=/issues/2]', :text => /Next/
1196 end
1196 end
1197 end
1197 end
1198
1198
1199 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1199 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1200 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1200 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1201 @request.session['issues_index_sort'] = 'id'
1201 @request.session['issues_index_sort'] = 'id'
1202
1202
1203 get :show, :id => 1
1203 get :show, :id => 1
1204
1204
1205 assert_response :success
1205 assert_response :success
1206 assert_nil assigns(:prev_issue_id)
1206 assert_nil assigns(:prev_issue_id)
1207 assert_nil assigns(:next_issue_id)
1207 assert_nil assigns(:next_issue_id)
1208
1208
1209 assert_select 'a', :text => /Previous/, :count => 0
1209 assert_select 'a', :text => /Previous/, :count => 0
1210 assert_select 'a', :text => /Next/, :count => 0
1210 assert_select 'a', :text => /Next/, :count => 0
1211 end
1211 end
1212
1212
1213 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1213 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1214 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1214 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1215 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1215 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1216 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1216 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1217 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1217 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1218 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1218 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1219
1219
1220 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {},
1220 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {},
1221 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1221 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1222 @request.session[:query] = {:id => query.id, :project_id => nil}
1222 @request.session[:query] = {:id => query.id, :project_id => nil}
1223
1223
1224 get :show, :id => 3
1224 get :show, :id => 3
1225 assert_response :success
1225 assert_response :success
1226
1226
1227 assert_equal 2, assigns(:prev_issue_id)
1227 assert_equal 2, assigns(:prev_issue_id)
1228 assert_equal 1, assigns(:next_issue_id)
1228 assert_equal 1, assigns(:next_issue_id)
1229
1229
1230 assert_select 'div.next-prev-links' do
1230 assert_select 'div.next-prev-links' do
1231 assert_select 'a[href=/issues/2]', :text => /Previous/
1231 assert_select 'a[href=/issues/2]', :text => /Previous/
1232 assert_select 'a[href=/issues/1]', :text => /Next/
1232 assert_select 'a[href=/issues/1]', :text => /Next/
1233 end
1233 end
1234 end
1234 end
1235
1235
1236 def test_show_should_display_link_to_the_assignee
1236 def test_show_should_display_link_to_the_assignee
1237 get :show, :id => 2
1237 get :show, :id => 2
1238 assert_response :success
1238 assert_response :success
1239 assert_select '.assigned-to' do
1239 assert_select '.assigned-to' do
1240 assert_select 'a[href=/users/3]'
1240 assert_select 'a[href=/users/3]'
1241 end
1241 end
1242 end
1242 end
1243
1243
1244 def test_show_should_display_visible_changesets_from_other_projects
1244 def test_show_should_display_visible_changesets_from_other_projects
1245 project = Project.find(2)
1245 project = Project.find(2)
1246 issue = project.issues.first
1246 issue = project.issues.first
1247 issue.changeset_ids = [102]
1247 issue.changeset_ids = [102]
1248 issue.save!
1248 issue.save!
1249 # changesets from other projects should be displayed even if repository
1249 # changesets from other projects should be displayed even if repository
1250 # is disabled on issue's project
1250 # is disabled on issue's project
1251 project.disable_module! :repository
1251 project.disable_module! :repository
1252
1252
1253 @request.session[:user_id] = 2
1253 @request.session[:user_id] = 2
1254 get :show, :id => issue.id
1254 get :show, :id => issue.id
1255
1255
1256 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1256 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1257 end
1257 end
1258
1258
1259 def test_show_should_display_watchers
1259 def test_show_should_display_watchers
1260 @request.session[:user_id] = 2
1260 @request.session[:user_id] = 2
1261 Issue.find(1).add_watcher User.find(2)
1261 Issue.find(1).add_watcher User.find(2)
1262
1262
1263 get :show, :id => 1
1263 get :show, :id => 1
1264 assert_select 'div#watchers ul' do
1264 assert_select 'div#watchers ul' do
1265 assert_select 'li' do
1265 assert_select 'li' do
1266 assert_select 'a[href=/users/2]'
1266 assert_select 'a[href=/users/2]'
1267 assert_select 'a img[alt=Delete]'
1267 assert_select 'a img[alt=Delete]'
1268 end
1268 end
1269 end
1269 end
1270 end
1270 end
1271
1271
1272 def test_show_should_display_watchers_with_gravatars
1272 def test_show_should_display_watchers_with_gravatars
1273 @request.session[:user_id] = 2
1273 @request.session[:user_id] = 2
1274 Issue.find(1).add_watcher User.find(2)
1274 Issue.find(1).add_watcher User.find(2)
1275
1275
1276 with_settings :gravatar_enabled => '1' do
1276 with_settings :gravatar_enabled => '1' do
1277 get :show, :id => 1
1277 get :show, :id => 1
1278 end
1278 end
1279
1279
1280 assert_select 'div#watchers ul' do
1280 assert_select 'div#watchers ul' do
1281 assert_select 'li' do
1281 assert_select 'li' do
1282 assert_select 'img.gravatar'
1282 assert_select 'img.gravatar'
1283 assert_select 'a[href=/users/2]'
1283 assert_select 'a[href=/users/2]'
1284 assert_select 'a img[alt=Delete]'
1284 assert_select 'a img[alt=Delete]'
1285 end
1285 end
1286 end
1286 end
1287 end
1287 end
1288
1288
1289 def test_show_with_thumbnails_enabled_should_display_thumbnails
1289 def test_show_with_thumbnails_enabled_should_display_thumbnails
1290 @request.session[:user_id] = 2
1290 @request.session[:user_id] = 2
1291
1291
1292 with_settings :thumbnails_enabled => '1' do
1292 with_settings :thumbnails_enabled => '1' do
1293 get :show, :id => 14
1293 get :show, :id => 14
1294 assert_response :success
1294 assert_response :success
1295 end
1295 end
1296
1296
1297 assert_select 'div.thumbnails' do
1297 assert_select 'div.thumbnails' do
1298 assert_select 'a[href=/attachments/16/testfile.png]' do
1298 assert_select 'a[href=/attachments/16/testfile.png]' do
1299 assert_select 'img[src=/attachments/thumbnail/16]'
1299 assert_select 'img[src=/attachments/thumbnail/16]'
1300 end
1300 end
1301 end
1301 end
1302 end
1302 end
1303
1303
1304 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1304 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1305 @request.session[:user_id] = 2
1305 @request.session[:user_id] = 2
1306
1306
1307 with_settings :thumbnails_enabled => '0' do
1307 with_settings :thumbnails_enabled => '0' do
1308 get :show, :id => 14
1308 get :show, :id => 14
1309 assert_response :success
1309 assert_response :success
1310 end
1310 end
1311
1311
1312 assert_select 'div.thumbnails', 0
1312 assert_select 'div.thumbnails', 0
1313 end
1313 end
1314
1314
1315 def test_show_with_multi_custom_field
1315 def test_show_with_multi_custom_field
1316 field = CustomField.find(1)
1316 field = CustomField.find(1)
1317 field.update_attribute :multiple, true
1317 field.update_attribute :multiple, true
1318 issue = Issue.find(1)
1318 issue = Issue.find(1)
1319 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1319 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1320 issue.save!
1320 issue.save!
1321
1321
1322 get :show, :id => 1
1322 get :show, :id => 1
1323 assert_response :success
1323 assert_response :success
1324
1324
1325 assert_select 'td', :text => 'MySQL, Oracle'
1325 assert_select 'td', :text => 'MySQL, Oracle'
1326 end
1326 end
1327
1327
1328 def test_show_with_multi_user_custom_field
1328 def test_show_with_multi_user_custom_field
1329 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1329 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1330 :tracker_ids => [1], :is_for_all => true)
1330 :tracker_ids => [1], :is_for_all => true)
1331 issue = Issue.find(1)
1331 issue = Issue.find(1)
1332 issue.custom_field_values = {field.id => ['2', '3']}
1332 issue.custom_field_values = {field.id => ['2', '3']}
1333 issue.save!
1333 issue.save!
1334
1334
1335 get :show, :id => 1
1335 get :show, :id => 1
1336 assert_response :success
1336 assert_response :success
1337
1337
1338 # TODO: should display links
1338 # TODO: should display links
1339 assert_select 'td', :text => 'Dave Lopper, John Smith'
1339 assert_select 'td', :text => 'Dave Lopper, John Smith'
1340 end
1340 end
1341
1341
1342 def test_show_should_display_private_notes_with_permission_only
1342 def test_show_should_display_private_notes_with_permission_only
1343 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1343 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1344 @request.session[:user_id] = 2
1344 @request.session[:user_id] = 2
1345
1345
1346 get :show, :id => 2
1346 get :show, :id => 2
1347 assert_response :success
1347 assert_response :success
1348 assert_include journal, assigns(:journals)
1348 assert_include journal, assigns(:journals)
1349
1349
1350 Role.find(1).remove_permission! :view_private_notes
1350 Role.find(1).remove_permission! :view_private_notes
1351 get :show, :id => 2
1351 get :show, :id => 2
1352 assert_response :success
1352 assert_response :success
1353 assert_not_include journal, assigns(:journals)
1353 assert_not_include journal, assigns(:journals)
1354 end
1354 end
1355
1355
1356 def test_show_atom
1356 def test_show_atom
1357 get :show, :id => 2, :format => 'atom'
1357 get :show, :id => 2, :format => 'atom'
1358 assert_response :success
1358 assert_response :success
1359 assert_template 'journals/index'
1359 assert_template 'journals/index'
1360 # Inline image
1360 # Inline image
1361 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1361 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1362 end
1362 end
1363
1363
1364 def test_show_export_to_pdf
1364 def test_show_export_to_pdf
1365 get :show, :id => 3, :format => 'pdf'
1365 get :show, :id => 3, :format => 'pdf'
1366 assert_response :success
1366 assert_response :success
1367 assert_equal 'application/pdf', @response.content_type
1367 assert_equal 'application/pdf', @response.content_type
1368 assert @response.body.starts_with?('%PDF')
1368 assert @response.body.starts_with?('%PDF')
1369 assert_not_nil assigns(:issue)
1369 assert_not_nil assigns(:issue)
1370 end
1370 end
1371
1371
1372 def test_show_export_to_pdf_with_ancestors
1372 def test_show_export_to_pdf_with_ancestors
1373 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1373 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1374
1374
1375 get :show, :id => issue.id, :format => 'pdf'
1375 get :show, :id => issue.id, :format => 'pdf'
1376 assert_response :success
1376 assert_response :success
1377 assert_equal 'application/pdf', @response.content_type
1377 assert_equal 'application/pdf', @response.content_type
1378 assert @response.body.starts_with?('%PDF')
1378 assert @response.body.starts_with?('%PDF')
1379 end
1379 end
1380
1380
1381 def test_show_export_to_pdf_with_descendants
1381 def test_show_export_to_pdf_with_descendants
1382 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1382 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1383 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1383 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1384 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1384 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1385
1385
1386 get :show, :id => 1, :format => 'pdf'
1386 get :show, :id => 1, :format => 'pdf'
1387 assert_response :success
1387 assert_response :success
1388 assert_equal 'application/pdf', @response.content_type
1388 assert_equal 'application/pdf', @response.content_type
1389 assert @response.body.starts_with?('%PDF')
1389 assert @response.body.starts_with?('%PDF')
1390 end
1390 end
1391
1391
1392 def test_show_export_to_pdf_with_journals
1392 def test_show_export_to_pdf_with_journals
1393 get :show, :id => 1, :format => 'pdf'
1393 get :show, :id => 1, :format => 'pdf'
1394 assert_response :success
1394 assert_response :success
1395 assert_equal 'application/pdf', @response.content_type
1395 assert_equal 'application/pdf', @response.content_type
1396 assert @response.body.starts_with?('%PDF')
1396 assert @response.body.starts_with?('%PDF')
1397 end
1397 end
1398
1398
1399 def test_show_export_to_pdf_with_changesets
1399 def test_show_export_to_pdf_with_changesets
1400 Issue.find(3).changesets = Changeset.find_all_by_id(100, 101, 102)
1400 Issue.find(3).changesets = Changeset.find_all_by_id(100, 101, 102)
1401
1401
1402 get :show, :id => 3, :format => 'pdf'
1402 get :show, :id => 3, :format => 'pdf'
1403 assert_response :success
1403 assert_response :success
1404 assert_equal 'application/pdf', @response.content_type
1404 assert_equal 'application/pdf', @response.content_type
1405 assert @response.body.starts_with?('%PDF')
1405 assert @response.body.starts_with?('%PDF')
1406 end
1406 end
1407
1407
1408 def test_show_invalid_should_respond_with_404
1409 get :show, :id => 999
1410 assert_response 404
1411 end
1412
1408 def test_get_new
1413 def test_get_new
1409 @request.session[:user_id] = 2
1414 @request.session[:user_id] = 2
1410 get :new, :project_id => 1, :tracker_id => 1
1415 get :new, :project_id => 1, :tracker_id => 1
1411 assert_response :success
1416 assert_response :success
1412 assert_template 'new'
1417 assert_template 'new'
1413
1418
1414 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1419 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1415 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1420 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1416 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1421 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1417 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1422 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1418 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1423 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1419 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1424 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1420 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1425 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1421 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1426 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1422 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1427 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1423 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1428 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1424 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1429 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1425 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1430 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1426 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1431 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1427 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1432 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1428 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1433 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1429 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1434 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1430
1435
1431 # Be sure we don't display inactive IssuePriorities
1436 # Be sure we don't display inactive IssuePriorities
1432 assert ! IssuePriority.find(15).active?
1437 assert ! IssuePriority.find(15).active?
1433 assert_no_tag :option, :attributes => {:value => '15'},
1438 assert_no_tag :option, :attributes => {:value => '15'},
1434 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1439 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1435 end
1440 end
1436
1441
1437 def test_get_new_with_minimal_permissions
1442 def test_get_new_with_minimal_permissions
1438 Role.find(1).update_attribute :permissions, [:add_issues]
1443 Role.find(1).update_attribute :permissions, [:add_issues]
1439 WorkflowTransition.delete_all :role_id => 1
1444 WorkflowTransition.delete_all :role_id => 1
1440
1445
1441 @request.session[:user_id] = 2
1446 @request.session[:user_id] = 2
1442 get :new, :project_id => 1, :tracker_id => 1
1447 get :new, :project_id => 1, :tracker_id => 1
1443 assert_response :success
1448 assert_response :success
1444 assert_template 'new'
1449 assert_template 'new'
1445
1450
1446 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1451 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1447 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1452 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1448 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1453 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1449 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1454 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1450 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1455 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1451 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1456 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1452 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1457 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1453 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1458 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1454 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1459 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1455 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1460 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1456 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1461 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1457 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1462 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1458 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1463 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1459 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1464 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1460 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1465 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1461 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1466 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1462 end
1467 end
1463
1468
1464 def test_get_new_with_list_custom_field
1469 def test_get_new_with_list_custom_field
1465 @request.session[:user_id] = 2
1470 @request.session[:user_id] = 2
1466 get :new, :project_id => 1, :tracker_id => 1
1471 get :new, :project_id => 1, :tracker_id => 1
1467 assert_response :success
1472 assert_response :success
1468 assert_template 'new'
1473 assert_template 'new'
1469
1474
1470 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1475 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1471 assert_select 'option', 4
1476 assert_select 'option', 4
1472 assert_select 'option[value=MySQL]', :text => 'MySQL'
1477 assert_select 'option[value=MySQL]', :text => 'MySQL'
1473 end
1478 end
1474 end
1479 end
1475
1480
1476 def test_get_new_with_multi_custom_field
1481 def test_get_new_with_multi_custom_field
1477 field = IssueCustomField.find(1)
1482 field = IssueCustomField.find(1)
1478 field.update_attribute :multiple, true
1483 field.update_attribute :multiple, true
1479
1484
1480 @request.session[:user_id] = 2
1485 @request.session[:user_id] = 2
1481 get :new, :project_id => 1, :tracker_id => 1
1486 get :new, :project_id => 1, :tracker_id => 1
1482 assert_response :success
1487 assert_response :success
1483 assert_template 'new'
1488 assert_template 'new'
1484
1489
1485 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1490 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1486 assert_select 'option', 3
1491 assert_select 'option', 3
1487 assert_select 'option[value=MySQL]', :text => 'MySQL'
1492 assert_select 'option[value=MySQL]', :text => 'MySQL'
1488 end
1493 end
1489 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1494 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1490 end
1495 end
1491
1496
1492 def test_get_new_with_multi_user_custom_field
1497 def test_get_new_with_multi_user_custom_field
1493 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1498 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1494 :tracker_ids => [1], :is_for_all => true)
1499 :tracker_ids => [1], :is_for_all => true)
1495
1500
1496 @request.session[:user_id] = 2
1501 @request.session[:user_id] = 2
1497 get :new, :project_id => 1, :tracker_id => 1
1502 get :new, :project_id => 1, :tracker_id => 1
1498 assert_response :success
1503 assert_response :success
1499 assert_template 'new'
1504 assert_template 'new'
1500
1505
1501 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1506 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1502 assert_select 'option', Project.find(1).users.count
1507 assert_select 'option', Project.find(1).users.count
1503 assert_select 'option[value=2]', :text => 'John Smith'
1508 assert_select 'option[value=2]', :text => 'John Smith'
1504 end
1509 end
1505 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1510 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1506 end
1511 end
1507
1512
1508 def test_get_new_with_date_custom_field
1513 def test_get_new_with_date_custom_field
1509 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1514 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1510
1515
1511 @request.session[:user_id] = 2
1516 @request.session[:user_id] = 2
1512 get :new, :project_id => 1, :tracker_id => 1
1517 get :new, :project_id => 1, :tracker_id => 1
1513 assert_response :success
1518 assert_response :success
1514
1519
1515 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1520 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1516 end
1521 end
1517
1522
1518 def test_get_new_with_text_custom_field
1523 def test_get_new_with_text_custom_field
1519 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1524 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1520
1525
1521 @request.session[:user_id] = 2
1526 @request.session[:user_id] = 2
1522 get :new, :project_id => 1, :tracker_id => 1
1527 get :new, :project_id => 1, :tracker_id => 1
1523 assert_response :success
1528 assert_response :success
1524
1529
1525 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1530 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1526 end
1531 end
1527
1532
1528 def test_get_new_without_default_start_date_is_creation_date
1533 def test_get_new_without_default_start_date_is_creation_date
1529 Setting.default_issue_start_date_to_creation_date = 0
1534 Setting.default_issue_start_date_to_creation_date = 0
1530
1535
1531 @request.session[:user_id] = 2
1536 @request.session[:user_id] = 2
1532 get :new, :project_id => 1, :tracker_id => 1
1537 get :new, :project_id => 1, :tracker_id => 1
1533 assert_response :success
1538 assert_response :success
1534 assert_template 'new'
1539 assert_template 'new'
1535
1540
1536 assert_select 'input[name=?]', 'issue[start_date]'
1541 assert_select 'input[name=?]', 'issue[start_date]'
1537 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1542 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1538 end
1543 end
1539
1544
1540 def test_get_new_with_default_start_date_is_creation_date
1545 def test_get_new_with_default_start_date_is_creation_date
1541 Setting.default_issue_start_date_to_creation_date = 1
1546 Setting.default_issue_start_date_to_creation_date = 1
1542
1547
1543 @request.session[:user_id] = 2
1548 @request.session[:user_id] = 2
1544 get :new, :project_id => 1, :tracker_id => 1
1549 get :new, :project_id => 1, :tracker_id => 1
1545 assert_response :success
1550 assert_response :success
1546 assert_template 'new'
1551 assert_template 'new'
1547
1552
1548 assert_select 'input[name=?][value=?]', 'issue[start_date]', Date.today.to_s
1553 assert_select 'input[name=?][value=?]', 'issue[start_date]', Date.today.to_s
1549 end
1554 end
1550
1555
1551 def test_get_new_form_should_allow_attachment_upload
1556 def test_get_new_form_should_allow_attachment_upload
1552 @request.session[:user_id] = 2
1557 @request.session[:user_id] = 2
1553 get :new, :project_id => 1, :tracker_id => 1
1558 get :new, :project_id => 1, :tracker_id => 1
1554
1559
1555 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
1560 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
1556 assert_select 'input[name=?][type=file]', 'attachments[1][file]'
1561 assert_select 'input[name=?][type=file]', 'attachments[1][file]'
1557 assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]'
1562 assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]'
1558 end
1563 end
1559 end
1564 end
1560
1565
1561 def test_get_new_should_prefill_the_form_from_params
1566 def test_get_new_should_prefill_the_form_from_params
1562 @request.session[:user_id] = 2
1567 @request.session[:user_id] = 2
1563 get :new, :project_id => 1,
1568 get :new, :project_id => 1,
1564 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1569 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1565
1570
1566 issue = assigns(:issue)
1571 issue = assigns(:issue)
1567 assert_equal 3, issue.tracker_id
1572 assert_equal 3, issue.tracker_id
1568 assert_equal 'Prefilled', issue.description
1573 assert_equal 'Prefilled', issue.description
1569 assert_equal 'Custom field value', issue.custom_field_value(2)
1574 assert_equal 'Custom field value', issue.custom_field_value(2)
1570
1575
1571 assert_select 'select[name=?]', 'issue[tracker_id]' do
1576 assert_select 'select[name=?]', 'issue[tracker_id]' do
1572 assert_select 'option[value=3][selected=selected]'
1577 assert_select 'option[value=3][selected=selected]'
1573 end
1578 end
1574 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1579 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1575 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1580 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1576 end
1581 end
1577
1582
1578 def test_get_new_should_mark_required_fields
1583 def test_get_new_should_mark_required_fields
1579 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1584 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1580 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1585 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1581 WorkflowPermission.delete_all
1586 WorkflowPermission.delete_all
1582 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1587 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1583 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1588 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1584 @request.session[:user_id] = 2
1589 @request.session[:user_id] = 2
1585
1590
1586 get :new, :project_id => 1
1591 get :new, :project_id => 1
1587 assert_response :success
1592 assert_response :success
1588 assert_template 'new'
1593 assert_template 'new'
1589
1594
1590 assert_select 'label[for=issue_start_date]' do
1595 assert_select 'label[for=issue_start_date]' do
1591 assert_select 'span[class=required]', 0
1596 assert_select 'span[class=required]', 0
1592 end
1597 end
1593 assert_select 'label[for=issue_due_date]' do
1598 assert_select 'label[for=issue_due_date]' do
1594 assert_select 'span[class=required]'
1599 assert_select 'span[class=required]'
1595 end
1600 end
1596 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1601 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1597 assert_select 'span[class=required]', 0
1602 assert_select 'span[class=required]', 0
1598 end
1603 end
1599 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1604 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1600 assert_select 'span[class=required]'
1605 assert_select 'span[class=required]'
1601 end
1606 end
1602 end
1607 end
1603
1608
1604 def test_get_new_should_not_display_readonly_fields
1609 def test_get_new_should_not_display_readonly_fields
1605 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1610 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1606 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1611 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1607 WorkflowPermission.delete_all
1612 WorkflowPermission.delete_all
1608 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1613 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1609 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1614 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1610 @request.session[:user_id] = 2
1615 @request.session[:user_id] = 2
1611
1616
1612 get :new, :project_id => 1
1617 get :new, :project_id => 1
1613 assert_response :success
1618 assert_response :success
1614 assert_template 'new'
1619 assert_template 'new'
1615
1620
1616 assert_select 'input[name=?]', 'issue[start_date]'
1621 assert_select 'input[name=?]', 'issue[start_date]'
1617 assert_select 'input[name=?]', 'issue[due_date]', 0
1622 assert_select 'input[name=?]', 'issue[due_date]', 0
1618 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1623 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1619 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1624 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1620 end
1625 end
1621
1626
1622 def test_get_new_without_tracker_id
1627 def test_get_new_without_tracker_id
1623 @request.session[:user_id] = 2
1628 @request.session[:user_id] = 2
1624 get :new, :project_id => 1
1629 get :new, :project_id => 1
1625 assert_response :success
1630 assert_response :success
1626 assert_template 'new'
1631 assert_template 'new'
1627
1632
1628 issue = assigns(:issue)
1633 issue = assigns(:issue)
1629 assert_not_nil issue
1634 assert_not_nil issue
1630 assert_equal Project.find(1).trackers.first, issue.tracker
1635 assert_equal Project.find(1).trackers.first, issue.tracker
1631 end
1636 end
1632
1637
1633 def test_get_new_with_no_default_status_should_display_an_error
1638 def test_get_new_with_no_default_status_should_display_an_error
1634 @request.session[:user_id] = 2
1639 @request.session[:user_id] = 2
1635 IssueStatus.delete_all
1640 IssueStatus.delete_all
1636
1641
1637 get :new, :project_id => 1
1642 get :new, :project_id => 1
1638 assert_response 500
1643 assert_response 500
1639 assert_error_tag :content => /No default issue/
1644 assert_error_tag :content => /No default issue/
1640 end
1645 end
1641
1646
1642 def test_get_new_with_no_tracker_should_display_an_error
1647 def test_get_new_with_no_tracker_should_display_an_error
1643 @request.session[:user_id] = 2
1648 @request.session[:user_id] = 2
1644 Tracker.delete_all
1649 Tracker.delete_all
1645
1650
1646 get :new, :project_id => 1
1651 get :new, :project_id => 1
1647 assert_response 500
1652 assert_response 500
1648 assert_error_tag :content => /No tracker/
1653 assert_error_tag :content => /No tracker/
1649 end
1654 end
1650
1655
1651 def test_update_new_form
1656 def test_update_new_form
1652 @request.session[:user_id] = 2
1657 @request.session[:user_id] = 2
1653 xhr :post, :new, :project_id => 1,
1658 xhr :post, :new, :project_id => 1,
1654 :issue => {:tracker_id => 2,
1659 :issue => {:tracker_id => 2,
1655 :subject => 'This is the test_new issue',
1660 :subject => 'This is the test_new issue',
1656 :description => 'This is the description',
1661 :description => 'This is the description',
1657 :priority_id => 5}
1662 :priority_id => 5}
1658 assert_response :success
1663 assert_response :success
1659 assert_template 'update_form'
1664 assert_template 'update_form'
1660 assert_template 'form'
1665 assert_template 'form'
1661 assert_equal 'text/javascript', response.content_type
1666 assert_equal 'text/javascript', response.content_type
1662
1667
1663 issue = assigns(:issue)
1668 issue = assigns(:issue)
1664 assert_kind_of Issue, issue
1669 assert_kind_of Issue, issue
1665 assert_equal 1, issue.project_id
1670 assert_equal 1, issue.project_id
1666 assert_equal 2, issue.tracker_id
1671 assert_equal 2, issue.tracker_id
1667 assert_equal 'This is the test_new issue', issue.subject
1672 assert_equal 'This is the test_new issue', issue.subject
1668 end
1673 end
1669
1674
1670 def test_update_new_form_should_propose_transitions_based_on_initial_status
1675 def test_update_new_form_should_propose_transitions_based_on_initial_status
1671 @request.session[:user_id] = 2
1676 @request.session[:user_id] = 2
1672 WorkflowTransition.delete_all
1677 WorkflowTransition.delete_all
1673 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
1678 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
1674 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1679 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1675 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1680 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1676
1681
1677 xhr :post, :new, :project_id => 1,
1682 xhr :post, :new, :project_id => 1,
1678 :issue => {:tracker_id => 1,
1683 :issue => {:tracker_id => 1,
1679 :status_id => 5,
1684 :status_id => 5,
1680 :subject => 'This is an issue'}
1685 :subject => 'This is an issue'}
1681
1686
1682 assert_equal 5, assigns(:issue).status_id
1687 assert_equal 5, assigns(:issue).status_id
1683 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
1688 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
1684 end
1689 end
1685
1690
1686 def test_post_create
1691 def test_post_create
1687 @request.session[:user_id] = 2
1692 @request.session[:user_id] = 2
1688 assert_difference 'Issue.count' do
1693 assert_difference 'Issue.count' do
1689 post :create, :project_id => 1,
1694 post :create, :project_id => 1,
1690 :issue => {:tracker_id => 3,
1695 :issue => {:tracker_id => 3,
1691 :status_id => 2,
1696 :status_id => 2,
1692 :subject => 'This is the test_new issue',
1697 :subject => 'This is the test_new issue',
1693 :description => 'This is the description',
1698 :description => 'This is the description',
1694 :priority_id => 5,
1699 :priority_id => 5,
1695 :start_date => '2010-11-07',
1700 :start_date => '2010-11-07',
1696 :estimated_hours => '',
1701 :estimated_hours => '',
1697 :custom_field_values => {'2' => 'Value for field 2'}}
1702 :custom_field_values => {'2' => 'Value for field 2'}}
1698 end
1703 end
1699 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1704 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1700
1705
1701 issue = Issue.find_by_subject('This is the test_new issue')
1706 issue = Issue.find_by_subject('This is the test_new issue')
1702 assert_not_nil issue
1707 assert_not_nil issue
1703 assert_equal 2, issue.author_id
1708 assert_equal 2, issue.author_id
1704 assert_equal 3, issue.tracker_id
1709 assert_equal 3, issue.tracker_id
1705 assert_equal 2, issue.status_id
1710 assert_equal 2, issue.status_id
1706 assert_equal Date.parse('2010-11-07'), issue.start_date
1711 assert_equal Date.parse('2010-11-07'), issue.start_date
1707 assert_nil issue.estimated_hours
1712 assert_nil issue.estimated_hours
1708 v = issue.custom_values.where(:custom_field_id => 2).first
1713 v = issue.custom_values.where(:custom_field_id => 2).first
1709 assert_not_nil v
1714 assert_not_nil v
1710 assert_equal 'Value for field 2', v.value
1715 assert_equal 'Value for field 2', v.value
1711 end
1716 end
1712
1717
1713 def test_post_new_with_group_assignment
1718 def test_post_new_with_group_assignment
1714 group = Group.find(11)
1719 group = Group.find(11)
1715 project = Project.find(1)
1720 project = Project.find(1)
1716 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1721 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1717
1722
1718 with_settings :issue_group_assignment => '1' do
1723 with_settings :issue_group_assignment => '1' do
1719 @request.session[:user_id] = 2
1724 @request.session[:user_id] = 2
1720 assert_difference 'Issue.count' do
1725 assert_difference 'Issue.count' do
1721 post :create, :project_id => project.id,
1726 post :create, :project_id => project.id,
1722 :issue => {:tracker_id => 3,
1727 :issue => {:tracker_id => 3,
1723 :status_id => 1,
1728 :status_id => 1,
1724 :subject => 'This is the test_new_with_group_assignment issue',
1729 :subject => 'This is the test_new_with_group_assignment issue',
1725 :assigned_to_id => group.id}
1730 :assigned_to_id => group.id}
1726 end
1731 end
1727 end
1732 end
1728 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1733 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1729
1734
1730 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1735 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1731 assert_not_nil issue
1736 assert_not_nil issue
1732 assert_equal group, issue.assigned_to
1737 assert_equal group, issue.assigned_to
1733 end
1738 end
1734
1739
1735 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1740 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1736 Setting.default_issue_start_date_to_creation_date = 0
1741 Setting.default_issue_start_date_to_creation_date = 0
1737
1742
1738 @request.session[:user_id] = 2
1743 @request.session[:user_id] = 2
1739 assert_difference 'Issue.count' do
1744 assert_difference 'Issue.count' do
1740 post :create, :project_id => 1,
1745 post :create, :project_id => 1,
1741 :issue => {:tracker_id => 3,
1746 :issue => {:tracker_id => 3,
1742 :status_id => 2,
1747 :status_id => 2,
1743 :subject => 'This is the test_new issue',
1748 :subject => 'This is the test_new issue',
1744 :description => 'This is the description',
1749 :description => 'This is the description',
1745 :priority_id => 5,
1750 :priority_id => 5,
1746 :estimated_hours => '',
1751 :estimated_hours => '',
1747 :custom_field_values => {'2' => 'Value for field 2'}}
1752 :custom_field_values => {'2' => 'Value for field 2'}}
1748 end
1753 end
1749 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1754 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1750
1755
1751 issue = Issue.find_by_subject('This is the test_new issue')
1756 issue = Issue.find_by_subject('This is the test_new issue')
1752 assert_not_nil issue
1757 assert_not_nil issue
1753 assert_nil issue.start_date
1758 assert_nil issue.start_date
1754 end
1759 end
1755
1760
1756 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1761 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1757 Setting.default_issue_start_date_to_creation_date = 1
1762 Setting.default_issue_start_date_to_creation_date = 1
1758
1763
1759 @request.session[:user_id] = 2
1764 @request.session[:user_id] = 2
1760 assert_difference 'Issue.count' do
1765 assert_difference 'Issue.count' do
1761 post :create, :project_id => 1,
1766 post :create, :project_id => 1,
1762 :issue => {:tracker_id => 3,
1767 :issue => {:tracker_id => 3,
1763 :status_id => 2,
1768 :status_id => 2,
1764 :subject => 'This is the test_new issue',
1769 :subject => 'This is the test_new issue',
1765 :description => 'This is the description',
1770 :description => 'This is the description',
1766 :priority_id => 5,
1771 :priority_id => 5,
1767 :estimated_hours => '',
1772 :estimated_hours => '',
1768 :custom_field_values => {'2' => 'Value for field 2'}}
1773 :custom_field_values => {'2' => 'Value for field 2'}}
1769 end
1774 end
1770 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1775 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1771
1776
1772 issue = Issue.find_by_subject('This is the test_new issue')
1777 issue = Issue.find_by_subject('This is the test_new issue')
1773 assert_not_nil issue
1778 assert_not_nil issue
1774 assert_equal Date.today, issue.start_date
1779 assert_equal Date.today, issue.start_date
1775 end
1780 end
1776
1781
1777 def test_post_create_and_continue
1782 def test_post_create_and_continue
1778 @request.session[:user_id] = 2
1783 @request.session[:user_id] = 2
1779 assert_difference 'Issue.count' do
1784 assert_difference 'Issue.count' do
1780 post :create, :project_id => 1,
1785 post :create, :project_id => 1,
1781 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1786 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1782 :continue => ''
1787 :continue => ''
1783 end
1788 end
1784
1789
1785 issue = Issue.first(:order => 'id DESC')
1790 issue = Issue.first(:order => 'id DESC')
1786 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1791 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1787 assert_not_nil flash[:notice], "flash was not set"
1792 assert_not_nil flash[:notice], "flash was not set"
1788 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message"
1793 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message"
1789 end
1794 end
1790
1795
1791 def test_post_create_without_custom_fields_param
1796 def test_post_create_without_custom_fields_param
1792 @request.session[:user_id] = 2
1797 @request.session[:user_id] = 2
1793 assert_difference 'Issue.count' do
1798 assert_difference 'Issue.count' do
1794 post :create, :project_id => 1,
1799 post :create, :project_id => 1,
1795 :issue => {:tracker_id => 1,
1800 :issue => {:tracker_id => 1,
1796 :subject => 'This is the test_new issue',
1801 :subject => 'This is the test_new issue',
1797 :description => 'This is the description',
1802 :description => 'This is the description',
1798 :priority_id => 5}
1803 :priority_id => 5}
1799 end
1804 end
1800 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1805 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1801 end
1806 end
1802
1807
1803 def test_post_create_with_multi_custom_field
1808 def test_post_create_with_multi_custom_field
1804 field = IssueCustomField.find_by_name('Database')
1809 field = IssueCustomField.find_by_name('Database')
1805 field.update_attribute(:multiple, true)
1810 field.update_attribute(:multiple, true)
1806
1811
1807 @request.session[:user_id] = 2
1812 @request.session[:user_id] = 2
1808 assert_difference 'Issue.count' do
1813 assert_difference 'Issue.count' do
1809 post :create, :project_id => 1,
1814 post :create, :project_id => 1,
1810 :issue => {:tracker_id => 1,
1815 :issue => {:tracker_id => 1,
1811 :subject => 'This is the test_new issue',
1816 :subject => 'This is the test_new issue',
1812 :description => 'This is the description',
1817 :description => 'This is the description',
1813 :priority_id => 5,
1818 :priority_id => 5,
1814 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1819 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1815 end
1820 end
1816 assert_response 302
1821 assert_response 302
1817 issue = Issue.first(:order => 'id DESC')
1822 issue = Issue.first(:order => 'id DESC')
1818 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1823 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1819 end
1824 end
1820
1825
1821 def test_post_create_with_empty_multi_custom_field
1826 def test_post_create_with_empty_multi_custom_field
1822 field = IssueCustomField.find_by_name('Database')
1827 field = IssueCustomField.find_by_name('Database')
1823 field.update_attribute(:multiple, true)
1828 field.update_attribute(:multiple, true)
1824
1829
1825 @request.session[:user_id] = 2
1830 @request.session[:user_id] = 2
1826 assert_difference 'Issue.count' do
1831 assert_difference 'Issue.count' do
1827 post :create, :project_id => 1,
1832 post :create, :project_id => 1,
1828 :issue => {:tracker_id => 1,
1833 :issue => {:tracker_id => 1,
1829 :subject => 'This is the test_new issue',
1834 :subject => 'This is the test_new issue',
1830 :description => 'This is the description',
1835 :description => 'This is the description',
1831 :priority_id => 5,
1836 :priority_id => 5,
1832 :custom_field_values => {'1' => ['']}}
1837 :custom_field_values => {'1' => ['']}}
1833 end
1838 end
1834 assert_response 302
1839 assert_response 302
1835 issue = Issue.first(:order => 'id DESC')
1840 issue = Issue.first(:order => 'id DESC')
1836 assert_equal [''], issue.custom_field_value(1).sort
1841 assert_equal [''], issue.custom_field_value(1).sort
1837 end
1842 end
1838
1843
1839 def test_post_create_with_multi_user_custom_field
1844 def test_post_create_with_multi_user_custom_field
1840 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1845 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1841 :tracker_ids => [1], :is_for_all => true)
1846 :tracker_ids => [1], :is_for_all => true)
1842
1847
1843 @request.session[:user_id] = 2
1848 @request.session[:user_id] = 2
1844 assert_difference 'Issue.count' do
1849 assert_difference 'Issue.count' do
1845 post :create, :project_id => 1,
1850 post :create, :project_id => 1,
1846 :issue => {:tracker_id => 1,
1851 :issue => {:tracker_id => 1,
1847 :subject => 'This is the test_new issue',
1852 :subject => 'This is the test_new issue',
1848 :description => 'This is the description',
1853 :description => 'This is the description',
1849 :priority_id => 5,
1854 :priority_id => 5,
1850 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1855 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1851 end
1856 end
1852 assert_response 302
1857 assert_response 302
1853 issue = Issue.first(:order => 'id DESC')
1858 issue = Issue.first(:order => 'id DESC')
1854 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1859 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1855 end
1860 end
1856
1861
1857 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1862 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1858 field = IssueCustomField.find_by_name('Database')
1863 field = IssueCustomField.find_by_name('Database')
1859 field.update_attribute(:is_required, true)
1864 field.update_attribute(:is_required, true)
1860
1865
1861 @request.session[:user_id] = 2
1866 @request.session[:user_id] = 2
1862 assert_no_difference 'Issue.count' do
1867 assert_no_difference 'Issue.count' do
1863 post :create, :project_id => 1,
1868 post :create, :project_id => 1,
1864 :issue => {:tracker_id => 1,
1869 :issue => {:tracker_id => 1,
1865 :subject => 'This is the test_new issue',
1870 :subject => 'This is the test_new issue',
1866 :description => 'This is the description',
1871 :description => 'This is the description',
1867 :priority_id => 5}
1872 :priority_id => 5}
1868 end
1873 end
1869 assert_response :success
1874 assert_response :success
1870 assert_template 'new'
1875 assert_template 'new'
1871 issue = assigns(:issue)
1876 issue = assigns(:issue)
1872 assert_not_nil issue
1877 assert_not_nil issue
1873 assert_error_tag :content => /Database can&#x27;t be blank/
1878 assert_error_tag :content => /Database can&#x27;t be blank/
1874 end
1879 end
1875
1880
1876 def test_create_should_validate_required_fields
1881 def test_create_should_validate_required_fields
1877 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1882 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1878 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1883 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1879 WorkflowPermission.delete_all
1884 WorkflowPermission.delete_all
1880 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1885 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1881 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1886 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1882 @request.session[:user_id] = 2
1887 @request.session[:user_id] = 2
1883
1888
1884 assert_no_difference 'Issue.count' do
1889 assert_no_difference 'Issue.count' do
1885 post :create, :project_id => 1, :issue => {
1890 post :create, :project_id => 1, :issue => {
1886 :tracker_id => 2,
1891 :tracker_id => 2,
1887 :status_id => 1,
1892 :status_id => 1,
1888 :subject => 'Test',
1893 :subject => 'Test',
1889 :start_date => '',
1894 :start_date => '',
1890 :due_date => '',
1895 :due_date => '',
1891 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
1896 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
1892 }
1897 }
1893 assert_response :success
1898 assert_response :success
1894 assert_template 'new'
1899 assert_template 'new'
1895 end
1900 end
1896
1901
1897 assert_error_tag :content => /Due date can&#x27;t be blank/i
1902 assert_error_tag :content => /Due date can&#x27;t be blank/i
1898 assert_error_tag :content => /Bar can&#x27;t be blank/i
1903 assert_error_tag :content => /Bar can&#x27;t be blank/i
1899 end
1904 end
1900
1905
1901 def test_create_should_ignore_readonly_fields
1906 def test_create_should_ignore_readonly_fields
1902 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1907 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1903 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1908 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1904 WorkflowPermission.delete_all
1909 WorkflowPermission.delete_all
1905 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1910 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1906 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1911 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1907 @request.session[:user_id] = 2
1912 @request.session[:user_id] = 2
1908
1913
1909 assert_difference 'Issue.count' do
1914 assert_difference 'Issue.count' do
1910 post :create, :project_id => 1, :issue => {
1915 post :create, :project_id => 1, :issue => {
1911 :tracker_id => 2,
1916 :tracker_id => 2,
1912 :status_id => 1,
1917 :status_id => 1,
1913 :subject => 'Test',
1918 :subject => 'Test',
1914 :start_date => '2012-07-14',
1919 :start_date => '2012-07-14',
1915 :due_date => '2012-07-16',
1920 :due_date => '2012-07-16',
1916 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
1921 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
1917 }
1922 }
1918 assert_response 302
1923 assert_response 302
1919 end
1924 end
1920
1925
1921 issue = Issue.first(:order => 'id DESC')
1926 issue = Issue.first(:order => 'id DESC')
1922 assert_equal Date.parse('2012-07-14'), issue.start_date
1927 assert_equal Date.parse('2012-07-14'), issue.start_date
1923 assert_nil issue.due_date
1928 assert_nil issue.due_date
1924 assert_equal 'value1', issue.custom_field_value(cf1)
1929 assert_equal 'value1', issue.custom_field_value(cf1)
1925 assert_nil issue.custom_field_value(cf2)
1930 assert_nil issue.custom_field_value(cf2)
1926 end
1931 end
1927
1932
1928 def test_post_create_with_watchers
1933 def test_post_create_with_watchers
1929 @request.session[:user_id] = 2
1934 @request.session[:user_id] = 2
1930 ActionMailer::Base.deliveries.clear
1935 ActionMailer::Base.deliveries.clear
1931
1936
1932 assert_difference 'Watcher.count', 2 do
1937 assert_difference 'Watcher.count', 2 do
1933 post :create, :project_id => 1,
1938 post :create, :project_id => 1,
1934 :issue => {:tracker_id => 1,
1939 :issue => {:tracker_id => 1,
1935 :subject => 'This is a new issue with watchers',
1940 :subject => 'This is a new issue with watchers',
1936 :description => 'This is the description',
1941 :description => 'This is the description',
1937 :priority_id => 5,
1942 :priority_id => 5,
1938 :watcher_user_ids => ['2', '3']}
1943 :watcher_user_ids => ['2', '3']}
1939 end
1944 end
1940 issue = Issue.find_by_subject('This is a new issue with watchers')
1945 issue = Issue.find_by_subject('This is a new issue with watchers')
1941 assert_not_nil issue
1946 assert_not_nil issue
1942 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1947 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1943
1948
1944 # Watchers added
1949 # Watchers added
1945 assert_equal [2, 3], issue.watcher_user_ids.sort
1950 assert_equal [2, 3], issue.watcher_user_ids.sort
1946 assert issue.watched_by?(User.find(3))
1951 assert issue.watched_by?(User.find(3))
1947 # Watchers notified
1952 # Watchers notified
1948 mail = ActionMailer::Base.deliveries.last
1953 mail = ActionMailer::Base.deliveries.last
1949 assert_not_nil mail
1954 assert_not_nil mail
1950 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1955 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1951 end
1956 end
1952
1957
1953 def test_post_create_subissue
1958 def test_post_create_subissue
1954 @request.session[:user_id] = 2
1959 @request.session[:user_id] = 2
1955
1960
1956 assert_difference 'Issue.count' do
1961 assert_difference 'Issue.count' do
1957 post :create, :project_id => 1,
1962 post :create, :project_id => 1,
1958 :issue => {:tracker_id => 1,
1963 :issue => {:tracker_id => 1,
1959 :subject => 'This is a child issue',
1964 :subject => 'This is a child issue',
1960 :parent_issue_id => '2'}
1965 :parent_issue_id => '2'}
1961 assert_response 302
1966 assert_response 302
1962 end
1967 end
1963 issue = Issue.order('id DESC').first
1968 issue = Issue.order('id DESC').first
1964 assert_equal Issue.find(2), issue.parent
1969 assert_equal Issue.find(2), issue.parent
1965 end
1970 end
1966
1971
1967 def test_post_create_subissue_with_sharp_parent_id
1972 def test_post_create_subissue_with_sharp_parent_id
1968 @request.session[:user_id] = 2
1973 @request.session[:user_id] = 2
1969
1974
1970 assert_difference 'Issue.count' do
1975 assert_difference 'Issue.count' do
1971 post :create, :project_id => 1,
1976 post :create, :project_id => 1,
1972 :issue => {:tracker_id => 1,
1977 :issue => {:tracker_id => 1,
1973 :subject => 'This is a child issue',
1978 :subject => 'This is a child issue',
1974 :parent_issue_id => '#2'}
1979 :parent_issue_id => '#2'}
1975 assert_response 302
1980 assert_response 302
1976 end
1981 end
1977 issue = Issue.order('id DESC').first
1982 issue = Issue.order('id DESC').first
1978 assert_equal Issue.find(2), issue.parent
1983 assert_equal Issue.find(2), issue.parent
1979 end
1984 end
1980
1985
1981 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
1986 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
1982 @request.session[:user_id] = 2
1987 @request.session[:user_id] = 2
1983
1988
1984 assert_no_difference 'Issue.count' do
1989 assert_no_difference 'Issue.count' do
1985 post :create, :project_id => 1,
1990 post :create, :project_id => 1,
1986 :issue => {:tracker_id => 1,
1991 :issue => {:tracker_id => 1,
1987 :subject => 'This is a child issue',
1992 :subject => 'This is a child issue',
1988 :parent_issue_id => '4'}
1993 :parent_issue_id => '4'}
1989
1994
1990 assert_response :success
1995 assert_response :success
1991 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
1996 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
1992 assert_error_tag :content => /Parent task is invalid/i
1997 assert_error_tag :content => /Parent task is invalid/i
1993 end
1998 end
1994 end
1999 end
1995
2000
1996 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
2001 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
1997 @request.session[:user_id] = 2
2002 @request.session[:user_id] = 2
1998
2003
1999 assert_no_difference 'Issue.count' do
2004 assert_no_difference 'Issue.count' do
2000 post :create, :project_id => 1,
2005 post :create, :project_id => 1,
2001 :issue => {:tracker_id => 1,
2006 :issue => {:tracker_id => 1,
2002 :subject => 'This is a child issue',
2007 :subject => 'This is a child issue',
2003 :parent_issue_id => '01ABC'}
2008 :parent_issue_id => '01ABC'}
2004
2009
2005 assert_response :success
2010 assert_response :success
2006 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2011 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2007 assert_error_tag :content => /Parent task is invalid/i
2012 assert_error_tag :content => /Parent task is invalid/i
2008 end
2013 end
2009 end
2014 end
2010
2015
2011 def test_post_create_private
2016 def test_post_create_private
2012 @request.session[:user_id] = 2
2017 @request.session[:user_id] = 2
2013
2018
2014 assert_difference 'Issue.count' do
2019 assert_difference 'Issue.count' do
2015 post :create, :project_id => 1,
2020 post :create, :project_id => 1,
2016 :issue => {:tracker_id => 1,
2021 :issue => {:tracker_id => 1,
2017 :subject => 'This is a private issue',
2022 :subject => 'This is a private issue',
2018 :is_private => '1'}
2023 :is_private => '1'}
2019 end
2024 end
2020 issue = Issue.first(:order => 'id DESC')
2025 issue = Issue.first(:order => 'id DESC')
2021 assert issue.is_private?
2026 assert issue.is_private?
2022 end
2027 end
2023
2028
2024 def test_post_create_private_with_set_own_issues_private_permission
2029 def test_post_create_private_with_set_own_issues_private_permission
2025 role = Role.find(1)
2030 role = Role.find(1)
2026 role.remove_permission! :set_issues_private
2031 role.remove_permission! :set_issues_private
2027 role.add_permission! :set_own_issues_private
2032 role.add_permission! :set_own_issues_private
2028
2033
2029 @request.session[:user_id] = 2
2034 @request.session[:user_id] = 2
2030
2035
2031 assert_difference 'Issue.count' do
2036 assert_difference 'Issue.count' do
2032 post :create, :project_id => 1,
2037 post :create, :project_id => 1,
2033 :issue => {:tracker_id => 1,
2038 :issue => {:tracker_id => 1,
2034 :subject => 'This is a private issue',
2039 :subject => 'This is a private issue',
2035 :is_private => '1'}
2040 :is_private => '1'}
2036 end
2041 end
2037 issue = Issue.first(:order => 'id DESC')
2042 issue = Issue.first(:order => 'id DESC')
2038 assert issue.is_private?
2043 assert issue.is_private?
2039 end
2044 end
2040
2045
2041 def test_post_create_should_send_a_notification
2046 def test_post_create_should_send_a_notification
2042 ActionMailer::Base.deliveries.clear
2047 ActionMailer::Base.deliveries.clear
2043 @request.session[:user_id] = 2
2048 @request.session[:user_id] = 2
2044 assert_difference 'Issue.count' do
2049 assert_difference 'Issue.count' do
2045 post :create, :project_id => 1,
2050 post :create, :project_id => 1,
2046 :issue => {:tracker_id => 3,
2051 :issue => {:tracker_id => 3,
2047 :subject => 'This is the test_new issue',
2052 :subject => 'This is the test_new issue',
2048 :description => 'This is the description',
2053 :description => 'This is the description',
2049 :priority_id => 5,
2054 :priority_id => 5,
2050 :estimated_hours => '',
2055 :estimated_hours => '',
2051 :custom_field_values => {'2' => 'Value for field 2'}}
2056 :custom_field_values => {'2' => 'Value for field 2'}}
2052 end
2057 end
2053 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2058 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2054
2059
2055 assert_equal 1, ActionMailer::Base.deliveries.size
2060 assert_equal 1, ActionMailer::Base.deliveries.size
2056 end
2061 end
2057
2062
2058 def test_post_create_should_preserve_fields_values_on_validation_failure
2063 def test_post_create_should_preserve_fields_values_on_validation_failure
2059 @request.session[:user_id] = 2
2064 @request.session[:user_id] = 2
2060 post :create, :project_id => 1,
2065 post :create, :project_id => 1,
2061 :issue => {:tracker_id => 1,
2066 :issue => {:tracker_id => 1,
2062 # empty subject
2067 # empty subject
2063 :subject => '',
2068 :subject => '',
2064 :description => 'This is a description',
2069 :description => 'This is a description',
2065 :priority_id => 6,
2070 :priority_id => 6,
2066 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2071 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2067 assert_response :success
2072 assert_response :success
2068 assert_template 'new'
2073 assert_template 'new'
2069
2074
2070 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
2075 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
2071 :content => "\nThis is a description"
2076 :content => "\nThis is a description"
2072 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2077 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2073 :child => { :tag => 'option', :attributes => { :selected => 'selected',
2078 :child => { :tag => 'option', :attributes => { :selected => 'selected',
2074 :value => '6' },
2079 :value => '6' },
2075 :content => 'High' }
2080 :content => 'High' }
2076 # Custom fields
2081 # Custom fields
2077 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
2082 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
2078 :child => { :tag => 'option', :attributes => { :selected => 'selected',
2083 :child => { :tag => 'option', :attributes => { :selected => 'selected',
2079 :value => 'Oracle' },
2084 :value => 'Oracle' },
2080 :content => 'Oracle' }
2085 :content => 'Oracle' }
2081 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
2086 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
2082 :value => 'Value for field 2'}
2087 :value => 'Value for field 2'}
2083 end
2088 end
2084
2089
2085 def test_post_create_with_failure_should_preserve_watchers
2090 def test_post_create_with_failure_should_preserve_watchers
2086 assert !User.find(8).member_of?(Project.find(1))
2091 assert !User.find(8).member_of?(Project.find(1))
2087
2092
2088 @request.session[:user_id] = 2
2093 @request.session[:user_id] = 2
2089 post :create, :project_id => 1,
2094 post :create, :project_id => 1,
2090 :issue => {:tracker_id => 1,
2095 :issue => {:tracker_id => 1,
2091 :watcher_user_ids => ['3', '8']}
2096 :watcher_user_ids => ['3', '8']}
2092 assert_response :success
2097 assert_response :success
2093 assert_template 'new'
2098 assert_template 'new'
2094
2099
2095 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil}
2100 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil}
2096 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'}
2101 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'}
2097 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'}
2102 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'}
2098 end
2103 end
2099
2104
2100 def test_post_create_should_ignore_non_safe_attributes
2105 def test_post_create_should_ignore_non_safe_attributes
2101 @request.session[:user_id] = 2
2106 @request.session[:user_id] = 2
2102 assert_nothing_raised do
2107 assert_nothing_raised do
2103 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2108 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2104 end
2109 end
2105 end
2110 end
2106
2111
2107 def test_post_create_with_attachment
2112 def test_post_create_with_attachment
2108 set_tmp_attachments_directory
2113 set_tmp_attachments_directory
2109 @request.session[:user_id] = 2
2114 @request.session[:user_id] = 2
2110
2115
2111 assert_difference 'Issue.count' do
2116 assert_difference 'Issue.count' do
2112 assert_difference 'Attachment.count' do
2117 assert_difference 'Attachment.count' do
2113 post :create, :project_id => 1,
2118 post :create, :project_id => 1,
2114 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2119 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2115 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2120 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2116 end
2121 end
2117 end
2122 end
2118
2123
2119 issue = Issue.first(:order => 'id DESC')
2124 issue = Issue.first(:order => 'id DESC')
2120 attachment = Attachment.first(:order => 'id DESC')
2125 attachment = Attachment.first(:order => 'id DESC')
2121
2126
2122 assert_equal issue, attachment.container
2127 assert_equal issue, attachment.container
2123 assert_equal 2, attachment.author_id
2128 assert_equal 2, attachment.author_id
2124 assert_equal 'testfile.txt', attachment.filename
2129 assert_equal 'testfile.txt', attachment.filename
2125 assert_equal 'text/plain', attachment.content_type
2130 assert_equal 'text/plain', attachment.content_type
2126 assert_equal 'test file', attachment.description
2131 assert_equal 'test file', attachment.description
2127 assert_equal 59, attachment.filesize
2132 assert_equal 59, attachment.filesize
2128 assert File.exists?(attachment.diskfile)
2133 assert File.exists?(attachment.diskfile)
2129 assert_equal 59, File.size(attachment.diskfile)
2134 assert_equal 59, File.size(attachment.diskfile)
2130 end
2135 end
2131
2136
2132 def test_post_create_with_failure_should_save_attachments
2137 def test_post_create_with_failure_should_save_attachments
2133 set_tmp_attachments_directory
2138 set_tmp_attachments_directory
2134 @request.session[:user_id] = 2
2139 @request.session[:user_id] = 2
2135
2140
2136 assert_no_difference 'Issue.count' do
2141 assert_no_difference 'Issue.count' do
2137 assert_difference 'Attachment.count' do
2142 assert_difference 'Attachment.count' do
2138 post :create, :project_id => 1,
2143 post :create, :project_id => 1,
2139 :issue => { :tracker_id => '1', :subject => '' },
2144 :issue => { :tracker_id => '1', :subject => '' },
2140 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2145 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2141 assert_response :success
2146 assert_response :success
2142 assert_template 'new'
2147 assert_template 'new'
2143 end
2148 end
2144 end
2149 end
2145
2150
2146 attachment = Attachment.first(:order => 'id DESC')
2151 attachment = Attachment.first(:order => 'id DESC')
2147 assert_equal 'testfile.txt', attachment.filename
2152 assert_equal 'testfile.txt', attachment.filename
2148 assert File.exists?(attachment.diskfile)
2153 assert File.exists?(attachment.diskfile)
2149 assert_nil attachment.container
2154 assert_nil attachment.container
2150
2155
2151 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2156 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2152 assert_tag 'span', :content => /testfile.txt/
2157 assert_tag 'span', :content => /testfile.txt/
2153 end
2158 end
2154
2159
2155 def test_post_create_with_failure_should_keep_saved_attachments
2160 def test_post_create_with_failure_should_keep_saved_attachments
2156 set_tmp_attachments_directory
2161 set_tmp_attachments_directory
2157 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2162 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2158 @request.session[:user_id] = 2
2163 @request.session[:user_id] = 2
2159
2164
2160 assert_no_difference 'Issue.count' do
2165 assert_no_difference 'Issue.count' do
2161 assert_no_difference 'Attachment.count' do
2166 assert_no_difference 'Attachment.count' do
2162 post :create, :project_id => 1,
2167 post :create, :project_id => 1,
2163 :issue => { :tracker_id => '1', :subject => '' },
2168 :issue => { :tracker_id => '1', :subject => '' },
2164 :attachments => {'p0' => {'token' => attachment.token}}
2169 :attachments => {'p0' => {'token' => attachment.token}}
2165 assert_response :success
2170 assert_response :success
2166 assert_template 'new'
2171 assert_template 'new'
2167 end
2172 end
2168 end
2173 end
2169
2174
2170 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2175 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2171 assert_tag 'span', :content => /testfile.txt/
2176 assert_tag 'span', :content => /testfile.txt/
2172 end
2177 end
2173
2178
2174 def test_post_create_should_attach_saved_attachments
2179 def test_post_create_should_attach_saved_attachments
2175 set_tmp_attachments_directory
2180 set_tmp_attachments_directory
2176 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2181 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2177 @request.session[:user_id] = 2
2182 @request.session[:user_id] = 2
2178
2183
2179 assert_difference 'Issue.count' do
2184 assert_difference 'Issue.count' do
2180 assert_no_difference 'Attachment.count' do
2185 assert_no_difference 'Attachment.count' do
2181 post :create, :project_id => 1,
2186 post :create, :project_id => 1,
2182 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2187 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2183 :attachments => {'p0' => {'token' => attachment.token}}
2188 :attachments => {'p0' => {'token' => attachment.token}}
2184 assert_response 302
2189 assert_response 302
2185 end
2190 end
2186 end
2191 end
2187
2192
2188 issue = Issue.first(:order => 'id DESC')
2193 issue = Issue.first(:order => 'id DESC')
2189 assert_equal 1, issue.attachments.count
2194 assert_equal 1, issue.attachments.count
2190
2195
2191 attachment.reload
2196 attachment.reload
2192 assert_equal issue, attachment.container
2197 assert_equal issue, attachment.container
2193 end
2198 end
2194
2199
2195 context "without workflow privilege" do
2200 context "without workflow privilege" do
2196 setup do
2201 setup do
2197 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2202 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2198 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2203 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2199 end
2204 end
2200
2205
2201 context "#new" do
2206 context "#new" do
2202 should "propose default status only" do
2207 should "propose default status only" do
2203 get :new, :project_id => 1
2208 get :new, :project_id => 1
2204 assert_response :success
2209 assert_response :success
2205 assert_template 'new'
2210 assert_template 'new'
2206 assert_tag :tag => 'select',
2211 assert_tag :tag => 'select',
2207 :attributes => {:name => 'issue[status_id]'},
2212 :attributes => {:name => 'issue[status_id]'},
2208 :children => {:count => 1},
2213 :children => {:count => 1},
2209 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
2214 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
2210 end
2215 end
2211
2216
2212 should "accept default status" do
2217 should "accept default status" do
2213 assert_difference 'Issue.count' do
2218 assert_difference 'Issue.count' do
2214 post :create, :project_id => 1,
2219 post :create, :project_id => 1,
2215 :issue => {:tracker_id => 1,
2220 :issue => {:tracker_id => 1,
2216 :subject => 'This is an issue',
2221 :subject => 'This is an issue',
2217 :status_id => 1}
2222 :status_id => 1}
2218 end
2223 end
2219 issue = Issue.last(:order => 'id')
2224 issue = Issue.last(:order => 'id')
2220 assert_equal IssueStatus.default, issue.status
2225 assert_equal IssueStatus.default, issue.status
2221 end
2226 end
2222
2227
2223 should "ignore unauthorized status" do
2228 should "ignore unauthorized status" do
2224 assert_difference 'Issue.count' do
2229 assert_difference 'Issue.count' do
2225 post :create, :project_id => 1,
2230 post :create, :project_id => 1,
2226 :issue => {:tracker_id => 1,
2231 :issue => {:tracker_id => 1,
2227 :subject => 'This is an issue',
2232 :subject => 'This is an issue',
2228 :status_id => 3}
2233 :status_id => 3}
2229 end
2234 end
2230 issue = Issue.last(:order => 'id')
2235 issue = Issue.last(:order => 'id')
2231 assert_equal IssueStatus.default, issue.status
2236 assert_equal IssueStatus.default, issue.status
2232 end
2237 end
2233 end
2238 end
2234
2239
2235 context "#update" do
2240 context "#update" do
2236 should "ignore status change" do
2241 should "ignore status change" do
2237 assert_difference 'Journal.count' do
2242 assert_difference 'Journal.count' do
2238 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2243 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2239 end
2244 end
2240 assert_equal 1, Issue.find(1).status_id
2245 assert_equal 1, Issue.find(1).status_id
2241 end
2246 end
2242
2247
2243 should "ignore attributes changes" do
2248 should "ignore attributes changes" do
2244 assert_difference 'Journal.count' do
2249 assert_difference 'Journal.count' do
2245 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2250 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2246 end
2251 end
2247 issue = Issue.find(1)
2252 issue = Issue.find(1)
2248 assert_equal "Can't print recipes", issue.subject
2253 assert_equal "Can't print recipes", issue.subject
2249 assert_nil issue.assigned_to
2254 assert_nil issue.assigned_to
2250 end
2255 end
2251 end
2256 end
2252 end
2257 end
2253
2258
2254 context "with workflow privilege" do
2259 context "with workflow privilege" do
2255 setup do
2260 setup do
2256 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2261 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2257 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2262 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2258 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2263 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2259 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2264 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2260 end
2265 end
2261
2266
2262 context "#update" do
2267 context "#update" do
2263 should "accept authorized status" do
2268 should "accept authorized status" do
2264 assert_difference 'Journal.count' do
2269 assert_difference 'Journal.count' do
2265 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2270 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2266 end
2271 end
2267 assert_equal 3, Issue.find(1).status_id
2272 assert_equal 3, Issue.find(1).status_id
2268 end
2273 end
2269
2274
2270 should "ignore unauthorized status" do
2275 should "ignore unauthorized status" do
2271 assert_difference 'Journal.count' do
2276 assert_difference 'Journal.count' do
2272 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2277 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2273 end
2278 end
2274 assert_equal 1, Issue.find(1).status_id
2279 assert_equal 1, Issue.find(1).status_id
2275 end
2280 end
2276
2281
2277 should "accept authorized attributes changes" do
2282 should "accept authorized attributes changes" do
2278 assert_difference 'Journal.count' do
2283 assert_difference 'Journal.count' do
2279 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
2284 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
2280 end
2285 end
2281 issue = Issue.find(1)
2286 issue = Issue.find(1)
2282 assert_equal 2, issue.assigned_to_id
2287 assert_equal 2, issue.assigned_to_id
2283 end
2288 end
2284
2289
2285 should "ignore unauthorized attributes changes" do
2290 should "ignore unauthorized attributes changes" do
2286 assert_difference 'Journal.count' do
2291 assert_difference 'Journal.count' do
2287 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
2292 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
2288 end
2293 end
2289 issue = Issue.find(1)
2294 issue = Issue.find(1)
2290 assert_equal "Can't print recipes", issue.subject
2295 assert_equal "Can't print recipes", issue.subject
2291 end
2296 end
2292 end
2297 end
2293
2298
2294 context "and :edit_issues permission" do
2299 context "and :edit_issues permission" do
2295 setup do
2300 setup do
2296 Role.anonymous.add_permission! :add_issues, :edit_issues
2301 Role.anonymous.add_permission! :add_issues, :edit_issues
2297 end
2302 end
2298
2303
2299 should "accept authorized status" do
2304 should "accept authorized status" do
2300 assert_difference 'Journal.count' do
2305 assert_difference 'Journal.count' do
2301 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2306 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2302 end
2307 end
2303 assert_equal 3, Issue.find(1).status_id
2308 assert_equal 3, Issue.find(1).status_id
2304 end
2309 end
2305
2310
2306 should "ignore unauthorized status" do
2311 should "ignore unauthorized status" do
2307 assert_difference 'Journal.count' do
2312 assert_difference 'Journal.count' do
2308 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2313 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2309 end
2314 end
2310 assert_equal 1, Issue.find(1).status_id
2315 assert_equal 1, Issue.find(1).status_id
2311 end
2316 end
2312
2317
2313 should "accept authorized attributes changes" do
2318 should "accept authorized attributes changes" do
2314 assert_difference 'Journal.count' do
2319 assert_difference 'Journal.count' do
2315 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2320 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2316 end
2321 end
2317 issue = Issue.find(1)
2322 issue = Issue.find(1)
2318 assert_equal "changed", issue.subject
2323 assert_equal "changed", issue.subject
2319 assert_equal 2, issue.assigned_to_id
2324 assert_equal 2, issue.assigned_to_id
2320 end
2325 end
2321 end
2326 end
2322 end
2327 end
2323
2328
2324 def test_new_as_copy
2329 def test_new_as_copy
2325 @request.session[:user_id] = 2
2330 @request.session[:user_id] = 2
2326 get :new, :project_id => 1, :copy_from => 1
2331 get :new, :project_id => 1, :copy_from => 1
2327
2332
2328 assert_response :success
2333 assert_response :success
2329 assert_template 'new'
2334 assert_template 'new'
2330
2335
2331 assert_not_nil assigns(:issue)
2336 assert_not_nil assigns(:issue)
2332 orig = Issue.find(1)
2337 orig = Issue.find(1)
2333 assert_equal 1, assigns(:issue).project_id
2338 assert_equal 1, assigns(:issue).project_id
2334 assert_equal orig.subject, assigns(:issue).subject
2339 assert_equal orig.subject, assigns(:issue).subject
2335 assert assigns(:issue).copy?
2340 assert assigns(:issue).copy?
2336
2341
2337 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2342 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2338 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2343 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2339 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2344 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2340 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
2345 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
2341 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2346 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2342 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
2347 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
2343 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2348 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2344 end
2349 end
2345
2350
2346 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2351 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2347 @request.session[:user_id] = 2
2352 @request.session[:user_id] = 2
2348 issue = Issue.find(3)
2353 issue = Issue.find(3)
2349 assert issue.attachments.count > 0
2354 assert issue.attachments.count > 0
2350 get :new, :project_id => 1, :copy_from => 3
2355 get :new, :project_id => 1, :copy_from => 3
2351
2356
2352 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
2357 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
2353 end
2358 end
2354
2359
2355 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2360 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2356 @request.session[:user_id] = 2
2361 @request.session[:user_id] = 2
2357 issue = Issue.find(3)
2362 issue = Issue.find(3)
2358 issue.attachments.delete_all
2363 issue.attachments.delete_all
2359 get :new, :project_id => 1, :copy_from => 3
2364 get :new, :project_id => 1, :copy_from => 3
2360
2365
2361 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
2366 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
2362 end
2367 end
2363
2368
2364 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2369 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2365 @request.session[:user_id] = 2
2370 @request.session[:user_id] = 2
2366 issue = Issue.generate_with_descendants!
2371 issue = Issue.generate_with_descendants!
2367 get :new, :project_id => 1, :copy_from => issue.id
2372 get :new, :project_id => 1, :copy_from => issue.id
2368
2373
2369 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]'
2374 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]'
2370 end
2375 end
2371
2376
2372 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2377 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2373 @request.session[:user_id] = 2
2378 @request.session[:user_id] = 2
2374 get :new, :project_id => 1, :copy_from => 99999
2379 get :new, :project_id => 1, :copy_from => 99999
2375 assert_response 404
2380 assert_response 404
2376 end
2381 end
2377
2382
2378 def test_create_as_copy_on_different_project
2383 def test_create_as_copy_on_different_project
2379 @request.session[:user_id] = 2
2384 @request.session[:user_id] = 2
2380 assert_difference 'Issue.count' do
2385 assert_difference 'Issue.count' do
2381 post :create, :project_id => 1, :copy_from => 1,
2386 post :create, :project_id => 1, :copy_from => 1,
2382 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2387 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2383
2388
2384 assert_not_nil assigns(:issue)
2389 assert_not_nil assigns(:issue)
2385 assert assigns(:issue).copy?
2390 assert assigns(:issue).copy?
2386 end
2391 end
2387 issue = Issue.first(:order => 'id DESC')
2392 issue = Issue.first(:order => 'id DESC')
2388 assert_redirected_to "/issues/#{issue.id}"
2393 assert_redirected_to "/issues/#{issue.id}"
2389
2394
2390 assert_equal 2, issue.project_id
2395 assert_equal 2, issue.project_id
2391 assert_equal 3, issue.tracker_id
2396 assert_equal 3, issue.tracker_id
2392 assert_equal 'Copy', issue.subject
2397 assert_equal 'Copy', issue.subject
2393 end
2398 end
2394
2399
2395 def test_create_as_copy_should_copy_attachments
2400 def test_create_as_copy_should_copy_attachments
2396 @request.session[:user_id] = 2
2401 @request.session[:user_id] = 2
2397 issue = Issue.find(3)
2402 issue = Issue.find(3)
2398 count = issue.attachments.count
2403 count = issue.attachments.count
2399 assert count > 0
2404 assert count > 0
2400
2405
2401 assert_difference 'Issue.count' do
2406 assert_difference 'Issue.count' do
2402 assert_difference 'Attachment.count', count do
2407 assert_difference 'Attachment.count', count do
2403 assert_no_difference 'Journal.count' do
2408 assert_no_difference 'Journal.count' do
2404 post :create, :project_id => 1, :copy_from => 3,
2409 post :create, :project_id => 1, :copy_from => 3,
2405 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2410 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2406 :copy_attachments => '1'
2411 :copy_attachments => '1'
2407 end
2412 end
2408 end
2413 end
2409 end
2414 end
2410 copy = Issue.first(:order => 'id DESC')
2415 copy = Issue.first(:order => 'id DESC')
2411 assert_equal count, copy.attachments.count
2416 assert_equal count, copy.attachments.count
2412 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2417 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2413 end
2418 end
2414
2419
2415 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2420 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2416 @request.session[:user_id] = 2
2421 @request.session[:user_id] = 2
2417 issue = Issue.find(3)
2422 issue = Issue.find(3)
2418 count = issue.attachments.count
2423 count = issue.attachments.count
2419 assert count > 0
2424 assert count > 0
2420
2425
2421 assert_difference 'Issue.count' do
2426 assert_difference 'Issue.count' do
2422 assert_no_difference 'Attachment.count' do
2427 assert_no_difference 'Attachment.count' do
2423 assert_no_difference 'Journal.count' do
2428 assert_no_difference 'Journal.count' do
2424 post :create, :project_id => 1, :copy_from => 3,
2429 post :create, :project_id => 1, :copy_from => 3,
2425 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2430 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2426 end
2431 end
2427 end
2432 end
2428 end
2433 end
2429 copy = Issue.first(:order => 'id DESC')
2434 copy = Issue.first(:order => 'id DESC')
2430 assert_equal 0, copy.attachments.count
2435 assert_equal 0, copy.attachments.count
2431 end
2436 end
2432
2437
2433 def test_create_as_copy_with_attachments_should_add_new_files
2438 def test_create_as_copy_with_attachments_should_add_new_files
2434 @request.session[:user_id] = 2
2439 @request.session[:user_id] = 2
2435 issue = Issue.find(3)
2440 issue = Issue.find(3)
2436 count = issue.attachments.count
2441 count = issue.attachments.count
2437 assert count > 0
2442 assert count > 0
2438
2443
2439 assert_difference 'Issue.count' do
2444 assert_difference 'Issue.count' do
2440 assert_difference 'Attachment.count', count + 1 do
2445 assert_difference 'Attachment.count', count + 1 do
2441 assert_no_difference 'Journal.count' do
2446 assert_no_difference 'Journal.count' do
2442 post :create, :project_id => 1, :copy_from => 3,
2447 post :create, :project_id => 1, :copy_from => 3,
2443 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2448 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2444 :copy_attachments => '1',
2449 :copy_attachments => '1',
2445 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2450 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2446 end
2451 end
2447 end
2452 end
2448 end
2453 end
2449 copy = Issue.first(:order => 'id DESC')
2454 copy = Issue.first(:order => 'id DESC')
2450 assert_equal count + 1, copy.attachments.count
2455 assert_equal count + 1, copy.attachments.count
2451 end
2456 end
2452
2457
2453 def test_create_as_copy_should_add_relation_with_copied_issue
2458 def test_create_as_copy_should_add_relation_with_copied_issue
2454 @request.session[:user_id] = 2
2459 @request.session[:user_id] = 2
2455
2460
2456 assert_difference 'Issue.count' do
2461 assert_difference 'Issue.count' do
2457 assert_difference 'IssueRelation.count' do
2462 assert_difference 'IssueRelation.count' do
2458 post :create, :project_id => 1, :copy_from => 1,
2463 post :create, :project_id => 1, :copy_from => 1,
2459 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2464 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2460 end
2465 end
2461 end
2466 end
2462 copy = Issue.first(:order => 'id DESC')
2467 copy = Issue.first(:order => 'id DESC')
2463 assert_equal 1, copy.relations.size
2468 assert_equal 1, copy.relations.size
2464 end
2469 end
2465
2470
2466 def test_create_as_copy_should_copy_subtasks
2471 def test_create_as_copy_should_copy_subtasks
2467 @request.session[:user_id] = 2
2472 @request.session[:user_id] = 2
2468 issue = Issue.generate_with_descendants!
2473 issue = Issue.generate_with_descendants!
2469 count = issue.descendants.count
2474 count = issue.descendants.count
2470
2475
2471 assert_difference 'Issue.count', count+1 do
2476 assert_difference 'Issue.count', count+1 do
2472 assert_no_difference 'Journal.count' do
2477 assert_no_difference 'Journal.count' do
2473 post :create, :project_id => 1, :copy_from => issue.id,
2478 post :create, :project_id => 1, :copy_from => issue.id,
2474 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'},
2479 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'},
2475 :copy_subtasks => '1'
2480 :copy_subtasks => '1'
2476 end
2481 end
2477 end
2482 end
2478 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2483 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2479 assert_equal count, copy.descendants.count
2484 assert_equal count, copy.descendants.count
2480 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2485 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2481 end
2486 end
2482
2487
2483 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2488 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2484 @request.session[:user_id] = 2
2489 @request.session[:user_id] = 2
2485 issue = Issue.generate_with_descendants!
2490 issue = Issue.generate_with_descendants!
2486
2491
2487 assert_difference 'Issue.count', 1 do
2492 assert_difference 'Issue.count', 1 do
2488 assert_no_difference 'Journal.count' do
2493 assert_no_difference 'Journal.count' do
2489 post :create, :project_id => 1, :copy_from => 3,
2494 post :create, :project_id => 1, :copy_from => 3,
2490 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'}
2495 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'}
2491 end
2496 end
2492 end
2497 end
2493 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2498 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2494 assert_equal 0, copy.descendants.count
2499 assert_equal 0, copy.descendants.count
2495 end
2500 end
2496
2501
2497 def test_create_as_copy_with_failure
2502 def test_create_as_copy_with_failure
2498 @request.session[:user_id] = 2
2503 @request.session[:user_id] = 2
2499 post :create, :project_id => 1, :copy_from => 1,
2504 post :create, :project_id => 1, :copy_from => 1,
2500 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2505 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2501
2506
2502 assert_response :success
2507 assert_response :success
2503 assert_template 'new'
2508 assert_template 'new'
2504
2509
2505 assert_not_nil assigns(:issue)
2510 assert_not_nil assigns(:issue)
2506 assert assigns(:issue).copy?
2511 assert assigns(:issue).copy?
2507
2512
2508 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2513 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2509 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2514 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2510 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2515 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2511 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2516 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2512 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2517 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2513 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2518 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2514 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2519 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2515 end
2520 end
2516
2521
2517 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2522 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2518 @request.session[:user_id] = 2
2523 @request.session[:user_id] = 2
2519 assert !User.find(2).member_of?(Project.find(4))
2524 assert !User.find(2).member_of?(Project.find(4))
2520
2525
2521 assert_difference 'Issue.count' do
2526 assert_difference 'Issue.count' do
2522 post :create, :project_id => 1, :copy_from => 1,
2527 post :create, :project_id => 1, :copy_from => 1,
2523 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2528 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2524 end
2529 end
2525 issue = Issue.first(:order => 'id DESC')
2530 issue = Issue.first(:order => 'id DESC')
2526 assert_equal 1, issue.project_id
2531 assert_equal 1, issue.project_id
2527 end
2532 end
2528
2533
2529 def test_get_edit
2534 def test_get_edit
2530 @request.session[:user_id] = 2
2535 @request.session[:user_id] = 2
2531 get :edit, :id => 1
2536 get :edit, :id => 1
2532 assert_response :success
2537 assert_response :success
2533 assert_template 'edit'
2538 assert_template 'edit'
2534 assert_not_nil assigns(:issue)
2539 assert_not_nil assigns(:issue)
2535 assert_equal Issue.find(1), assigns(:issue)
2540 assert_equal Issue.find(1), assigns(:issue)
2536
2541
2537 # Be sure we don't display inactive IssuePriorities
2542 # Be sure we don't display inactive IssuePriorities
2538 assert ! IssuePriority.find(15).active?
2543 assert ! IssuePriority.find(15).active?
2539 assert_no_tag :option, :attributes => {:value => '15'},
2544 assert_no_tag :option, :attributes => {:value => '15'},
2540 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2545 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2541 end
2546 end
2542
2547
2543 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2548 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2544 @request.session[:user_id] = 2
2549 @request.session[:user_id] = 2
2545 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2550 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2546
2551
2547 get :edit, :id => 1
2552 get :edit, :id => 1
2548 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2553 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2549 end
2554 end
2550
2555
2551 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2556 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2552 @request.session[:user_id] = 2
2557 @request.session[:user_id] = 2
2553 Role.find_by_name('Manager').remove_permission! :log_time
2558 Role.find_by_name('Manager').remove_permission! :log_time
2554
2559
2555 get :edit, :id => 1
2560 get :edit, :id => 1
2556 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2561 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2557 end
2562 end
2558
2563
2559 def test_get_edit_with_params
2564 def test_get_edit_with_params
2560 @request.session[:user_id] = 2
2565 @request.session[:user_id] = 2
2561 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2566 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2562 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2567 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2563 assert_response :success
2568 assert_response :success
2564 assert_template 'edit'
2569 assert_template 'edit'
2565
2570
2566 issue = assigns(:issue)
2571 issue = assigns(:issue)
2567 assert_not_nil issue
2572 assert_not_nil issue
2568
2573
2569 assert_equal 5, issue.status_id
2574 assert_equal 5, issue.status_id
2570 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2575 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2571 :child => { :tag => 'option',
2576 :child => { :tag => 'option',
2572 :content => 'Closed',
2577 :content => 'Closed',
2573 :attributes => { :selected => 'selected' } }
2578 :attributes => { :selected => 'selected' } }
2574
2579
2575 assert_equal 7, issue.priority_id
2580 assert_equal 7, issue.priority_id
2576 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2581 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2577 :child => { :tag => 'option',
2582 :child => { :tag => 'option',
2578 :content => 'Urgent',
2583 :content => 'Urgent',
2579 :attributes => { :selected => 'selected' } }
2584 :attributes => { :selected => 'selected' } }
2580
2585
2581 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2586 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2582 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2587 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2583 :child => { :tag => 'option',
2588 :child => { :tag => 'option',
2584 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2589 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2585 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2590 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2586 end
2591 end
2587
2592
2588 def test_get_edit_with_multi_custom_field
2593 def test_get_edit_with_multi_custom_field
2589 field = CustomField.find(1)
2594 field = CustomField.find(1)
2590 field.update_attribute :multiple, true
2595 field.update_attribute :multiple, true
2591 issue = Issue.find(1)
2596 issue = Issue.find(1)
2592 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2597 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2593 issue.save!
2598 issue.save!
2594
2599
2595 @request.session[:user_id] = 2
2600 @request.session[:user_id] = 2
2596 get :edit, :id => 1
2601 get :edit, :id => 1
2597 assert_response :success
2602 assert_response :success
2598 assert_template 'edit'
2603 assert_template 'edit'
2599
2604
2600 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2605 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2601 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2606 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2602 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2607 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2603 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2608 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2604 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2609 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2605 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2610 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2606 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2611 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2607 end
2612 end
2608
2613
2609 def test_update_edit_form
2614 def test_update_edit_form
2610 @request.session[:user_id] = 2
2615 @request.session[:user_id] = 2
2611 xhr :put, :new, :project_id => 1,
2616 xhr :put, :new, :project_id => 1,
2612 :id => 1,
2617 :id => 1,
2613 :issue => {:tracker_id => 2,
2618 :issue => {:tracker_id => 2,
2614 :subject => 'This is the test_new issue',
2619 :subject => 'This is the test_new issue',
2615 :description => 'This is the description',
2620 :description => 'This is the description',
2616 :priority_id => 5}
2621 :priority_id => 5}
2617 assert_response :success
2622 assert_response :success
2618 assert_equal 'text/javascript', response.content_type
2623 assert_equal 'text/javascript', response.content_type
2619 assert_template 'update_form'
2624 assert_template 'update_form'
2620 assert_template 'form'
2625 assert_template 'form'
2621
2626
2622 issue = assigns(:issue)
2627 issue = assigns(:issue)
2623 assert_kind_of Issue, issue
2628 assert_kind_of Issue, issue
2624 assert_equal 1, issue.id
2629 assert_equal 1, issue.id
2625 assert_equal 1, issue.project_id
2630 assert_equal 1, issue.project_id
2626 assert_equal 2, issue.tracker_id
2631 assert_equal 2, issue.tracker_id
2627 assert_equal 'This is the test_new issue', issue.subject
2632 assert_equal 'This is the test_new issue', issue.subject
2628 end
2633 end
2629
2634
2630 def test_update_edit_form_should_keep_issue_author
2635 def test_update_edit_form_should_keep_issue_author
2631 @request.session[:user_id] = 3
2636 @request.session[:user_id] = 3
2632 xhr :put, :new, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2637 xhr :put, :new, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2633 assert_response :success
2638 assert_response :success
2634 assert_equal 'text/javascript', response.content_type
2639 assert_equal 'text/javascript', response.content_type
2635
2640
2636 issue = assigns(:issue)
2641 issue = assigns(:issue)
2637 assert_equal User.find(2), issue.author
2642 assert_equal User.find(2), issue.author
2638 assert_equal 2, issue.author_id
2643 assert_equal 2, issue.author_id
2639 assert_not_equal User.current, issue.author
2644 assert_not_equal User.current, issue.author
2640 end
2645 end
2641
2646
2642 def test_update_edit_form_should_propose_transitions_based_on_initial_status
2647 def test_update_edit_form_should_propose_transitions_based_on_initial_status
2643 @request.session[:user_id] = 2
2648 @request.session[:user_id] = 2
2644 WorkflowTransition.delete_all
2649 WorkflowTransition.delete_all
2645 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2650 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2646 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2651 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2647 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2652 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2648
2653
2649 xhr :put, :new, :project_id => 1,
2654 xhr :put, :new, :project_id => 1,
2650 :id => 2,
2655 :id => 2,
2651 :issue => {:tracker_id => 2,
2656 :issue => {:tracker_id => 2,
2652 :status_id => 5,
2657 :status_id => 5,
2653 :subject => 'This is an issue'}
2658 :subject => 'This is an issue'}
2654
2659
2655 assert_equal 5, assigns(:issue).status_id
2660 assert_equal 5, assigns(:issue).status_id
2656 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2661 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2657 end
2662 end
2658
2663
2659 def test_update_edit_form_with_project_change
2664 def test_update_edit_form_with_project_change
2660 @request.session[:user_id] = 2
2665 @request.session[:user_id] = 2
2661 xhr :put, :new, :project_id => 1,
2666 xhr :put, :new, :project_id => 1,
2662 :id => 1,
2667 :id => 1,
2663 :issue => {:project_id => 2,
2668 :issue => {:project_id => 2,
2664 :tracker_id => 2,
2669 :tracker_id => 2,
2665 :subject => 'This is the test_new issue',
2670 :subject => 'This is the test_new issue',
2666 :description => 'This is the description',
2671 :description => 'This is the description',
2667 :priority_id => 5}
2672 :priority_id => 5}
2668 assert_response :success
2673 assert_response :success
2669 assert_template 'form'
2674 assert_template 'form'
2670
2675
2671 issue = assigns(:issue)
2676 issue = assigns(:issue)
2672 assert_kind_of Issue, issue
2677 assert_kind_of Issue, issue
2673 assert_equal 1, issue.id
2678 assert_equal 1, issue.id
2674 assert_equal 2, issue.project_id
2679 assert_equal 2, issue.project_id
2675 assert_equal 2, issue.tracker_id
2680 assert_equal 2, issue.tracker_id
2676 assert_equal 'This is the test_new issue', issue.subject
2681 assert_equal 'This is the test_new issue', issue.subject
2677 end
2682 end
2678
2683
2679 def test_put_update_without_custom_fields_param
2684 def test_put_update_without_custom_fields_param
2680 @request.session[:user_id] = 2
2685 @request.session[:user_id] = 2
2681 ActionMailer::Base.deliveries.clear
2686 ActionMailer::Base.deliveries.clear
2682
2687
2683 issue = Issue.find(1)
2688 issue = Issue.find(1)
2684 assert_equal '125', issue.custom_value_for(2).value
2689 assert_equal '125', issue.custom_value_for(2).value
2685 old_subject = issue.subject
2690 old_subject = issue.subject
2686 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2691 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2687
2692
2688 assert_difference('Journal.count') do
2693 assert_difference('Journal.count') do
2689 assert_difference('JournalDetail.count', 2) do
2694 assert_difference('JournalDetail.count', 2) do
2690 put :update, :id => 1, :issue => {:subject => new_subject,
2695 put :update, :id => 1, :issue => {:subject => new_subject,
2691 :priority_id => '6',
2696 :priority_id => '6',
2692 :category_id => '1' # no change
2697 :category_id => '1' # no change
2693 }
2698 }
2694 end
2699 end
2695 end
2700 end
2696 assert_redirected_to :action => 'show', :id => '1'
2701 assert_redirected_to :action => 'show', :id => '1'
2697 issue.reload
2702 issue.reload
2698 assert_equal new_subject, issue.subject
2703 assert_equal new_subject, issue.subject
2699 # Make sure custom fields were not cleared
2704 # Make sure custom fields were not cleared
2700 assert_equal '125', issue.custom_value_for(2).value
2705 assert_equal '125', issue.custom_value_for(2).value
2701
2706
2702 mail = ActionMailer::Base.deliveries.last
2707 mail = ActionMailer::Base.deliveries.last
2703 assert_not_nil mail
2708 assert_not_nil mail
2704 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2709 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2705 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2710 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2706 end
2711 end
2707
2712
2708 def test_put_update_with_project_change
2713 def test_put_update_with_project_change
2709 @request.session[:user_id] = 2
2714 @request.session[:user_id] = 2
2710 ActionMailer::Base.deliveries.clear
2715 ActionMailer::Base.deliveries.clear
2711
2716
2712 assert_difference('Journal.count') do
2717 assert_difference('Journal.count') do
2713 assert_difference('JournalDetail.count', 3) do
2718 assert_difference('JournalDetail.count', 3) do
2714 put :update, :id => 1, :issue => {:project_id => '2',
2719 put :update, :id => 1, :issue => {:project_id => '2',
2715 :tracker_id => '1', # no change
2720 :tracker_id => '1', # no change
2716 :priority_id => '6',
2721 :priority_id => '6',
2717 :category_id => '3'
2722 :category_id => '3'
2718 }
2723 }
2719 end
2724 end
2720 end
2725 end
2721 assert_redirected_to :action => 'show', :id => '1'
2726 assert_redirected_to :action => 'show', :id => '1'
2722 issue = Issue.find(1)
2727 issue = Issue.find(1)
2723 assert_equal 2, issue.project_id
2728 assert_equal 2, issue.project_id
2724 assert_equal 1, issue.tracker_id
2729 assert_equal 1, issue.tracker_id
2725 assert_equal 6, issue.priority_id
2730 assert_equal 6, issue.priority_id
2726 assert_equal 3, issue.category_id
2731 assert_equal 3, issue.category_id
2727
2732
2728 mail = ActionMailer::Base.deliveries.last
2733 mail = ActionMailer::Base.deliveries.last
2729 assert_not_nil mail
2734 assert_not_nil mail
2730 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2735 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2731 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2736 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2732 end
2737 end
2733
2738
2734 def test_put_update_with_tracker_change
2739 def test_put_update_with_tracker_change
2735 @request.session[:user_id] = 2
2740 @request.session[:user_id] = 2
2736 ActionMailer::Base.deliveries.clear
2741 ActionMailer::Base.deliveries.clear
2737
2742
2738 assert_difference('Journal.count') do
2743 assert_difference('Journal.count') do
2739 assert_difference('JournalDetail.count', 2) do
2744 assert_difference('JournalDetail.count', 2) do
2740 put :update, :id => 1, :issue => {:project_id => '1',
2745 put :update, :id => 1, :issue => {:project_id => '1',
2741 :tracker_id => '2',
2746 :tracker_id => '2',
2742 :priority_id => '6'
2747 :priority_id => '6'
2743 }
2748 }
2744 end
2749 end
2745 end
2750 end
2746 assert_redirected_to :action => 'show', :id => '1'
2751 assert_redirected_to :action => 'show', :id => '1'
2747 issue = Issue.find(1)
2752 issue = Issue.find(1)
2748 assert_equal 1, issue.project_id
2753 assert_equal 1, issue.project_id
2749 assert_equal 2, issue.tracker_id
2754 assert_equal 2, issue.tracker_id
2750 assert_equal 6, issue.priority_id
2755 assert_equal 6, issue.priority_id
2751 assert_equal 1, issue.category_id
2756 assert_equal 1, issue.category_id
2752
2757
2753 mail = ActionMailer::Base.deliveries.last
2758 mail = ActionMailer::Base.deliveries.last
2754 assert_not_nil mail
2759 assert_not_nil mail
2755 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2760 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2756 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2761 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2757 end
2762 end
2758
2763
2759 def test_put_update_with_custom_field_change
2764 def test_put_update_with_custom_field_change
2760 @request.session[:user_id] = 2
2765 @request.session[:user_id] = 2
2761 issue = Issue.find(1)
2766 issue = Issue.find(1)
2762 assert_equal '125', issue.custom_value_for(2).value
2767 assert_equal '125', issue.custom_value_for(2).value
2763
2768
2764 assert_difference('Journal.count') do
2769 assert_difference('Journal.count') do
2765 assert_difference('JournalDetail.count', 3) do
2770 assert_difference('JournalDetail.count', 3) do
2766 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2771 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2767 :priority_id => '6',
2772 :priority_id => '6',
2768 :category_id => '1', # no change
2773 :category_id => '1', # no change
2769 :custom_field_values => { '2' => 'New custom value' }
2774 :custom_field_values => { '2' => 'New custom value' }
2770 }
2775 }
2771 end
2776 end
2772 end
2777 end
2773 assert_redirected_to :action => 'show', :id => '1'
2778 assert_redirected_to :action => 'show', :id => '1'
2774 issue.reload
2779 issue.reload
2775 assert_equal 'New custom value', issue.custom_value_for(2).value
2780 assert_equal 'New custom value', issue.custom_value_for(2).value
2776
2781
2777 mail = ActionMailer::Base.deliveries.last
2782 mail = ActionMailer::Base.deliveries.last
2778 assert_not_nil mail
2783 assert_not_nil mail
2779 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2784 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2780 end
2785 end
2781
2786
2782 def test_put_update_with_multi_custom_field_change
2787 def test_put_update_with_multi_custom_field_change
2783 field = CustomField.find(1)
2788 field = CustomField.find(1)
2784 field.update_attribute :multiple, true
2789 field.update_attribute :multiple, true
2785 issue = Issue.find(1)
2790 issue = Issue.find(1)
2786 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2791 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2787 issue.save!
2792 issue.save!
2788
2793
2789 @request.session[:user_id] = 2
2794 @request.session[:user_id] = 2
2790 assert_difference('Journal.count') do
2795 assert_difference('Journal.count') do
2791 assert_difference('JournalDetail.count', 3) do
2796 assert_difference('JournalDetail.count', 3) do
2792 put :update, :id => 1,
2797 put :update, :id => 1,
2793 :issue => {
2798 :issue => {
2794 :subject => 'Custom field change',
2799 :subject => 'Custom field change',
2795 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2800 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2796 }
2801 }
2797 end
2802 end
2798 end
2803 end
2799 assert_redirected_to :action => 'show', :id => '1'
2804 assert_redirected_to :action => 'show', :id => '1'
2800 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2805 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2801 end
2806 end
2802
2807
2803 def test_put_update_with_status_and_assignee_change
2808 def test_put_update_with_status_and_assignee_change
2804 issue = Issue.find(1)
2809 issue = Issue.find(1)
2805 assert_equal 1, issue.status_id
2810 assert_equal 1, issue.status_id
2806 @request.session[:user_id] = 2
2811 @request.session[:user_id] = 2
2807 assert_difference('TimeEntry.count', 0) do
2812 assert_difference('TimeEntry.count', 0) do
2808 put :update,
2813 put :update,
2809 :id => 1,
2814 :id => 1,
2810 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
2815 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
2811 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2816 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2812 end
2817 end
2813 assert_redirected_to :action => 'show', :id => '1'
2818 assert_redirected_to :action => 'show', :id => '1'
2814 issue.reload
2819 issue.reload
2815 assert_equal 2, issue.status_id
2820 assert_equal 2, issue.status_id
2816 j = Journal.order('id DESC').first
2821 j = Journal.order('id DESC').first
2817 assert_equal 'Assigned to dlopper', j.notes
2822 assert_equal 'Assigned to dlopper', j.notes
2818 assert_equal 2, j.details.size
2823 assert_equal 2, j.details.size
2819
2824
2820 mail = ActionMailer::Base.deliveries.last
2825 mail = ActionMailer::Base.deliveries.last
2821 assert_mail_body_match "Status changed from New to Assigned", mail
2826 assert_mail_body_match "Status changed from New to Assigned", mail
2822 # subject should contain the new status
2827 # subject should contain the new status
2823 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2828 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2824 end
2829 end
2825
2830
2826 def test_put_update_with_note_only
2831 def test_put_update_with_note_only
2827 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2832 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2828 # anonymous user
2833 # anonymous user
2829 put :update,
2834 put :update,
2830 :id => 1,
2835 :id => 1,
2831 :issue => { :notes => notes }
2836 :issue => { :notes => notes }
2832 assert_redirected_to :action => 'show', :id => '1'
2837 assert_redirected_to :action => 'show', :id => '1'
2833 j = Journal.order('id DESC').first
2838 j = Journal.order('id DESC').first
2834 assert_equal notes, j.notes
2839 assert_equal notes, j.notes
2835 assert_equal 0, j.details.size
2840 assert_equal 0, j.details.size
2836 assert_equal User.anonymous, j.user
2841 assert_equal User.anonymous, j.user
2837
2842
2838 mail = ActionMailer::Base.deliveries.last
2843 mail = ActionMailer::Base.deliveries.last
2839 assert_mail_body_match notes, mail
2844 assert_mail_body_match notes, mail
2840 end
2845 end
2841
2846
2842 def test_put_update_with_private_note_only
2847 def test_put_update_with_private_note_only
2843 notes = 'Private note'
2848 notes = 'Private note'
2844 @request.session[:user_id] = 2
2849 @request.session[:user_id] = 2
2845
2850
2846 assert_difference 'Journal.count' do
2851 assert_difference 'Journal.count' do
2847 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
2852 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
2848 assert_redirected_to :action => 'show', :id => '1'
2853 assert_redirected_to :action => 'show', :id => '1'
2849 end
2854 end
2850
2855
2851 j = Journal.order('id DESC').first
2856 j = Journal.order('id DESC').first
2852 assert_equal notes, j.notes
2857 assert_equal notes, j.notes
2853 assert_equal true, j.private_notes
2858 assert_equal true, j.private_notes
2854 end
2859 end
2855
2860
2856 def test_put_update_with_private_note_and_changes
2861 def test_put_update_with_private_note_and_changes
2857 notes = 'Private note'
2862 notes = 'Private note'
2858 @request.session[:user_id] = 2
2863 @request.session[:user_id] = 2
2859
2864
2860 assert_difference 'Journal.count', 2 do
2865 assert_difference 'Journal.count', 2 do
2861 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
2866 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
2862 assert_redirected_to :action => 'show', :id => '1'
2867 assert_redirected_to :action => 'show', :id => '1'
2863 end
2868 end
2864
2869
2865 j = Journal.order('id DESC').first
2870 j = Journal.order('id DESC').first
2866 assert_equal notes, j.notes
2871 assert_equal notes, j.notes
2867 assert_equal true, j.private_notes
2872 assert_equal true, j.private_notes
2868 assert_equal 0, j.details.count
2873 assert_equal 0, j.details.count
2869
2874
2870 j = Journal.order('id DESC').offset(1).first
2875 j = Journal.order('id DESC').offset(1).first
2871 assert_nil j.notes
2876 assert_nil j.notes
2872 assert_equal false, j.private_notes
2877 assert_equal false, j.private_notes
2873 assert_equal 1, j.details.count
2878 assert_equal 1, j.details.count
2874 end
2879 end
2875
2880
2876 def test_put_update_with_note_and_spent_time
2881 def test_put_update_with_note_and_spent_time
2877 @request.session[:user_id] = 2
2882 @request.session[:user_id] = 2
2878 spent_hours_before = Issue.find(1).spent_hours
2883 spent_hours_before = Issue.find(1).spent_hours
2879 assert_difference('TimeEntry.count') do
2884 assert_difference('TimeEntry.count') do
2880 put :update,
2885 put :update,
2881 :id => 1,
2886 :id => 1,
2882 :issue => { :notes => '2.5 hours added' },
2887 :issue => { :notes => '2.5 hours added' },
2883 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2888 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2884 end
2889 end
2885 assert_redirected_to :action => 'show', :id => '1'
2890 assert_redirected_to :action => 'show', :id => '1'
2886
2891
2887 issue = Issue.find(1)
2892 issue = Issue.find(1)
2888
2893
2889 j = Journal.order('id DESC').first
2894 j = Journal.order('id DESC').first
2890 assert_equal '2.5 hours added', j.notes
2895 assert_equal '2.5 hours added', j.notes
2891 assert_equal 0, j.details.size
2896 assert_equal 0, j.details.size
2892
2897
2893 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2898 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2894 assert_not_nil t
2899 assert_not_nil t
2895 assert_equal 2.5, t.hours
2900 assert_equal 2.5, t.hours
2896 assert_equal spent_hours_before + 2.5, issue.spent_hours
2901 assert_equal spent_hours_before + 2.5, issue.spent_hours
2897 end
2902 end
2898
2903
2899 def test_put_update_with_attachment_only
2904 def test_put_update_with_attachment_only
2900 set_tmp_attachments_directory
2905 set_tmp_attachments_directory
2901
2906
2902 # Delete all fixtured journals, a race condition can occur causing the wrong
2907 # Delete all fixtured journals, a race condition can occur causing the wrong
2903 # journal to get fetched in the next find.
2908 # journal to get fetched in the next find.
2904 Journal.delete_all
2909 Journal.delete_all
2905
2910
2906 # anonymous user
2911 # anonymous user
2907 assert_difference 'Attachment.count' do
2912 assert_difference 'Attachment.count' do
2908 put :update, :id => 1,
2913 put :update, :id => 1,
2909 :issue => {:notes => ''},
2914 :issue => {:notes => ''},
2910 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2915 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2911 end
2916 end
2912
2917
2913 assert_redirected_to :action => 'show', :id => '1'
2918 assert_redirected_to :action => 'show', :id => '1'
2914 j = Issue.find(1).journals.reorder('id DESC').first
2919 j = Issue.find(1).journals.reorder('id DESC').first
2915 assert j.notes.blank?
2920 assert j.notes.blank?
2916 assert_equal 1, j.details.size
2921 assert_equal 1, j.details.size
2917 assert_equal 'testfile.txt', j.details.first.value
2922 assert_equal 'testfile.txt', j.details.first.value
2918 assert_equal User.anonymous, j.user
2923 assert_equal User.anonymous, j.user
2919
2924
2920 attachment = Attachment.first(:order => 'id DESC')
2925 attachment = Attachment.first(:order => 'id DESC')
2921 assert_equal Issue.find(1), attachment.container
2926 assert_equal Issue.find(1), attachment.container
2922 assert_equal User.anonymous, attachment.author
2927 assert_equal User.anonymous, attachment.author
2923 assert_equal 'testfile.txt', attachment.filename
2928 assert_equal 'testfile.txt', attachment.filename
2924 assert_equal 'text/plain', attachment.content_type
2929 assert_equal 'text/plain', attachment.content_type
2925 assert_equal 'test file', attachment.description
2930 assert_equal 'test file', attachment.description
2926 assert_equal 59, attachment.filesize
2931 assert_equal 59, attachment.filesize
2927 assert File.exists?(attachment.diskfile)
2932 assert File.exists?(attachment.diskfile)
2928 assert_equal 59, File.size(attachment.diskfile)
2933 assert_equal 59, File.size(attachment.diskfile)
2929
2934
2930 mail = ActionMailer::Base.deliveries.last
2935 mail = ActionMailer::Base.deliveries.last
2931 assert_mail_body_match 'testfile.txt', mail
2936 assert_mail_body_match 'testfile.txt', mail
2932 end
2937 end
2933
2938
2934 def test_put_update_with_failure_should_save_attachments
2939 def test_put_update_with_failure_should_save_attachments
2935 set_tmp_attachments_directory
2940 set_tmp_attachments_directory
2936 @request.session[:user_id] = 2
2941 @request.session[:user_id] = 2
2937
2942
2938 assert_no_difference 'Journal.count' do
2943 assert_no_difference 'Journal.count' do
2939 assert_difference 'Attachment.count' do
2944 assert_difference 'Attachment.count' do
2940 put :update, :id => 1,
2945 put :update, :id => 1,
2941 :issue => { :subject => '' },
2946 :issue => { :subject => '' },
2942 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2947 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2943 assert_response :success
2948 assert_response :success
2944 assert_template 'edit'
2949 assert_template 'edit'
2945 end
2950 end
2946 end
2951 end
2947
2952
2948 attachment = Attachment.first(:order => 'id DESC')
2953 attachment = Attachment.first(:order => 'id DESC')
2949 assert_equal 'testfile.txt', attachment.filename
2954 assert_equal 'testfile.txt', attachment.filename
2950 assert File.exists?(attachment.diskfile)
2955 assert File.exists?(attachment.diskfile)
2951 assert_nil attachment.container
2956 assert_nil attachment.container
2952
2957
2953 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2958 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2954 assert_tag 'span', :content => /testfile.txt/
2959 assert_tag 'span', :content => /testfile.txt/
2955 end
2960 end
2956
2961
2957 def test_put_update_with_failure_should_keep_saved_attachments
2962 def test_put_update_with_failure_should_keep_saved_attachments
2958 set_tmp_attachments_directory
2963 set_tmp_attachments_directory
2959 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2964 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2960 @request.session[:user_id] = 2
2965 @request.session[:user_id] = 2
2961
2966
2962 assert_no_difference 'Journal.count' do
2967 assert_no_difference 'Journal.count' do
2963 assert_no_difference 'Attachment.count' do
2968 assert_no_difference 'Attachment.count' do
2964 put :update, :id => 1,
2969 put :update, :id => 1,
2965 :issue => { :subject => '' },
2970 :issue => { :subject => '' },
2966 :attachments => {'p0' => {'token' => attachment.token}}
2971 :attachments => {'p0' => {'token' => attachment.token}}
2967 assert_response :success
2972 assert_response :success
2968 assert_template 'edit'
2973 assert_template 'edit'
2969 end
2974 end
2970 end
2975 end
2971
2976
2972 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2977 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2973 assert_tag 'span', :content => /testfile.txt/
2978 assert_tag 'span', :content => /testfile.txt/
2974 end
2979 end
2975
2980
2976 def test_put_update_should_attach_saved_attachments
2981 def test_put_update_should_attach_saved_attachments
2977 set_tmp_attachments_directory
2982 set_tmp_attachments_directory
2978 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2983 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2979 @request.session[:user_id] = 2
2984 @request.session[:user_id] = 2
2980
2985
2981 assert_difference 'Journal.count' do
2986 assert_difference 'Journal.count' do
2982 assert_difference 'JournalDetail.count' do
2987 assert_difference 'JournalDetail.count' do
2983 assert_no_difference 'Attachment.count' do
2988 assert_no_difference 'Attachment.count' do
2984 put :update, :id => 1,
2989 put :update, :id => 1,
2985 :issue => {:notes => 'Attachment added'},
2990 :issue => {:notes => 'Attachment added'},
2986 :attachments => {'p0' => {'token' => attachment.token}}
2991 :attachments => {'p0' => {'token' => attachment.token}}
2987 assert_redirected_to '/issues/1'
2992 assert_redirected_to '/issues/1'
2988 end
2993 end
2989 end
2994 end
2990 end
2995 end
2991
2996
2992 attachment.reload
2997 attachment.reload
2993 assert_equal Issue.find(1), attachment.container
2998 assert_equal Issue.find(1), attachment.container
2994
2999
2995 journal = Journal.first(:order => 'id DESC')
3000 journal = Journal.first(:order => 'id DESC')
2996 assert_equal 1, journal.details.size
3001 assert_equal 1, journal.details.size
2997 assert_equal 'testfile.txt', journal.details.first.value
3002 assert_equal 'testfile.txt', journal.details.first.value
2998 end
3003 end
2999
3004
3000 def test_put_update_with_attachment_that_fails_to_save
3005 def test_put_update_with_attachment_that_fails_to_save
3001 set_tmp_attachments_directory
3006 set_tmp_attachments_directory
3002
3007
3003 # Delete all fixtured journals, a race condition can occur causing the wrong
3008 # Delete all fixtured journals, a race condition can occur causing the wrong
3004 # journal to get fetched in the next find.
3009 # journal to get fetched in the next find.
3005 Journal.delete_all
3010 Journal.delete_all
3006
3011
3007 # Mock out the unsaved attachment
3012 # Mock out the unsaved attachment
3008 Attachment.any_instance.stubs(:create).returns(Attachment.new)
3013 Attachment.any_instance.stubs(:create).returns(Attachment.new)
3009
3014
3010 # anonymous user
3015 # anonymous user
3011 put :update,
3016 put :update,
3012 :id => 1,
3017 :id => 1,
3013 :issue => {:notes => ''},
3018 :issue => {:notes => ''},
3014 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3019 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3015 assert_redirected_to :action => 'show', :id => '1'
3020 assert_redirected_to :action => 'show', :id => '1'
3016 assert_equal '1 file(s) could not be saved.', flash[:warning]
3021 assert_equal '1 file(s) could not be saved.', flash[:warning]
3017 end
3022 end
3018
3023
3019 def test_put_update_with_no_change
3024 def test_put_update_with_no_change
3020 issue = Issue.find(1)
3025 issue = Issue.find(1)
3021 issue.journals.clear
3026 issue.journals.clear
3022 ActionMailer::Base.deliveries.clear
3027 ActionMailer::Base.deliveries.clear
3023
3028
3024 put :update,
3029 put :update,
3025 :id => 1,
3030 :id => 1,
3026 :issue => {:notes => ''}
3031 :issue => {:notes => ''}
3027 assert_redirected_to :action => 'show', :id => '1'
3032 assert_redirected_to :action => 'show', :id => '1'
3028
3033
3029 issue.reload
3034 issue.reload
3030 assert issue.journals.empty?
3035 assert issue.journals.empty?
3031 # No email should be sent
3036 # No email should be sent
3032 assert ActionMailer::Base.deliveries.empty?
3037 assert ActionMailer::Base.deliveries.empty?
3033 end
3038 end
3034
3039
3035 def test_put_update_should_send_a_notification
3040 def test_put_update_should_send_a_notification
3036 @request.session[:user_id] = 2
3041 @request.session[:user_id] = 2
3037 ActionMailer::Base.deliveries.clear
3042 ActionMailer::Base.deliveries.clear
3038 issue = Issue.find(1)
3043 issue = Issue.find(1)
3039 old_subject = issue.subject
3044 old_subject = issue.subject
3040 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3045 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3041
3046
3042 put :update, :id => 1, :issue => {:subject => new_subject,
3047 put :update, :id => 1, :issue => {:subject => new_subject,
3043 :priority_id => '6',
3048 :priority_id => '6',
3044 :category_id => '1' # no change
3049 :category_id => '1' # no change
3045 }
3050 }
3046 assert_equal 1, ActionMailer::Base.deliveries.size
3051 assert_equal 1, ActionMailer::Base.deliveries.size
3047 end
3052 end
3048
3053
3049 def test_put_update_with_invalid_spent_time_hours_only
3054 def test_put_update_with_invalid_spent_time_hours_only
3050 @request.session[:user_id] = 2
3055 @request.session[:user_id] = 2
3051 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3056 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3052
3057
3053 assert_no_difference('Journal.count') do
3058 assert_no_difference('Journal.count') do
3054 put :update,
3059 put :update,
3055 :id => 1,
3060 :id => 1,
3056 :issue => {:notes => notes},
3061 :issue => {:notes => notes},
3057 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3062 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3058 end
3063 end
3059 assert_response :success
3064 assert_response :success
3060 assert_template 'edit'
3065 assert_template 'edit'
3061
3066
3062 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3067 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3063 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes
3068 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes
3064 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
3069 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
3065 end
3070 end
3066
3071
3067 def test_put_update_with_invalid_spent_time_comments_only
3072 def test_put_update_with_invalid_spent_time_comments_only
3068 @request.session[:user_id] = 2
3073 @request.session[:user_id] = 2
3069 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3074 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3070
3075
3071 assert_no_difference('Journal.count') do
3076 assert_no_difference('Journal.count') do
3072 put :update,
3077 put :update,
3073 :id => 1,
3078 :id => 1,
3074 :issue => {:notes => notes},
3079 :issue => {:notes => notes},
3075 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3080 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3076 end
3081 end
3077 assert_response :success
3082 assert_response :success
3078 assert_template 'edit'
3083 assert_template 'edit'
3079
3084
3080 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3085 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3081 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/}
3086 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/}
3082 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes
3087 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes
3083 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
3088 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
3084 end
3089 end
3085
3090
3086 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3091 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3087 issue = Issue.find(2)
3092 issue = Issue.find(2)
3088 @request.session[:user_id] = 2
3093 @request.session[:user_id] = 2
3089
3094
3090 put :update,
3095 put :update,
3091 :id => issue.id,
3096 :id => issue.id,
3092 :issue => {
3097 :issue => {
3093 :fixed_version_id => 4
3098 :fixed_version_id => 4
3094 }
3099 }
3095
3100
3096 assert_response :redirect
3101 assert_response :redirect
3097 issue.reload
3102 issue.reload
3098 assert_equal 4, issue.fixed_version_id
3103 assert_equal 4, issue.fixed_version_id
3099 assert_not_equal issue.project_id, issue.fixed_version.project_id
3104 assert_not_equal issue.project_id, issue.fixed_version.project_id
3100 end
3105 end
3101
3106
3102 def test_put_update_should_redirect_back_using_the_back_url_parameter
3107 def test_put_update_should_redirect_back_using_the_back_url_parameter
3103 issue = Issue.find(2)
3108 issue = Issue.find(2)
3104 @request.session[:user_id] = 2
3109 @request.session[:user_id] = 2
3105
3110
3106 put :update,
3111 put :update,
3107 :id => issue.id,
3112 :id => issue.id,
3108 :issue => {
3113 :issue => {
3109 :fixed_version_id => 4
3114 :fixed_version_id => 4
3110 },
3115 },
3111 :back_url => '/issues'
3116 :back_url => '/issues'
3112
3117
3113 assert_response :redirect
3118 assert_response :redirect
3114 assert_redirected_to '/issues'
3119 assert_redirected_to '/issues'
3115 end
3120 end
3116
3121
3117 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3122 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3118 issue = Issue.find(2)
3123 issue = Issue.find(2)
3119 @request.session[:user_id] = 2
3124 @request.session[:user_id] = 2
3120
3125
3121 put :update,
3126 put :update,
3122 :id => issue.id,
3127 :id => issue.id,
3123 :issue => {
3128 :issue => {
3124 :fixed_version_id => 4
3129 :fixed_version_id => 4
3125 },
3130 },
3126 :back_url => 'http://google.com'
3131 :back_url => 'http://google.com'
3127
3132
3128 assert_response :redirect
3133 assert_response :redirect
3129 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3134 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3130 end
3135 end
3131
3136
3132 def test_get_bulk_edit
3137 def test_get_bulk_edit
3133 @request.session[:user_id] = 2
3138 @request.session[:user_id] = 2
3134 get :bulk_edit, :ids => [1, 2]
3139 get :bulk_edit, :ids => [1, 2]
3135 assert_response :success
3140 assert_response :success
3136 assert_template 'bulk_edit'
3141 assert_template 'bulk_edit'
3137
3142
3138 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
3143 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
3139 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
3144 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
3140
3145
3141 # Project specific custom field, date type
3146 # Project specific custom field, date type
3142 field = CustomField.find(9)
3147 field = CustomField.find(9)
3143 assert !field.is_for_all?
3148 assert !field.is_for_all?
3144 assert_equal 'date', field.field_format
3149 assert_equal 'date', field.field_format
3145 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
3150 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
3146
3151
3147 # System wide custom field
3152 # System wide custom field
3148 assert CustomField.find(1).is_for_all?
3153 assert CustomField.find(1).is_for_all?
3149 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
3154 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
3150
3155
3151 # Be sure we don't display inactive IssuePriorities
3156 # Be sure we don't display inactive IssuePriorities
3152 assert ! IssuePriority.find(15).active?
3157 assert ! IssuePriority.find(15).active?
3153 assert_no_tag :option, :attributes => {:value => '15'},
3158 assert_no_tag :option, :attributes => {:value => '15'},
3154 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
3159 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
3155 end
3160 end
3156
3161
3157 def test_get_bulk_edit_on_different_projects
3162 def test_get_bulk_edit_on_different_projects
3158 @request.session[:user_id] = 2
3163 @request.session[:user_id] = 2
3159 get :bulk_edit, :ids => [1, 2, 6]
3164 get :bulk_edit, :ids => [1, 2, 6]
3160 assert_response :success
3165 assert_response :success
3161 assert_template 'bulk_edit'
3166 assert_template 'bulk_edit'
3162
3167
3163 # Can not set issues from different projects as children of an issue
3168 # Can not set issues from different projects as children of an issue
3164 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
3169 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
3165
3170
3166 # Project specific custom field, date type
3171 # Project specific custom field, date type
3167 field = CustomField.find(9)
3172 field = CustomField.find(9)
3168 assert !field.is_for_all?
3173 assert !field.is_for_all?
3169 assert !field.project_ids.include?(Issue.find(6).project_id)
3174 assert !field.project_ids.include?(Issue.find(6).project_id)
3170 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
3175 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
3171 end
3176 end
3172
3177
3173 def test_get_bulk_edit_with_user_custom_field
3178 def test_get_bulk_edit_with_user_custom_field
3174 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
3179 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
3175
3180
3176 @request.session[:user_id] = 2
3181 @request.session[:user_id] = 2
3177 get :bulk_edit, :ids => [1, 2]
3182 get :bulk_edit, :ids => [1, 2]
3178 assert_response :success
3183 assert_response :success
3179 assert_template 'bulk_edit'
3184 assert_template 'bulk_edit'
3180
3185
3181 assert_tag :select,
3186 assert_tag :select,
3182 :attributes => {:name => "issue[custom_field_values][#{field.id}]", :class => 'user_cf'},
3187 :attributes => {:name => "issue[custom_field_values][#{field.id}]", :class => 'user_cf'},
3183 :children => {
3188 :children => {
3184 :only => {:tag => 'option'},
3189 :only => {:tag => 'option'},
3185 :count => Project.find(1).users.count + 2 # "no change" + "none" options
3190 :count => Project.find(1).users.count + 2 # "no change" + "none" options
3186 }
3191 }
3187 end
3192 end
3188
3193
3189 def test_get_bulk_edit_with_version_custom_field
3194 def test_get_bulk_edit_with_version_custom_field
3190 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
3195 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
3191
3196
3192 @request.session[:user_id] = 2
3197 @request.session[:user_id] = 2
3193 get :bulk_edit, :ids => [1, 2]
3198 get :bulk_edit, :ids => [1, 2]
3194 assert_response :success
3199 assert_response :success
3195 assert_template 'bulk_edit'
3200 assert_template 'bulk_edit'
3196
3201
3197 assert_tag :select,
3202 assert_tag :select,
3198 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
3203 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
3199 :children => {
3204 :children => {
3200 :only => {:tag => 'option'},
3205 :only => {:tag => 'option'},
3201 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3206 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3202 }
3207 }
3203 end
3208 end
3204
3209
3205 def test_get_bulk_edit_with_multi_custom_field
3210 def test_get_bulk_edit_with_multi_custom_field
3206 field = CustomField.find(1)
3211 field = CustomField.find(1)
3207 field.update_attribute :multiple, true
3212 field.update_attribute :multiple, true
3208
3213
3209 @request.session[:user_id] = 2
3214 @request.session[:user_id] = 2
3210 get :bulk_edit, :ids => [1, 2]
3215 get :bulk_edit, :ids => [1, 2]
3211 assert_response :success
3216 assert_response :success
3212 assert_template 'bulk_edit'
3217 assert_template 'bulk_edit'
3213
3218
3214 assert_tag :select,
3219 assert_tag :select,
3215 :attributes => {:name => "issue[custom_field_values][1][]"},
3220 :attributes => {:name => "issue[custom_field_values][1][]"},
3216 :children => {
3221 :children => {
3217 :only => {:tag => 'option'},
3222 :only => {:tag => 'option'},
3218 :count => field.possible_values.size + 1 # "none" options
3223 :count => field.possible_values.size + 1 # "none" options
3219 }
3224 }
3220 end
3225 end
3221
3226
3222 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3227 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3223 WorkflowTransition.delete_all
3228 WorkflowTransition.delete_all
3224 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
3229 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
3225 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
3230 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
3226 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
3231 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
3227 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3232 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3228 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3233 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3229 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3234 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3230 @request.session[:user_id] = 2
3235 @request.session[:user_id] = 2
3231 get :bulk_edit, :ids => [1, 2]
3236 get :bulk_edit, :ids => [1, 2]
3232
3237
3233 assert_response :success
3238 assert_response :success
3234 statuses = assigns(:available_statuses)
3239 statuses = assigns(:available_statuses)
3235 assert_not_nil statuses
3240 assert_not_nil statuses
3236 assert_equal [1, 3], statuses.map(&:id).sort
3241 assert_equal [1, 3], statuses.map(&:id).sort
3237
3242
3238 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
3243 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
3239 :children => {:count => 3} # 2 statuses + "no change" option
3244 :children => {:count => 3} # 2 statuses + "no change" option
3240 end
3245 end
3241
3246
3242 def test_bulk_edit_should_propose_target_project_open_shared_versions
3247 def test_bulk_edit_should_propose_target_project_open_shared_versions
3243 @request.session[:user_id] = 2
3248 @request.session[:user_id] = 2
3244 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3249 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3245 assert_response :success
3250 assert_response :success
3246 assert_template 'bulk_edit'
3251 assert_template 'bulk_edit'
3247 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
3252 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
3248 assert_tag 'select',
3253 assert_tag 'select',
3249 :attributes => {:name => 'issue[fixed_version_id]'},
3254 :attributes => {:name => 'issue[fixed_version_id]'},
3250 :descendant => {:tag => 'option', :content => '2.0'}
3255 :descendant => {:tag => 'option', :content => '2.0'}
3251 end
3256 end
3252
3257
3253 def test_bulk_edit_should_propose_target_project_categories
3258 def test_bulk_edit_should_propose_target_project_categories
3254 @request.session[:user_id] = 2
3259 @request.session[:user_id] = 2
3255 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3260 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3256 assert_response :success
3261 assert_response :success
3257 assert_template 'bulk_edit'
3262 assert_template 'bulk_edit'
3258 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3263 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3259 assert_tag 'select',
3264 assert_tag 'select',
3260 :attributes => {:name => 'issue[category_id]'},
3265 :attributes => {:name => 'issue[category_id]'},
3261 :descendant => {:tag => 'option', :content => 'Recipes'}
3266 :descendant => {:tag => 'option', :content => 'Recipes'}
3262 end
3267 end
3263
3268
3264 def test_bulk_update
3269 def test_bulk_update
3265 @request.session[:user_id] = 2
3270 @request.session[:user_id] = 2
3266 # update issues priority
3271 # update issues priority
3267 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3272 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3268 :issue => {:priority_id => 7,
3273 :issue => {:priority_id => 7,
3269 :assigned_to_id => '',
3274 :assigned_to_id => '',
3270 :custom_field_values => {'2' => ''}}
3275 :custom_field_values => {'2' => ''}}
3271
3276
3272 assert_response 302
3277 assert_response 302
3273 # check that the issues were updated
3278 # check that the issues were updated
3274 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
3279 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
3275
3280
3276 issue = Issue.find(1)
3281 issue = Issue.find(1)
3277 journal = issue.journals.reorder('created_on DESC').first
3282 journal = issue.journals.reorder('created_on DESC').first
3278 assert_equal '125', issue.custom_value_for(2).value
3283 assert_equal '125', issue.custom_value_for(2).value
3279 assert_equal 'Bulk editing', journal.notes
3284 assert_equal 'Bulk editing', journal.notes
3280 assert_equal 1, journal.details.size
3285 assert_equal 1, journal.details.size
3281 end
3286 end
3282
3287
3283 def test_bulk_update_with_group_assignee
3288 def test_bulk_update_with_group_assignee
3284 group = Group.find(11)
3289 group = Group.find(11)
3285 project = Project.find(1)
3290 project = Project.find(1)
3286 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3291 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3287
3292
3288 @request.session[:user_id] = 2
3293 @request.session[:user_id] = 2
3289 # update issues assignee
3294 # update issues assignee
3290 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3295 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3291 :issue => {:priority_id => '',
3296 :issue => {:priority_id => '',
3292 :assigned_to_id => group.id,
3297 :assigned_to_id => group.id,
3293 :custom_field_values => {'2' => ''}}
3298 :custom_field_values => {'2' => ''}}
3294
3299
3295 assert_response 302
3300 assert_response 302
3296 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
3301 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
3297 end
3302 end
3298
3303
3299 def test_bulk_update_on_different_projects
3304 def test_bulk_update_on_different_projects
3300 @request.session[:user_id] = 2
3305 @request.session[:user_id] = 2
3301 # update issues priority
3306 # update issues priority
3302 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3307 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3303 :issue => {:priority_id => 7,
3308 :issue => {:priority_id => 7,
3304 :assigned_to_id => '',
3309 :assigned_to_id => '',
3305 :custom_field_values => {'2' => ''}}
3310 :custom_field_values => {'2' => ''}}
3306
3311
3307 assert_response 302
3312 assert_response 302
3308 # check that the issues were updated
3313 # check that the issues were updated
3309 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3314 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3310
3315
3311 issue = Issue.find(1)
3316 issue = Issue.find(1)
3312 journal = issue.journals.reorder('created_on DESC').first
3317 journal = issue.journals.reorder('created_on DESC').first
3313 assert_equal '125', issue.custom_value_for(2).value
3318 assert_equal '125', issue.custom_value_for(2).value
3314 assert_equal 'Bulk editing', journal.notes
3319 assert_equal 'Bulk editing', journal.notes
3315 assert_equal 1, journal.details.size
3320 assert_equal 1, journal.details.size
3316 end
3321 end
3317
3322
3318 def test_bulk_update_on_different_projects_without_rights
3323 def test_bulk_update_on_different_projects_without_rights
3319 @request.session[:user_id] = 3
3324 @request.session[:user_id] = 3
3320 user = User.find(3)
3325 user = User.find(3)
3321 action = { :controller => "issues", :action => "bulk_update" }
3326 action = { :controller => "issues", :action => "bulk_update" }
3322 assert user.allowed_to?(action, Issue.find(1).project)
3327 assert user.allowed_to?(action, Issue.find(1).project)
3323 assert ! user.allowed_to?(action, Issue.find(6).project)
3328 assert ! user.allowed_to?(action, Issue.find(6).project)
3324 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3329 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3325 :issue => {:priority_id => 7,
3330 :issue => {:priority_id => 7,
3326 :assigned_to_id => '',
3331 :assigned_to_id => '',
3327 :custom_field_values => {'2' => ''}}
3332 :custom_field_values => {'2' => ''}}
3328 assert_response 403
3333 assert_response 403
3329 assert_not_equal "Bulk should fail", Journal.last.notes
3334 assert_not_equal "Bulk should fail", Journal.last.notes
3330 end
3335 end
3331
3336
3332 def test_bullk_update_should_send_a_notification
3337 def test_bullk_update_should_send_a_notification
3333 @request.session[:user_id] = 2
3338 @request.session[:user_id] = 2
3334 ActionMailer::Base.deliveries.clear
3339 ActionMailer::Base.deliveries.clear
3335 post(:bulk_update,
3340 post(:bulk_update,
3336 {
3341 {
3337 :ids => [1, 2],
3342 :ids => [1, 2],
3338 :notes => 'Bulk editing',
3343 :notes => 'Bulk editing',
3339 :issue => {
3344 :issue => {
3340 :priority_id => 7,
3345 :priority_id => 7,
3341 :assigned_to_id => '',
3346 :assigned_to_id => '',
3342 :custom_field_values => {'2' => ''}
3347 :custom_field_values => {'2' => ''}
3343 }
3348 }
3344 })
3349 })
3345
3350
3346 assert_response 302
3351 assert_response 302
3347 assert_equal 2, ActionMailer::Base.deliveries.size
3352 assert_equal 2, ActionMailer::Base.deliveries.size
3348 end
3353 end
3349
3354
3350 def test_bulk_update_project
3355 def test_bulk_update_project
3351 @request.session[:user_id] = 2
3356 @request.session[:user_id] = 2
3352 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3357 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3353 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3358 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3354 # Issues moved to project 2
3359 # Issues moved to project 2
3355 assert_equal 2, Issue.find(1).project_id
3360 assert_equal 2, Issue.find(1).project_id
3356 assert_equal 2, Issue.find(2).project_id
3361 assert_equal 2, Issue.find(2).project_id
3357 # No tracker change
3362 # No tracker change
3358 assert_equal 1, Issue.find(1).tracker_id
3363 assert_equal 1, Issue.find(1).tracker_id
3359 assert_equal 2, Issue.find(2).tracker_id
3364 assert_equal 2, Issue.find(2).tracker_id
3360 end
3365 end
3361
3366
3362 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3367 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3363 @request.session[:user_id] = 2
3368 @request.session[:user_id] = 2
3364 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3369 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3365 assert_redirected_to '/issues/1'
3370 assert_redirected_to '/issues/1'
3366 end
3371 end
3367
3372
3368 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3373 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3369 @request.session[:user_id] = 2
3374 @request.session[:user_id] = 2
3370 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3375 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3371 assert_redirected_to '/projects/onlinestore/issues'
3376 assert_redirected_to '/projects/onlinestore/issues'
3372 end
3377 end
3373
3378
3374 def test_bulk_update_tracker
3379 def test_bulk_update_tracker
3375 @request.session[:user_id] = 2
3380 @request.session[:user_id] = 2
3376 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3381 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3377 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3382 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3378 assert_equal 2, Issue.find(1).tracker_id
3383 assert_equal 2, Issue.find(1).tracker_id
3379 assert_equal 2, Issue.find(2).tracker_id
3384 assert_equal 2, Issue.find(2).tracker_id
3380 end
3385 end
3381
3386
3382 def test_bulk_update_status
3387 def test_bulk_update_status
3383 @request.session[:user_id] = 2
3388 @request.session[:user_id] = 2
3384 # update issues priority
3389 # update issues priority
3385 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3390 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3386 :issue => {:priority_id => '',
3391 :issue => {:priority_id => '',
3387 :assigned_to_id => '',
3392 :assigned_to_id => '',
3388 :status_id => '5'}
3393 :status_id => '5'}
3389
3394
3390 assert_response 302
3395 assert_response 302
3391 issue = Issue.find(1)
3396 issue = Issue.find(1)
3392 assert issue.closed?
3397 assert issue.closed?
3393 end
3398 end
3394
3399
3395 def test_bulk_update_priority
3400 def test_bulk_update_priority
3396 @request.session[:user_id] = 2
3401 @request.session[:user_id] = 2
3397 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3402 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3398
3403
3399 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3404 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3400 assert_equal 6, Issue.find(1).priority_id
3405 assert_equal 6, Issue.find(1).priority_id
3401 assert_equal 6, Issue.find(2).priority_id
3406 assert_equal 6, Issue.find(2).priority_id
3402 end
3407 end
3403
3408
3404 def test_bulk_update_with_notes
3409 def test_bulk_update_with_notes
3405 @request.session[:user_id] = 2
3410 @request.session[:user_id] = 2
3406 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3411 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3407
3412
3408 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3413 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3409 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3414 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3410 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3415 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3411 end
3416 end
3412
3417
3413 def test_bulk_update_parent_id
3418 def test_bulk_update_parent_id
3414 @request.session[:user_id] = 2
3419 @request.session[:user_id] = 2
3415 post :bulk_update, :ids => [1, 3],
3420 post :bulk_update, :ids => [1, 3],
3416 :notes => 'Bulk editing parent',
3421 :notes => 'Bulk editing parent',
3417 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
3422 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
3418
3423
3419 assert_response 302
3424 assert_response 302
3420 parent = Issue.find(2)
3425 parent = Issue.find(2)
3421 assert_equal parent.id, Issue.find(1).parent_id
3426 assert_equal parent.id, Issue.find(1).parent_id
3422 assert_equal parent.id, Issue.find(3).parent_id
3427 assert_equal parent.id, Issue.find(3).parent_id
3423 assert_equal [1, 3], parent.children.collect(&:id).sort
3428 assert_equal [1, 3], parent.children.collect(&:id).sort
3424 end
3429 end
3425
3430
3426 def test_bulk_update_custom_field
3431 def test_bulk_update_custom_field
3427 @request.session[:user_id] = 2
3432 @request.session[:user_id] = 2
3428 # update issues priority
3433 # update issues priority
3429 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
3434 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
3430 :issue => {:priority_id => '',
3435 :issue => {:priority_id => '',
3431 :assigned_to_id => '',
3436 :assigned_to_id => '',
3432 :custom_field_values => {'2' => '777'}}
3437 :custom_field_values => {'2' => '777'}}
3433
3438
3434 assert_response 302
3439 assert_response 302
3435
3440
3436 issue = Issue.find(1)
3441 issue = Issue.find(1)
3437 journal = issue.journals.reorder('created_on DESC').first
3442 journal = issue.journals.reorder('created_on DESC').first
3438 assert_equal '777', issue.custom_value_for(2).value
3443 assert_equal '777', issue.custom_value_for(2).value
3439 assert_equal 1, journal.details.size
3444 assert_equal 1, journal.details.size
3440 assert_equal '125', journal.details.first.old_value
3445 assert_equal '125', journal.details.first.old_value
3441 assert_equal '777', journal.details.first.value
3446 assert_equal '777', journal.details.first.value
3442 end
3447 end
3443
3448
3444 def test_bulk_update_custom_field_to_blank
3449 def test_bulk_update_custom_field_to_blank
3445 @request.session[:user_id] = 2
3450 @request.session[:user_id] = 2
3446 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
3451 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
3447 :issue => {:priority_id => '',
3452 :issue => {:priority_id => '',
3448 :assigned_to_id => '',
3453 :assigned_to_id => '',
3449 :custom_field_values => {'1' => '__none__'}}
3454 :custom_field_values => {'1' => '__none__'}}
3450 assert_response 302
3455 assert_response 302
3451 assert_equal '', Issue.find(1).custom_field_value(1)
3456 assert_equal '', Issue.find(1).custom_field_value(1)
3452 assert_equal '', Issue.find(3).custom_field_value(1)
3457 assert_equal '', Issue.find(3).custom_field_value(1)
3453 end
3458 end
3454
3459
3455 def test_bulk_update_multi_custom_field
3460 def test_bulk_update_multi_custom_field
3456 field = CustomField.find(1)
3461 field = CustomField.find(1)
3457 field.update_attribute :multiple, true
3462 field.update_attribute :multiple, true
3458
3463
3459 @request.session[:user_id] = 2
3464 @request.session[:user_id] = 2
3460 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
3465 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
3461 :issue => {:priority_id => '',
3466 :issue => {:priority_id => '',
3462 :assigned_to_id => '',
3467 :assigned_to_id => '',
3463 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
3468 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
3464
3469
3465 assert_response 302
3470 assert_response 302
3466
3471
3467 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
3472 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
3468 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
3473 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
3469 # the custom field is not associated with the issue tracker
3474 # the custom field is not associated with the issue tracker
3470 assert_nil Issue.find(2).custom_field_value(1)
3475 assert_nil Issue.find(2).custom_field_value(1)
3471 end
3476 end
3472
3477
3473 def test_bulk_update_multi_custom_field_to_blank
3478 def test_bulk_update_multi_custom_field_to_blank
3474 field = CustomField.find(1)
3479 field = CustomField.find(1)
3475 field.update_attribute :multiple, true
3480 field.update_attribute :multiple, true
3476
3481
3477 @request.session[:user_id] = 2
3482 @request.session[:user_id] = 2
3478 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
3483 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
3479 :issue => {:priority_id => '',
3484 :issue => {:priority_id => '',
3480 :assigned_to_id => '',
3485 :assigned_to_id => '',
3481 :custom_field_values => {'1' => ['__none__']}}
3486 :custom_field_values => {'1' => ['__none__']}}
3482 assert_response 302
3487 assert_response 302
3483 assert_equal [''], Issue.find(1).custom_field_value(1)
3488 assert_equal [''], Issue.find(1).custom_field_value(1)
3484 assert_equal [''], Issue.find(3).custom_field_value(1)
3489 assert_equal [''], Issue.find(3).custom_field_value(1)
3485 end
3490 end
3486
3491
3487 def test_bulk_update_unassign
3492 def test_bulk_update_unassign
3488 assert_not_nil Issue.find(2).assigned_to
3493 assert_not_nil Issue.find(2).assigned_to
3489 @request.session[:user_id] = 2
3494 @request.session[:user_id] = 2
3490 # unassign issues
3495 # unassign issues
3491 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
3496 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
3492 assert_response 302
3497 assert_response 302
3493 # check that the issues were updated
3498 # check that the issues were updated
3494 assert_nil Issue.find(2).assigned_to
3499 assert_nil Issue.find(2).assigned_to
3495 end
3500 end
3496
3501
3497 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
3502 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
3498 @request.session[:user_id] = 2
3503 @request.session[:user_id] = 2
3499
3504
3500 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
3505 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
3501
3506
3502 assert_response :redirect
3507 assert_response :redirect
3503 issues = Issue.find([1,2])
3508 issues = Issue.find([1,2])
3504 issues.each do |issue|
3509 issues.each do |issue|
3505 assert_equal 4, issue.fixed_version_id
3510 assert_equal 4, issue.fixed_version_id
3506 assert_not_equal issue.project_id, issue.fixed_version.project_id
3511 assert_not_equal issue.project_id, issue.fixed_version.project_id
3507 end
3512 end
3508 end
3513 end
3509
3514
3510 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
3515 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
3511 @request.session[:user_id] = 2
3516 @request.session[:user_id] = 2
3512 post :bulk_update, :ids => [1,2], :back_url => '/issues'
3517 post :bulk_update, :ids => [1,2], :back_url => '/issues'
3513
3518
3514 assert_response :redirect
3519 assert_response :redirect
3515 assert_redirected_to '/issues'
3520 assert_redirected_to '/issues'
3516 end
3521 end
3517
3522
3518 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3523 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3519 @request.session[:user_id] = 2
3524 @request.session[:user_id] = 2
3520 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3525 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3521
3526
3522 assert_response :redirect
3527 assert_response :redirect
3523 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3528 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3524 end
3529 end
3525
3530
3526 def test_bulk_update_with_failure_should_set_flash
3531 def test_bulk_update_with_failure_should_set_flash
3527 @request.session[:user_id] = 2
3532 @request.session[:user_id] = 2
3528 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3533 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3529 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3534 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3530
3535
3531 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3536 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3532 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3537 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3533 end
3538 end
3534
3539
3535 def test_get_bulk_copy
3540 def test_get_bulk_copy
3536 @request.session[:user_id] = 2
3541 @request.session[:user_id] = 2
3537 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
3542 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
3538 assert_response :success
3543 assert_response :success
3539 assert_template 'bulk_edit'
3544 assert_template 'bulk_edit'
3540
3545
3541 issues = assigns(:issues)
3546 issues = assigns(:issues)
3542 assert_not_nil issues
3547 assert_not_nil issues
3543 assert_equal [1, 2, 3], issues.map(&:id).sort
3548 assert_equal [1, 2, 3], issues.map(&:id).sort
3544
3549
3545 assert_select 'input[name=copy_attachments]'
3550 assert_select 'input[name=copy_attachments]'
3546 end
3551 end
3547
3552
3548 def test_bulk_copy_to_another_project
3553 def test_bulk_copy_to_another_project
3549 @request.session[:user_id] = 2
3554 @request.session[:user_id] = 2
3550 assert_difference 'Issue.count', 2 do
3555 assert_difference 'Issue.count', 2 do
3551 assert_no_difference 'Project.find(1).issues.count' do
3556 assert_no_difference 'Project.find(1).issues.count' do
3552 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3557 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3553 end
3558 end
3554 end
3559 end
3555 assert_redirected_to '/projects/ecookbook/issues'
3560 assert_redirected_to '/projects/ecookbook/issues'
3556
3561
3557 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3562 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3558 copies.each do |copy|
3563 copies.each do |copy|
3559 assert_equal 2, copy.project_id
3564 assert_equal 2, copy.project_id
3560 end
3565 end
3561 end
3566 end
3562
3567
3563 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3568 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3564 @request.session[:user_id] = 2
3569 @request.session[:user_id] = 2
3565 issues = [
3570 issues = [
3566 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil),
3571 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil),
3567 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3)
3572 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3)
3568 ]
3573 ]
3569
3574
3570 assert_difference 'Issue.count', issues.size do
3575 assert_difference 'Issue.count', issues.size do
3571 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
3576 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
3572 :issue => {
3577 :issue => {
3573 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3578 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3574 :status_id => '', :start_date => '', :due_date => ''
3579 :status_id => '', :start_date => '', :due_date => ''
3575 }
3580 }
3576 end
3581 end
3577
3582
3578 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3583 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3579 issues.each do |orig|
3584 issues.each do |orig|
3580 copy = copies.detect {|c| c.subject == orig.subject}
3585 copy = copies.detect {|c| c.subject == orig.subject}
3581 assert_not_nil copy
3586 assert_not_nil copy
3582 assert_equal orig.project_id, copy.project_id
3587 assert_equal orig.project_id, copy.project_id
3583 assert_equal orig.tracker_id, copy.tracker_id
3588 assert_equal orig.tracker_id, copy.tracker_id
3584 assert_equal orig.status_id, copy.status_id
3589 assert_equal orig.status_id, copy.status_id
3585 assert_equal orig.assigned_to_id, copy.assigned_to_id
3590 assert_equal orig.assigned_to_id, copy.assigned_to_id
3586 assert_equal orig.priority_id, copy.priority_id
3591 assert_equal orig.priority_id, copy.priority_id
3587 end
3592 end
3588 end
3593 end
3589
3594
3590 def test_bulk_copy_should_allow_changing_the_issue_attributes
3595 def test_bulk_copy_should_allow_changing_the_issue_attributes
3591 # Fixes random test failure with Mysql
3596 # Fixes random test failure with Mysql
3592 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3597 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3593 # doesn't return the expected results
3598 # doesn't return the expected results
3594 Issue.delete_all("project_id=2")
3599 Issue.delete_all("project_id=2")
3595
3600
3596 @request.session[:user_id] = 2
3601 @request.session[:user_id] = 2
3597 assert_difference 'Issue.count', 2 do
3602 assert_difference 'Issue.count', 2 do
3598 assert_no_difference 'Project.find(1).issues.count' do
3603 assert_no_difference 'Project.find(1).issues.count' do
3599 post :bulk_update, :ids => [1, 2], :copy => '1',
3604 post :bulk_update, :ids => [1, 2], :copy => '1',
3600 :issue => {
3605 :issue => {
3601 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3606 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3602 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
3607 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
3603 }
3608 }
3604 end
3609 end
3605 end
3610 end
3606
3611
3607 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3612 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3608 assert_equal 2, copied_issues.size
3613 assert_equal 2, copied_issues.size
3609 copied_issues.each do |issue|
3614 copied_issues.each do |issue|
3610 assert_equal 2, issue.project_id, "Project is incorrect"
3615 assert_equal 2, issue.project_id, "Project is incorrect"
3611 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3616 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3612 assert_equal 1, issue.status_id, "Status is incorrect"
3617 assert_equal 1, issue.status_id, "Status is incorrect"
3613 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3618 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3614 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3619 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3615 end
3620 end
3616 end
3621 end
3617
3622
3618 def test_bulk_copy_should_allow_adding_a_note
3623 def test_bulk_copy_should_allow_adding_a_note
3619 @request.session[:user_id] = 2
3624 @request.session[:user_id] = 2
3620 assert_difference 'Issue.count', 1 do
3625 assert_difference 'Issue.count', 1 do
3621 post :bulk_update, :ids => [1], :copy => '1',
3626 post :bulk_update, :ids => [1], :copy => '1',
3622 :notes => 'Copying one issue',
3627 :notes => 'Copying one issue',
3623 :issue => {
3628 :issue => {
3624 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3629 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3625 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3630 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3626 }
3631 }
3627 end
3632 end
3628
3633
3629 issue = Issue.first(:order => 'id DESC')
3634 issue = Issue.first(:order => 'id DESC')
3630 assert_equal 1, issue.journals.size
3635 assert_equal 1, issue.journals.size
3631 journal = issue.journals.first
3636 journal = issue.journals.first
3632 assert_equal 0, journal.details.size
3637 assert_equal 0, journal.details.size
3633 assert_equal 'Copying one issue', journal.notes
3638 assert_equal 'Copying one issue', journal.notes
3634 end
3639 end
3635
3640
3636 def test_bulk_copy_should_allow_not_copying_the_attachments
3641 def test_bulk_copy_should_allow_not_copying_the_attachments
3637 attachment_count = Issue.find(3).attachments.size
3642 attachment_count = Issue.find(3).attachments.size
3638 assert attachment_count > 0
3643 assert attachment_count > 0
3639 @request.session[:user_id] = 2
3644 @request.session[:user_id] = 2
3640
3645
3641 assert_difference 'Issue.count', 1 do
3646 assert_difference 'Issue.count', 1 do
3642 assert_no_difference 'Attachment.count' do
3647 assert_no_difference 'Attachment.count' do
3643 post :bulk_update, :ids => [3], :copy => '1',
3648 post :bulk_update, :ids => [3], :copy => '1',
3644 :issue => {
3649 :issue => {
3645 :project_id => ''
3650 :project_id => ''
3646 }
3651 }
3647 end
3652 end
3648 end
3653 end
3649 end
3654 end
3650
3655
3651 def test_bulk_copy_should_allow_copying_the_attachments
3656 def test_bulk_copy_should_allow_copying_the_attachments
3652 attachment_count = Issue.find(3).attachments.size
3657 attachment_count = Issue.find(3).attachments.size
3653 assert attachment_count > 0
3658 assert attachment_count > 0
3654 @request.session[:user_id] = 2
3659 @request.session[:user_id] = 2
3655
3660
3656 assert_difference 'Issue.count', 1 do
3661 assert_difference 'Issue.count', 1 do
3657 assert_difference 'Attachment.count', attachment_count do
3662 assert_difference 'Attachment.count', attachment_count do
3658 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
3663 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
3659 :issue => {
3664 :issue => {
3660 :project_id => ''
3665 :project_id => ''
3661 }
3666 }
3662 end
3667 end
3663 end
3668 end
3664 end
3669 end
3665
3670
3666 def test_bulk_copy_should_add_relations_with_copied_issues
3671 def test_bulk_copy_should_add_relations_with_copied_issues
3667 @request.session[:user_id] = 2
3672 @request.session[:user_id] = 2
3668
3673
3669 assert_difference 'Issue.count', 2 do
3674 assert_difference 'Issue.count', 2 do
3670 assert_difference 'IssueRelation.count', 2 do
3675 assert_difference 'IssueRelation.count', 2 do
3671 post :bulk_update, :ids => [1, 3], :copy => '1',
3676 post :bulk_update, :ids => [1, 3], :copy => '1',
3672 :issue => {
3677 :issue => {
3673 :project_id => '1'
3678 :project_id => '1'
3674 }
3679 }
3675 end
3680 end
3676 end
3681 end
3677 end
3682 end
3678
3683
3679 def test_bulk_copy_should_allow_not_copying_the_subtasks
3684 def test_bulk_copy_should_allow_not_copying_the_subtasks
3680 issue = Issue.generate_with_descendants!
3685 issue = Issue.generate_with_descendants!
3681 @request.session[:user_id] = 2
3686 @request.session[:user_id] = 2
3682
3687
3683 assert_difference 'Issue.count', 1 do
3688 assert_difference 'Issue.count', 1 do
3684 post :bulk_update, :ids => [issue.id], :copy => '1',
3689 post :bulk_update, :ids => [issue.id], :copy => '1',
3685 :issue => {
3690 :issue => {
3686 :project_id => ''
3691 :project_id => ''
3687 }
3692 }
3688 end
3693 end
3689 end
3694 end
3690
3695
3691 def test_bulk_copy_should_allow_copying_the_subtasks
3696 def test_bulk_copy_should_allow_copying_the_subtasks
3692 issue = Issue.generate_with_descendants!
3697 issue = Issue.generate_with_descendants!
3693 count = issue.descendants.count
3698 count = issue.descendants.count
3694 @request.session[:user_id] = 2
3699 @request.session[:user_id] = 2
3695
3700
3696 assert_difference 'Issue.count', count+1 do
3701 assert_difference 'Issue.count', count+1 do
3697 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
3702 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
3698 :issue => {
3703 :issue => {
3699 :project_id => ''
3704 :project_id => ''
3700 }
3705 }
3701 end
3706 end
3702 copy = Issue.where(:parent_id => nil).order("id DESC").first
3707 copy = Issue.where(:parent_id => nil).order("id DESC").first
3703 assert_equal count, copy.descendants.count
3708 assert_equal count, copy.descendants.count
3704 end
3709 end
3705
3710
3706 def test_bulk_copy_should_not_copy_selected_subtasks_twice
3711 def test_bulk_copy_should_not_copy_selected_subtasks_twice
3707 issue = Issue.generate_with_descendants!
3712 issue = Issue.generate_with_descendants!
3708 count = issue.descendants.count
3713 count = issue.descendants.count
3709 @request.session[:user_id] = 2
3714 @request.session[:user_id] = 2
3710
3715
3711 assert_difference 'Issue.count', count+1 do
3716 assert_difference 'Issue.count', count+1 do
3712 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
3717 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
3713 :issue => {
3718 :issue => {
3714 :project_id => ''
3719 :project_id => ''
3715 }
3720 }
3716 end
3721 end
3717 copy = Issue.where(:parent_id => nil).order("id DESC").first
3722 copy = Issue.where(:parent_id => nil).order("id DESC").first
3718 assert_equal count, copy.descendants.count
3723 assert_equal count, copy.descendants.count
3719 end
3724 end
3720
3725
3721 def test_bulk_copy_to_another_project_should_follow_when_needed
3726 def test_bulk_copy_to_another_project_should_follow_when_needed
3722 @request.session[:user_id] = 2
3727 @request.session[:user_id] = 2
3723 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3728 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3724 issue = Issue.first(:order => 'id DESC')
3729 issue = Issue.first(:order => 'id DESC')
3725 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3730 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3726 end
3731 end
3727
3732
3728 def test_destroy_issue_with_no_time_entries
3733 def test_destroy_issue_with_no_time_entries
3729 assert_nil TimeEntry.find_by_issue_id(2)
3734 assert_nil TimeEntry.find_by_issue_id(2)
3730 @request.session[:user_id] = 2
3735 @request.session[:user_id] = 2
3731
3736
3732 assert_difference 'Issue.count', -1 do
3737 assert_difference 'Issue.count', -1 do
3733 delete :destroy, :id => 2
3738 delete :destroy, :id => 2
3734 end
3739 end
3735 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3740 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3736 assert_nil Issue.find_by_id(2)
3741 assert_nil Issue.find_by_id(2)
3737 end
3742 end
3738
3743
3739 def test_destroy_issues_with_time_entries
3744 def test_destroy_issues_with_time_entries
3740 @request.session[:user_id] = 2
3745 @request.session[:user_id] = 2
3741
3746
3742 assert_no_difference 'Issue.count' do
3747 assert_no_difference 'Issue.count' do
3743 delete :destroy, :ids => [1, 3]
3748 delete :destroy, :ids => [1, 3]
3744 end
3749 end
3745 assert_response :success
3750 assert_response :success
3746 assert_template 'destroy'
3751 assert_template 'destroy'
3747 assert_not_nil assigns(:hours)
3752 assert_not_nil assigns(:hours)
3748 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3753 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3749 assert_tag 'form',
3754 assert_tag 'form',
3750 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3755 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3751 end
3756 end
3752
3757
3753 def test_destroy_issues_and_destroy_time_entries
3758 def test_destroy_issues_and_destroy_time_entries
3754 @request.session[:user_id] = 2
3759 @request.session[:user_id] = 2
3755
3760
3756 assert_difference 'Issue.count', -2 do
3761 assert_difference 'Issue.count', -2 do
3757 assert_difference 'TimeEntry.count', -3 do
3762 assert_difference 'TimeEntry.count', -3 do
3758 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3763 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3759 end
3764 end
3760 end
3765 end
3761 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3766 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3762 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3767 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3763 assert_nil TimeEntry.find_by_id([1, 2])
3768 assert_nil TimeEntry.find_by_id([1, 2])
3764 end
3769 end
3765
3770
3766 def test_destroy_issues_and_assign_time_entries_to_project
3771 def test_destroy_issues_and_assign_time_entries_to_project
3767 @request.session[:user_id] = 2
3772 @request.session[:user_id] = 2
3768
3773
3769 assert_difference 'Issue.count', -2 do
3774 assert_difference 'Issue.count', -2 do
3770 assert_no_difference 'TimeEntry.count' do
3775 assert_no_difference 'TimeEntry.count' do
3771 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3776 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3772 end
3777 end
3773 end
3778 end
3774 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3779 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3775 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3780 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3776 assert_nil TimeEntry.find(1).issue_id
3781 assert_nil TimeEntry.find(1).issue_id
3777 assert_nil TimeEntry.find(2).issue_id
3782 assert_nil TimeEntry.find(2).issue_id
3778 end
3783 end
3779
3784
3780 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3785 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3781 @request.session[:user_id] = 2
3786 @request.session[:user_id] = 2
3782
3787
3783 assert_difference 'Issue.count', -2 do
3788 assert_difference 'Issue.count', -2 do
3784 assert_no_difference 'TimeEntry.count' do
3789 assert_no_difference 'TimeEntry.count' do
3785 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3790 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3786 end
3791 end
3787 end
3792 end
3788 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3793 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3789 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3794 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3790 assert_equal 2, TimeEntry.find(1).issue_id
3795 assert_equal 2, TimeEntry.find(1).issue_id
3791 assert_equal 2, TimeEntry.find(2).issue_id
3796 assert_equal 2, TimeEntry.find(2).issue_id
3792 end
3797 end
3793
3798
3794 def test_destroy_issues_from_different_projects
3799 def test_destroy_issues_from_different_projects
3795 @request.session[:user_id] = 2
3800 @request.session[:user_id] = 2
3796
3801
3797 assert_difference 'Issue.count', -3 do
3802 assert_difference 'Issue.count', -3 do
3798 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3803 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3799 end
3804 end
3800 assert_redirected_to :controller => 'issues', :action => 'index'
3805 assert_redirected_to :controller => 'issues', :action => 'index'
3801 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3806 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3802 end
3807 end
3803
3808
3804 def test_destroy_parent_and_child_issues
3809 def test_destroy_parent_and_child_issues
3805 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3810 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3806 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3811 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3807 assert child.is_descendant_of?(parent.reload)
3812 assert child.is_descendant_of?(parent.reload)
3808
3813
3809 @request.session[:user_id] = 2
3814 @request.session[:user_id] = 2
3810 assert_difference 'Issue.count', -2 do
3815 assert_difference 'Issue.count', -2 do
3811 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3816 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3812 end
3817 end
3813 assert_response 302
3818 assert_response 302
3814 end
3819 end
3815
3820
3821 def test_destroy_invalid_should_respond_with_404
3822 @request.session[:user_id] = 2
3823 assert_no_difference 'Issue.count' do
3824 delete :destroy, :id => 999
3825 end
3826 assert_response 404
3827 end
3828
3816 def test_default_search_scope
3829 def test_default_search_scope
3817 get :index
3830 get :index
3818 assert_tag :div, :attributes => {:id => 'quick-search'},
3831 assert_tag :div, :attributes => {:id => 'quick-search'},
3819 :child => {:tag => 'form',
3832 :child => {:tag => 'form',
3820 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3833 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3821 end
3834 end
3822 end
3835 end
General Comments 0
You need to be logged in to leave comments. Login now