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