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