##// END OF EJS Templates
Fixes test conditions....
Jean-Philippe Lang -
r7956:cad148cb5ccd
parent child
Show More
@@ -1,2052 +1,2052
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 require 'issues_controller'
19 require 'issues_controller'
20
20
21 class IssuesControllerTest < ActionController::TestCase
21 class IssuesControllerTest < ActionController::TestCase
22 fixtures :projects,
22 fixtures :projects,
23 :users,
23 :users,
24 :roles,
24 :roles,
25 :members,
25 :members,
26 :member_roles,
26 :member_roles,
27 :issues,
27 :issues,
28 :issue_statuses,
28 :issue_statuses,
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
45
46 include Redmine::I18n
46 include Redmine::I18n
47
47
48 def setup
48 def setup
49 @controller = IssuesController.new
49 @controller = IssuesController.new
50 @request = ActionController::TestRequest.new
50 @request = ActionController::TestRequest.new
51 @response = ActionController::TestResponse.new
51 @response = ActionController::TestResponse.new
52 User.current = nil
52 User.current = nil
53 end
53 end
54
54
55 def test_index
55 def test_index
56 Setting.default_language = 'en'
56 Setting.default_language = 'en'
57
57
58 get :index
58 get :index
59 assert_response :success
59 assert_response :success
60 assert_template 'index'
60 assert_template 'index'
61 assert_not_nil assigns(:issues)
61 assert_not_nil assigns(:issues)
62 assert_nil assigns(:project)
62 assert_nil assigns(:project)
63 assert_tag :tag => 'a', :content => /Can't print recipes/
63 assert_tag :tag => 'a', :content => /Can't print recipes/
64 assert_tag :tag => 'a', :content => /Subproject issue/
64 assert_tag :tag => 'a', :content => /Subproject issue/
65 # private projects hidden
65 # private projects hidden
66 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
66 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
67 assert_no_tag :tag => 'a', :content => /Issue on project 2/
67 assert_no_tag :tag => 'a', :content => /Issue on project 2/
68 # project column
68 # project column
69 assert_tag :tag => 'th', :content => /Project/
69 assert_tag :tag => 'th', :content => /Project/
70 end
70 end
71
71
72 def test_index_should_not_list_issues_when_module_disabled
72 def test_index_should_not_list_issues_when_module_disabled
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 get :index
74 get :index
75 assert_response :success
75 assert_response :success
76 assert_template 'index'
76 assert_template 'index'
77 assert_not_nil assigns(:issues)
77 assert_not_nil assigns(:issues)
78 assert_nil assigns(:project)
78 assert_nil assigns(:project)
79 assert_no_tag :tag => 'a', :content => /Can't print recipes/
79 assert_no_tag :tag => 'a', :content => /Can't print recipes/
80 assert_tag :tag => 'a', :content => /Subproject issue/
80 assert_tag :tag => 'a', :content => /Subproject issue/
81 end
81 end
82
82
83 def test_index_should_list_visible_issues_only
83 def test_index_should_list_visible_issues_only
84 get :index, :per_page => 100
84 get :index, :per_page => 100
85 assert_response :success
85 assert_response :success
86 assert_not_nil assigns(:issues)
86 assert_not_nil assigns(:issues)
87 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
87 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
88 end
88 end
89
89
90 def test_index_with_project
90 def test_index_with_project
91 Setting.display_subprojects_issues = 0
91 Setting.display_subprojects_issues = 0
92 get :index, :project_id => 1
92 get :index, :project_id => 1
93 assert_response :success
93 assert_response :success
94 assert_template 'index'
94 assert_template 'index'
95 assert_not_nil assigns(:issues)
95 assert_not_nil assigns(:issues)
96 assert_tag :tag => 'a', :content => /Can't print recipes/
96 assert_tag :tag => 'a', :content => /Can't print recipes/
97 assert_no_tag :tag => 'a', :content => /Subproject issue/
97 assert_no_tag :tag => 'a', :content => /Subproject issue/
98 end
98 end
99
99
100 def test_index_with_project_and_subprojects
100 def test_index_with_project_and_subprojects
101 Setting.display_subprojects_issues = 1
101 Setting.display_subprojects_issues = 1
102 get :index, :project_id => 1
102 get :index, :project_id => 1
103 assert_response :success
103 assert_response :success
104 assert_template 'index'
104 assert_template 'index'
105 assert_not_nil assigns(:issues)
105 assert_not_nil assigns(:issues)
106 assert_tag :tag => 'a', :content => /Can't print recipes/
106 assert_tag :tag => 'a', :content => /Can't print recipes/
107 assert_tag :tag => 'a', :content => /Subproject issue/
107 assert_tag :tag => 'a', :content => /Subproject issue/
108 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
108 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
109 end
109 end
110
110
111 def test_index_with_project_and_subprojects_should_show_private_subprojects
111 def test_index_with_project_and_subprojects_should_show_private_subprojects
112 @request.session[:user_id] = 2
112 @request.session[:user_id] = 2
113 Setting.display_subprojects_issues = 1
113 Setting.display_subprojects_issues = 1
114 get :index, :project_id => 1
114 get :index, :project_id => 1
115 assert_response :success
115 assert_response :success
116 assert_template 'index'
116 assert_template 'index'
117 assert_not_nil assigns(:issues)
117 assert_not_nil assigns(:issues)
118 assert_tag :tag => 'a', :content => /Can't print recipes/
118 assert_tag :tag => 'a', :content => /Can't print recipes/
119 assert_tag :tag => 'a', :content => /Subproject issue/
119 assert_tag :tag => 'a', :content => /Subproject issue/
120 assert_tag :tag => 'a', :content => /Issue of a private subproject/
120 assert_tag :tag => 'a', :content => /Issue of a private subproject/
121 end
121 end
122
122
123 def test_index_with_project_and_default_filter
123 def test_index_with_project_and_default_filter
124 get :index, :project_id => 1, :set_filter => 1
124 get :index, :project_id => 1, :set_filter => 1
125 assert_response :success
125 assert_response :success
126 assert_template 'index'
126 assert_template 'index'
127 assert_not_nil assigns(:issues)
127 assert_not_nil assigns(:issues)
128
128
129 query = assigns(:query)
129 query = assigns(:query)
130 assert_not_nil query
130 assert_not_nil query
131 # default filter
131 # default filter
132 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
132 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
133 end
133 end
134
134
135 def test_index_with_project_and_filter
135 def test_index_with_project_and_filter
136 get :index, :project_id => 1, :set_filter => 1,
136 get :index, :project_id => 1, :set_filter => 1,
137 :f => ['tracker_id'],
137 :f => ['tracker_id'],
138 :op => {'tracker_id' => '='},
138 :op => {'tracker_id' => '='},
139 :v => {'tracker_id' => ['1']}
139 :v => {'tracker_id' => ['1']}
140 assert_response :success
140 assert_response :success
141 assert_template 'index'
141 assert_template 'index'
142 assert_not_nil assigns(:issues)
142 assert_not_nil assigns(:issues)
143
143
144 query = assigns(:query)
144 query = assigns(:query)
145 assert_not_nil query
145 assert_not_nil query
146 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
146 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
147 end
147 end
148
148
149 def test_index_with_short_filters
149 def test_index_with_short_filters
150
150
151 to_test = {
151 to_test = {
152 'status_id' => {
152 'status_id' => {
153 'o' => { :op => 'o', :values => [''] },
153 'o' => { :op => 'o', :values => [''] },
154 'c' => { :op => 'c', :values => [''] },
154 'c' => { :op => 'c', :values => [''] },
155 '7' => { :op => '=', :values => ['7'] },
155 '7' => { :op => '=', :values => ['7'] },
156 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
156 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
157 '=7' => { :op => '=', :values => ['7'] },
157 '=7' => { :op => '=', :values => ['7'] },
158 '!3' => { :op => '!', :values => ['3'] },
158 '!3' => { :op => '!', :values => ['3'] },
159 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
159 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
160 'subject' => {
160 'subject' => {
161 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
161 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
162 'o' => { :op => '=', :values => ['o'] },
162 'o' => { :op => '=', :values => ['o'] },
163 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
163 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
164 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
164 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
165 'tracker_id' => {
165 'tracker_id' => {
166 '3' => { :op => '=', :values => ['3'] },
166 '3' => { :op => '=', :values => ['3'] },
167 '=3' => { :op => '=', :values => ['3'] }},
167 '=3' => { :op => '=', :values => ['3'] }},
168 'start_date' => {
168 'start_date' => {
169 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
169 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
170 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
170 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
171 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
171 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
172 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
172 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
173 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
173 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
174 '<t+2' => { :op => '<t+', :values => ['2'] },
174 '<t+2' => { :op => '<t+', :values => ['2'] },
175 '>t+2' => { :op => '>t+', :values => ['2'] },
175 '>t+2' => { :op => '>t+', :values => ['2'] },
176 't+2' => { :op => 't+', :values => ['2'] },
176 't+2' => { :op => 't+', :values => ['2'] },
177 't' => { :op => 't', :values => [''] },
177 't' => { :op => 't', :values => [''] },
178 'w' => { :op => 'w', :values => [''] },
178 'w' => { :op => 'w', :values => [''] },
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-2' => { :op => 't-', :values => ['2'] }},
181 't-2' => { :op => 't-', :values => ['2'] }},
182 'created_on' => {
182 'created_on' => {
183 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
183 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
184 '<t+2' => { :op => '=', :values => ['<t+2'] },
184 '<t+2' => { :op => '=', :values => ['<t+2'] },
185 '>t+2' => { :op => '=', :values => ['>t+2'] },
185 '>t+2' => { :op => '=', :values => ['>t+2'] },
186 't+2' => { :op => 't', :values => ['+2'] }},
186 't+2' => { :op => 't', :values => ['+2'] }},
187 'cf_1' => {
187 'cf_1' => {
188 'c' => { :op => '=', :values => ['c'] },
188 'c' => { :op => '=', :values => ['c'] },
189 '!c' => { :op => '!', :values => ['c'] },
189 '!c' => { :op => '!', :values => ['c'] },
190 '!*' => { :op => '!*', :values => [''] },
190 '!*' => { :op => '!*', :values => [''] },
191 '*' => { :op => '*', :values => [''] }},
191 '*' => { :op => '*', :values => [''] }},
192 'estimated_hours' => {
192 'estimated_hours' => {
193 '=13.4' => { :op => '=', :values => ['13.4'] },
193 '=13.4' => { :op => '=', :values => ['13.4'] },
194 '>=45' => { :op => '>=', :values => ['45'] },
194 '>=45' => { :op => '>=', :values => ['45'] },
195 '<=125' => { :op => '<=', :values => ['125'] },
195 '<=125' => { :op => '<=', :values => ['125'] },
196 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
196 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
197 '!*' => { :op => '!*', :values => [''] },
197 '!*' => { :op => '!*', :values => [''] },
198 '*' => { :op => '*', :values => [''] }}
198 '*' => { :op => '*', :values => [''] }}
199 }
199 }
200
200
201 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
201 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
202
202
203 to_test.each do |field, expression_and_expected|
203 to_test.each do |field, expression_and_expected|
204 expression_and_expected.each do |filter_expression, expected|
204 expression_and_expected.each do |filter_expression, expected|
205
205
206 get :index, :set_filter => 1, field => filter_expression
206 get :index, :set_filter => 1, field => filter_expression
207
207
208 assert_response :success
208 assert_response :success
209 assert_template 'index'
209 assert_template 'index'
210 assert_not_nil assigns(:issues)
210 assert_not_nil assigns(:issues)
211
211
212 query = assigns(:query)
212 query = assigns(:query)
213 assert_not_nil query
213 assert_not_nil query
214 assert query.has_filter?(field)
214 assert query.has_filter?(field)
215 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
215 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
216 end
216 end
217 end
217 end
218
218
219 end
219 end
220
220
221 def test_index_with_project_and_empty_filters
221 def test_index_with_project_and_empty_filters
222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
223 assert_response :success
223 assert_response :success
224 assert_template 'index'
224 assert_template 'index'
225 assert_not_nil assigns(:issues)
225 assert_not_nil assigns(:issues)
226
226
227 query = assigns(:query)
227 query = assigns(:query)
228 assert_not_nil query
228 assert_not_nil query
229 # no filter
229 # no filter
230 assert_equal({}, query.filters)
230 assert_equal({}, query.filters)
231 end
231 end
232
232
233 def test_index_with_query
233 def test_index_with_query
234 get :index, :project_id => 1, :query_id => 5
234 get :index, :project_id => 1, :query_id => 5
235 assert_response :success
235 assert_response :success
236 assert_template 'index'
236 assert_template 'index'
237 assert_not_nil assigns(:issues)
237 assert_not_nil assigns(:issues)
238 assert_nil assigns(:issue_count_by_group)
238 assert_nil assigns(:issue_count_by_group)
239 end
239 end
240
240
241 def test_index_with_query_grouped_by_tracker
241 def test_index_with_query_grouped_by_tracker
242 get :index, :project_id => 1, :query_id => 6
242 get :index, :project_id => 1, :query_id => 6
243 assert_response :success
243 assert_response :success
244 assert_template 'index'
244 assert_template 'index'
245 assert_not_nil assigns(:issues)
245 assert_not_nil assigns(:issues)
246 assert_not_nil assigns(:issue_count_by_group)
246 assert_not_nil assigns(:issue_count_by_group)
247 end
247 end
248
248
249 def test_index_with_query_grouped_by_list_custom_field
249 def test_index_with_query_grouped_by_list_custom_field
250 get :index, :project_id => 1, :query_id => 9
250 get :index, :project_id => 1, :query_id => 9
251 assert_response :success
251 assert_response :success
252 assert_template 'index'
252 assert_template 'index'
253 assert_not_nil assigns(:issues)
253 assert_not_nil assigns(:issues)
254 assert_not_nil assigns(:issue_count_by_group)
254 assert_not_nil assigns(:issue_count_by_group)
255 end
255 end
256
256
257 def test_private_query_should_not_be_available_to_other_users
257 def test_private_query_should_not_be_available_to_other_users
258 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
258 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
259 @request.session[:user_id] = 3
259 @request.session[:user_id] = 3
260
260
261 get :index, :query_id => q.id
261 get :index, :query_id => q.id
262 assert_response 403
262 assert_response 403
263 end
263 end
264
264
265 def test_private_query_should_be_available_to_its_user
265 def test_private_query_should_be_available_to_its_user
266 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
266 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
267 @request.session[:user_id] = 2
267 @request.session[:user_id] = 2
268
268
269 get :index, :query_id => q.id
269 get :index, :query_id => q.id
270 assert_response :success
270 assert_response :success
271 end
271 end
272
272
273 def test_public_query_should_be_available_to_other_users
273 def test_public_query_should_be_available_to_other_users
274 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
274 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
275 @request.session[:user_id] = 3
275 @request.session[:user_id] = 3
276
276
277 get :index, :query_id => q.id
277 get :index, :query_id => q.id
278 assert_response :success
278 assert_response :success
279 end
279 end
280
280
281 def test_index_csv
281 def test_index_csv
282 get :index, :format => 'csv'
282 get :index, :format => 'csv'
283 assert_response :success
283 assert_response :success
284 assert_not_nil assigns(:issues)
284 assert_not_nil assigns(:issues)
285 assert_equal 'text/csv', @response.content_type
285 assert_equal 'text/csv', @response.content_type
286 assert @response.body.starts_with?("#,")
286 assert @response.body.starts_with?("#,")
287 lines = @response.body.chomp.split("\n")
287 lines = @response.body.chomp.split("\n")
288 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
288 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
289 end
289 end
290
290
291 def test_index_csv_with_project
291 def test_index_csv_with_project
292 get :index, :project_id => 1, :format => 'csv'
292 get :index, :project_id => 1, :format => 'csv'
293 assert_response :success
293 assert_response :success
294 assert_not_nil assigns(:issues)
294 assert_not_nil assigns(:issues)
295 assert_equal 'text/csv', @response.content_type
295 assert_equal 'text/csv', @response.content_type
296 end
296 end
297
297
298 def test_index_csv_with_description
298 def test_index_csv_with_description
299 get :index, :format => 'csv', :description => '1'
299 get :index, :format => 'csv', :description => '1'
300 assert_response :success
300 assert_response :success
301 assert_not_nil assigns(:issues)
301 assert_not_nil assigns(:issues)
302 assert_equal 'text/csv', @response.content_type
302 assert_equal 'text/csv', @response.content_type
303 assert @response.body.starts_with?("#,")
303 assert @response.body.starts_with?("#,")
304 lines = @response.body.chomp.split("\n")
304 lines = @response.body.chomp.split("\n")
305 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
305 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
306 end
306 end
307
307
308 def test_index_csv_with_all_columns
308 def test_index_csv_with_all_columns
309 get :index, :format => 'csv', :columns => 'all'
309 get :index, :format => 'csv', :columns => 'all'
310 assert_response :success
310 assert_response :success
311 assert_not_nil assigns(:issues)
311 assert_not_nil assigns(:issues)
312 assert_equal 'text/csv', @response.content_type
312 assert_equal 'text/csv', @response.content_type
313 assert @response.body.starts_with?("#,")
313 assert @response.body.starts_with?("#,")
314 lines = @response.body.chomp.split("\n")
314 lines = @response.body.chomp.split("\n")
315 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
315 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
316 end
316 end
317
317
318 def test_index_csv_big_5
318 def test_index_csv_big_5
319 with_settings :default_language => "zh-TW" do
319 with_settings :default_language => "zh-TW" do
320 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
320 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
321 str_big5 = "\xa4@\xa4\xeb"
321 str_big5 = "\xa4@\xa4\xeb"
322 if str_utf8.respond_to?(:force_encoding)
322 if str_utf8.respond_to?(:force_encoding)
323 str_utf8.force_encoding('UTF-8')
323 str_utf8.force_encoding('UTF-8')
324 str_big5.force_encoding('Big5')
324 str_big5.force_encoding('Big5')
325 end
325 end
326 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
326 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
327 :status_id => 1, :priority => IssuePriority.all.first,
327 :status_id => 1, :priority => IssuePriority.all.first,
328 :subject => str_utf8)
328 :subject => str_utf8)
329 assert issue.save
329 assert issue.save
330
330
331 get :index, :project_id => 1,
331 get :index, :project_id => 1,
332 :f => ['subject'],
332 :f => ['subject'],
333 :op => '=', :values => [str_utf8],
333 :op => '=', :values => [str_utf8],
334 :format => 'csv'
334 :format => 'csv'
335 assert_equal 'text/csv', @response.content_type
335 assert_equal 'text/csv', @response.content_type
336 lines = @response.body.chomp.split("\n")
336 lines = @response.body.chomp.split("\n")
337 s1 = "\xaa\xac\xbaA"
337 s1 = "\xaa\xac\xbaA"
338 if str_utf8.respond_to?(:force_encoding)
338 if str_utf8.respond_to?(:force_encoding)
339 s1.force_encoding('Big5')
339 s1.force_encoding('Big5')
340 end
340 end
341 assert lines[0].include?(s1)
341 assert lines[0].include?(s1)
342 assert lines[1].include?(str_big5)
342 assert lines[1].include?(str_big5)
343 end
343 end
344 end
344 end
345
345
346 def test_index_csv_cannot_convert_should_be_replaced_big_5
346 def test_index_csv_cannot_convert_should_be_replaced_big_5
347 with_settings :default_language => "zh-TW" do
347 with_settings :default_language => "zh-TW" do
348 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
348 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
349 if str_utf8.respond_to?(:force_encoding)
349 if str_utf8.respond_to?(:force_encoding)
350 str_utf8.force_encoding('UTF-8')
350 str_utf8.force_encoding('UTF-8')
351 end
351 end
352 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
352 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
353 :status_id => 1, :priority => IssuePriority.all.first,
353 :status_id => 1, :priority => IssuePriority.all.first,
354 :subject => str_utf8)
354 :subject => str_utf8)
355 assert issue.save
355 assert issue.save
356
356
357 get :index, :project_id => 1,
357 get :index, :project_id => 1,
358 :f => ['subject'],
358 :f => ['subject'],
359 :op => '=', :values => [str_utf8],
359 :op => '=', :values => [str_utf8],
360 :c => ['status', 'subject'],
360 :c => ['status', 'subject'],
361 :format => 'csv',
361 :format => 'csv',
362 :set_filter => 1
362 :set_filter => 1
363 assert_equal 'text/csv', @response.content_type
363 assert_equal 'text/csv', @response.content_type
364 lines = @response.body.chomp.split("\n")
364 lines = @response.body.chomp.split("\n")
365 s1 = "\xaa\xac\xbaA" # status
365 s1 = "\xaa\xac\xbaA" # status
366 if str_utf8.respond_to?(:force_encoding)
366 if str_utf8.respond_to?(:force_encoding)
367 s1.force_encoding('Big5')
367 s1.force_encoding('Big5')
368 end
368 end
369 assert lines[0].include?(s1)
369 assert lines[0].include?(s1)
370 s2 = lines[1].split(",")[2]
370 s2 = lines[1].split(",")[2]
371 if s1.respond_to?(:force_encoding)
371 if s1.respond_to?(:force_encoding)
372 s3 = "\xa5H?" # subject
372 s3 = "\xa5H?" # subject
373 s3.force_encoding('Big5')
373 s3.force_encoding('Big5')
374 assert_equal s3, s2
374 assert_equal s3, s2
375 elsif RUBY_PLATFORM == 'java'
375 elsif RUBY_PLATFORM == 'java'
376 assert_equal "??", s2
376 assert_equal "??", s2
377 else
377 else
378 assert_equal "\xa5H???", s2
378 assert_equal "\xa5H???", s2
379 end
379 end
380 end
380 end
381 end
381 end
382
382
383 def test_index_csv_tw
383 def test_index_csv_tw
384 with_settings :default_language => "zh-TW" do
384 with_settings :default_language => "zh-TW" do
385 str1 = "test_index_csv_tw"
385 str1 = "test_index_csv_tw"
386 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
386 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
387 :status_id => 1, :priority => IssuePriority.all.first,
387 :status_id => 1, :priority => IssuePriority.all.first,
388 :subject => str1, :estimated_hours => '1234.5')
388 :subject => str1, :estimated_hours => '1234.5')
389 assert issue.save
389 assert issue.save
390 assert_equal 1234.5, issue.estimated_hours
390 assert_equal 1234.5, issue.estimated_hours
391
391
392 get :index, :project_id => 1,
392 get :index, :project_id => 1,
393 :f => ['subject'],
393 :f => ['subject'],
394 :op => '=', :values => [str1],
394 :op => '=', :values => [str1],
395 :c => ['estimated_hours', 'subject'],
395 :c => ['estimated_hours', 'subject'],
396 :format => 'csv',
396 :format => 'csv',
397 :set_filter => 1
397 :set_filter => 1
398 assert_equal 'text/csv', @response.content_type
398 assert_equal 'text/csv', @response.content_type
399 lines = @response.body.chomp.split("\n")
399 lines = @response.body.chomp.split("\n")
400 assert_equal "#{issue.id},1234.5,#{str1}", lines[1]
400 assert_equal "#{issue.id},1234.5,#{str1}", lines[1]
401
401
402 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
402 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
403 if str_tw.respond_to?(:force_encoding)
403 if str_tw.respond_to?(:force_encoding)
404 str_tw.force_encoding('UTF-8')
404 str_tw.force_encoding('UTF-8')
405 end
405 end
406 assert_equal str_tw, l(:general_lang_name)
406 assert_equal str_tw, l(:general_lang_name)
407 assert_equal ',', l(:general_csv_separator)
407 assert_equal ',', l(:general_csv_separator)
408 assert_equal '.', l(:general_csv_decimal_separator)
408 assert_equal '.', l(:general_csv_decimal_separator)
409 end
409 end
410 end
410 end
411
411
412 def test_index_csv_fr
412 def test_index_csv_fr
413 with_settings :default_language => "fr" do
413 with_settings :default_language => "fr" do
414 str1 = "test_index_csv_fr"
414 str1 = "test_index_csv_fr"
415 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
415 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
416 :status_id => 1, :priority => IssuePriority.all.first,
416 :status_id => 1, :priority => IssuePriority.all.first,
417 :subject => str1, :estimated_hours => '1234.5')
417 :subject => str1, :estimated_hours => '1234.5')
418 assert issue.save
418 assert issue.save
419 assert_equal 1234.5, issue.estimated_hours
419 assert_equal 1234.5, issue.estimated_hours
420
420
421 get :index, :project_id => 1,
421 get :index, :project_id => 1,
422 :f => ['subject'],
422 :f => ['subject'],
423 :op => '=', :values => [str1],
423 :op => '=', :values => [str1],
424 :c => ['estimated_hours', 'subject'],
424 :c => ['estimated_hours', 'subject'],
425 :format => 'csv',
425 :format => 'csv',
426 :set_filter => 1
426 :set_filter => 1
427 assert_equal 'text/csv', @response.content_type
427 assert_equal 'text/csv', @response.content_type
428 lines = @response.body.chomp.split("\n")
428 lines = @response.body.chomp.split("\n")
429 assert_equal "#{issue.id};1234,5;#{str1}", lines[1]
429 assert_equal "#{issue.id};1234,5;#{str1}", lines[1]
430
430
431 str_fr = "Fran\xc3\xa7ais"
431 str_fr = "Fran\xc3\xa7ais"
432 if str_fr.respond_to?(:force_encoding)
432 if str_fr.respond_to?(:force_encoding)
433 str_fr.force_encoding('UTF-8')
433 str_fr.force_encoding('UTF-8')
434 end
434 end
435 assert_equal str_fr, l(:general_lang_name)
435 assert_equal str_fr, l(:general_lang_name)
436 assert_equal ';', l(:general_csv_separator)
436 assert_equal ';', l(:general_csv_separator)
437 assert_equal ',', l(:general_csv_decimal_separator)
437 assert_equal ',', l(:general_csv_decimal_separator)
438 end
438 end
439 end
439 end
440
440
441 def test_index_pdf
441 def test_index_pdf
442 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
442 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
443 with_settings :default_language => lang do
443 with_settings :default_language => lang do
444
444
445 get :index
445 get :index
446 assert_response :success
446 assert_response :success
447 assert_template 'index'
447 assert_template 'index'
448
448
449 if lang == "ja"
449 if lang == "ja"
450 if RUBY_PLATFORM != 'java'
450 if RUBY_PLATFORM != 'java'
451 assert_equal "CP932", l(:general_pdf_encoding)
451 assert_equal "CP932", l(:general_pdf_encoding)
452 end
452 end
453 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
453 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
454 next
454 next
455 end
455 end
456 end
456 end
457
457
458 get :index, :format => 'pdf'
458 get :index, :format => 'pdf'
459 assert_response :success
459 assert_response :success
460 assert_not_nil assigns(:issues)
460 assert_not_nil assigns(:issues)
461 assert_equal 'application/pdf', @response.content_type
461 assert_equal 'application/pdf', @response.content_type
462
462
463 get :index, :project_id => 1, :format => 'pdf'
463 get :index, :project_id => 1, :format => 'pdf'
464 assert_response :success
464 assert_response :success
465 assert_not_nil assigns(:issues)
465 assert_not_nil assigns(:issues)
466 assert_equal 'application/pdf', @response.content_type
466 assert_equal 'application/pdf', @response.content_type
467
467
468 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
468 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
469 assert_response :success
469 assert_response :success
470 assert_not_nil assigns(:issues)
470 assert_not_nil assigns(:issues)
471 assert_equal 'application/pdf', @response.content_type
471 assert_equal 'application/pdf', @response.content_type
472 end
472 end
473 end
473 end
474 end
474 end
475
475
476 def test_index_pdf_with_query_grouped_by_list_custom_field
476 def test_index_pdf_with_query_grouped_by_list_custom_field
477 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
477 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
478 assert_response :success
478 assert_response :success
479 assert_not_nil assigns(:issues)
479 assert_not_nil assigns(:issues)
480 assert_not_nil assigns(:issue_count_by_group)
480 assert_not_nil assigns(:issue_count_by_group)
481 assert_equal 'application/pdf', @response.content_type
481 assert_equal 'application/pdf', @response.content_type
482 end
482 end
483
483
484 def test_index_sort
484 def test_index_sort
485 get :index, :sort => 'tracker,id:desc'
485 get :index, :sort => 'tracker,id:desc'
486 assert_response :success
486 assert_response :success
487
487
488 sort_params = @request.session['issues_index_sort']
488 sort_params = @request.session['issues_index_sort']
489 assert sort_params.is_a?(String)
489 assert sort_params.is_a?(String)
490 assert_equal 'tracker,id:desc', sort_params
490 assert_equal 'tracker,id:desc', sort_params
491
491
492 issues = assigns(:issues)
492 issues = assigns(:issues)
493 assert_not_nil issues
493 assert_not_nil issues
494 assert !issues.empty?
494 assert !issues.empty?
495 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
495 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
496 end
496 end
497
497
498 def test_index_sort_by_field_not_included_in_columns
498 def test_index_sort_by_field_not_included_in_columns
499 Setting.issue_list_default_columns = %w(subject author)
499 Setting.issue_list_default_columns = %w(subject author)
500 get :index, :sort => 'tracker'
500 get :index, :sort => 'tracker'
501 end
501 end
502
502
503 def test_index_sort_by_assigned_to
503 def test_index_sort_by_assigned_to
504 get :index, :sort => 'assigned_to'
504 get :index, :sort => 'assigned_to'
505 assert_response :success
505 assert_response :success
506 assignees = assigns(:issues).collect(&:assigned_to).compact
506 assignees = assigns(:issues).collect(&:assigned_to).compact
507 assert_equal assignees.sort, assignees
507 assert_equal assignees.sort, assignees
508 end
508 end
509
509
510 def test_index_sort_by_assigned_to_desc
510 def test_index_sort_by_assigned_to_desc
511 get :index, :sort => 'assigned_to:desc'
511 get :index, :sort => 'assigned_to:desc'
512 assert_response :success
512 assert_response :success
513 assignees = assigns(:issues).collect(&:assigned_to).compact
513 assignees = assigns(:issues).collect(&:assigned_to).compact
514 assert_equal assignees.sort.reverse, assignees
514 assert_equal assignees.sort.reverse, assignees
515 end
515 end
516
516
517 def test_index_group_by_assigned_to
517 def test_index_group_by_assigned_to
518 get :index, :group_by => 'assigned_to', :sort => 'priority'
518 get :index, :group_by => 'assigned_to', :sort => 'priority'
519 assert_response :success
519 assert_response :success
520 end
520 end
521
521
522 def test_index_sort_by_author
522 def test_index_sort_by_author
523 get :index, :sort => 'author'
523 get :index, :sort => 'author'
524 assert_response :success
524 assert_response :success
525 authors = assigns(:issues).collect(&:author)
525 authors = assigns(:issues).collect(&:author)
526 assert_equal authors.sort, authors
526 assert_equal authors.sort, authors
527 end
527 end
528
528
529 def test_index_sort_by_author_desc
529 def test_index_sort_by_author_desc
530 get :index, :sort => 'author:desc'
530 get :index, :sort => 'author:desc'
531 assert_response :success
531 assert_response :success
532 authors = assigns(:issues).collect(&:author)
532 authors = assigns(:issues).collect(&:author)
533 assert_equal authors.sort.reverse, authors
533 assert_equal authors.sort.reverse, authors
534 end
534 end
535
535
536 def test_index_group_by_author
536 def test_index_group_by_author
537 get :index, :group_by => 'author', :sort => 'priority'
537 get :index, :group_by => 'author', :sort => 'priority'
538 assert_response :success
538 assert_response :success
539 end
539 end
540
540
541 def test_index_group_by_spent_hours
541 def test_index_sort_by_spent_hours
542 get :index, :group_by => 'author', :sort => 'spent_hours:desc'
542 get :index, :sort => 'spent_hours:desc'
543 assert_response :success
543 assert_response :success
544 hours = assigns(:issues).collect(&:spent_hours)
544 hours = assigns(:issues).collect(&:spent_hours)
545 assert_equal hours.sort.reverse, hours
545 assert_equal hours.sort.reverse, hours
546 end
546 end
547
547
548 def test_index_with_columns
548 def test_index_with_columns
549 columns = ['tracker', 'subject', 'assigned_to']
549 columns = ['tracker', 'subject', 'assigned_to']
550 get :index, :set_filter => 1, :c => columns
550 get :index, :set_filter => 1, :c => columns
551 assert_response :success
551 assert_response :success
552
552
553 # query should use specified columns
553 # query should use specified columns
554 query = assigns(:query)
554 query = assigns(:query)
555 assert_kind_of Query, query
555 assert_kind_of Query, query
556 assert_equal columns, query.column_names.map(&:to_s)
556 assert_equal columns, query.column_names.map(&:to_s)
557
557
558 # columns should be stored in session
558 # columns should be stored in session
559 assert_kind_of Hash, session[:query]
559 assert_kind_of Hash, session[:query]
560 assert_kind_of Array, session[:query][:column_names]
560 assert_kind_of Array, session[:query][:column_names]
561 assert_equal columns, session[:query][:column_names].map(&:to_s)
561 assert_equal columns, session[:query][:column_names].map(&:to_s)
562
562
563 # ensure only these columns are kept in the selected columns list
563 # ensure only these columns are kept in the selected columns list
564 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
564 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
565 :children => { :count => 3 }
565 :children => { :count => 3 }
566 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
566 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
567 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
567 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
568 end
568 end
569
569
570 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
570 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
571 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
571 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
572 get :index, :set_filter => 1
572 get :index, :set_filter => 1
573
573
574 # query should use specified columns
574 # query should use specified columns
575 query = assigns(:query)
575 query = assigns(:query)
576 assert_kind_of Query, query
576 assert_kind_of Query, query
577 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
577 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
578 end
578 end
579
579
580 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
580 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
581 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
581 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
582 columns = ['tracker', 'subject', 'assigned_to']
582 columns = ['tracker', 'subject', 'assigned_to']
583 get :index, :set_filter => 1, :c => columns
583 get :index, :set_filter => 1, :c => columns
584
584
585 # query should use specified columns
585 # query should use specified columns
586 query = assigns(:query)
586 query = assigns(:query)
587 assert_kind_of Query, query
587 assert_kind_of Query, query
588 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
588 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
589 end
589 end
590
590
591 def test_index_with_custom_field_column
591 def test_index_with_custom_field_column
592 columns = %w(tracker subject cf_2)
592 columns = %w(tracker subject cf_2)
593 get :index, :set_filter => 1, :c => columns
593 get :index, :set_filter => 1, :c => columns
594 assert_response :success
594 assert_response :success
595
595
596 # query should use specified columns
596 # query should use specified columns
597 query = assigns(:query)
597 query = assigns(:query)
598 assert_kind_of Query, query
598 assert_kind_of Query, query
599 assert_equal columns, query.column_names.map(&:to_s)
599 assert_equal columns, query.column_names.map(&:to_s)
600
600
601 assert_tag :td,
601 assert_tag :td,
602 :attributes => {:class => 'cf_2 string'},
602 :attributes => {:class => 'cf_2 string'},
603 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
603 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
604 end
604 end
605
605
606 def test_index_with_date_column
606 def test_index_with_date_column
607 Issue.find(1).update_attribute :start_date, '1987-08-24'
607 Issue.find(1).update_attribute :start_date, '1987-08-24'
608
608
609 with_settings :date_format => '%d/%m/%Y' do
609 with_settings :date_format => '%d/%m/%Y' do
610 get :index, :set_filter => 1, :c => %w(start_date)
610 get :index, :set_filter => 1, :c => %w(start_date)
611 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
611 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
612 end
612 end
613 end
613 end
614
614
615 def test_index_with_done_ratio
615 def test_index_with_done_ratio
616 Issue.find(1).update_attribute :done_ratio, 40
616 Issue.find(1).update_attribute :done_ratio, 40
617
617
618 get :index, :set_filter => 1, :c => %w(done_ratio)
618 get :index, :set_filter => 1, :c => %w(done_ratio)
619 assert_tag 'td', :attributes => {:class => /done_ratio/},
619 assert_tag 'td', :attributes => {:class => /done_ratio/},
620 :child => {:tag => 'table', :attributes => {:class => 'progress'},
620 :child => {:tag => 'table', :attributes => {:class => 'progress'},
621 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
621 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
622 }
622 }
623 end
623 end
624
624
625 def test_index_with_spent_hours_column
625 def test_index_with_spent_hours_column
626 get :index, :set_filter => 1, :c => %w(subject spent_hours)
626 get :index, :set_filter => 1, :c => %w(subject spent_hours)
627
627
628 assert_tag 'tr', :attributes => {:id => 'issue-3'},
628 assert_tag 'tr', :attributes => {:id => 'issue-3'},
629 :child => {
629 :child => {
630 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
630 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
631 }
631 }
632 end
632 end
633
633
634 def test_index_should_not_show_spent_hours_column_without_permission
634 def test_index_should_not_show_spent_hours_column_without_permission
635 Role.anonymous.remove_permission! :view_time_entries
635 Role.anonymous.remove_permission! :view_time_entries
636 get :index, :set_filter => 1, :c => %w(subject spent_hours)
636 get :index, :set_filter => 1, :c => %w(subject spent_hours)
637
637
638 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
638 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
639 end
639 end
640
640
641 def test_index_with_fixed_version
641 def test_index_with_fixed_version
642 get :index, :set_filter => 1, :c => %w(fixed_version)
642 get :index, :set_filter => 1, :c => %w(fixed_version)
643 assert_tag 'td', :attributes => {:class => /fixed_version/},
643 assert_tag 'td', :attributes => {:class => /fixed_version/},
644 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
644 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
645 end
645 end
646
646
647 def test_index_send_html_if_query_is_invalid
647 def test_index_send_html_if_query_is_invalid
648 get :index, :f => ['start_date'], :op => {:start_date => '='}
648 get :index, :f => ['start_date'], :op => {:start_date => '='}
649 assert_equal 'text/html', @response.content_type
649 assert_equal 'text/html', @response.content_type
650 assert_template 'index'
650 assert_template 'index'
651 end
651 end
652
652
653 def test_index_send_nothing_if_query_is_invalid
653 def test_index_send_nothing_if_query_is_invalid
654 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
654 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
655 assert_equal 'text/csv', @response.content_type
655 assert_equal 'text/csv', @response.content_type
656 assert @response.body.blank?
656 assert @response.body.blank?
657 end
657 end
658
658
659 def test_index_should_rescue_invalid_sql_query
659 def test_index_should_rescue_invalid_sql_query
660 Query.any_instance.stubs(:statement).returns("INVALID STATEMENT")
660 Query.any_instance.stubs(:statement).returns("INVALID STATEMENT")
661
661
662 get :index
662 get :index
663 assert_response 500
663 assert_response 500
664 assert_tag 'p', :content => /An error occurred/
664 assert_tag 'p', :content => /An error occurred/
665 assert_nil session[:query]
665 assert_nil session[:query]
666 assert_nil session[:issues_index_sort]
666 assert_nil session[:issues_index_sort]
667 end
667 end
668
668
669 def test_show_by_anonymous
669 def test_show_by_anonymous
670 get :show, :id => 1
670 get :show, :id => 1
671 assert_response :success
671 assert_response :success
672 assert_template 'show'
672 assert_template 'show'
673 assert_not_nil assigns(:issue)
673 assert_not_nil assigns(:issue)
674 assert_equal Issue.find(1), assigns(:issue)
674 assert_equal Issue.find(1), assigns(:issue)
675
675
676 # anonymous role is allowed to add a note
676 # anonymous role is allowed to add a note
677 assert_tag :tag => 'form',
677 assert_tag :tag => 'form',
678 :descendant => { :tag => 'fieldset',
678 :descendant => { :tag => 'fieldset',
679 :child => { :tag => 'legend',
679 :child => { :tag => 'legend',
680 :content => /Notes/ } }
680 :content => /Notes/ } }
681 assert_tag :tag => 'title',
681 assert_tag :tag => 'title',
682 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
682 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
683 end
683 end
684
684
685 def test_show_by_manager
685 def test_show_by_manager
686 @request.session[:user_id] = 2
686 @request.session[:user_id] = 2
687 get :show, :id => 1
687 get :show, :id => 1
688 assert_response :success
688 assert_response :success
689
689
690 assert_tag :tag => 'a',
690 assert_tag :tag => 'a',
691 :content => /Quote/
691 :content => /Quote/
692
692
693 assert_tag :tag => 'form',
693 assert_tag :tag => 'form',
694 :descendant => { :tag => 'fieldset',
694 :descendant => { :tag => 'fieldset',
695 :child => { :tag => 'legend',
695 :child => { :tag => 'legend',
696 :content => /Change properties/ } },
696 :content => /Change properties/ } },
697 :descendant => { :tag => 'fieldset',
697 :descendant => { :tag => 'fieldset',
698 :child => { :tag => 'legend',
698 :child => { :tag => 'legend',
699 :content => /Log time/ } },
699 :content => /Log time/ } },
700 :descendant => { :tag => 'fieldset',
700 :descendant => { :tag => 'fieldset',
701 :child => { :tag => 'legend',
701 :child => { :tag => 'legend',
702 :content => /Notes/ } }
702 :content => /Notes/ } }
703 end
703 end
704
704
705 def test_update_form_should_not_display_inactive_enumerations
705 def test_update_form_should_not_display_inactive_enumerations
706 @request.session[:user_id] = 2
706 @request.session[:user_id] = 2
707 get :show, :id => 1
707 get :show, :id => 1
708 assert_response :success
708 assert_response :success
709
709
710 assert ! IssuePriority.find(15).active?
710 assert ! IssuePriority.find(15).active?
711 assert_no_tag :option, :attributes => {:value => '15'},
711 assert_no_tag :option, :attributes => {:value => '15'},
712 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
712 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
713 end
713 end
714
714
715 def test_update_form_should_allow_attachment_upload
715 def test_update_form_should_allow_attachment_upload
716 @request.session[:user_id] = 2
716 @request.session[:user_id] = 2
717 get :show, :id => 1
717 get :show, :id => 1
718
718
719 assert_tag :tag => 'form',
719 assert_tag :tag => 'form',
720 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
720 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
721 :descendant => {
721 :descendant => {
722 :tag => 'input',
722 :tag => 'input',
723 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
723 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
724 }
724 }
725 end
725 end
726
726
727 def test_show_should_deny_anonymous_access_without_permission
727 def test_show_should_deny_anonymous_access_without_permission
728 Role.anonymous.remove_permission!(:view_issues)
728 Role.anonymous.remove_permission!(:view_issues)
729 get :show, :id => 1
729 get :show, :id => 1
730 assert_response :redirect
730 assert_response :redirect
731 end
731 end
732
732
733 def test_show_should_deny_anonymous_access_to_private_issue
733 def test_show_should_deny_anonymous_access_to_private_issue
734 Issue.update_all(["is_private = ?", true], "id = 1")
734 Issue.update_all(["is_private = ?", true], "id = 1")
735 get :show, :id => 1
735 get :show, :id => 1
736 assert_response :redirect
736 assert_response :redirect
737 end
737 end
738
738
739 def test_show_should_deny_non_member_access_without_permission
739 def test_show_should_deny_non_member_access_without_permission
740 Role.non_member.remove_permission!(:view_issues)
740 Role.non_member.remove_permission!(:view_issues)
741 @request.session[:user_id] = 9
741 @request.session[:user_id] = 9
742 get :show, :id => 1
742 get :show, :id => 1
743 assert_response 403
743 assert_response 403
744 end
744 end
745
745
746 def test_show_should_deny_non_member_access_to_private_issue
746 def test_show_should_deny_non_member_access_to_private_issue
747 Issue.update_all(["is_private = ?", true], "id = 1")
747 Issue.update_all(["is_private = ?", true], "id = 1")
748 @request.session[:user_id] = 9
748 @request.session[:user_id] = 9
749 get :show, :id => 1
749 get :show, :id => 1
750 assert_response 403
750 assert_response 403
751 end
751 end
752
752
753 def test_show_should_deny_member_access_without_permission
753 def test_show_should_deny_member_access_without_permission
754 Role.find(1).remove_permission!(:view_issues)
754 Role.find(1).remove_permission!(:view_issues)
755 @request.session[:user_id] = 2
755 @request.session[:user_id] = 2
756 get :show, :id => 1
756 get :show, :id => 1
757 assert_response 403
757 assert_response 403
758 end
758 end
759
759
760 def test_show_should_deny_member_access_to_private_issue_without_permission
760 def test_show_should_deny_member_access_to_private_issue_without_permission
761 Issue.update_all(["is_private = ?", true], "id = 1")
761 Issue.update_all(["is_private = ?", true], "id = 1")
762 @request.session[:user_id] = 3
762 @request.session[:user_id] = 3
763 get :show, :id => 1
763 get :show, :id => 1
764 assert_response 403
764 assert_response 403
765 end
765 end
766
766
767 def test_show_should_allow_author_access_to_private_issue
767 def test_show_should_allow_author_access_to_private_issue
768 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
768 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
769 @request.session[:user_id] = 3
769 @request.session[:user_id] = 3
770 get :show, :id => 1
770 get :show, :id => 1
771 assert_response :success
771 assert_response :success
772 end
772 end
773
773
774 def test_show_should_allow_assignee_access_to_private_issue
774 def test_show_should_allow_assignee_access_to_private_issue
775 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
775 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
776 @request.session[:user_id] = 3
776 @request.session[:user_id] = 3
777 get :show, :id => 1
777 get :show, :id => 1
778 assert_response :success
778 assert_response :success
779 end
779 end
780
780
781 def test_show_should_allow_member_access_to_private_issue_with_permission
781 def test_show_should_allow_member_access_to_private_issue_with_permission
782 Issue.update_all(["is_private = ?", true], "id = 1")
782 Issue.update_all(["is_private = ?", true], "id = 1")
783 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
783 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
784 @request.session[:user_id] = 3
784 @request.session[:user_id] = 3
785 get :show, :id => 1
785 get :show, :id => 1
786 assert_response :success
786 assert_response :success
787 end
787 end
788
788
789 def test_show_should_not_disclose_relations_to_invisible_issues
789 def test_show_should_not_disclose_relations_to_invisible_issues
790 Setting.cross_project_issue_relations = '1'
790 Setting.cross_project_issue_relations = '1'
791 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
791 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
792 # Relation to a private project issue
792 # Relation to a private project issue
793 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
793 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
794
794
795 get :show, :id => 1
795 get :show, :id => 1
796 assert_response :success
796 assert_response :success
797
797
798 assert_tag :div, :attributes => { :id => 'relations' },
798 assert_tag :div, :attributes => { :id => 'relations' },
799 :descendant => { :tag => 'a', :content => /#2$/ }
799 :descendant => { :tag => 'a', :content => /#2$/ }
800 assert_no_tag :div, :attributes => { :id => 'relations' },
800 assert_no_tag :div, :attributes => { :id => 'relations' },
801 :descendant => { :tag => 'a', :content => /#4$/ }
801 :descendant => { :tag => 'a', :content => /#4$/ }
802 end
802 end
803
803
804 def test_show_should_list_subtasks
804 def test_show_should_list_subtasks
805 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
805 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
806
806
807 get :show, :id => 1
807 get :show, :id => 1
808 assert_response :success
808 assert_response :success
809 assert_tag 'div', :attributes => {:id => 'issue_tree'},
809 assert_tag 'div', :attributes => {:id => 'issue_tree'},
810 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
810 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
811 end
811 end
812
812
813 def test_show_should_list_parents
813 def test_show_should_list_parents
814 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
814 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
815
815
816 get :show, :id => issue.id
816 get :show, :id => issue.id
817 assert_response :success
817 assert_response :success
818 assert_tag 'div', :attributes => {:class => 'subject'},
818 assert_tag 'div', :attributes => {:class => 'subject'},
819 :descendant => {:tag => 'h3', :content => 'Child Issue'}
819 :descendant => {:tag => 'h3', :content => 'Child Issue'}
820 assert_tag 'div', :attributes => {:class => 'subject'},
820 assert_tag 'div', :attributes => {:class => 'subject'},
821 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
821 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
822 end
822 end
823
823
824 def test_show_atom
824 def test_show_atom
825 get :show, :id => 2, :format => 'atom'
825 get :show, :id => 2, :format => 'atom'
826 assert_response :success
826 assert_response :success
827 assert_template 'journals/index'
827 assert_template 'journals/index'
828 # Inline image
828 # Inline image
829 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
829 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
830 end
830 end
831
831
832 def test_show_export_to_pdf
832 def test_show_export_to_pdf
833 get :show, :id => 3, :format => 'pdf'
833 get :show, :id => 3, :format => 'pdf'
834 assert_response :success
834 assert_response :success
835 assert_equal 'application/pdf', @response.content_type
835 assert_equal 'application/pdf', @response.content_type
836 assert @response.body.starts_with?('%PDF')
836 assert @response.body.starts_with?('%PDF')
837 assert_not_nil assigns(:issue)
837 assert_not_nil assigns(:issue)
838 end
838 end
839
839
840 def test_get_new
840 def test_get_new
841 @request.session[:user_id] = 2
841 @request.session[:user_id] = 2
842 get :new, :project_id => 1, :tracker_id => 1
842 get :new, :project_id => 1, :tracker_id => 1
843 assert_response :success
843 assert_response :success
844 assert_template 'new'
844 assert_template 'new'
845
845
846 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
846 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
847 :value => 'Default string' }
847 :value => 'Default string' }
848
848
849 # Be sure we don't display inactive IssuePriorities
849 # Be sure we don't display inactive IssuePriorities
850 assert ! IssuePriority.find(15).active?
850 assert ! IssuePriority.find(15).active?
851 assert_no_tag :option, :attributes => {:value => '15'},
851 assert_no_tag :option, :attributes => {:value => '15'},
852 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
852 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
853 end
853 end
854
854
855 def test_get_new_without_default_start_date_is_creation_date
855 def test_get_new_without_default_start_date_is_creation_date
856 Setting.default_issue_start_date_to_creation_date = 0
856 Setting.default_issue_start_date_to_creation_date = 0
857
857
858 @request.session[:user_id] = 2
858 @request.session[:user_id] = 2
859 get :new, :project_id => 1, :tracker_id => 1
859 get :new, :project_id => 1, :tracker_id => 1
860 assert_response :success
860 assert_response :success
861 assert_template 'new'
861 assert_template 'new'
862
862
863 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
863 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
864 :value => nil }
864 :value => nil }
865 end
865 end
866
866
867 def test_get_new_with_default_start_date_is_creation_date
867 def test_get_new_with_default_start_date_is_creation_date
868 Setting.default_issue_start_date_to_creation_date = 1
868 Setting.default_issue_start_date_to_creation_date = 1
869
869
870 @request.session[:user_id] = 2
870 @request.session[:user_id] = 2
871 get :new, :project_id => 1, :tracker_id => 1
871 get :new, :project_id => 1, :tracker_id => 1
872 assert_response :success
872 assert_response :success
873 assert_template 'new'
873 assert_template 'new'
874
874
875 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
875 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
876 :value => Date.today.to_s }
876 :value => Date.today.to_s }
877 end
877 end
878
878
879 def test_get_new_form_should_allow_attachment_upload
879 def test_get_new_form_should_allow_attachment_upload
880 @request.session[:user_id] = 2
880 @request.session[:user_id] = 2
881 get :new, :project_id => 1, :tracker_id => 1
881 get :new, :project_id => 1, :tracker_id => 1
882
882
883 assert_tag :tag => 'form',
883 assert_tag :tag => 'form',
884 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
884 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
885 :descendant => {
885 :descendant => {
886 :tag => 'input',
886 :tag => 'input',
887 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
887 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
888 }
888 }
889 end
889 end
890
890
891 def test_get_new_without_tracker_id
891 def test_get_new_without_tracker_id
892 @request.session[:user_id] = 2
892 @request.session[:user_id] = 2
893 get :new, :project_id => 1
893 get :new, :project_id => 1
894 assert_response :success
894 assert_response :success
895 assert_template 'new'
895 assert_template 'new'
896
896
897 issue = assigns(:issue)
897 issue = assigns(:issue)
898 assert_not_nil issue
898 assert_not_nil issue
899 assert_equal Project.find(1).trackers.first, issue.tracker
899 assert_equal Project.find(1).trackers.first, issue.tracker
900 end
900 end
901
901
902 def test_get_new_with_no_default_status_should_display_an_error
902 def test_get_new_with_no_default_status_should_display_an_error
903 @request.session[:user_id] = 2
903 @request.session[:user_id] = 2
904 IssueStatus.delete_all
904 IssueStatus.delete_all
905
905
906 get :new, :project_id => 1
906 get :new, :project_id => 1
907 assert_response 500
907 assert_response 500
908 assert_error_tag :content => /No default issue/
908 assert_error_tag :content => /No default issue/
909 end
909 end
910
910
911 def test_get_new_with_no_tracker_should_display_an_error
911 def test_get_new_with_no_tracker_should_display_an_error
912 @request.session[:user_id] = 2
912 @request.session[:user_id] = 2
913 Tracker.delete_all
913 Tracker.delete_all
914
914
915 get :new, :project_id => 1
915 get :new, :project_id => 1
916 assert_response 500
916 assert_response 500
917 assert_error_tag :content => /No tracker/
917 assert_error_tag :content => /No tracker/
918 end
918 end
919
919
920 def test_update_new_form
920 def test_update_new_form
921 @request.session[:user_id] = 2
921 @request.session[:user_id] = 2
922 xhr :post, :new, :project_id => 1,
922 xhr :post, :new, :project_id => 1,
923 :issue => {:tracker_id => 2,
923 :issue => {:tracker_id => 2,
924 :subject => 'This is the test_new issue',
924 :subject => 'This is the test_new issue',
925 :description => 'This is the description',
925 :description => 'This is the description',
926 :priority_id => 5}
926 :priority_id => 5}
927 assert_response :success
927 assert_response :success
928 assert_template 'attributes'
928 assert_template 'attributes'
929
929
930 issue = assigns(:issue)
930 issue = assigns(:issue)
931 assert_kind_of Issue, issue
931 assert_kind_of Issue, issue
932 assert_equal 1, issue.project_id
932 assert_equal 1, issue.project_id
933 assert_equal 2, issue.tracker_id
933 assert_equal 2, issue.tracker_id
934 assert_equal 'This is the test_new issue', issue.subject
934 assert_equal 'This is the test_new issue', issue.subject
935 end
935 end
936
936
937 def test_post_create
937 def test_post_create
938 @request.session[:user_id] = 2
938 @request.session[:user_id] = 2
939 assert_difference 'Issue.count' do
939 assert_difference 'Issue.count' do
940 post :create, :project_id => 1,
940 post :create, :project_id => 1,
941 :issue => {:tracker_id => 3,
941 :issue => {:tracker_id => 3,
942 :status_id => 2,
942 :status_id => 2,
943 :subject => 'This is the test_new issue',
943 :subject => 'This is the test_new issue',
944 :description => 'This is the description',
944 :description => 'This is the description',
945 :priority_id => 5,
945 :priority_id => 5,
946 :start_date => '2010-11-07',
946 :start_date => '2010-11-07',
947 :estimated_hours => '',
947 :estimated_hours => '',
948 :custom_field_values => {'2' => 'Value for field 2'}}
948 :custom_field_values => {'2' => 'Value for field 2'}}
949 end
949 end
950 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
950 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
951
951
952 issue = Issue.find_by_subject('This is the test_new issue')
952 issue = Issue.find_by_subject('This is the test_new issue')
953 assert_not_nil issue
953 assert_not_nil issue
954 assert_equal 2, issue.author_id
954 assert_equal 2, issue.author_id
955 assert_equal 3, issue.tracker_id
955 assert_equal 3, issue.tracker_id
956 assert_equal 2, issue.status_id
956 assert_equal 2, issue.status_id
957 assert_equal Date.parse('2010-11-07'), issue.start_date
957 assert_equal Date.parse('2010-11-07'), issue.start_date
958 assert_nil issue.estimated_hours
958 assert_nil issue.estimated_hours
959 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
959 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
960 assert_not_nil v
960 assert_not_nil v
961 assert_equal 'Value for field 2', v.value
961 assert_equal 'Value for field 2', v.value
962 end
962 end
963
963
964 def test_post_new_with_group_assignment
964 def test_post_new_with_group_assignment
965 group = Group.find(11)
965 group = Group.find(11)
966 project = Project.find(1)
966 project = Project.find(1)
967 project.members << Member.new(:principal => group, :roles => [Role.first])
967 project.members << Member.new(:principal => group, :roles => [Role.first])
968
968
969 with_settings :issue_group_assignment => '1' do
969 with_settings :issue_group_assignment => '1' do
970 @request.session[:user_id] = 2
970 @request.session[:user_id] = 2
971 assert_difference 'Issue.count' do
971 assert_difference 'Issue.count' do
972 post :create, :project_id => project.id,
972 post :create, :project_id => project.id,
973 :issue => {:tracker_id => 3,
973 :issue => {:tracker_id => 3,
974 :status_id => 1,
974 :status_id => 1,
975 :subject => 'This is the test_new_with_group_assignment issue',
975 :subject => 'This is the test_new_with_group_assignment issue',
976 :assigned_to_id => group.id}
976 :assigned_to_id => group.id}
977 end
977 end
978 end
978 end
979 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
979 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
980
980
981 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
981 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
982 assert_not_nil issue
982 assert_not_nil issue
983 assert_equal group, issue.assigned_to
983 assert_equal group, issue.assigned_to
984 end
984 end
985
985
986 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
986 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
987 Setting.default_issue_start_date_to_creation_date = 0
987 Setting.default_issue_start_date_to_creation_date = 0
988
988
989 @request.session[:user_id] = 2
989 @request.session[:user_id] = 2
990 assert_difference 'Issue.count' do
990 assert_difference 'Issue.count' do
991 post :create, :project_id => 1,
991 post :create, :project_id => 1,
992 :issue => {:tracker_id => 3,
992 :issue => {:tracker_id => 3,
993 :status_id => 2,
993 :status_id => 2,
994 :subject => 'This is the test_new issue',
994 :subject => 'This is the test_new issue',
995 :description => 'This is the description',
995 :description => 'This is the description',
996 :priority_id => 5,
996 :priority_id => 5,
997 :estimated_hours => '',
997 :estimated_hours => '',
998 :custom_field_values => {'2' => 'Value for field 2'}}
998 :custom_field_values => {'2' => 'Value for field 2'}}
999 end
999 end
1000 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1000 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1001
1001
1002 issue = Issue.find_by_subject('This is the test_new issue')
1002 issue = Issue.find_by_subject('This is the test_new issue')
1003 assert_not_nil issue
1003 assert_not_nil issue
1004 assert_nil issue.start_date
1004 assert_nil issue.start_date
1005 end
1005 end
1006
1006
1007 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1007 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1008 Setting.default_issue_start_date_to_creation_date = 1
1008 Setting.default_issue_start_date_to_creation_date = 1
1009
1009
1010 @request.session[:user_id] = 2
1010 @request.session[:user_id] = 2
1011 assert_difference 'Issue.count' do
1011 assert_difference 'Issue.count' do
1012 post :create, :project_id => 1,
1012 post :create, :project_id => 1,
1013 :issue => {:tracker_id => 3,
1013 :issue => {:tracker_id => 3,
1014 :status_id => 2,
1014 :status_id => 2,
1015 :subject => 'This is the test_new issue',
1015 :subject => 'This is the test_new issue',
1016 :description => 'This is the description',
1016 :description => 'This is the description',
1017 :priority_id => 5,
1017 :priority_id => 5,
1018 :estimated_hours => '',
1018 :estimated_hours => '',
1019 :custom_field_values => {'2' => 'Value for field 2'}}
1019 :custom_field_values => {'2' => 'Value for field 2'}}
1020 end
1020 end
1021 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1021 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1022
1022
1023 issue = Issue.find_by_subject('This is the test_new issue')
1023 issue = Issue.find_by_subject('This is the test_new issue')
1024 assert_not_nil issue
1024 assert_not_nil issue
1025 assert_equal Date.today, issue.start_date
1025 assert_equal Date.today, issue.start_date
1026 end
1026 end
1027
1027
1028 def test_post_create_and_continue
1028 def test_post_create_and_continue
1029 @request.session[:user_id] = 2
1029 @request.session[:user_id] = 2
1030 assert_difference 'Issue.count' do
1030 assert_difference 'Issue.count' do
1031 post :create, :project_id => 1,
1031 post :create, :project_id => 1,
1032 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1032 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1033 :continue => ''
1033 :continue => ''
1034 end
1034 end
1035
1035
1036 issue = Issue.first(:order => 'id DESC')
1036 issue = Issue.first(:order => 'id DESC')
1037 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1037 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1038 assert_not_nil flash[:notice], "flash was not set"
1038 assert_not_nil flash[:notice], "flash was not set"
1039 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1039 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1040 end
1040 end
1041
1041
1042 def test_post_create_without_custom_fields_param
1042 def test_post_create_without_custom_fields_param
1043 @request.session[:user_id] = 2
1043 @request.session[:user_id] = 2
1044 assert_difference 'Issue.count' do
1044 assert_difference 'Issue.count' do
1045 post :create, :project_id => 1,
1045 post :create, :project_id => 1,
1046 :issue => {:tracker_id => 1,
1046 :issue => {:tracker_id => 1,
1047 :subject => 'This is the test_new issue',
1047 :subject => 'This is the test_new issue',
1048 :description => 'This is the description',
1048 :description => 'This is the description',
1049 :priority_id => 5}
1049 :priority_id => 5}
1050 end
1050 end
1051 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1051 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1052 end
1052 end
1053
1053
1054 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1054 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1055 field = IssueCustomField.find_by_name('Database')
1055 field = IssueCustomField.find_by_name('Database')
1056 field.update_attribute(:is_required, true)
1056 field.update_attribute(:is_required, true)
1057
1057
1058 @request.session[:user_id] = 2
1058 @request.session[:user_id] = 2
1059 post :create, :project_id => 1,
1059 post :create, :project_id => 1,
1060 :issue => {:tracker_id => 1,
1060 :issue => {:tracker_id => 1,
1061 :subject => 'This is the test_new issue',
1061 :subject => 'This is the test_new issue',
1062 :description => 'This is the description',
1062 :description => 'This is the description',
1063 :priority_id => 5}
1063 :priority_id => 5}
1064 assert_response :success
1064 assert_response :success
1065 assert_template 'new'
1065 assert_template 'new'
1066 issue = assigns(:issue)
1066 issue = assigns(:issue)
1067 assert_not_nil issue
1067 assert_not_nil issue
1068 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
1068 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
1069 end
1069 end
1070
1070
1071 def test_post_create_with_watchers
1071 def test_post_create_with_watchers
1072 @request.session[:user_id] = 2
1072 @request.session[:user_id] = 2
1073 ActionMailer::Base.deliveries.clear
1073 ActionMailer::Base.deliveries.clear
1074
1074
1075 assert_difference 'Watcher.count', 2 do
1075 assert_difference 'Watcher.count', 2 do
1076 post :create, :project_id => 1,
1076 post :create, :project_id => 1,
1077 :issue => {:tracker_id => 1,
1077 :issue => {:tracker_id => 1,
1078 :subject => 'This is a new issue with watchers',
1078 :subject => 'This is a new issue with watchers',
1079 :description => 'This is the description',
1079 :description => 'This is the description',
1080 :priority_id => 5,
1080 :priority_id => 5,
1081 :watcher_user_ids => ['2', '3']}
1081 :watcher_user_ids => ['2', '3']}
1082 end
1082 end
1083 issue = Issue.find_by_subject('This is a new issue with watchers')
1083 issue = Issue.find_by_subject('This is a new issue with watchers')
1084 assert_not_nil issue
1084 assert_not_nil issue
1085 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1085 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1086
1086
1087 # Watchers added
1087 # Watchers added
1088 assert_equal [2, 3], issue.watcher_user_ids.sort
1088 assert_equal [2, 3], issue.watcher_user_ids.sort
1089 assert issue.watched_by?(User.find(3))
1089 assert issue.watched_by?(User.find(3))
1090 # Watchers notified
1090 # Watchers notified
1091 mail = ActionMailer::Base.deliveries.last
1091 mail = ActionMailer::Base.deliveries.last
1092 assert_kind_of TMail::Mail, mail
1092 assert_kind_of TMail::Mail, mail
1093 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1093 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1094 end
1094 end
1095
1095
1096 def test_post_create_subissue
1096 def test_post_create_subissue
1097 @request.session[:user_id] = 2
1097 @request.session[:user_id] = 2
1098
1098
1099 assert_difference 'Issue.count' do
1099 assert_difference 'Issue.count' do
1100 post :create, :project_id => 1,
1100 post :create, :project_id => 1,
1101 :issue => {:tracker_id => 1,
1101 :issue => {:tracker_id => 1,
1102 :subject => 'This is a child issue',
1102 :subject => 'This is a child issue',
1103 :parent_issue_id => 2}
1103 :parent_issue_id => 2}
1104 end
1104 end
1105 issue = Issue.find_by_subject('This is a child issue')
1105 issue = Issue.find_by_subject('This is a child issue')
1106 assert_not_nil issue
1106 assert_not_nil issue
1107 assert_equal Issue.find(2), issue.parent
1107 assert_equal Issue.find(2), issue.parent
1108 end
1108 end
1109
1109
1110 def test_post_create_subissue_with_non_numeric_parent_id
1110 def test_post_create_subissue_with_non_numeric_parent_id
1111 @request.session[:user_id] = 2
1111 @request.session[:user_id] = 2
1112
1112
1113 assert_difference 'Issue.count' do
1113 assert_difference 'Issue.count' do
1114 post :create, :project_id => 1,
1114 post :create, :project_id => 1,
1115 :issue => {:tracker_id => 1,
1115 :issue => {:tracker_id => 1,
1116 :subject => 'This is a child issue',
1116 :subject => 'This is a child issue',
1117 :parent_issue_id => 'ABC'}
1117 :parent_issue_id => 'ABC'}
1118 end
1118 end
1119 issue = Issue.find_by_subject('This is a child issue')
1119 issue = Issue.find_by_subject('This is a child issue')
1120 assert_not_nil issue
1120 assert_not_nil issue
1121 assert_nil issue.parent
1121 assert_nil issue.parent
1122 end
1122 end
1123
1123
1124 def test_post_create_private
1124 def test_post_create_private
1125 @request.session[:user_id] = 2
1125 @request.session[:user_id] = 2
1126
1126
1127 assert_difference 'Issue.count' do
1127 assert_difference 'Issue.count' do
1128 post :create, :project_id => 1,
1128 post :create, :project_id => 1,
1129 :issue => {:tracker_id => 1,
1129 :issue => {:tracker_id => 1,
1130 :subject => 'This is a private issue',
1130 :subject => 'This is a private issue',
1131 :is_private => '1'}
1131 :is_private => '1'}
1132 end
1132 end
1133 issue = Issue.first(:order => 'id DESC')
1133 issue = Issue.first(:order => 'id DESC')
1134 assert issue.is_private?
1134 assert issue.is_private?
1135 end
1135 end
1136
1136
1137 def test_post_create_private_with_set_own_issues_private_permission
1137 def test_post_create_private_with_set_own_issues_private_permission
1138 role = Role.find(1)
1138 role = Role.find(1)
1139 role.remove_permission! :set_issues_private
1139 role.remove_permission! :set_issues_private
1140 role.add_permission! :set_own_issues_private
1140 role.add_permission! :set_own_issues_private
1141
1141
1142 @request.session[:user_id] = 2
1142 @request.session[:user_id] = 2
1143
1143
1144 assert_difference 'Issue.count' do
1144 assert_difference 'Issue.count' do
1145 post :create, :project_id => 1,
1145 post :create, :project_id => 1,
1146 :issue => {:tracker_id => 1,
1146 :issue => {:tracker_id => 1,
1147 :subject => 'This is a private issue',
1147 :subject => 'This is a private issue',
1148 :is_private => '1'}
1148 :is_private => '1'}
1149 end
1149 end
1150 issue = Issue.first(:order => 'id DESC')
1150 issue = Issue.first(:order => 'id DESC')
1151 assert issue.is_private?
1151 assert issue.is_private?
1152 end
1152 end
1153
1153
1154 def test_post_create_should_send_a_notification
1154 def test_post_create_should_send_a_notification
1155 ActionMailer::Base.deliveries.clear
1155 ActionMailer::Base.deliveries.clear
1156 @request.session[:user_id] = 2
1156 @request.session[:user_id] = 2
1157 assert_difference 'Issue.count' do
1157 assert_difference 'Issue.count' do
1158 post :create, :project_id => 1,
1158 post :create, :project_id => 1,
1159 :issue => {:tracker_id => 3,
1159 :issue => {:tracker_id => 3,
1160 :subject => 'This is the test_new issue',
1160 :subject => 'This is the test_new issue',
1161 :description => 'This is the description',
1161 :description => 'This is the description',
1162 :priority_id => 5,
1162 :priority_id => 5,
1163 :estimated_hours => '',
1163 :estimated_hours => '',
1164 :custom_field_values => {'2' => 'Value for field 2'}}
1164 :custom_field_values => {'2' => 'Value for field 2'}}
1165 end
1165 end
1166 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1166 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1167
1167
1168 assert_equal 1, ActionMailer::Base.deliveries.size
1168 assert_equal 1, ActionMailer::Base.deliveries.size
1169 end
1169 end
1170
1170
1171 def test_post_create_should_preserve_fields_values_on_validation_failure
1171 def test_post_create_should_preserve_fields_values_on_validation_failure
1172 @request.session[:user_id] = 2
1172 @request.session[:user_id] = 2
1173 post :create, :project_id => 1,
1173 post :create, :project_id => 1,
1174 :issue => {:tracker_id => 1,
1174 :issue => {:tracker_id => 1,
1175 # empty subject
1175 # empty subject
1176 :subject => '',
1176 :subject => '',
1177 :description => 'This is a description',
1177 :description => 'This is a description',
1178 :priority_id => 6,
1178 :priority_id => 6,
1179 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1179 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1180 assert_response :success
1180 assert_response :success
1181 assert_template 'new'
1181 assert_template 'new'
1182
1182
1183 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1183 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1184 :content => 'This is a description'
1184 :content => 'This is a description'
1185 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1185 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1186 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1186 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1187 :value => '6' },
1187 :value => '6' },
1188 :content => 'High' }
1188 :content => 'High' }
1189 # Custom fields
1189 # Custom fields
1190 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1190 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1191 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1191 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1192 :value => 'Oracle' },
1192 :value => 'Oracle' },
1193 :content => 'Oracle' }
1193 :content => 'Oracle' }
1194 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1194 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1195 :value => 'Value for field 2'}
1195 :value => 'Value for field 2'}
1196 end
1196 end
1197
1197
1198 def test_post_create_should_ignore_non_safe_attributes
1198 def test_post_create_should_ignore_non_safe_attributes
1199 @request.session[:user_id] = 2
1199 @request.session[:user_id] = 2
1200 assert_nothing_raised do
1200 assert_nothing_raised do
1201 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1201 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1202 end
1202 end
1203 end
1203 end
1204
1204
1205 def test_post_create_with_attachment
1205 def test_post_create_with_attachment
1206 set_tmp_attachments_directory
1206 set_tmp_attachments_directory
1207 @request.session[:user_id] = 2
1207 @request.session[:user_id] = 2
1208
1208
1209 assert_difference 'Issue.count' do
1209 assert_difference 'Issue.count' do
1210 assert_difference 'Attachment.count' do
1210 assert_difference 'Attachment.count' do
1211 post :create, :project_id => 1,
1211 post :create, :project_id => 1,
1212 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1212 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1213 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1213 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1214 end
1214 end
1215 end
1215 end
1216
1216
1217 issue = Issue.first(:order => 'id DESC')
1217 issue = Issue.first(:order => 'id DESC')
1218 attachment = Attachment.first(:order => 'id DESC')
1218 attachment = Attachment.first(:order => 'id DESC')
1219
1219
1220 assert_equal issue, attachment.container
1220 assert_equal issue, attachment.container
1221 assert_equal 2, attachment.author_id
1221 assert_equal 2, attachment.author_id
1222 assert_equal 'testfile.txt', attachment.filename
1222 assert_equal 'testfile.txt', attachment.filename
1223 assert_equal 'text/plain', attachment.content_type
1223 assert_equal 'text/plain', attachment.content_type
1224 assert_equal 'test file', attachment.description
1224 assert_equal 'test file', attachment.description
1225 assert_equal 59, attachment.filesize
1225 assert_equal 59, attachment.filesize
1226 assert File.exists?(attachment.diskfile)
1226 assert File.exists?(attachment.diskfile)
1227 assert_equal 59, File.size(attachment.diskfile)
1227 assert_equal 59, File.size(attachment.diskfile)
1228 end
1228 end
1229
1229
1230 context "without workflow privilege" do
1230 context "without workflow privilege" do
1231 setup do
1231 setup do
1232 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1232 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1233 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1233 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1234 end
1234 end
1235
1235
1236 context "#new" do
1236 context "#new" do
1237 should "propose default status only" do
1237 should "propose default status only" do
1238 get :new, :project_id => 1
1238 get :new, :project_id => 1
1239 assert_response :success
1239 assert_response :success
1240 assert_template 'new'
1240 assert_template 'new'
1241 assert_tag :tag => 'select',
1241 assert_tag :tag => 'select',
1242 :attributes => {:name => 'issue[status_id]'},
1242 :attributes => {:name => 'issue[status_id]'},
1243 :children => {:count => 1},
1243 :children => {:count => 1},
1244 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1244 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1245 end
1245 end
1246
1246
1247 should "accept default status" do
1247 should "accept default status" do
1248 assert_difference 'Issue.count' do
1248 assert_difference 'Issue.count' do
1249 post :create, :project_id => 1,
1249 post :create, :project_id => 1,
1250 :issue => {:tracker_id => 1,
1250 :issue => {:tracker_id => 1,
1251 :subject => 'This is an issue',
1251 :subject => 'This is an issue',
1252 :status_id => 1}
1252 :status_id => 1}
1253 end
1253 end
1254 issue = Issue.last(:order => 'id')
1254 issue = Issue.last(:order => 'id')
1255 assert_equal IssueStatus.default, issue.status
1255 assert_equal IssueStatus.default, issue.status
1256 end
1256 end
1257
1257
1258 should "ignore unauthorized status" do
1258 should "ignore unauthorized status" do
1259 assert_difference 'Issue.count' do
1259 assert_difference 'Issue.count' do
1260 post :create, :project_id => 1,
1260 post :create, :project_id => 1,
1261 :issue => {:tracker_id => 1,
1261 :issue => {:tracker_id => 1,
1262 :subject => 'This is an issue',
1262 :subject => 'This is an issue',
1263 :status_id => 3}
1263 :status_id => 3}
1264 end
1264 end
1265 issue = Issue.last(:order => 'id')
1265 issue = Issue.last(:order => 'id')
1266 assert_equal IssueStatus.default, issue.status
1266 assert_equal IssueStatus.default, issue.status
1267 end
1267 end
1268 end
1268 end
1269
1269
1270 context "#update" do
1270 context "#update" do
1271 should "ignore status change" do
1271 should "ignore status change" do
1272 assert_difference 'Journal.count' do
1272 assert_difference 'Journal.count' do
1273 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1273 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1274 end
1274 end
1275 assert_equal 1, Issue.find(1).status_id
1275 assert_equal 1, Issue.find(1).status_id
1276 end
1276 end
1277
1277
1278 should "ignore attributes changes" do
1278 should "ignore attributes changes" do
1279 assert_difference 'Journal.count' do
1279 assert_difference 'Journal.count' do
1280 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1280 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1281 end
1281 end
1282 issue = Issue.find(1)
1282 issue = Issue.find(1)
1283 assert_equal "Can't print recipes", issue.subject
1283 assert_equal "Can't print recipes", issue.subject
1284 assert_nil issue.assigned_to
1284 assert_nil issue.assigned_to
1285 end
1285 end
1286 end
1286 end
1287 end
1287 end
1288
1288
1289 context "with workflow privilege" do
1289 context "with workflow privilege" do
1290 setup do
1290 setup do
1291 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1291 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1292 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1292 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1293 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1293 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1294 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1294 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1295 end
1295 end
1296
1296
1297 context "#update" do
1297 context "#update" do
1298 should "accept authorized status" do
1298 should "accept authorized status" do
1299 assert_difference 'Journal.count' do
1299 assert_difference 'Journal.count' do
1300 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1300 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1301 end
1301 end
1302 assert_equal 3, Issue.find(1).status_id
1302 assert_equal 3, Issue.find(1).status_id
1303 end
1303 end
1304
1304
1305 should "ignore unauthorized status" do
1305 should "ignore unauthorized status" do
1306 assert_difference 'Journal.count' do
1306 assert_difference 'Journal.count' do
1307 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1307 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1308 end
1308 end
1309 assert_equal 1, Issue.find(1).status_id
1309 assert_equal 1, Issue.find(1).status_id
1310 end
1310 end
1311
1311
1312 should "accept authorized attributes changes" do
1312 should "accept authorized attributes changes" do
1313 assert_difference 'Journal.count' do
1313 assert_difference 'Journal.count' do
1314 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1314 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1315 end
1315 end
1316 issue = Issue.find(1)
1316 issue = Issue.find(1)
1317 assert_equal 2, issue.assigned_to_id
1317 assert_equal 2, issue.assigned_to_id
1318 end
1318 end
1319
1319
1320 should "ignore unauthorized attributes changes" do
1320 should "ignore unauthorized attributes changes" do
1321 assert_difference 'Journal.count' do
1321 assert_difference 'Journal.count' do
1322 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1322 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1323 end
1323 end
1324 issue = Issue.find(1)
1324 issue = Issue.find(1)
1325 assert_equal "Can't print recipes", issue.subject
1325 assert_equal "Can't print recipes", issue.subject
1326 end
1326 end
1327 end
1327 end
1328
1328
1329 context "and :edit_issues permission" do
1329 context "and :edit_issues permission" do
1330 setup do
1330 setup do
1331 Role.anonymous.add_permission! :add_issues, :edit_issues
1331 Role.anonymous.add_permission! :add_issues, :edit_issues
1332 end
1332 end
1333
1333
1334 should "accept authorized status" do
1334 should "accept authorized status" do
1335 assert_difference 'Journal.count' do
1335 assert_difference 'Journal.count' do
1336 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1336 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1337 end
1337 end
1338 assert_equal 3, Issue.find(1).status_id
1338 assert_equal 3, Issue.find(1).status_id
1339 end
1339 end
1340
1340
1341 should "ignore unauthorized status" do
1341 should "ignore unauthorized status" do
1342 assert_difference 'Journal.count' do
1342 assert_difference 'Journal.count' do
1343 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1343 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1344 end
1344 end
1345 assert_equal 1, Issue.find(1).status_id
1345 assert_equal 1, Issue.find(1).status_id
1346 end
1346 end
1347
1347
1348 should "accept authorized attributes changes" do
1348 should "accept authorized attributes changes" do
1349 assert_difference 'Journal.count' do
1349 assert_difference 'Journal.count' do
1350 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1350 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1351 end
1351 end
1352 issue = Issue.find(1)
1352 issue = Issue.find(1)
1353 assert_equal "changed", issue.subject
1353 assert_equal "changed", issue.subject
1354 assert_equal 2, issue.assigned_to_id
1354 assert_equal 2, issue.assigned_to_id
1355 end
1355 end
1356 end
1356 end
1357 end
1357 end
1358
1358
1359 def test_copy_issue
1359 def test_copy_issue
1360 @request.session[:user_id] = 2
1360 @request.session[:user_id] = 2
1361 get :new, :project_id => 1, :copy_from => 1
1361 get :new, :project_id => 1, :copy_from => 1
1362 assert_template 'new'
1362 assert_template 'new'
1363 assert_not_nil assigns(:issue)
1363 assert_not_nil assigns(:issue)
1364 orig = Issue.find(1)
1364 orig = Issue.find(1)
1365 assert_equal orig.subject, assigns(:issue).subject
1365 assert_equal orig.subject, assigns(:issue).subject
1366 end
1366 end
1367
1367
1368 def test_get_edit
1368 def test_get_edit
1369 @request.session[:user_id] = 2
1369 @request.session[:user_id] = 2
1370 get :edit, :id => 1
1370 get :edit, :id => 1
1371 assert_response :success
1371 assert_response :success
1372 assert_template 'edit'
1372 assert_template 'edit'
1373 assert_not_nil assigns(:issue)
1373 assert_not_nil assigns(:issue)
1374 assert_equal Issue.find(1), assigns(:issue)
1374 assert_equal Issue.find(1), assigns(:issue)
1375
1375
1376 # Be sure we don't display inactive IssuePriorities
1376 # Be sure we don't display inactive IssuePriorities
1377 assert ! IssuePriority.find(15).active?
1377 assert ! IssuePriority.find(15).active?
1378 assert_no_tag :option, :attributes => {:value => '15'},
1378 assert_no_tag :option, :attributes => {:value => '15'},
1379 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1379 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1380 end
1380 end
1381
1381
1382 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1382 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1383 @request.session[:user_id] = 2
1383 @request.session[:user_id] = 2
1384 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1384 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1385
1385
1386 get :edit, :id => 1
1386 get :edit, :id => 1
1387 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1387 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1388 end
1388 end
1389
1389
1390 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1390 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1391 @request.session[:user_id] = 2
1391 @request.session[:user_id] = 2
1392 Role.find_by_name('Manager').remove_permission! :log_time
1392 Role.find_by_name('Manager').remove_permission! :log_time
1393
1393
1394 get :edit, :id => 1
1394 get :edit, :id => 1
1395 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1395 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1396 end
1396 end
1397
1397
1398 def test_get_edit_with_params
1398 def test_get_edit_with_params
1399 @request.session[:user_id] = 2
1399 @request.session[:user_id] = 2
1400 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1400 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1401 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1401 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1402 assert_response :success
1402 assert_response :success
1403 assert_template 'edit'
1403 assert_template 'edit'
1404
1404
1405 issue = assigns(:issue)
1405 issue = assigns(:issue)
1406 assert_not_nil issue
1406 assert_not_nil issue
1407
1407
1408 assert_equal 5, issue.status_id
1408 assert_equal 5, issue.status_id
1409 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1409 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1410 :child => { :tag => 'option',
1410 :child => { :tag => 'option',
1411 :content => 'Closed',
1411 :content => 'Closed',
1412 :attributes => { :selected => 'selected' } }
1412 :attributes => { :selected => 'selected' } }
1413
1413
1414 assert_equal 7, issue.priority_id
1414 assert_equal 7, issue.priority_id
1415 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1415 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1416 :child => { :tag => 'option',
1416 :child => { :tag => 'option',
1417 :content => 'Urgent',
1417 :content => 'Urgent',
1418 :attributes => { :selected => 'selected' } }
1418 :attributes => { :selected => 'selected' } }
1419
1419
1420 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1420 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1421 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1421 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1422 :child => { :tag => 'option',
1422 :child => { :tag => 'option',
1423 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1423 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1424 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1424 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1425 end
1425 end
1426
1426
1427 def test_update_edit_form
1427 def test_update_edit_form
1428 @request.session[:user_id] = 2
1428 @request.session[:user_id] = 2
1429 xhr :post, :new, :project_id => 1,
1429 xhr :post, :new, :project_id => 1,
1430 :id => 1,
1430 :id => 1,
1431 :issue => {:tracker_id => 2,
1431 :issue => {:tracker_id => 2,
1432 :subject => 'This is the test_new issue',
1432 :subject => 'This is the test_new issue',
1433 :description => 'This is the description',
1433 :description => 'This is the description',
1434 :priority_id => 5}
1434 :priority_id => 5}
1435 assert_response :success
1435 assert_response :success
1436 assert_template 'attributes'
1436 assert_template 'attributes'
1437
1437
1438 issue = assigns(:issue)
1438 issue = assigns(:issue)
1439 assert_kind_of Issue, issue
1439 assert_kind_of Issue, issue
1440 assert_equal 1, issue.id
1440 assert_equal 1, issue.id
1441 assert_equal 1, issue.project_id
1441 assert_equal 1, issue.project_id
1442 assert_equal 2, issue.tracker_id
1442 assert_equal 2, issue.tracker_id
1443 assert_equal 'This is the test_new issue', issue.subject
1443 assert_equal 'This is the test_new issue', issue.subject
1444 end
1444 end
1445
1445
1446 def test_update_using_invalid_http_verbs
1446 def test_update_using_invalid_http_verbs
1447 @request.session[:user_id] = 2
1447 @request.session[:user_id] = 2
1448 subject = 'Updated by an invalid http verb'
1448 subject = 'Updated by an invalid http verb'
1449
1449
1450 get :update, :id => 1, :issue => {:subject => subject}
1450 get :update, :id => 1, :issue => {:subject => subject}
1451 assert_not_equal subject, Issue.find(1).subject
1451 assert_not_equal subject, Issue.find(1).subject
1452
1452
1453 post :update, :id => 1, :issue => {:subject => subject}
1453 post :update, :id => 1, :issue => {:subject => subject}
1454 assert_not_equal subject, Issue.find(1).subject
1454 assert_not_equal subject, Issue.find(1).subject
1455
1455
1456 delete :update, :id => 1, :issue => {:subject => subject}
1456 delete :update, :id => 1, :issue => {:subject => subject}
1457 assert_not_equal subject, Issue.find(1).subject
1457 assert_not_equal subject, Issue.find(1).subject
1458 end
1458 end
1459
1459
1460 def test_put_update_without_custom_fields_param
1460 def test_put_update_without_custom_fields_param
1461 @request.session[:user_id] = 2
1461 @request.session[:user_id] = 2
1462 ActionMailer::Base.deliveries.clear
1462 ActionMailer::Base.deliveries.clear
1463
1463
1464 issue = Issue.find(1)
1464 issue = Issue.find(1)
1465 assert_equal '125', issue.custom_value_for(2).value
1465 assert_equal '125', issue.custom_value_for(2).value
1466 old_subject = issue.subject
1466 old_subject = issue.subject
1467 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1467 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1468
1468
1469 assert_difference('Journal.count') do
1469 assert_difference('Journal.count') do
1470 assert_difference('JournalDetail.count', 2) do
1470 assert_difference('JournalDetail.count', 2) do
1471 put :update, :id => 1, :issue => {:subject => new_subject,
1471 put :update, :id => 1, :issue => {:subject => new_subject,
1472 :priority_id => '6',
1472 :priority_id => '6',
1473 :category_id => '1' # no change
1473 :category_id => '1' # no change
1474 }
1474 }
1475 end
1475 end
1476 end
1476 end
1477 assert_redirected_to :action => 'show', :id => '1'
1477 assert_redirected_to :action => 'show', :id => '1'
1478 issue.reload
1478 issue.reload
1479 assert_equal new_subject, issue.subject
1479 assert_equal new_subject, issue.subject
1480 # Make sure custom fields were not cleared
1480 # Make sure custom fields were not cleared
1481 assert_equal '125', issue.custom_value_for(2).value
1481 assert_equal '125', issue.custom_value_for(2).value
1482
1482
1483 mail = ActionMailer::Base.deliveries.last
1483 mail = ActionMailer::Base.deliveries.last
1484 assert_kind_of TMail::Mail, mail
1484 assert_kind_of TMail::Mail, mail
1485 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1485 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1486 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1486 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1487 end
1487 end
1488
1488
1489 def test_put_update_with_custom_field_change
1489 def test_put_update_with_custom_field_change
1490 @request.session[:user_id] = 2
1490 @request.session[:user_id] = 2
1491 issue = Issue.find(1)
1491 issue = Issue.find(1)
1492 assert_equal '125', issue.custom_value_for(2).value
1492 assert_equal '125', issue.custom_value_for(2).value
1493
1493
1494 assert_difference('Journal.count') do
1494 assert_difference('Journal.count') do
1495 assert_difference('JournalDetail.count', 3) do
1495 assert_difference('JournalDetail.count', 3) do
1496 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1496 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1497 :priority_id => '6',
1497 :priority_id => '6',
1498 :category_id => '1', # no change
1498 :category_id => '1', # no change
1499 :custom_field_values => { '2' => 'New custom value' }
1499 :custom_field_values => { '2' => 'New custom value' }
1500 }
1500 }
1501 end
1501 end
1502 end
1502 end
1503 assert_redirected_to :action => 'show', :id => '1'
1503 assert_redirected_to :action => 'show', :id => '1'
1504 issue.reload
1504 issue.reload
1505 assert_equal 'New custom value', issue.custom_value_for(2).value
1505 assert_equal 'New custom value', issue.custom_value_for(2).value
1506
1506
1507 mail = ActionMailer::Base.deliveries.last
1507 mail = ActionMailer::Base.deliveries.last
1508 assert_kind_of TMail::Mail, mail
1508 assert_kind_of TMail::Mail, mail
1509 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1509 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1510 end
1510 end
1511
1511
1512 def test_put_update_with_status_and_assignee_change
1512 def test_put_update_with_status_and_assignee_change
1513 issue = Issue.find(1)
1513 issue = Issue.find(1)
1514 assert_equal 1, issue.status_id
1514 assert_equal 1, issue.status_id
1515 @request.session[:user_id] = 2
1515 @request.session[:user_id] = 2
1516 assert_difference('TimeEntry.count', 0) do
1516 assert_difference('TimeEntry.count', 0) do
1517 put :update,
1517 put :update,
1518 :id => 1,
1518 :id => 1,
1519 :issue => { :status_id => 2, :assigned_to_id => 3 },
1519 :issue => { :status_id => 2, :assigned_to_id => 3 },
1520 :notes => 'Assigned to dlopper',
1520 :notes => 'Assigned to dlopper',
1521 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1521 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1522 end
1522 end
1523 assert_redirected_to :action => 'show', :id => '1'
1523 assert_redirected_to :action => 'show', :id => '1'
1524 issue.reload
1524 issue.reload
1525 assert_equal 2, issue.status_id
1525 assert_equal 2, issue.status_id
1526 j = Journal.find(:first, :order => 'id DESC')
1526 j = Journal.find(:first, :order => 'id DESC')
1527 assert_equal 'Assigned to dlopper', j.notes
1527 assert_equal 'Assigned to dlopper', j.notes
1528 assert_equal 2, j.details.size
1528 assert_equal 2, j.details.size
1529
1529
1530 mail = ActionMailer::Base.deliveries.last
1530 mail = ActionMailer::Base.deliveries.last
1531 assert mail.body.include?("Status changed from New to Assigned")
1531 assert mail.body.include?("Status changed from New to Assigned")
1532 # subject should contain the new status
1532 # subject should contain the new status
1533 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1533 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1534 end
1534 end
1535
1535
1536 def test_put_update_with_note_only
1536 def test_put_update_with_note_only
1537 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1537 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1538 # anonymous user
1538 # anonymous user
1539 put :update,
1539 put :update,
1540 :id => 1,
1540 :id => 1,
1541 :notes => notes
1541 :notes => notes
1542 assert_redirected_to :action => 'show', :id => '1'
1542 assert_redirected_to :action => 'show', :id => '1'
1543 j = Journal.find(:first, :order => 'id DESC')
1543 j = Journal.find(:first, :order => 'id DESC')
1544 assert_equal notes, j.notes
1544 assert_equal notes, j.notes
1545 assert_equal 0, j.details.size
1545 assert_equal 0, j.details.size
1546 assert_equal User.anonymous, j.user
1546 assert_equal User.anonymous, j.user
1547
1547
1548 mail = ActionMailer::Base.deliveries.last
1548 mail = ActionMailer::Base.deliveries.last
1549 assert mail.body.include?(notes)
1549 assert mail.body.include?(notes)
1550 end
1550 end
1551
1551
1552 def test_put_update_with_note_and_spent_time
1552 def test_put_update_with_note_and_spent_time
1553 @request.session[:user_id] = 2
1553 @request.session[:user_id] = 2
1554 spent_hours_before = Issue.find(1).spent_hours
1554 spent_hours_before = Issue.find(1).spent_hours
1555 assert_difference('TimeEntry.count') do
1555 assert_difference('TimeEntry.count') do
1556 put :update,
1556 put :update,
1557 :id => 1,
1557 :id => 1,
1558 :notes => '2.5 hours added',
1558 :notes => '2.5 hours added',
1559 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1559 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1560 end
1560 end
1561 assert_redirected_to :action => 'show', :id => '1'
1561 assert_redirected_to :action => 'show', :id => '1'
1562
1562
1563 issue = Issue.find(1)
1563 issue = Issue.find(1)
1564
1564
1565 j = Journal.find(:first, :order => 'id DESC')
1565 j = Journal.find(:first, :order => 'id DESC')
1566 assert_equal '2.5 hours added', j.notes
1566 assert_equal '2.5 hours added', j.notes
1567 assert_equal 0, j.details.size
1567 assert_equal 0, j.details.size
1568
1568
1569 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1569 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1570 assert_not_nil t
1570 assert_not_nil t
1571 assert_equal 2.5, t.hours
1571 assert_equal 2.5, t.hours
1572 assert_equal spent_hours_before + 2.5, issue.spent_hours
1572 assert_equal spent_hours_before + 2.5, issue.spent_hours
1573 end
1573 end
1574
1574
1575 def test_put_update_with_attachment_only
1575 def test_put_update_with_attachment_only
1576 set_tmp_attachments_directory
1576 set_tmp_attachments_directory
1577
1577
1578 # Delete all fixtured journals, a race condition can occur causing the wrong
1578 # Delete all fixtured journals, a race condition can occur causing the wrong
1579 # journal to get fetched in the next find.
1579 # journal to get fetched in the next find.
1580 Journal.delete_all
1580 Journal.delete_all
1581
1581
1582 # anonymous user
1582 # anonymous user
1583 assert_difference 'Attachment.count' do
1583 assert_difference 'Attachment.count' do
1584 put :update, :id => 1,
1584 put :update, :id => 1,
1585 :notes => '',
1585 :notes => '',
1586 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1586 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1587 end
1587 end
1588
1588
1589 assert_redirected_to :action => 'show', :id => '1'
1589 assert_redirected_to :action => 'show', :id => '1'
1590 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1590 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1591 assert j.notes.blank?
1591 assert j.notes.blank?
1592 assert_equal 1, j.details.size
1592 assert_equal 1, j.details.size
1593 assert_equal 'testfile.txt', j.details.first.value
1593 assert_equal 'testfile.txt', j.details.first.value
1594 assert_equal User.anonymous, j.user
1594 assert_equal User.anonymous, j.user
1595
1595
1596 attachment = Attachment.first(:order => 'id DESC')
1596 attachment = Attachment.first(:order => 'id DESC')
1597 assert_equal Issue.find(1), attachment.container
1597 assert_equal Issue.find(1), attachment.container
1598 assert_equal User.anonymous, attachment.author
1598 assert_equal User.anonymous, attachment.author
1599 assert_equal 'testfile.txt', attachment.filename
1599 assert_equal 'testfile.txt', attachment.filename
1600 assert_equal 'text/plain', attachment.content_type
1600 assert_equal 'text/plain', attachment.content_type
1601 assert_equal 'test file', attachment.description
1601 assert_equal 'test file', attachment.description
1602 assert_equal 59, attachment.filesize
1602 assert_equal 59, attachment.filesize
1603 assert File.exists?(attachment.diskfile)
1603 assert File.exists?(attachment.diskfile)
1604 assert_equal 59, File.size(attachment.diskfile)
1604 assert_equal 59, File.size(attachment.diskfile)
1605
1605
1606 mail = ActionMailer::Base.deliveries.last
1606 mail = ActionMailer::Base.deliveries.last
1607 assert mail.body.include?('testfile.txt')
1607 assert mail.body.include?('testfile.txt')
1608 end
1608 end
1609
1609
1610 def test_put_update_with_attachment_that_fails_to_save
1610 def test_put_update_with_attachment_that_fails_to_save
1611 set_tmp_attachments_directory
1611 set_tmp_attachments_directory
1612
1612
1613 # Delete all fixtured journals, a race condition can occur causing the wrong
1613 # Delete all fixtured journals, a race condition can occur causing the wrong
1614 # journal to get fetched in the next find.
1614 # journal to get fetched in the next find.
1615 Journal.delete_all
1615 Journal.delete_all
1616
1616
1617 # Mock out the unsaved attachment
1617 # Mock out the unsaved attachment
1618 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1618 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1619
1619
1620 # anonymous user
1620 # anonymous user
1621 put :update,
1621 put :update,
1622 :id => 1,
1622 :id => 1,
1623 :notes => '',
1623 :notes => '',
1624 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1624 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1625 assert_redirected_to :action => 'show', :id => '1'
1625 assert_redirected_to :action => 'show', :id => '1'
1626 assert_equal '1 file(s) could not be saved.', flash[:warning]
1626 assert_equal '1 file(s) could not be saved.', flash[:warning]
1627
1627
1628 end if Object.const_defined?(:Mocha)
1628 end if Object.const_defined?(:Mocha)
1629
1629
1630 def test_put_update_with_no_change
1630 def test_put_update_with_no_change
1631 issue = Issue.find(1)
1631 issue = Issue.find(1)
1632 issue.journals.clear
1632 issue.journals.clear
1633 ActionMailer::Base.deliveries.clear
1633 ActionMailer::Base.deliveries.clear
1634
1634
1635 put :update,
1635 put :update,
1636 :id => 1,
1636 :id => 1,
1637 :notes => ''
1637 :notes => ''
1638 assert_redirected_to :action => 'show', :id => '1'
1638 assert_redirected_to :action => 'show', :id => '1'
1639
1639
1640 issue.reload
1640 issue.reload
1641 assert issue.journals.empty?
1641 assert issue.journals.empty?
1642 # No email should be sent
1642 # No email should be sent
1643 assert ActionMailer::Base.deliveries.empty?
1643 assert ActionMailer::Base.deliveries.empty?
1644 end
1644 end
1645
1645
1646 def test_put_update_should_send_a_notification
1646 def test_put_update_should_send_a_notification
1647 @request.session[:user_id] = 2
1647 @request.session[:user_id] = 2
1648 ActionMailer::Base.deliveries.clear
1648 ActionMailer::Base.deliveries.clear
1649 issue = Issue.find(1)
1649 issue = Issue.find(1)
1650 old_subject = issue.subject
1650 old_subject = issue.subject
1651 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1651 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1652
1652
1653 put :update, :id => 1, :issue => {:subject => new_subject,
1653 put :update, :id => 1, :issue => {:subject => new_subject,
1654 :priority_id => '6',
1654 :priority_id => '6',
1655 :category_id => '1' # no change
1655 :category_id => '1' # no change
1656 }
1656 }
1657 assert_equal 1, ActionMailer::Base.deliveries.size
1657 assert_equal 1, ActionMailer::Base.deliveries.size
1658 end
1658 end
1659
1659
1660 def test_put_update_with_invalid_spent_time_hours_only
1660 def test_put_update_with_invalid_spent_time_hours_only
1661 @request.session[:user_id] = 2
1661 @request.session[:user_id] = 2
1662 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1662 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1663
1663
1664 assert_no_difference('Journal.count') do
1664 assert_no_difference('Journal.count') do
1665 put :update,
1665 put :update,
1666 :id => 1,
1666 :id => 1,
1667 :notes => notes,
1667 :notes => notes,
1668 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1668 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1669 end
1669 end
1670 assert_response :success
1670 assert_response :success
1671 assert_template 'edit'
1671 assert_template 'edit'
1672
1672
1673 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1673 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1674 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1674 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1675 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1675 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1676 end
1676 end
1677
1677
1678 def test_put_update_with_invalid_spent_time_comments_only
1678 def test_put_update_with_invalid_spent_time_comments_only
1679 @request.session[:user_id] = 2
1679 @request.session[:user_id] = 2
1680 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1680 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1681
1681
1682 assert_no_difference('Journal.count') do
1682 assert_no_difference('Journal.count') do
1683 put :update,
1683 put :update,
1684 :id => 1,
1684 :id => 1,
1685 :notes => notes,
1685 :notes => notes,
1686 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1686 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1687 end
1687 end
1688 assert_response :success
1688 assert_response :success
1689 assert_template 'edit'
1689 assert_template 'edit'
1690
1690
1691 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1691 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1692 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1692 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1693 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1693 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1694 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1694 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1695 end
1695 end
1696
1696
1697 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1697 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1698 issue = Issue.find(2)
1698 issue = Issue.find(2)
1699 @request.session[:user_id] = 2
1699 @request.session[:user_id] = 2
1700
1700
1701 put :update,
1701 put :update,
1702 :id => issue.id,
1702 :id => issue.id,
1703 :issue => {
1703 :issue => {
1704 :fixed_version_id => 4
1704 :fixed_version_id => 4
1705 }
1705 }
1706
1706
1707 assert_response :redirect
1707 assert_response :redirect
1708 issue.reload
1708 issue.reload
1709 assert_equal 4, issue.fixed_version_id
1709 assert_equal 4, issue.fixed_version_id
1710 assert_not_equal issue.project_id, issue.fixed_version.project_id
1710 assert_not_equal issue.project_id, issue.fixed_version.project_id
1711 end
1711 end
1712
1712
1713 def test_put_update_should_redirect_back_using_the_back_url_parameter
1713 def test_put_update_should_redirect_back_using_the_back_url_parameter
1714 issue = Issue.find(2)
1714 issue = Issue.find(2)
1715 @request.session[:user_id] = 2
1715 @request.session[:user_id] = 2
1716
1716
1717 put :update,
1717 put :update,
1718 :id => issue.id,
1718 :id => issue.id,
1719 :issue => {
1719 :issue => {
1720 :fixed_version_id => 4
1720 :fixed_version_id => 4
1721 },
1721 },
1722 :back_url => '/issues'
1722 :back_url => '/issues'
1723
1723
1724 assert_response :redirect
1724 assert_response :redirect
1725 assert_redirected_to '/issues'
1725 assert_redirected_to '/issues'
1726 end
1726 end
1727
1727
1728 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1728 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1729 issue = Issue.find(2)
1729 issue = Issue.find(2)
1730 @request.session[:user_id] = 2
1730 @request.session[:user_id] = 2
1731
1731
1732 put :update,
1732 put :update,
1733 :id => issue.id,
1733 :id => issue.id,
1734 :issue => {
1734 :issue => {
1735 :fixed_version_id => 4
1735 :fixed_version_id => 4
1736 },
1736 },
1737 :back_url => 'http://google.com'
1737 :back_url => 'http://google.com'
1738
1738
1739 assert_response :redirect
1739 assert_response :redirect
1740 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1740 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1741 end
1741 end
1742
1742
1743 def test_get_bulk_edit
1743 def test_get_bulk_edit
1744 @request.session[:user_id] = 2
1744 @request.session[:user_id] = 2
1745 get :bulk_edit, :ids => [1, 2]
1745 get :bulk_edit, :ids => [1, 2]
1746 assert_response :success
1746 assert_response :success
1747 assert_template 'bulk_edit'
1747 assert_template 'bulk_edit'
1748
1748
1749 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1749 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1750
1750
1751 # Project specific custom field, date type
1751 # Project specific custom field, date type
1752 field = CustomField.find(9)
1752 field = CustomField.find(9)
1753 assert !field.is_for_all?
1753 assert !field.is_for_all?
1754 assert_equal 'date', field.field_format
1754 assert_equal 'date', field.field_format
1755 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1755 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1756
1756
1757 # System wide custom field
1757 # System wide custom field
1758 assert CustomField.find(1).is_for_all?
1758 assert CustomField.find(1).is_for_all?
1759 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1759 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1760
1760
1761 # Be sure we don't display inactive IssuePriorities
1761 # Be sure we don't display inactive IssuePriorities
1762 assert ! IssuePriority.find(15).active?
1762 assert ! IssuePriority.find(15).active?
1763 assert_no_tag :option, :attributes => {:value => '15'},
1763 assert_no_tag :option, :attributes => {:value => '15'},
1764 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1764 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1765 end
1765 end
1766
1766
1767 def test_get_bulk_edit_on_different_projects
1767 def test_get_bulk_edit_on_different_projects
1768 @request.session[:user_id] = 2
1768 @request.session[:user_id] = 2
1769 get :bulk_edit, :ids => [1, 2, 6]
1769 get :bulk_edit, :ids => [1, 2, 6]
1770 assert_response :success
1770 assert_response :success
1771 assert_template 'bulk_edit'
1771 assert_template 'bulk_edit'
1772
1772
1773 # Can not set issues from different projects as children of an issue
1773 # Can not set issues from different projects as children of an issue
1774 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1774 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1775
1775
1776 # Project specific custom field, date type
1776 # Project specific custom field, date type
1777 field = CustomField.find(9)
1777 field = CustomField.find(9)
1778 assert !field.is_for_all?
1778 assert !field.is_for_all?
1779 assert !field.project_ids.include?(Issue.find(6).project_id)
1779 assert !field.project_ids.include?(Issue.find(6).project_id)
1780 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1780 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1781 end
1781 end
1782
1782
1783 def test_get_bulk_edit_with_user_custom_field
1783 def test_get_bulk_edit_with_user_custom_field
1784 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1784 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1785
1785
1786 @request.session[:user_id] = 2
1786 @request.session[:user_id] = 2
1787 get :bulk_edit, :ids => [1, 2]
1787 get :bulk_edit, :ids => [1, 2]
1788 assert_response :success
1788 assert_response :success
1789 assert_template 'bulk_edit'
1789 assert_template 'bulk_edit'
1790
1790
1791 assert_tag :select,
1791 assert_tag :select,
1792 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1792 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1793 :children => {
1793 :children => {
1794 :only => {:tag => 'option'},
1794 :only => {:tag => 'option'},
1795 :count => Project.find(1).users.count + 1
1795 :count => Project.find(1).users.count + 1
1796 }
1796 }
1797 end
1797 end
1798
1798
1799 def test_get_bulk_edit_with_version_custom_field
1799 def test_get_bulk_edit_with_version_custom_field
1800 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1800 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1801
1801
1802 @request.session[:user_id] = 2
1802 @request.session[:user_id] = 2
1803 get :bulk_edit, :ids => [1, 2]
1803 get :bulk_edit, :ids => [1, 2]
1804 assert_response :success
1804 assert_response :success
1805 assert_template 'bulk_edit'
1805 assert_template 'bulk_edit'
1806
1806
1807 assert_tag :select,
1807 assert_tag :select,
1808 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1808 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1809 :children => {
1809 :children => {
1810 :only => {:tag => 'option'},
1810 :only => {:tag => 'option'},
1811 :count => Project.find(1).shared_versions.count + 1
1811 :count => Project.find(1).shared_versions.count + 1
1812 }
1812 }
1813 end
1813 end
1814
1814
1815 def test_bulk_update
1815 def test_bulk_update
1816 @request.session[:user_id] = 2
1816 @request.session[:user_id] = 2
1817 # update issues priority
1817 # update issues priority
1818 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1818 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1819 :issue => {:priority_id => 7,
1819 :issue => {:priority_id => 7,
1820 :assigned_to_id => '',
1820 :assigned_to_id => '',
1821 :custom_field_values => {'2' => ''}}
1821 :custom_field_values => {'2' => ''}}
1822
1822
1823 assert_response 302
1823 assert_response 302
1824 # check that the issues were updated
1824 # check that the issues were updated
1825 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1825 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1826
1826
1827 issue = Issue.find(1)
1827 issue = Issue.find(1)
1828 journal = issue.journals.find(:first, :order => 'created_on DESC')
1828 journal = issue.journals.find(:first, :order => 'created_on DESC')
1829 assert_equal '125', issue.custom_value_for(2).value
1829 assert_equal '125', issue.custom_value_for(2).value
1830 assert_equal 'Bulk editing', journal.notes
1830 assert_equal 'Bulk editing', journal.notes
1831 assert_equal 1, journal.details.size
1831 assert_equal 1, journal.details.size
1832 end
1832 end
1833
1833
1834 def test_bulk_update_with_group_assignee
1834 def test_bulk_update_with_group_assignee
1835 group = Group.find(11)
1835 group = Group.find(11)
1836 project = Project.find(1)
1836 project = Project.find(1)
1837 project.members << Member.new(:principal => group, :roles => [Role.first])
1837 project.members << Member.new(:principal => group, :roles => [Role.first])
1838
1838
1839 @request.session[:user_id] = 2
1839 @request.session[:user_id] = 2
1840 # update issues assignee
1840 # update issues assignee
1841 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1841 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1842 :issue => {:priority_id => '',
1842 :issue => {:priority_id => '',
1843 :assigned_to_id => group.id,
1843 :assigned_to_id => group.id,
1844 :custom_field_values => {'2' => ''}}
1844 :custom_field_values => {'2' => ''}}
1845
1845
1846 assert_response 302
1846 assert_response 302
1847 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1847 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1848 end
1848 end
1849
1849
1850 def test_bulk_update_on_different_projects
1850 def test_bulk_update_on_different_projects
1851 @request.session[:user_id] = 2
1851 @request.session[:user_id] = 2
1852 # update issues priority
1852 # update issues priority
1853 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1853 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1854 :issue => {:priority_id => 7,
1854 :issue => {:priority_id => 7,
1855 :assigned_to_id => '',
1855 :assigned_to_id => '',
1856 :custom_field_values => {'2' => ''}}
1856 :custom_field_values => {'2' => ''}}
1857
1857
1858 assert_response 302
1858 assert_response 302
1859 # check that the issues were updated
1859 # check that the issues were updated
1860 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1860 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1861
1861
1862 issue = Issue.find(1)
1862 issue = Issue.find(1)
1863 journal = issue.journals.find(:first, :order => 'created_on DESC')
1863 journal = issue.journals.find(:first, :order => 'created_on DESC')
1864 assert_equal '125', issue.custom_value_for(2).value
1864 assert_equal '125', issue.custom_value_for(2).value
1865 assert_equal 'Bulk editing', journal.notes
1865 assert_equal 'Bulk editing', journal.notes
1866 assert_equal 1, journal.details.size
1866 assert_equal 1, journal.details.size
1867 end
1867 end
1868
1868
1869 def test_bulk_update_on_different_projects_without_rights
1869 def test_bulk_update_on_different_projects_without_rights
1870 @request.session[:user_id] = 3
1870 @request.session[:user_id] = 3
1871 user = User.find(3)
1871 user = User.find(3)
1872 action = { :controller => "issues", :action => "bulk_update" }
1872 action = { :controller => "issues", :action => "bulk_update" }
1873 assert user.allowed_to?(action, Issue.find(1).project)
1873 assert user.allowed_to?(action, Issue.find(1).project)
1874 assert ! user.allowed_to?(action, Issue.find(6).project)
1874 assert ! user.allowed_to?(action, Issue.find(6).project)
1875 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1875 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1876 :issue => {:priority_id => 7,
1876 :issue => {:priority_id => 7,
1877 :assigned_to_id => '',
1877 :assigned_to_id => '',
1878 :custom_field_values => {'2' => ''}}
1878 :custom_field_values => {'2' => ''}}
1879 assert_response 403
1879 assert_response 403
1880 assert_not_equal "Bulk should fail", Journal.last.notes
1880 assert_not_equal "Bulk should fail", Journal.last.notes
1881 end
1881 end
1882
1882
1883 def test_bullk_update_should_send_a_notification
1883 def test_bullk_update_should_send_a_notification
1884 @request.session[:user_id] = 2
1884 @request.session[:user_id] = 2
1885 ActionMailer::Base.deliveries.clear
1885 ActionMailer::Base.deliveries.clear
1886 post(:bulk_update,
1886 post(:bulk_update,
1887 {
1887 {
1888 :ids => [1, 2],
1888 :ids => [1, 2],
1889 :notes => 'Bulk editing',
1889 :notes => 'Bulk editing',
1890 :issue => {
1890 :issue => {
1891 :priority_id => 7,
1891 :priority_id => 7,
1892 :assigned_to_id => '',
1892 :assigned_to_id => '',
1893 :custom_field_values => {'2' => ''}
1893 :custom_field_values => {'2' => ''}
1894 }
1894 }
1895 })
1895 })
1896
1896
1897 assert_response 302
1897 assert_response 302
1898 assert_equal 2, ActionMailer::Base.deliveries.size
1898 assert_equal 2, ActionMailer::Base.deliveries.size
1899 end
1899 end
1900
1900
1901 def test_bulk_update_status
1901 def test_bulk_update_status
1902 @request.session[:user_id] = 2
1902 @request.session[:user_id] = 2
1903 # update issues priority
1903 # update issues priority
1904 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1904 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1905 :issue => {:priority_id => '',
1905 :issue => {:priority_id => '',
1906 :assigned_to_id => '',
1906 :assigned_to_id => '',
1907 :status_id => '5'}
1907 :status_id => '5'}
1908
1908
1909 assert_response 302
1909 assert_response 302
1910 issue = Issue.find(1)
1910 issue = Issue.find(1)
1911 assert issue.closed?
1911 assert issue.closed?
1912 end
1912 end
1913
1913
1914 def test_bulk_update_parent_id
1914 def test_bulk_update_parent_id
1915 @request.session[:user_id] = 2
1915 @request.session[:user_id] = 2
1916 post :bulk_update, :ids => [1, 3],
1916 post :bulk_update, :ids => [1, 3],
1917 :notes => 'Bulk editing parent',
1917 :notes => 'Bulk editing parent',
1918 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1918 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1919
1919
1920 assert_response 302
1920 assert_response 302
1921 parent = Issue.find(2)
1921 parent = Issue.find(2)
1922 assert_equal parent.id, Issue.find(1).parent_id
1922 assert_equal parent.id, Issue.find(1).parent_id
1923 assert_equal parent.id, Issue.find(3).parent_id
1923 assert_equal parent.id, Issue.find(3).parent_id
1924 assert_equal [1, 3], parent.children.collect(&:id).sort
1924 assert_equal [1, 3], parent.children.collect(&:id).sort
1925 end
1925 end
1926
1926
1927 def test_bulk_update_custom_field
1927 def test_bulk_update_custom_field
1928 @request.session[:user_id] = 2
1928 @request.session[:user_id] = 2
1929 # update issues priority
1929 # update issues priority
1930 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1930 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1931 :issue => {:priority_id => '',
1931 :issue => {:priority_id => '',
1932 :assigned_to_id => '',
1932 :assigned_to_id => '',
1933 :custom_field_values => {'2' => '777'}}
1933 :custom_field_values => {'2' => '777'}}
1934
1934
1935 assert_response 302
1935 assert_response 302
1936
1936
1937 issue = Issue.find(1)
1937 issue = Issue.find(1)
1938 journal = issue.journals.find(:first, :order => 'created_on DESC')
1938 journal = issue.journals.find(:first, :order => 'created_on DESC')
1939 assert_equal '777', issue.custom_value_for(2).value
1939 assert_equal '777', issue.custom_value_for(2).value
1940 assert_equal 1, journal.details.size
1940 assert_equal 1, journal.details.size
1941 assert_equal '125', journal.details.first.old_value
1941 assert_equal '125', journal.details.first.old_value
1942 assert_equal '777', journal.details.first.value
1942 assert_equal '777', journal.details.first.value
1943 end
1943 end
1944
1944
1945 def test_bulk_update_unassign
1945 def test_bulk_update_unassign
1946 assert_not_nil Issue.find(2).assigned_to
1946 assert_not_nil Issue.find(2).assigned_to
1947 @request.session[:user_id] = 2
1947 @request.session[:user_id] = 2
1948 # unassign issues
1948 # unassign issues
1949 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1949 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1950 assert_response 302
1950 assert_response 302
1951 # check that the issues were updated
1951 # check that the issues were updated
1952 assert_nil Issue.find(2).assigned_to
1952 assert_nil Issue.find(2).assigned_to
1953 end
1953 end
1954
1954
1955 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1955 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1956 @request.session[:user_id] = 2
1956 @request.session[:user_id] = 2
1957
1957
1958 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1958 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1959
1959
1960 assert_response :redirect
1960 assert_response :redirect
1961 issues = Issue.find([1,2])
1961 issues = Issue.find([1,2])
1962 issues.each do |issue|
1962 issues.each do |issue|
1963 assert_equal 4, issue.fixed_version_id
1963 assert_equal 4, issue.fixed_version_id
1964 assert_not_equal issue.project_id, issue.fixed_version.project_id
1964 assert_not_equal issue.project_id, issue.fixed_version.project_id
1965 end
1965 end
1966 end
1966 end
1967
1967
1968 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1968 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1969 @request.session[:user_id] = 2
1969 @request.session[:user_id] = 2
1970 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1970 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1971
1971
1972 assert_response :redirect
1972 assert_response :redirect
1973 assert_redirected_to '/issues'
1973 assert_redirected_to '/issues'
1974 end
1974 end
1975
1975
1976 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1976 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1977 @request.session[:user_id] = 2
1977 @request.session[:user_id] = 2
1978 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1978 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1979
1979
1980 assert_response :redirect
1980 assert_response :redirect
1981 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1981 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1982 end
1982 end
1983
1983
1984 def test_destroy_issue_with_no_time_entries
1984 def test_destroy_issue_with_no_time_entries
1985 assert_nil TimeEntry.find_by_issue_id(2)
1985 assert_nil TimeEntry.find_by_issue_id(2)
1986 @request.session[:user_id] = 2
1986 @request.session[:user_id] = 2
1987 post :destroy, :id => 2
1987 post :destroy, :id => 2
1988 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1988 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1989 assert_nil Issue.find_by_id(2)
1989 assert_nil Issue.find_by_id(2)
1990 end
1990 end
1991
1991
1992 def test_destroy_issues_with_time_entries
1992 def test_destroy_issues_with_time_entries
1993 @request.session[:user_id] = 2
1993 @request.session[:user_id] = 2
1994 post :destroy, :ids => [1, 3]
1994 post :destroy, :ids => [1, 3]
1995 assert_response :success
1995 assert_response :success
1996 assert_template 'destroy'
1996 assert_template 'destroy'
1997 assert_not_nil assigns(:hours)
1997 assert_not_nil assigns(:hours)
1998 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1998 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1999 end
1999 end
2000
2000
2001 def test_destroy_issues_and_destroy_time_entries
2001 def test_destroy_issues_and_destroy_time_entries
2002 @request.session[:user_id] = 2
2002 @request.session[:user_id] = 2
2003 post :destroy, :ids => [1, 3], :todo => 'destroy'
2003 post :destroy, :ids => [1, 3], :todo => 'destroy'
2004 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2004 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2005 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2005 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2006 assert_nil TimeEntry.find_by_id([1, 2])
2006 assert_nil TimeEntry.find_by_id([1, 2])
2007 end
2007 end
2008
2008
2009 def test_destroy_issues_and_assign_time_entries_to_project
2009 def test_destroy_issues_and_assign_time_entries_to_project
2010 @request.session[:user_id] = 2
2010 @request.session[:user_id] = 2
2011 post :destroy, :ids => [1, 3], :todo => 'nullify'
2011 post :destroy, :ids => [1, 3], :todo => 'nullify'
2012 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2012 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2013 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2013 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2014 assert_nil TimeEntry.find(1).issue_id
2014 assert_nil TimeEntry.find(1).issue_id
2015 assert_nil TimeEntry.find(2).issue_id
2015 assert_nil TimeEntry.find(2).issue_id
2016 end
2016 end
2017
2017
2018 def test_destroy_issues_and_reassign_time_entries_to_another_issue
2018 def test_destroy_issues_and_reassign_time_entries_to_another_issue
2019 @request.session[:user_id] = 2
2019 @request.session[:user_id] = 2
2020 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
2020 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
2021 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2021 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2022 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2022 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2023 assert_equal 2, TimeEntry.find(1).issue_id
2023 assert_equal 2, TimeEntry.find(1).issue_id
2024 assert_equal 2, TimeEntry.find(2).issue_id
2024 assert_equal 2, TimeEntry.find(2).issue_id
2025 end
2025 end
2026
2026
2027 def test_destroy_issues_from_different_projects
2027 def test_destroy_issues_from_different_projects
2028 @request.session[:user_id] = 2
2028 @request.session[:user_id] = 2
2029 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
2029 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
2030 assert_redirected_to :controller => 'issues', :action => 'index'
2030 assert_redirected_to :controller => 'issues', :action => 'index'
2031 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
2031 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
2032 end
2032 end
2033
2033
2034 def test_destroy_parent_and_child_issues
2034 def test_destroy_parent_and_child_issues
2035 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
2035 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
2036 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
2036 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
2037 assert child.is_descendant_of?(parent.reload)
2037 assert child.is_descendant_of?(parent.reload)
2038
2038
2039 @request.session[:user_id] = 2
2039 @request.session[:user_id] = 2
2040 assert_difference 'Issue.count', -2 do
2040 assert_difference 'Issue.count', -2 do
2041 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
2041 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
2042 end
2042 end
2043 assert_response 302
2043 assert_response 302
2044 end
2044 end
2045
2045
2046 def test_default_search_scope
2046 def test_default_search_scope
2047 get :index
2047 get :index
2048 assert_tag :div, :attributes => {:id => 'quick-search'},
2048 assert_tag :div, :attributes => {:id => 'quick-search'},
2049 :child => {:tag => 'form',
2049 :child => {:tag => 'form',
2050 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
2050 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
2051 end
2051 end
2052 end
2052 end
General Comments 0
You need to be logged in to leave comments. Login now