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