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