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