##// END OF EJS Templates
Use valid filters in #test_index_with_sort_filters....
Jean-Philippe Lang -
r8930:53f9979696f0
parent child
Show More
@@ -1,3109 +1,3107
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 :repositories,
45 :repositories,
46 :changesets
46 :changesets
47
47
48 include Redmine::I18n
48 include Redmine::I18n
49
49
50 def setup
50 def setup
51 @controller = IssuesController.new
51 @controller = IssuesController.new
52 @request = ActionController::TestRequest.new
52 @request = ActionController::TestRequest.new
53 @response = ActionController::TestResponse.new
53 @response = ActionController::TestResponse.new
54 User.current = nil
54 User.current = nil
55 end
55 end
56
56
57 def test_index
57 def test_index
58 with_settings :default_language => "en" do
58 with_settings :default_language => "en" do
59 get :index
59 get :index
60 assert_response :success
60 assert_response :success
61 assert_template 'index'
61 assert_template 'index'
62 assert_not_nil assigns(:issues)
62 assert_not_nil assigns(:issues)
63 assert_nil assigns(:project)
63 assert_nil assigns(:project)
64 assert_tag :tag => 'a', :content => /Can't print recipes/
64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 assert_tag :tag => 'a', :content => /Subproject issue/
65 assert_tag :tag => 'a', :content => /Subproject issue/
66 # private projects hidden
66 # private projects hidden
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 # project column
69 # project column
70 assert_tag :tag => 'th', :content => /Project/
70 assert_tag :tag => 'th', :content => /Project/
71 end
71 end
72 end
72 end
73
73
74 def test_index_should_not_list_issues_when_module_disabled
74 def test_index_should_not_list_issues_when_module_disabled
75 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
76 get :index
76 get :index
77 assert_response :success
77 assert_response :success
78 assert_template 'index'
78 assert_template 'index'
79 assert_not_nil assigns(:issues)
79 assert_not_nil assigns(:issues)
80 assert_nil assigns(:project)
80 assert_nil assigns(:project)
81 assert_no_tag :tag => 'a', :content => /Can't print recipes/
81 assert_no_tag :tag => 'a', :content => /Can't print recipes/
82 assert_tag :tag => 'a', :content => /Subproject issue/
82 assert_tag :tag => 'a', :content => /Subproject issue/
83 end
83 end
84
84
85 def test_index_should_list_visible_issues_only
85 def test_index_should_list_visible_issues_only
86 get :index, :per_page => 100
86 get :index, :per_page => 100
87 assert_response :success
87 assert_response :success
88 assert_not_nil assigns(:issues)
88 assert_not_nil assigns(:issues)
89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
90 end
90 end
91
91
92 def test_index_with_project
92 def test_index_with_project
93 Setting.display_subprojects_issues = 0
93 Setting.display_subprojects_issues = 0
94 get :index, :project_id => 1
94 get :index, :project_id => 1
95 assert_response :success
95 assert_response :success
96 assert_template 'index'
96 assert_template 'index'
97 assert_not_nil assigns(:issues)
97 assert_not_nil assigns(:issues)
98 assert_tag :tag => 'a', :content => /Can't print recipes/
98 assert_tag :tag => 'a', :content => /Can't print recipes/
99 assert_no_tag :tag => 'a', :content => /Subproject issue/
99 assert_no_tag :tag => 'a', :content => /Subproject issue/
100 end
100 end
101
101
102 def test_index_with_project_and_subprojects
102 def test_index_with_project_and_subprojects
103 Setting.display_subprojects_issues = 1
103 Setting.display_subprojects_issues = 1
104 get :index, :project_id => 1
104 get :index, :project_id => 1
105 assert_response :success
105 assert_response :success
106 assert_template 'index'
106 assert_template 'index'
107 assert_not_nil assigns(:issues)
107 assert_not_nil assigns(:issues)
108 assert_tag :tag => 'a', :content => /Can't print recipes/
108 assert_tag :tag => 'a', :content => /Can't print recipes/
109 assert_tag :tag => 'a', :content => /Subproject issue/
109 assert_tag :tag => 'a', :content => /Subproject issue/
110 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
110 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
111 end
111 end
112
112
113 def test_index_with_project_and_subprojects_should_show_private_subprojects
113 def test_index_with_project_and_subprojects_should_show_private_subprojects
114 @request.session[:user_id] = 2
114 @request.session[:user_id] = 2
115 Setting.display_subprojects_issues = 1
115 Setting.display_subprojects_issues = 1
116 get :index, :project_id => 1
116 get :index, :project_id => 1
117 assert_response :success
117 assert_response :success
118 assert_template 'index'
118 assert_template 'index'
119 assert_not_nil assigns(:issues)
119 assert_not_nil assigns(:issues)
120 assert_tag :tag => 'a', :content => /Can't print recipes/
120 assert_tag :tag => 'a', :content => /Can't print recipes/
121 assert_tag :tag => 'a', :content => /Subproject issue/
121 assert_tag :tag => 'a', :content => /Subproject issue/
122 assert_tag :tag => 'a', :content => /Issue of a private subproject/
122 assert_tag :tag => 'a', :content => /Issue of a private subproject/
123 end
123 end
124
124
125 def test_index_with_project_and_default_filter
125 def test_index_with_project_and_default_filter
126 get :index, :project_id => 1, :set_filter => 1
126 get :index, :project_id => 1, :set_filter => 1
127 assert_response :success
127 assert_response :success
128 assert_template 'index'
128 assert_template 'index'
129 assert_not_nil assigns(:issues)
129 assert_not_nil assigns(:issues)
130
130
131 query = assigns(:query)
131 query = assigns(:query)
132 assert_not_nil query
132 assert_not_nil query
133 # default filter
133 # default filter
134 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
134 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
135 end
135 end
136
136
137 def test_index_with_project_and_filter
137 def test_index_with_project_and_filter
138 get :index, :project_id => 1, :set_filter => 1,
138 get :index, :project_id => 1, :set_filter => 1,
139 :f => ['tracker_id'],
139 :f => ['tracker_id'],
140 :op => {'tracker_id' => '='},
140 :op => {'tracker_id' => '='},
141 :v => {'tracker_id' => ['1']}
141 :v => {'tracker_id' => ['1']}
142 assert_response :success
142 assert_response :success
143 assert_template 'index'
143 assert_template 'index'
144 assert_not_nil assigns(:issues)
144 assert_not_nil assigns(:issues)
145
145
146 query = assigns(:query)
146 query = assigns(:query)
147 assert_not_nil query
147 assert_not_nil query
148 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
148 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
149 end
149 end
150
150
151 def test_index_with_short_filters
151 def test_index_with_short_filters
152
153 to_test = {
152 to_test = {
154 'status_id' => {
153 'status_id' => {
155 'o' => { :op => 'o', :values => [''] },
154 'o' => { :op => 'o', :values => [''] },
156 'c' => { :op => 'c', :values => [''] },
155 'c' => { :op => 'c', :values => [''] },
157 '7' => { :op => '=', :values => ['7'] },
156 '7' => { :op => '=', :values => ['7'] },
158 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
157 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
159 '=7' => { :op => '=', :values => ['7'] },
158 '=7' => { :op => '=', :values => ['7'] },
160 '!3' => { :op => '!', :values => ['3'] },
159 '!3' => { :op => '!', :values => ['3'] },
161 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
160 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
162 'subject' => {
161 'subject' => {
163 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
162 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
164 'o' => { :op => '=', :values => ['o'] },
163 'o' => { :op => '=', :values => ['o'] },
165 '~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'] },
166 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
165 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
167 'tracker_id' => {
166 'tracker_id' => {
168 '3' => { :op => '=', :values => ['3'] },
167 '3' => { :op => '=', :values => ['3'] },
169 '=3' => { :op => '=', :values => ['3'] }},
168 '=3' => { :op => '=', :values => ['3'] }},
170 'start_date' => {
169 'start_date' => {
171 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
170 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
172 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
171 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
173 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
172 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
174 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
173 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
175 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
174 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
176 '<t+2' => { :op => '<t+', :values => ['2'] },
175 '<t+2' => { :op => '<t+', :values => ['2'] },
177 '>t+2' => { :op => '>t+', :values => ['2'] },
176 '>t+2' => { :op => '>t+', :values => ['2'] },
178 't+2' => { :op => 't+', :values => ['2'] },
177 't+2' => { :op => 't+', :values => ['2'] },
179 't' => { :op => 't', :values => [''] },
178 't' => { :op => 't', :values => [''] },
180 'w' => { :op => 'w', :values => [''] },
179 'w' => { :op => 'w', :values => [''] },
181 '>t-2' => { :op => '>t-', :values => ['2'] },
180 '>t-2' => { :op => '>t-', :values => ['2'] },
182 '<t-2' => { :op => '<t-', :values => ['2'] },
181 '<t-2' => { :op => '<t-', :values => ['2'] },
183 't-2' => { :op => 't-', :values => ['2'] }},
182 't-2' => { :op => 't-', :values => ['2'] }},
184 'created_on' => {
183 'created_on' => {
185 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
184 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
186 '<t+2' => { :op => '=', :values => ['<t+2'] },
185 '<t-2' => { :op => '<t-', :values => ['2'] },
187 '>t+2' => { :op => '=', :values => ['>t+2'] },
186 '>t-2' => { :op => '>t-', :values => ['2'] },
188 't+2' => { :op => 't', :values => ['+2'] }},
187 't-2' => { :op => 't-', :values => ['2'] }},
189 'cf_1' => {
188 'cf_1' => {
190 'c' => { :op => '=', :values => ['c'] },
189 'c' => { :op => '=', :values => ['c'] },
191 '!c' => { :op => '!', :values => ['c'] },
190 '!c' => { :op => '!', :values => ['c'] },
192 '!*' => { :op => '!*', :values => [''] },
191 '!*' => { :op => '!*', :values => [''] },
193 '*' => { :op => '*', :values => [''] }},
192 '*' => { :op => '*', :values => [''] }},
194 'estimated_hours' => {
193 'estimated_hours' => {
195 '=13.4' => { :op => '=', :values => ['13.4'] },
194 '=13.4' => { :op => '=', :values => ['13.4'] },
196 '>=45' => { :op => '>=', :values => ['45'] },
195 '>=45' => { :op => '>=', :values => ['45'] },
197 '<=125' => { :op => '<=', :values => ['125'] },
196 '<=125' => { :op => '<=', :values => ['125'] },
198 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
197 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
199 '!*' => { :op => '!*', :values => [''] },
198 '!*' => { :op => '!*', :values => [''] },
200 '*' => { :op => '*', :values => [''] }}
199 '*' => { :op => '*', :values => [''] }}
201 }
200 }
202
201
203 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
202 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
204
203
205 to_test.each do |field, expression_and_expected|
204 to_test.each do |field, expression_and_expected|
206 expression_and_expected.each do |filter_expression, expected|
205 expression_and_expected.each do |filter_expression, expected|
207
206
208 get :index, :set_filter => 1, field => filter_expression
207 get :index, :set_filter => 1, field => filter_expression
209
208
210 assert_response :success
209 assert_response :success
211 assert_template 'index'
210 assert_template 'index'
212 assert_not_nil assigns(:issues)
211 assert_not_nil assigns(:issues)
213
212
214 query = assigns(:query)
213 query = assigns(:query)
215 assert_not_nil query
214 assert_not_nil query
216 assert query.has_filter?(field)
215 assert query.has_filter?(field)
217 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
216 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
218 end
217 end
219 end
218 end
220
221 end
219 end
222
220
223 def test_index_with_project_and_empty_filters
221 def test_index_with_project_and_empty_filters
224 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
225 assert_response :success
223 assert_response :success
226 assert_template 'index'
224 assert_template 'index'
227 assert_not_nil assigns(:issues)
225 assert_not_nil assigns(:issues)
228
226
229 query = assigns(:query)
227 query = assigns(:query)
230 assert_not_nil query
228 assert_not_nil query
231 # no filter
229 # no filter
232 assert_equal({}, query.filters)
230 assert_equal({}, query.filters)
233 end
231 end
234
232
235 def test_index_with_query
233 def test_index_with_query
236 get :index, :project_id => 1, :query_id => 5
234 get :index, :project_id => 1, :query_id => 5
237 assert_response :success
235 assert_response :success
238 assert_template 'index'
236 assert_template 'index'
239 assert_not_nil assigns(:issues)
237 assert_not_nil assigns(:issues)
240 assert_nil assigns(:issue_count_by_group)
238 assert_nil assigns(:issue_count_by_group)
241 end
239 end
242
240
243 def test_index_with_query_grouped_by_tracker
241 def test_index_with_query_grouped_by_tracker
244 get :index, :project_id => 1, :query_id => 6
242 get :index, :project_id => 1, :query_id => 6
245 assert_response :success
243 assert_response :success
246 assert_template 'index'
244 assert_template 'index'
247 assert_not_nil assigns(:issues)
245 assert_not_nil assigns(:issues)
248 assert_not_nil assigns(:issue_count_by_group)
246 assert_not_nil assigns(:issue_count_by_group)
249 end
247 end
250
248
251 def test_index_with_query_grouped_by_list_custom_field
249 def test_index_with_query_grouped_by_list_custom_field
252 get :index, :project_id => 1, :query_id => 9
250 get :index, :project_id => 1, :query_id => 9
253 assert_response :success
251 assert_response :success
254 assert_template 'index'
252 assert_template 'index'
255 assert_not_nil assigns(:issues)
253 assert_not_nil assigns(:issues)
256 assert_not_nil assigns(:issue_count_by_group)
254 assert_not_nil assigns(:issue_count_by_group)
257 end
255 end
258
256
259 def test_index_with_query_id_and_project_id_should_set_session_query
257 def test_index_with_query_id_and_project_id_should_set_session_query
260 get :index, :project_id => 1, :query_id => 4
258 get :index, :project_id => 1, :query_id => 4
261 assert_response :success
259 assert_response :success
262 assert_kind_of Hash, session[:query]
260 assert_kind_of Hash, session[:query]
263 assert_equal 4, session[:query][:id]
261 assert_equal 4, session[:query][:id]
264 assert_equal 1, session[:query][:project_id]
262 assert_equal 1, session[:query][:project_id]
265 end
263 end
266
264
267 def test_index_with_cross_project_query_in_session_should_show_project_issues
265 def test_index_with_cross_project_query_in_session_should_show_project_issues
268 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
266 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
269 @request.session[:query] = {:id => q.id, :project_id => 1}
267 @request.session[:query] = {:id => q.id, :project_id => 1}
270
268
271 with_settings :display_subprojects_issues => '0' do
269 with_settings :display_subprojects_issues => '0' do
272 get :index, :project_id => 1
270 get :index, :project_id => 1
273 end
271 end
274 assert_response :success
272 assert_response :success
275 assert_not_nil assigns(:query)
273 assert_not_nil assigns(:query)
276 assert_equal q.id, assigns(:query).id
274 assert_equal q.id, assigns(:query).id
277 assert_equal 1, assigns(:query).project_id
275 assert_equal 1, assigns(:query).project_id
278 assert_equal [1], assigns(:issues).map(&:project_id).uniq
276 assert_equal [1], assigns(:issues).map(&:project_id).uniq
279 end
277 end
280
278
281 def test_private_query_should_not_be_available_to_other_users
279 def test_private_query_should_not_be_available_to_other_users
282 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
280 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
283 @request.session[:user_id] = 3
281 @request.session[:user_id] = 3
284
282
285 get :index, :query_id => q.id
283 get :index, :query_id => q.id
286 assert_response 403
284 assert_response 403
287 end
285 end
288
286
289 def test_private_query_should_be_available_to_its_user
287 def test_private_query_should_be_available_to_its_user
290 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
288 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
291 @request.session[:user_id] = 2
289 @request.session[:user_id] = 2
292
290
293 get :index, :query_id => q.id
291 get :index, :query_id => q.id
294 assert_response :success
292 assert_response :success
295 end
293 end
296
294
297 def test_public_query_should_be_available_to_other_users
295 def test_public_query_should_be_available_to_other_users
298 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
296 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
299 @request.session[:user_id] = 3
297 @request.session[:user_id] = 3
300
298
301 get :index, :query_id => q.id
299 get :index, :query_id => q.id
302 assert_response :success
300 assert_response :success
303 end
301 end
304
302
305 def test_index_csv
303 def test_index_csv
306 get :index, :format => 'csv'
304 get :index, :format => 'csv'
307 assert_response :success
305 assert_response :success
308 assert_not_nil assigns(:issues)
306 assert_not_nil assigns(:issues)
309 assert_equal 'text/csv', @response.content_type
307 assert_equal 'text/csv', @response.content_type
310 assert @response.body.starts_with?("#,")
308 assert @response.body.starts_with?("#,")
311 lines = @response.body.chomp.split("\n")
309 lines = @response.body.chomp.split("\n")
312 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
310 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
313 end
311 end
314
312
315 def test_index_csv_with_project
313 def test_index_csv_with_project
316 get :index, :project_id => 1, :format => 'csv'
314 get :index, :project_id => 1, :format => 'csv'
317 assert_response :success
315 assert_response :success
318 assert_not_nil assigns(:issues)
316 assert_not_nil assigns(:issues)
319 assert_equal 'text/csv', @response.content_type
317 assert_equal 'text/csv', @response.content_type
320 end
318 end
321
319
322 def test_index_csv_with_description
320 def test_index_csv_with_description
323 get :index, :format => 'csv', :description => '1'
321 get :index, :format => 'csv', :description => '1'
324 assert_response :success
322 assert_response :success
325 assert_not_nil assigns(:issues)
323 assert_not_nil assigns(:issues)
326 assert_equal 'text/csv', @response.content_type
324 assert_equal 'text/csv', @response.content_type
327 assert @response.body.starts_with?("#,")
325 assert @response.body.starts_with?("#,")
328 lines = @response.body.chomp.split("\n")
326 lines = @response.body.chomp.split("\n")
329 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
327 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
330 end
328 end
331
329
332 def test_index_csv_with_spent_time_column
330 def test_index_csv_with_spent_time_column
333 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column')
331 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column')
334 TimeEntry.generate!(:project_id => issue.project_id, :issue_id => issue.id, :hours => 7.33)
332 TimeEntry.generate!(:project_id => issue.project_id, :issue_id => issue.id, :hours => 7.33)
335
333
336 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
334 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
337 assert_response :success
335 assert_response :success
338 assert_equal 'text/csv', @response.content_type
336 assert_equal 'text/csv', @response.content_type
339 lines = @response.body.chomp.split("\n")
337 lines = @response.body.chomp.split("\n")
340 assert_include "#{issue.id},#{issue.subject},7.33", lines
338 assert_include "#{issue.id},#{issue.subject},7.33", lines
341 end
339 end
342
340
343 def test_index_csv_with_all_columns
341 def test_index_csv_with_all_columns
344 get :index, :format => 'csv', :columns => 'all'
342 get :index, :format => 'csv', :columns => 'all'
345 assert_response :success
343 assert_response :success
346 assert_not_nil assigns(:issues)
344 assert_not_nil assigns(:issues)
347 assert_equal 'text/csv', @response.content_type
345 assert_equal 'text/csv', @response.content_type
348 assert @response.body.starts_with?("#,")
346 assert @response.body.starts_with?("#,")
349 lines = @response.body.chomp.split("\n")
347 lines = @response.body.chomp.split("\n")
350 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
348 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
351 end
349 end
352
350
353 def test_index_csv_with_multi_column_field
351 def test_index_csv_with_multi_column_field
354 CustomField.find(1).update_attribute :multiple, true
352 CustomField.find(1).update_attribute :multiple, true
355 issue = Issue.find(1)
353 issue = Issue.find(1)
356 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
354 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
357 issue.save!
355 issue.save!
358
356
359 get :index, :format => 'csv', :columns => 'all'
357 get :index, :format => 'csv', :columns => 'all'
360 assert_response :success
358 assert_response :success
361 lines = @response.body.chomp.split("\n")
359 lines = @response.body.chomp.split("\n")
362 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
360 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
363 end
361 end
364
362
365 def test_index_csv_big_5
363 def test_index_csv_big_5
366 with_settings :default_language => "zh-TW" do
364 with_settings :default_language => "zh-TW" do
367 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
365 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
368 str_big5 = "\xa4@\xa4\xeb"
366 str_big5 = "\xa4@\xa4\xeb"
369 if str_utf8.respond_to?(:force_encoding)
367 if str_utf8.respond_to?(:force_encoding)
370 str_utf8.force_encoding('UTF-8')
368 str_utf8.force_encoding('UTF-8')
371 str_big5.force_encoding('Big5')
369 str_big5.force_encoding('Big5')
372 end
370 end
373 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
371 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
374 :status_id => 1, :priority => IssuePriority.all.first,
372 :status_id => 1, :priority => IssuePriority.all.first,
375 :subject => str_utf8)
373 :subject => str_utf8)
376 assert issue.save
374 assert issue.save
377
375
378 get :index, :project_id => 1,
376 get :index, :project_id => 1,
379 :f => ['subject'],
377 :f => ['subject'],
380 :op => '=', :values => [str_utf8],
378 :op => '=', :values => [str_utf8],
381 :format => 'csv'
379 :format => 'csv'
382 assert_equal 'text/csv', @response.content_type
380 assert_equal 'text/csv', @response.content_type
383 lines = @response.body.chomp.split("\n")
381 lines = @response.body.chomp.split("\n")
384 s1 = "\xaa\xac\xbaA"
382 s1 = "\xaa\xac\xbaA"
385 if str_utf8.respond_to?(:force_encoding)
383 if str_utf8.respond_to?(:force_encoding)
386 s1.force_encoding('Big5')
384 s1.force_encoding('Big5')
387 end
385 end
388 assert lines[0].include?(s1)
386 assert lines[0].include?(s1)
389 assert lines[1].include?(str_big5)
387 assert lines[1].include?(str_big5)
390 end
388 end
391 end
389 end
392
390
393 def test_index_csv_cannot_convert_should_be_replaced_big_5
391 def test_index_csv_cannot_convert_should_be_replaced_big_5
394 with_settings :default_language => "zh-TW" do
392 with_settings :default_language => "zh-TW" do
395 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
393 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
396 if str_utf8.respond_to?(:force_encoding)
394 if str_utf8.respond_to?(:force_encoding)
397 str_utf8.force_encoding('UTF-8')
395 str_utf8.force_encoding('UTF-8')
398 end
396 end
399 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
397 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
400 :status_id => 1, :priority => IssuePriority.all.first,
398 :status_id => 1, :priority => IssuePriority.all.first,
401 :subject => str_utf8)
399 :subject => str_utf8)
402 assert issue.save
400 assert issue.save
403
401
404 get :index, :project_id => 1,
402 get :index, :project_id => 1,
405 :f => ['subject'],
403 :f => ['subject'],
406 :op => '=', :values => [str_utf8],
404 :op => '=', :values => [str_utf8],
407 :c => ['status', 'subject'],
405 :c => ['status', 'subject'],
408 :format => 'csv',
406 :format => 'csv',
409 :set_filter => 1
407 :set_filter => 1
410 assert_equal 'text/csv', @response.content_type
408 assert_equal 'text/csv', @response.content_type
411 lines = @response.body.chomp.split("\n")
409 lines = @response.body.chomp.split("\n")
412 s1 = "\xaa\xac\xbaA" # status
410 s1 = "\xaa\xac\xbaA" # status
413 if str_utf8.respond_to?(:force_encoding)
411 if str_utf8.respond_to?(:force_encoding)
414 s1.force_encoding('Big5')
412 s1.force_encoding('Big5')
415 end
413 end
416 assert lines[0].include?(s1)
414 assert lines[0].include?(s1)
417 s2 = lines[1].split(",")[2]
415 s2 = lines[1].split(",")[2]
418 if s1.respond_to?(:force_encoding)
416 if s1.respond_to?(:force_encoding)
419 s3 = "\xa5H?" # subject
417 s3 = "\xa5H?" # subject
420 s3.force_encoding('Big5')
418 s3.force_encoding('Big5')
421 assert_equal s3, s2
419 assert_equal s3, s2
422 elsif RUBY_PLATFORM == 'java'
420 elsif RUBY_PLATFORM == 'java'
423 assert_equal "??", s2
421 assert_equal "??", s2
424 else
422 else
425 assert_equal "\xa5H???", s2
423 assert_equal "\xa5H???", s2
426 end
424 end
427 end
425 end
428 end
426 end
429
427
430 def test_index_csv_tw
428 def test_index_csv_tw
431 with_settings :default_language => "zh-TW" do
429 with_settings :default_language => "zh-TW" do
432 str1 = "test_index_csv_tw"
430 str1 = "test_index_csv_tw"
433 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
431 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
434 :status_id => 1, :priority => IssuePriority.all.first,
432 :status_id => 1, :priority => IssuePriority.all.first,
435 :subject => str1, :estimated_hours => '1234.5')
433 :subject => str1, :estimated_hours => '1234.5')
436 assert issue.save
434 assert issue.save
437 assert_equal 1234.5, issue.estimated_hours
435 assert_equal 1234.5, issue.estimated_hours
438
436
439 get :index, :project_id => 1,
437 get :index, :project_id => 1,
440 :f => ['subject'],
438 :f => ['subject'],
441 :op => '=', :values => [str1],
439 :op => '=', :values => [str1],
442 :c => ['estimated_hours', 'subject'],
440 :c => ['estimated_hours', 'subject'],
443 :format => 'csv',
441 :format => 'csv',
444 :set_filter => 1
442 :set_filter => 1
445 assert_equal 'text/csv', @response.content_type
443 assert_equal 'text/csv', @response.content_type
446 lines = @response.body.chomp.split("\n")
444 lines = @response.body.chomp.split("\n")
447 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
445 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
448
446
449 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
447 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
450 if str_tw.respond_to?(:force_encoding)
448 if str_tw.respond_to?(:force_encoding)
451 str_tw.force_encoding('UTF-8')
449 str_tw.force_encoding('UTF-8')
452 end
450 end
453 assert_equal str_tw, l(:general_lang_name)
451 assert_equal str_tw, l(:general_lang_name)
454 assert_equal ',', l(:general_csv_separator)
452 assert_equal ',', l(:general_csv_separator)
455 assert_equal '.', l(:general_csv_decimal_separator)
453 assert_equal '.', l(:general_csv_decimal_separator)
456 end
454 end
457 end
455 end
458
456
459 def test_index_csv_fr
457 def test_index_csv_fr
460 with_settings :default_language => "fr" do
458 with_settings :default_language => "fr" do
461 str1 = "test_index_csv_fr"
459 str1 = "test_index_csv_fr"
462 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
460 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
463 :status_id => 1, :priority => IssuePriority.all.first,
461 :status_id => 1, :priority => IssuePriority.all.first,
464 :subject => str1, :estimated_hours => '1234.5')
462 :subject => str1, :estimated_hours => '1234.5')
465 assert issue.save
463 assert issue.save
466 assert_equal 1234.5, issue.estimated_hours
464 assert_equal 1234.5, issue.estimated_hours
467
465
468 get :index, :project_id => 1,
466 get :index, :project_id => 1,
469 :f => ['subject'],
467 :f => ['subject'],
470 :op => '=', :values => [str1],
468 :op => '=', :values => [str1],
471 :c => ['estimated_hours', 'subject'],
469 :c => ['estimated_hours', 'subject'],
472 :format => 'csv',
470 :format => 'csv',
473 :set_filter => 1
471 :set_filter => 1
474 assert_equal 'text/csv', @response.content_type
472 assert_equal 'text/csv', @response.content_type
475 lines = @response.body.chomp.split("\n")
473 lines = @response.body.chomp.split("\n")
476 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
474 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
477
475
478 str_fr = "Fran\xc3\xa7ais"
476 str_fr = "Fran\xc3\xa7ais"
479 if str_fr.respond_to?(:force_encoding)
477 if str_fr.respond_to?(:force_encoding)
480 str_fr.force_encoding('UTF-8')
478 str_fr.force_encoding('UTF-8')
481 end
479 end
482 assert_equal str_fr, l(:general_lang_name)
480 assert_equal str_fr, l(:general_lang_name)
483 assert_equal ';', l(:general_csv_separator)
481 assert_equal ';', l(:general_csv_separator)
484 assert_equal ',', l(:general_csv_decimal_separator)
482 assert_equal ',', l(:general_csv_decimal_separator)
485 end
483 end
486 end
484 end
487
485
488 def test_index_pdf
486 def test_index_pdf
489 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
487 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
490 with_settings :default_language => lang do
488 with_settings :default_language => lang do
491
489
492 get :index
490 get :index
493 assert_response :success
491 assert_response :success
494 assert_template 'index'
492 assert_template 'index'
495
493
496 if lang == "ja"
494 if lang == "ja"
497 if RUBY_PLATFORM != 'java'
495 if RUBY_PLATFORM != 'java'
498 assert_equal "CP932", l(:general_pdf_encoding)
496 assert_equal "CP932", l(:general_pdf_encoding)
499 end
497 end
500 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
498 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
501 next
499 next
502 end
500 end
503 end
501 end
504
502
505 get :index, :format => 'pdf'
503 get :index, :format => 'pdf'
506 assert_response :success
504 assert_response :success
507 assert_not_nil assigns(:issues)
505 assert_not_nil assigns(:issues)
508 assert_equal 'application/pdf', @response.content_type
506 assert_equal 'application/pdf', @response.content_type
509
507
510 get :index, :project_id => 1, :format => 'pdf'
508 get :index, :project_id => 1, :format => 'pdf'
511 assert_response :success
509 assert_response :success
512 assert_not_nil assigns(:issues)
510 assert_not_nil assigns(:issues)
513 assert_equal 'application/pdf', @response.content_type
511 assert_equal 'application/pdf', @response.content_type
514
512
515 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
513 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
516 assert_response :success
514 assert_response :success
517 assert_not_nil assigns(:issues)
515 assert_not_nil assigns(:issues)
518 assert_equal 'application/pdf', @response.content_type
516 assert_equal 'application/pdf', @response.content_type
519 end
517 end
520 end
518 end
521 end
519 end
522
520
523 def test_index_pdf_with_query_grouped_by_list_custom_field
521 def test_index_pdf_with_query_grouped_by_list_custom_field
524 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
522 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
525 assert_response :success
523 assert_response :success
526 assert_not_nil assigns(:issues)
524 assert_not_nil assigns(:issues)
527 assert_not_nil assigns(:issue_count_by_group)
525 assert_not_nil assigns(:issue_count_by_group)
528 assert_equal 'application/pdf', @response.content_type
526 assert_equal 'application/pdf', @response.content_type
529 end
527 end
530
528
531 def test_index_sort
529 def test_index_sort
532 get :index, :sort => 'tracker,id:desc'
530 get :index, :sort => 'tracker,id:desc'
533 assert_response :success
531 assert_response :success
534
532
535 sort_params = @request.session['issues_index_sort']
533 sort_params = @request.session['issues_index_sort']
536 assert sort_params.is_a?(String)
534 assert sort_params.is_a?(String)
537 assert_equal 'tracker,id:desc', sort_params
535 assert_equal 'tracker,id:desc', sort_params
538
536
539 issues = assigns(:issues)
537 issues = assigns(:issues)
540 assert_not_nil issues
538 assert_not_nil issues
541 assert !issues.empty?
539 assert !issues.empty?
542 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
540 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
543 end
541 end
544
542
545 def test_index_sort_by_field_not_included_in_columns
543 def test_index_sort_by_field_not_included_in_columns
546 Setting.issue_list_default_columns = %w(subject author)
544 Setting.issue_list_default_columns = %w(subject author)
547 get :index, :sort => 'tracker'
545 get :index, :sort => 'tracker'
548 end
546 end
549
547
550 def test_index_sort_by_assigned_to
548 def test_index_sort_by_assigned_to
551 get :index, :sort => 'assigned_to'
549 get :index, :sort => 'assigned_to'
552 assert_response :success
550 assert_response :success
553 assignees = assigns(:issues).collect(&:assigned_to).compact
551 assignees = assigns(:issues).collect(&:assigned_to).compact
554 assert_equal assignees.sort, assignees
552 assert_equal assignees.sort, assignees
555 end
553 end
556
554
557 def test_index_sort_by_assigned_to_desc
555 def test_index_sort_by_assigned_to_desc
558 get :index, :sort => 'assigned_to:desc'
556 get :index, :sort => 'assigned_to:desc'
559 assert_response :success
557 assert_response :success
560 assignees = assigns(:issues).collect(&:assigned_to).compact
558 assignees = assigns(:issues).collect(&:assigned_to).compact
561 assert_equal assignees.sort.reverse, assignees
559 assert_equal assignees.sort.reverse, assignees
562 end
560 end
563
561
564 def test_index_group_by_assigned_to
562 def test_index_group_by_assigned_to
565 get :index, :group_by => 'assigned_to', :sort => 'priority'
563 get :index, :group_by => 'assigned_to', :sort => 'priority'
566 assert_response :success
564 assert_response :success
567 end
565 end
568
566
569 def test_index_sort_by_author
567 def test_index_sort_by_author
570 get :index, :sort => 'author'
568 get :index, :sort => 'author'
571 assert_response :success
569 assert_response :success
572 authors = assigns(:issues).collect(&:author)
570 authors = assigns(:issues).collect(&:author)
573 assert_equal authors.sort, authors
571 assert_equal authors.sort, authors
574 end
572 end
575
573
576 def test_index_sort_by_author_desc
574 def test_index_sort_by_author_desc
577 get :index, :sort => 'author:desc'
575 get :index, :sort => 'author:desc'
578 assert_response :success
576 assert_response :success
579 authors = assigns(:issues).collect(&:author)
577 authors = assigns(:issues).collect(&:author)
580 assert_equal authors.sort.reverse, authors
578 assert_equal authors.sort.reverse, authors
581 end
579 end
582
580
583 def test_index_group_by_author
581 def test_index_group_by_author
584 get :index, :group_by => 'author', :sort => 'priority'
582 get :index, :group_by => 'author', :sort => 'priority'
585 assert_response :success
583 assert_response :success
586 end
584 end
587
585
588 def test_index_sort_by_spent_hours
586 def test_index_sort_by_spent_hours
589 get :index, :sort => 'spent_hours:desc'
587 get :index, :sort => 'spent_hours:desc'
590 assert_response :success
588 assert_response :success
591 hours = assigns(:issues).collect(&:spent_hours)
589 hours = assigns(:issues).collect(&:spent_hours)
592 assert_equal hours.sort.reverse, hours
590 assert_equal hours.sort.reverse, hours
593 end
591 end
594
592
595 def test_index_with_columns
593 def test_index_with_columns
596 columns = ['tracker', 'subject', 'assigned_to']
594 columns = ['tracker', 'subject', 'assigned_to']
597 get :index, :set_filter => 1, :c => columns
595 get :index, :set_filter => 1, :c => columns
598 assert_response :success
596 assert_response :success
599
597
600 # query should use specified columns
598 # query should use specified columns
601 query = assigns(:query)
599 query = assigns(:query)
602 assert_kind_of Query, query
600 assert_kind_of Query, query
603 assert_equal columns, query.column_names.map(&:to_s)
601 assert_equal columns, query.column_names.map(&:to_s)
604
602
605 # columns should be stored in session
603 # columns should be stored in session
606 assert_kind_of Hash, session[:query]
604 assert_kind_of Hash, session[:query]
607 assert_kind_of Array, session[:query][:column_names]
605 assert_kind_of Array, session[:query][:column_names]
608 assert_equal columns, session[:query][:column_names].map(&:to_s)
606 assert_equal columns, session[:query][:column_names].map(&:to_s)
609
607
610 # ensure only these columns are kept in the selected columns list
608 # ensure only these columns are kept in the selected columns list
611 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
609 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
612 :children => { :count => 3 }
610 :children => { :count => 3 }
613 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
611 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
614 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
612 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
615 end
613 end
616
614
617 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
615 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
618 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
616 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
619 get :index, :set_filter => 1
617 get :index, :set_filter => 1
620
618
621 # query should use specified columns
619 # query should use specified columns
622 query = assigns(:query)
620 query = assigns(:query)
623 assert_kind_of Query, query
621 assert_kind_of Query, query
624 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
622 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
625 end
623 end
626
624
627 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
625 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
628 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
626 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
629 columns = ['tracker', 'subject', 'assigned_to']
627 columns = ['tracker', 'subject', 'assigned_to']
630 get :index, :set_filter => 1, :c => columns
628 get :index, :set_filter => 1, :c => columns
631
629
632 # query should use specified columns
630 # query should use specified columns
633 query = assigns(:query)
631 query = assigns(:query)
634 assert_kind_of Query, query
632 assert_kind_of Query, query
635 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
633 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
636 end
634 end
637
635
638 def test_index_with_custom_field_column
636 def test_index_with_custom_field_column
639 columns = %w(tracker subject cf_2)
637 columns = %w(tracker subject cf_2)
640 get :index, :set_filter => 1, :c => columns
638 get :index, :set_filter => 1, :c => columns
641 assert_response :success
639 assert_response :success
642
640
643 # query should use specified columns
641 # query should use specified columns
644 query = assigns(:query)
642 query = assigns(:query)
645 assert_kind_of Query, query
643 assert_kind_of Query, query
646 assert_equal columns, query.column_names.map(&:to_s)
644 assert_equal columns, query.column_names.map(&:to_s)
647
645
648 assert_tag :td,
646 assert_tag :td,
649 :attributes => {:class => 'cf_2 string'},
647 :attributes => {:class => 'cf_2 string'},
650 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
648 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
651 end
649 end
652
650
653 def test_index_with_multi_custom_field_column
651 def test_index_with_multi_custom_field_column
654 field = CustomField.find(1)
652 field = CustomField.find(1)
655 field.update_attribute :multiple, true
653 field.update_attribute :multiple, true
656 issue = Issue.find(1)
654 issue = Issue.find(1)
657 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
655 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
658 issue.save!
656 issue.save!
659
657
660 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
658 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
661 assert_response :success
659 assert_response :success
662
660
663 assert_tag :td,
661 assert_tag :td,
664 :attributes => {:class => /cf_1/},
662 :attributes => {:class => /cf_1/},
665 :content => 'MySQL, Oracle'
663 :content => 'MySQL, Oracle'
666 end
664 end
667
665
668 def test_index_with_multi_user_custom_field_column
666 def test_index_with_multi_user_custom_field_column
669 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
667 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
670 :tracker_ids => [1], :is_for_all => true)
668 :tracker_ids => [1], :is_for_all => true)
671 issue = Issue.find(1)
669 issue = Issue.find(1)
672 issue.custom_field_values = {field.id => ['2', '3']}
670 issue.custom_field_values = {field.id => ['2', '3']}
673 issue.save!
671 issue.save!
674
672
675 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
673 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
676 assert_response :success
674 assert_response :success
677
675
678 assert_tag :td,
676 assert_tag :td,
679 :attributes => {:class => /cf_#{field.id}/},
677 :attributes => {:class => /cf_#{field.id}/},
680 :child => {:tag => 'a', :content => 'John Smith'}
678 :child => {:tag => 'a', :content => 'John Smith'}
681 end
679 end
682
680
683 def test_index_with_date_column
681 def test_index_with_date_column
684 Issue.find(1).update_attribute :start_date, '1987-08-24'
682 Issue.find(1).update_attribute :start_date, '1987-08-24'
685
683
686 with_settings :date_format => '%d/%m/%Y' do
684 with_settings :date_format => '%d/%m/%Y' do
687 get :index, :set_filter => 1, :c => %w(start_date)
685 get :index, :set_filter => 1, :c => %w(start_date)
688 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
686 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
689 end
687 end
690 end
688 end
691
689
692 def test_index_with_done_ratio
690 def test_index_with_done_ratio
693 Issue.find(1).update_attribute :done_ratio, 40
691 Issue.find(1).update_attribute :done_ratio, 40
694
692
695 get :index, :set_filter => 1, :c => %w(done_ratio)
693 get :index, :set_filter => 1, :c => %w(done_ratio)
696 assert_tag 'td', :attributes => {:class => /done_ratio/},
694 assert_tag 'td', :attributes => {:class => /done_ratio/},
697 :child => {:tag => 'table', :attributes => {:class => 'progress'},
695 :child => {:tag => 'table', :attributes => {:class => 'progress'},
698 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
696 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
699 }
697 }
700 end
698 end
701
699
702 def test_index_with_spent_hours_column
700 def test_index_with_spent_hours_column
703 get :index, :set_filter => 1, :c => %w(subject spent_hours)
701 get :index, :set_filter => 1, :c => %w(subject spent_hours)
704
702
705 assert_tag 'tr', :attributes => {:id => 'issue-3'},
703 assert_tag 'tr', :attributes => {:id => 'issue-3'},
706 :child => {
704 :child => {
707 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
705 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
708 }
706 }
709 end
707 end
710
708
711 def test_index_should_not_show_spent_hours_column_without_permission
709 def test_index_should_not_show_spent_hours_column_without_permission
712 Role.anonymous.remove_permission! :view_time_entries
710 Role.anonymous.remove_permission! :view_time_entries
713 get :index, :set_filter => 1, :c => %w(subject spent_hours)
711 get :index, :set_filter => 1, :c => %w(subject spent_hours)
714
712
715 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
713 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
716 end
714 end
717
715
718 def test_index_with_fixed_version
716 def test_index_with_fixed_version
719 get :index, :set_filter => 1, :c => %w(fixed_version)
717 get :index, :set_filter => 1, :c => %w(fixed_version)
720 assert_tag 'td', :attributes => {:class => /fixed_version/},
718 assert_tag 'td', :attributes => {:class => /fixed_version/},
721 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
719 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
722 end
720 end
723
721
724 def test_index_send_html_if_query_is_invalid
722 def test_index_send_html_if_query_is_invalid
725 get :index, :f => ['start_date'], :op => {:start_date => '='}
723 get :index, :f => ['start_date'], :op => {:start_date => '='}
726 assert_equal 'text/html', @response.content_type
724 assert_equal 'text/html', @response.content_type
727 assert_template 'index'
725 assert_template 'index'
728 end
726 end
729
727
730 def test_index_send_nothing_if_query_is_invalid
728 def test_index_send_nothing_if_query_is_invalid
731 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
729 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
732 assert_equal 'text/csv', @response.content_type
730 assert_equal 'text/csv', @response.content_type
733 assert @response.body.blank?
731 assert @response.body.blank?
734 end
732 end
735
733
736 def test_show_by_anonymous
734 def test_show_by_anonymous
737 get :show, :id => 1
735 get :show, :id => 1
738 assert_response :success
736 assert_response :success
739 assert_template 'show'
737 assert_template 'show'
740 assert_not_nil assigns(:issue)
738 assert_not_nil assigns(:issue)
741 assert_equal Issue.find(1), assigns(:issue)
739 assert_equal Issue.find(1), assigns(:issue)
742
740
743 # anonymous role is allowed to add a note
741 # anonymous role is allowed to add a note
744 assert_tag :tag => 'form',
742 assert_tag :tag => 'form',
745 :descendant => { :tag => 'fieldset',
743 :descendant => { :tag => 'fieldset',
746 :child => { :tag => 'legend',
744 :child => { :tag => 'legend',
747 :content => /Notes/ } }
745 :content => /Notes/ } }
748 assert_tag :tag => 'title',
746 assert_tag :tag => 'title',
749 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
747 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
750 end
748 end
751
749
752 def test_show_by_manager
750 def test_show_by_manager
753 @request.session[:user_id] = 2
751 @request.session[:user_id] = 2
754 get :show, :id => 1
752 get :show, :id => 1
755 assert_response :success
753 assert_response :success
756
754
757 assert_tag :tag => 'a',
755 assert_tag :tag => 'a',
758 :content => /Quote/
756 :content => /Quote/
759
757
760 assert_tag :tag => 'form',
758 assert_tag :tag => 'form',
761 :descendant => { :tag => 'fieldset',
759 :descendant => { :tag => 'fieldset',
762 :child => { :tag => 'legend',
760 :child => { :tag => 'legend',
763 :content => /Change properties/ } },
761 :content => /Change properties/ } },
764 :descendant => { :tag => 'fieldset',
762 :descendant => { :tag => 'fieldset',
765 :child => { :tag => 'legend',
763 :child => { :tag => 'legend',
766 :content => /Log time/ } },
764 :content => /Log time/ } },
767 :descendant => { :tag => 'fieldset',
765 :descendant => { :tag => 'fieldset',
768 :child => { :tag => 'legend',
766 :child => { :tag => 'legend',
769 :content => /Notes/ } }
767 :content => /Notes/ } }
770 end
768 end
771
769
772 def test_show_should_display_update_form
770 def test_show_should_display_update_form
773 @request.session[:user_id] = 2
771 @request.session[:user_id] = 2
774 get :show, :id => 1
772 get :show, :id => 1
775 assert_response :success
773 assert_response :success
776
774
777 assert_tag 'form', :attributes => {:id => 'issue-form'}
775 assert_tag 'form', :attributes => {:id => 'issue-form'}
778 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
776 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
779 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
777 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
780 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
778 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
781 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
779 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
782 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
780 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
783 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
781 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
784 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
782 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
785 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
783 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
786 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
784 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
787 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
785 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
788 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
786 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
789 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
787 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
790 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
788 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
791 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
789 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
792 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
790 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
793 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
791 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
794 assert_tag 'textarea', :attributes => {:name => 'notes'}
792 assert_tag 'textarea', :attributes => {:name => 'notes'}
795 end
793 end
796
794
797 def test_show_should_display_update_form_with_minimal_permissions
795 def test_show_should_display_update_form_with_minimal_permissions
798 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
796 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
799 Workflow.delete_all :role_id => 1
797 Workflow.delete_all :role_id => 1
800
798
801 @request.session[:user_id] = 2
799 @request.session[:user_id] = 2
802 get :show, :id => 1
800 get :show, :id => 1
803 assert_response :success
801 assert_response :success
804
802
805 assert_tag 'form', :attributes => {:id => 'issue-form'}
803 assert_tag 'form', :attributes => {:id => 'issue-form'}
806 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
804 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
807 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
805 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
808 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
806 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
809 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
807 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
810 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
808 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
811 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
809 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
812 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
810 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
813 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
811 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
814 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
812 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
815 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
813 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
816 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
814 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
817 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
815 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
818 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
816 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
819 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
817 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
820 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
818 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
821 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
819 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
822 assert_tag 'textarea', :attributes => {:name => 'notes'}
820 assert_tag 'textarea', :attributes => {:name => 'notes'}
823 end
821 end
824
822
825 def test_show_should_display_update_form_with_workflow_permissions
823 def test_show_should_display_update_form_with_workflow_permissions
826 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
824 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
827
825
828 @request.session[:user_id] = 2
826 @request.session[:user_id] = 2
829 get :show, :id => 1
827 get :show, :id => 1
830 assert_response :success
828 assert_response :success
831
829
832 assert_tag 'form', :attributes => {:id => 'issue-form'}
830 assert_tag 'form', :attributes => {:id => 'issue-form'}
833 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
831 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
834 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
832 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
835 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
833 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
836 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
834 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
837 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
835 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
838 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
836 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
839 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
837 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
840 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
838 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
841 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
839 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
842 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
840 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
843 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
841 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
844 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
842 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
845 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
843 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
846 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
844 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
847 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
845 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
848 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
846 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
849 assert_tag 'textarea', :attributes => {:name => 'notes'}
847 assert_tag 'textarea', :attributes => {:name => 'notes'}
850 end
848 end
851
849
852 def test_show_should_not_display_update_form_without_permissions
850 def test_show_should_not_display_update_form_without_permissions
853 Role.find(1).update_attribute :permissions, [:view_issues]
851 Role.find(1).update_attribute :permissions, [:view_issues]
854
852
855 @request.session[:user_id] = 2
853 @request.session[:user_id] = 2
856 get :show, :id => 1
854 get :show, :id => 1
857 assert_response :success
855 assert_response :success
858
856
859 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
857 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
860 end
858 end
861
859
862 def test_update_form_should_not_display_inactive_enumerations
860 def test_update_form_should_not_display_inactive_enumerations
863 @request.session[:user_id] = 2
861 @request.session[:user_id] = 2
864 get :show, :id => 1
862 get :show, :id => 1
865 assert_response :success
863 assert_response :success
866
864
867 assert ! IssuePriority.find(15).active?
865 assert ! IssuePriority.find(15).active?
868 assert_no_tag :option, :attributes => {:value => '15'},
866 assert_no_tag :option, :attributes => {:value => '15'},
869 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
867 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
870 end
868 end
871
869
872 def test_update_form_should_allow_attachment_upload
870 def test_update_form_should_allow_attachment_upload
873 @request.session[:user_id] = 2
871 @request.session[:user_id] = 2
874 get :show, :id => 1
872 get :show, :id => 1
875
873
876 assert_tag :tag => 'form',
874 assert_tag :tag => 'form',
877 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
875 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
878 :descendant => {
876 :descendant => {
879 :tag => 'input',
877 :tag => 'input',
880 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
878 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
881 }
879 }
882 end
880 end
883
881
884 def test_show_should_deny_anonymous_access_without_permission
882 def test_show_should_deny_anonymous_access_without_permission
885 Role.anonymous.remove_permission!(:view_issues)
883 Role.anonymous.remove_permission!(:view_issues)
886 get :show, :id => 1
884 get :show, :id => 1
887 assert_response :redirect
885 assert_response :redirect
888 end
886 end
889
887
890 def test_show_should_deny_anonymous_access_to_private_issue
888 def test_show_should_deny_anonymous_access_to_private_issue
891 Issue.update_all(["is_private = ?", true], "id = 1")
889 Issue.update_all(["is_private = ?", true], "id = 1")
892 get :show, :id => 1
890 get :show, :id => 1
893 assert_response :redirect
891 assert_response :redirect
894 end
892 end
895
893
896 def test_show_should_deny_non_member_access_without_permission
894 def test_show_should_deny_non_member_access_without_permission
897 Role.non_member.remove_permission!(:view_issues)
895 Role.non_member.remove_permission!(:view_issues)
898 @request.session[:user_id] = 9
896 @request.session[:user_id] = 9
899 get :show, :id => 1
897 get :show, :id => 1
900 assert_response 403
898 assert_response 403
901 end
899 end
902
900
903 def test_show_should_deny_non_member_access_to_private_issue
901 def test_show_should_deny_non_member_access_to_private_issue
904 Issue.update_all(["is_private = ?", true], "id = 1")
902 Issue.update_all(["is_private = ?", true], "id = 1")
905 @request.session[:user_id] = 9
903 @request.session[:user_id] = 9
906 get :show, :id => 1
904 get :show, :id => 1
907 assert_response 403
905 assert_response 403
908 end
906 end
909
907
910 def test_show_should_deny_member_access_without_permission
908 def test_show_should_deny_member_access_without_permission
911 Role.find(1).remove_permission!(:view_issues)
909 Role.find(1).remove_permission!(:view_issues)
912 @request.session[:user_id] = 2
910 @request.session[:user_id] = 2
913 get :show, :id => 1
911 get :show, :id => 1
914 assert_response 403
912 assert_response 403
915 end
913 end
916
914
917 def test_show_should_deny_member_access_to_private_issue_without_permission
915 def test_show_should_deny_member_access_to_private_issue_without_permission
918 Issue.update_all(["is_private = ?", true], "id = 1")
916 Issue.update_all(["is_private = ?", true], "id = 1")
919 @request.session[:user_id] = 3
917 @request.session[:user_id] = 3
920 get :show, :id => 1
918 get :show, :id => 1
921 assert_response 403
919 assert_response 403
922 end
920 end
923
921
924 def test_show_should_allow_author_access_to_private_issue
922 def test_show_should_allow_author_access_to_private_issue
925 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
923 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
926 @request.session[:user_id] = 3
924 @request.session[:user_id] = 3
927 get :show, :id => 1
925 get :show, :id => 1
928 assert_response :success
926 assert_response :success
929 end
927 end
930
928
931 def test_show_should_allow_assignee_access_to_private_issue
929 def test_show_should_allow_assignee_access_to_private_issue
932 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
930 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
933 @request.session[:user_id] = 3
931 @request.session[:user_id] = 3
934 get :show, :id => 1
932 get :show, :id => 1
935 assert_response :success
933 assert_response :success
936 end
934 end
937
935
938 def test_show_should_allow_member_access_to_private_issue_with_permission
936 def test_show_should_allow_member_access_to_private_issue_with_permission
939 Issue.update_all(["is_private = ?", true], "id = 1")
937 Issue.update_all(["is_private = ?", true], "id = 1")
940 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
938 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
941 @request.session[:user_id] = 3
939 @request.session[:user_id] = 3
942 get :show, :id => 1
940 get :show, :id => 1
943 assert_response :success
941 assert_response :success
944 end
942 end
945
943
946 def test_show_should_not_disclose_relations_to_invisible_issues
944 def test_show_should_not_disclose_relations_to_invisible_issues
947 Setting.cross_project_issue_relations = '1'
945 Setting.cross_project_issue_relations = '1'
948 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
946 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
949 # Relation to a private project issue
947 # Relation to a private project issue
950 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
948 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
951
949
952 get :show, :id => 1
950 get :show, :id => 1
953 assert_response :success
951 assert_response :success
954
952
955 assert_tag :div, :attributes => { :id => 'relations' },
953 assert_tag :div, :attributes => { :id => 'relations' },
956 :descendant => { :tag => 'a', :content => /#2$/ }
954 :descendant => { :tag => 'a', :content => /#2$/ }
957 assert_no_tag :div, :attributes => { :id => 'relations' },
955 assert_no_tag :div, :attributes => { :id => 'relations' },
958 :descendant => { :tag => 'a', :content => /#4$/ }
956 :descendant => { :tag => 'a', :content => /#4$/ }
959 end
957 end
960
958
961 def test_show_should_list_subtasks
959 def test_show_should_list_subtasks
962 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
960 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
963
961
964 get :show, :id => 1
962 get :show, :id => 1
965 assert_response :success
963 assert_response :success
966 assert_tag 'div', :attributes => {:id => 'issue_tree'},
964 assert_tag 'div', :attributes => {:id => 'issue_tree'},
967 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
965 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
968 end
966 end
969
967
970 def test_show_should_list_parents
968 def test_show_should_list_parents
971 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
969 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
972
970
973 get :show, :id => issue.id
971 get :show, :id => issue.id
974 assert_response :success
972 assert_response :success
975 assert_tag 'div', :attributes => {:class => 'subject'},
973 assert_tag 'div', :attributes => {:class => 'subject'},
976 :descendant => {:tag => 'h3', :content => 'Child Issue'}
974 :descendant => {:tag => 'h3', :content => 'Child Issue'}
977 assert_tag 'div', :attributes => {:class => 'subject'},
975 assert_tag 'div', :attributes => {:class => 'subject'},
978 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
976 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
979 end
977 end
980
978
981 def test_show_should_not_display_prev_next_links_without_query_in_session
979 def test_show_should_not_display_prev_next_links_without_query_in_session
982 get :show, :id => 1
980 get :show, :id => 1
983 assert_response :success
981 assert_response :success
984 assert_nil assigns(:prev_issue_id)
982 assert_nil assigns(:prev_issue_id)
985 assert_nil assigns(:next_issue_id)
983 assert_nil assigns(:next_issue_id)
986
984
987 assert_no_tag 'div', :attributes => {:class => /next-prev-links/}
985 assert_no_tag 'div', :attributes => {:class => /next-prev-links/}
988 end
986 end
989
987
990 def test_show_should_display_prev_next_links_with_query_in_session
988 def test_show_should_display_prev_next_links_with_query_in_session
991 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
989 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
992 @request.session['issues_index_sort'] = 'id'
990 @request.session['issues_index_sort'] = 'id'
993
991
994 with_settings :display_subprojects_issues => '0' do
992 with_settings :display_subprojects_issues => '0' do
995 get :show, :id => 3
993 get :show, :id => 3
996 end
994 end
997
995
998 assert_response :success
996 assert_response :success
999 # Previous and next issues for all projects
997 # Previous and next issues for all projects
1000 assert_equal 2, assigns(:prev_issue_id)
998 assert_equal 2, assigns(:prev_issue_id)
1001 assert_equal 5, assigns(:next_issue_id)
999 assert_equal 5, assigns(:next_issue_id)
1002
1000
1003 assert_tag 'div', :attributes => {:class => /next-prev-links/}
1001 assert_tag 'div', :attributes => {:class => /next-prev-links/}
1004 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1002 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1005 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
1003 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
1006
1004
1007 count = Issue.open.visible.count
1005 count = Issue.open.visible.count
1008 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
1006 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
1009 end
1007 end
1010
1008
1011 def test_show_should_display_prev_next_links_with_saved_query_in_session
1009 def test_show_should_display_prev_next_links_with_saved_query_in_session
1012 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1010 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1013 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1011 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1014 :sort_criteria => [['id', 'asc']])
1012 :sort_criteria => [['id', 'asc']])
1015 @request.session[:query] = {:id => query.id, :project_id => nil}
1013 @request.session[:query] = {:id => query.id, :project_id => nil}
1016
1014
1017 get :show, :id => 11
1015 get :show, :id => 11
1018
1016
1019 assert_response :success
1017 assert_response :success
1020 assert_equal query, assigns(:query)
1018 assert_equal query, assigns(:query)
1021 # Previous and next issues for all projects
1019 # Previous and next issues for all projects
1022 assert_equal 8, assigns(:prev_issue_id)
1020 assert_equal 8, assigns(:prev_issue_id)
1023 assert_equal 12, assigns(:next_issue_id)
1021 assert_equal 12, assigns(:next_issue_id)
1024
1022
1025 assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/
1023 assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/
1026 assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/
1024 assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/
1027 end
1025 end
1028
1026
1029 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1027 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1030 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1028 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1031
1029
1032 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1030 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1033 @request.session['issues_index_sort'] = assoc_sort
1031 @request.session['issues_index_sort'] = assoc_sort
1034
1032
1035 get :show, :id => 3
1033 get :show, :id => 3
1036 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1034 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1037
1035
1038 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/
1036 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/
1039 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/
1037 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/
1040 end
1038 end
1041 end
1039 end
1042
1040
1043 def test_show_should_display_prev_next_links_with_project_query_in_session
1041 def test_show_should_display_prev_next_links_with_project_query_in_session
1044 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1042 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1045 @request.session['issues_index_sort'] = 'id'
1043 @request.session['issues_index_sort'] = 'id'
1046
1044
1047 with_settings :display_subprojects_issues => '0' do
1045 with_settings :display_subprojects_issues => '0' do
1048 get :show, :id => 3
1046 get :show, :id => 3
1049 end
1047 end
1050
1048
1051 assert_response :success
1049 assert_response :success
1052 # Previous and next issues inside project
1050 # Previous and next issues inside project
1053 assert_equal 2, assigns(:prev_issue_id)
1051 assert_equal 2, assigns(:prev_issue_id)
1054 assert_equal 7, assigns(:next_issue_id)
1052 assert_equal 7, assigns(:next_issue_id)
1055
1053
1056 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1054 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1057 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
1055 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
1058 end
1056 end
1059
1057
1060 def test_show_should_not_display_prev_link_for_first_issue
1058 def test_show_should_not_display_prev_link_for_first_issue
1061 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1059 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1062 @request.session['issues_index_sort'] = 'id'
1060 @request.session['issues_index_sort'] = 'id'
1063
1061
1064 with_settings :display_subprojects_issues => '0' do
1062 with_settings :display_subprojects_issues => '0' do
1065 get :show, :id => 1
1063 get :show, :id => 1
1066 end
1064 end
1067
1065
1068 assert_response :success
1066 assert_response :success
1069 assert_nil assigns(:prev_issue_id)
1067 assert_nil assigns(:prev_issue_id)
1070 assert_equal 2, assigns(:next_issue_id)
1068 assert_equal 2, assigns(:next_issue_id)
1071
1069
1072 assert_no_tag 'a', :content => /Previous/
1070 assert_no_tag 'a', :content => /Previous/
1073 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
1071 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
1074 end
1072 end
1075
1073
1076 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1074 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1077 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1075 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1078 @request.session['issues_index_sort'] = 'id'
1076 @request.session['issues_index_sort'] = 'id'
1079
1077
1080 get :show, :id => 1
1078 get :show, :id => 1
1081
1079
1082 assert_response :success
1080 assert_response :success
1083 assert_nil assigns(:prev_issue_id)
1081 assert_nil assigns(:prev_issue_id)
1084 assert_nil assigns(:next_issue_id)
1082 assert_nil assigns(:next_issue_id)
1085
1083
1086 assert_no_tag 'a', :content => /Previous/
1084 assert_no_tag 'a', :content => /Previous/
1087 assert_no_tag 'a', :content => /Next/
1085 assert_no_tag 'a', :content => /Next/
1088 end
1086 end
1089
1087
1090 def test_show_should_display_visible_changesets_from_other_projects
1088 def test_show_should_display_visible_changesets_from_other_projects
1091 project = Project.find(2)
1089 project = Project.find(2)
1092 issue = project.issues.first
1090 issue = project.issues.first
1093 issue.changeset_ids = [102]
1091 issue.changeset_ids = [102]
1094 issue.save!
1092 issue.save!
1095 project.disable_module! :repository
1093 project.disable_module! :repository
1096
1094
1097 @request.session[:user_id] = 2
1095 @request.session[:user_id] = 2
1098 get :show, :id => issue.id
1096 get :show, :id => issue.id
1099 assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"}
1097 assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"}
1100 end
1098 end
1101
1099
1102 def test_show_with_multi_custom_field
1100 def test_show_with_multi_custom_field
1103 field = CustomField.find(1)
1101 field = CustomField.find(1)
1104 field.update_attribute :multiple, true
1102 field.update_attribute :multiple, true
1105 issue = Issue.find(1)
1103 issue = Issue.find(1)
1106 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1104 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1107 issue.save!
1105 issue.save!
1108
1106
1109 get :show, :id => 1
1107 get :show, :id => 1
1110 assert_response :success
1108 assert_response :success
1111
1109
1112 assert_tag :td, :content => 'MySQL, Oracle'
1110 assert_tag :td, :content => 'MySQL, Oracle'
1113 end
1111 end
1114
1112
1115 def test_show_with_multi_user_custom_field
1113 def test_show_with_multi_user_custom_field
1116 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1114 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1117 :tracker_ids => [1], :is_for_all => true)
1115 :tracker_ids => [1], :is_for_all => true)
1118 issue = Issue.find(1)
1116 issue = Issue.find(1)
1119 issue.custom_field_values = {field.id => ['2', '3']}
1117 issue.custom_field_values = {field.id => ['2', '3']}
1120 issue.save!
1118 issue.save!
1121
1119
1122 get :show, :id => 1
1120 get :show, :id => 1
1123 assert_response :success
1121 assert_response :success
1124
1122
1125 # TODO: should display links
1123 # TODO: should display links
1126 assert_tag :td, :content => 'Dave Lopper, John Smith'
1124 assert_tag :td, :content => 'Dave Lopper, John Smith'
1127 end
1125 end
1128
1126
1129 def test_show_atom
1127 def test_show_atom
1130 get :show, :id => 2, :format => 'atom'
1128 get :show, :id => 2, :format => 'atom'
1131 assert_response :success
1129 assert_response :success
1132 assert_template 'journals/index'
1130 assert_template 'journals/index'
1133 # Inline image
1131 # Inline image
1134 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1132 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1135 end
1133 end
1136
1134
1137 def test_show_export_to_pdf
1135 def test_show_export_to_pdf
1138 get :show, :id => 3, :format => 'pdf'
1136 get :show, :id => 3, :format => 'pdf'
1139 assert_response :success
1137 assert_response :success
1140 assert_equal 'application/pdf', @response.content_type
1138 assert_equal 'application/pdf', @response.content_type
1141 assert @response.body.starts_with?('%PDF')
1139 assert @response.body.starts_with?('%PDF')
1142 assert_not_nil assigns(:issue)
1140 assert_not_nil assigns(:issue)
1143 end
1141 end
1144
1142
1145 def test_get_new
1143 def test_get_new
1146 @request.session[:user_id] = 2
1144 @request.session[:user_id] = 2
1147 get :new, :project_id => 1, :tracker_id => 1
1145 get :new, :project_id => 1, :tracker_id => 1
1148 assert_response :success
1146 assert_response :success
1149 assert_template 'new'
1147 assert_template 'new'
1150
1148
1151 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1149 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1152 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1150 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1153 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1151 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1154 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1152 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1155 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1153 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1156 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1154 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1157 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1155 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1158 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1156 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1159 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1157 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1160 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1158 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1161 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1159 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1162 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1160 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1163 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1161 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1164 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1162 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1165 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1163 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1166 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1164 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1167
1165
1168 # Be sure we don't display inactive IssuePriorities
1166 # Be sure we don't display inactive IssuePriorities
1169 assert ! IssuePriority.find(15).active?
1167 assert ! IssuePriority.find(15).active?
1170 assert_no_tag :option, :attributes => {:value => '15'},
1168 assert_no_tag :option, :attributes => {:value => '15'},
1171 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1169 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1172 end
1170 end
1173
1171
1174 def test_get_new_with_minimal_permissions
1172 def test_get_new_with_minimal_permissions
1175 Role.find(1).update_attribute :permissions, [:add_issues]
1173 Role.find(1).update_attribute :permissions, [:add_issues]
1176 Workflow.delete_all :role_id => 1
1174 Workflow.delete_all :role_id => 1
1177
1175
1178 @request.session[:user_id] = 2
1176 @request.session[:user_id] = 2
1179 get :new, :project_id => 1, :tracker_id => 1
1177 get :new, :project_id => 1, :tracker_id => 1
1180 assert_response :success
1178 assert_response :success
1181 assert_template 'new'
1179 assert_template 'new'
1182
1180
1183 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1181 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1184 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1182 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1185 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1183 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1186 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1184 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1187 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1185 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1188 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1186 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1189 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1187 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1190 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1188 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1191 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1189 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1192 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1190 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1193 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1191 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1194 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1192 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1195 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1193 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1196 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1194 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1197 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1195 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1198 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1196 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1199 end
1197 end
1200
1198
1201 def test_get_new_with_multi_custom_field
1199 def test_get_new_with_multi_custom_field
1202 field = IssueCustomField.find(1)
1200 field = IssueCustomField.find(1)
1203 field.update_attribute :multiple, true
1201 field.update_attribute :multiple, true
1204
1202
1205 @request.session[:user_id] = 2
1203 @request.session[:user_id] = 2
1206 get :new, :project_id => 1, :tracker_id => 1
1204 get :new, :project_id => 1, :tracker_id => 1
1207 assert_response :success
1205 assert_response :success
1208 assert_template 'new'
1206 assert_template 'new'
1209
1207
1210 assert_tag 'select',
1208 assert_tag 'select',
1211 :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'},
1209 :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'},
1212 :children => {:count => 3},
1210 :children => {:count => 3},
1213 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1211 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1214 assert_tag 'input',
1212 assert_tag 'input',
1215 :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''}
1213 :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''}
1216 end
1214 end
1217
1215
1218 def test_get_new_with_multi_user_custom_field
1216 def test_get_new_with_multi_user_custom_field
1219 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1217 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1220 :tracker_ids => [1], :is_for_all => true)
1218 :tracker_ids => [1], :is_for_all => true)
1221
1219
1222 @request.session[:user_id] = 2
1220 @request.session[:user_id] = 2
1223 get :new, :project_id => 1, :tracker_id => 1
1221 get :new, :project_id => 1, :tracker_id => 1
1224 assert_response :success
1222 assert_response :success
1225 assert_template 'new'
1223 assert_template 'new'
1226
1224
1227 assert_tag 'select',
1225 assert_tag 'select',
1228 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'},
1226 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'},
1229 :children => {:count => Project.find(1).users.count},
1227 :children => {:count => Project.find(1).users.count},
1230 :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'}
1228 :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'}
1231 assert_tag 'input',
1229 assert_tag 'input',
1232 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''}
1230 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''}
1233 end
1231 end
1234
1232
1235 def test_get_new_without_default_start_date_is_creation_date
1233 def test_get_new_without_default_start_date_is_creation_date
1236 Setting.default_issue_start_date_to_creation_date = 0
1234 Setting.default_issue_start_date_to_creation_date = 0
1237
1235
1238 @request.session[:user_id] = 2
1236 @request.session[:user_id] = 2
1239 get :new, :project_id => 1, :tracker_id => 1
1237 get :new, :project_id => 1, :tracker_id => 1
1240 assert_response :success
1238 assert_response :success
1241 assert_template 'new'
1239 assert_template 'new'
1242
1240
1243 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1241 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1244 :value => nil }
1242 :value => nil }
1245 end
1243 end
1246
1244
1247 def test_get_new_with_default_start_date_is_creation_date
1245 def test_get_new_with_default_start_date_is_creation_date
1248 Setting.default_issue_start_date_to_creation_date = 1
1246 Setting.default_issue_start_date_to_creation_date = 1
1249
1247
1250 @request.session[:user_id] = 2
1248 @request.session[:user_id] = 2
1251 get :new, :project_id => 1, :tracker_id => 1
1249 get :new, :project_id => 1, :tracker_id => 1
1252 assert_response :success
1250 assert_response :success
1253 assert_template 'new'
1251 assert_template 'new'
1254
1252
1255 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1253 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1256 :value => Date.today.to_s }
1254 :value => Date.today.to_s }
1257 end
1255 end
1258
1256
1259 def test_get_new_form_should_allow_attachment_upload
1257 def test_get_new_form_should_allow_attachment_upload
1260 @request.session[:user_id] = 2
1258 @request.session[:user_id] = 2
1261 get :new, :project_id => 1, :tracker_id => 1
1259 get :new, :project_id => 1, :tracker_id => 1
1262
1260
1263 assert_tag :tag => 'form',
1261 assert_tag :tag => 'form',
1264 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1262 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1265 :descendant => {
1263 :descendant => {
1266 :tag => 'input',
1264 :tag => 'input',
1267 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1265 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1268 }
1266 }
1269 end
1267 end
1270
1268
1271 def test_get_new_without_tracker_id
1269 def test_get_new_without_tracker_id
1272 @request.session[:user_id] = 2
1270 @request.session[:user_id] = 2
1273 get :new, :project_id => 1
1271 get :new, :project_id => 1
1274 assert_response :success
1272 assert_response :success
1275 assert_template 'new'
1273 assert_template 'new'
1276
1274
1277 issue = assigns(:issue)
1275 issue = assigns(:issue)
1278 assert_not_nil issue
1276 assert_not_nil issue
1279 assert_equal Project.find(1).trackers.first, issue.tracker
1277 assert_equal Project.find(1).trackers.first, issue.tracker
1280 end
1278 end
1281
1279
1282 def test_get_new_with_no_default_status_should_display_an_error
1280 def test_get_new_with_no_default_status_should_display_an_error
1283 @request.session[:user_id] = 2
1281 @request.session[:user_id] = 2
1284 IssueStatus.delete_all
1282 IssueStatus.delete_all
1285
1283
1286 get :new, :project_id => 1
1284 get :new, :project_id => 1
1287 assert_response 500
1285 assert_response 500
1288 assert_error_tag :content => /No default issue/
1286 assert_error_tag :content => /No default issue/
1289 end
1287 end
1290
1288
1291 def test_get_new_with_no_tracker_should_display_an_error
1289 def test_get_new_with_no_tracker_should_display_an_error
1292 @request.session[:user_id] = 2
1290 @request.session[:user_id] = 2
1293 Tracker.delete_all
1291 Tracker.delete_all
1294
1292
1295 get :new, :project_id => 1
1293 get :new, :project_id => 1
1296 assert_response 500
1294 assert_response 500
1297 assert_error_tag :content => /No tracker/
1295 assert_error_tag :content => /No tracker/
1298 end
1296 end
1299
1297
1300 def test_update_new_form
1298 def test_update_new_form
1301 @request.session[:user_id] = 2
1299 @request.session[:user_id] = 2
1302 xhr :post, :new, :project_id => 1,
1300 xhr :post, :new, :project_id => 1,
1303 :issue => {:tracker_id => 2,
1301 :issue => {:tracker_id => 2,
1304 :subject => 'This is the test_new issue',
1302 :subject => 'This is the test_new issue',
1305 :description => 'This is the description',
1303 :description => 'This is the description',
1306 :priority_id => 5}
1304 :priority_id => 5}
1307 assert_response :success
1305 assert_response :success
1308 assert_template 'attributes'
1306 assert_template 'attributes'
1309
1307
1310 issue = assigns(:issue)
1308 issue = assigns(:issue)
1311 assert_kind_of Issue, issue
1309 assert_kind_of Issue, issue
1312 assert_equal 1, issue.project_id
1310 assert_equal 1, issue.project_id
1313 assert_equal 2, issue.tracker_id
1311 assert_equal 2, issue.tracker_id
1314 assert_equal 'This is the test_new issue', issue.subject
1312 assert_equal 'This is the test_new issue', issue.subject
1315 end
1313 end
1316
1314
1317 def test_post_create
1315 def test_post_create
1318 @request.session[:user_id] = 2
1316 @request.session[:user_id] = 2
1319 assert_difference 'Issue.count' do
1317 assert_difference 'Issue.count' do
1320 post :create, :project_id => 1,
1318 post :create, :project_id => 1,
1321 :issue => {:tracker_id => 3,
1319 :issue => {:tracker_id => 3,
1322 :status_id => 2,
1320 :status_id => 2,
1323 :subject => 'This is the test_new issue',
1321 :subject => 'This is the test_new issue',
1324 :description => 'This is the description',
1322 :description => 'This is the description',
1325 :priority_id => 5,
1323 :priority_id => 5,
1326 :start_date => '2010-11-07',
1324 :start_date => '2010-11-07',
1327 :estimated_hours => '',
1325 :estimated_hours => '',
1328 :custom_field_values => {'2' => 'Value for field 2'}}
1326 :custom_field_values => {'2' => 'Value for field 2'}}
1329 end
1327 end
1330 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1328 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1331
1329
1332 issue = Issue.find_by_subject('This is the test_new issue')
1330 issue = Issue.find_by_subject('This is the test_new issue')
1333 assert_not_nil issue
1331 assert_not_nil issue
1334 assert_equal 2, issue.author_id
1332 assert_equal 2, issue.author_id
1335 assert_equal 3, issue.tracker_id
1333 assert_equal 3, issue.tracker_id
1336 assert_equal 2, issue.status_id
1334 assert_equal 2, issue.status_id
1337 assert_equal Date.parse('2010-11-07'), issue.start_date
1335 assert_equal Date.parse('2010-11-07'), issue.start_date
1338 assert_nil issue.estimated_hours
1336 assert_nil issue.estimated_hours
1339 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1337 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1340 assert_not_nil v
1338 assert_not_nil v
1341 assert_equal 'Value for field 2', v.value
1339 assert_equal 'Value for field 2', v.value
1342 end
1340 end
1343
1341
1344 def test_post_new_with_group_assignment
1342 def test_post_new_with_group_assignment
1345 group = Group.find(11)
1343 group = Group.find(11)
1346 project = Project.find(1)
1344 project = Project.find(1)
1347 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1345 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1348
1346
1349 with_settings :issue_group_assignment => '1' do
1347 with_settings :issue_group_assignment => '1' do
1350 @request.session[:user_id] = 2
1348 @request.session[:user_id] = 2
1351 assert_difference 'Issue.count' do
1349 assert_difference 'Issue.count' do
1352 post :create, :project_id => project.id,
1350 post :create, :project_id => project.id,
1353 :issue => {:tracker_id => 3,
1351 :issue => {:tracker_id => 3,
1354 :status_id => 1,
1352 :status_id => 1,
1355 :subject => 'This is the test_new_with_group_assignment issue',
1353 :subject => 'This is the test_new_with_group_assignment issue',
1356 :assigned_to_id => group.id}
1354 :assigned_to_id => group.id}
1357 end
1355 end
1358 end
1356 end
1359 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1357 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1360
1358
1361 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1359 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1362 assert_not_nil issue
1360 assert_not_nil issue
1363 assert_equal group, issue.assigned_to
1361 assert_equal group, issue.assigned_to
1364 end
1362 end
1365
1363
1366 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1364 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1367 Setting.default_issue_start_date_to_creation_date = 0
1365 Setting.default_issue_start_date_to_creation_date = 0
1368
1366
1369 @request.session[:user_id] = 2
1367 @request.session[:user_id] = 2
1370 assert_difference 'Issue.count' do
1368 assert_difference 'Issue.count' do
1371 post :create, :project_id => 1,
1369 post :create, :project_id => 1,
1372 :issue => {:tracker_id => 3,
1370 :issue => {:tracker_id => 3,
1373 :status_id => 2,
1371 :status_id => 2,
1374 :subject => 'This is the test_new issue',
1372 :subject => 'This is the test_new issue',
1375 :description => 'This is the description',
1373 :description => 'This is the description',
1376 :priority_id => 5,
1374 :priority_id => 5,
1377 :estimated_hours => '',
1375 :estimated_hours => '',
1378 :custom_field_values => {'2' => 'Value for field 2'}}
1376 :custom_field_values => {'2' => 'Value for field 2'}}
1379 end
1377 end
1380 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1378 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1381
1379
1382 issue = Issue.find_by_subject('This is the test_new issue')
1380 issue = Issue.find_by_subject('This is the test_new issue')
1383 assert_not_nil issue
1381 assert_not_nil issue
1384 assert_nil issue.start_date
1382 assert_nil issue.start_date
1385 end
1383 end
1386
1384
1387 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1385 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1388 Setting.default_issue_start_date_to_creation_date = 1
1386 Setting.default_issue_start_date_to_creation_date = 1
1389
1387
1390 @request.session[:user_id] = 2
1388 @request.session[:user_id] = 2
1391 assert_difference 'Issue.count' do
1389 assert_difference 'Issue.count' do
1392 post :create, :project_id => 1,
1390 post :create, :project_id => 1,
1393 :issue => {:tracker_id => 3,
1391 :issue => {:tracker_id => 3,
1394 :status_id => 2,
1392 :status_id => 2,
1395 :subject => 'This is the test_new issue',
1393 :subject => 'This is the test_new issue',
1396 :description => 'This is the description',
1394 :description => 'This is the description',
1397 :priority_id => 5,
1395 :priority_id => 5,
1398 :estimated_hours => '',
1396 :estimated_hours => '',
1399 :custom_field_values => {'2' => 'Value for field 2'}}
1397 :custom_field_values => {'2' => 'Value for field 2'}}
1400 end
1398 end
1401 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1399 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1402
1400
1403 issue = Issue.find_by_subject('This is the test_new issue')
1401 issue = Issue.find_by_subject('This is the test_new issue')
1404 assert_not_nil issue
1402 assert_not_nil issue
1405 assert_equal Date.today, issue.start_date
1403 assert_equal Date.today, issue.start_date
1406 end
1404 end
1407
1405
1408 def test_post_create_and_continue
1406 def test_post_create_and_continue
1409 @request.session[:user_id] = 2
1407 @request.session[:user_id] = 2
1410 assert_difference 'Issue.count' do
1408 assert_difference 'Issue.count' do
1411 post :create, :project_id => 1,
1409 post :create, :project_id => 1,
1412 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1410 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1413 :continue => ''
1411 :continue => ''
1414 end
1412 end
1415
1413
1416 issue = Issue.first(:order => 'id DESC')
1414 issue = Issue.first(:order => 'id DESC')
1417 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1415 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1418 assert_not_nil flash[:notice], "flash was not set"
1416 assert_not_nil flash[:notice], "flash was not set"
1419 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1417 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1420 end
1418 end
1421
1419
1422 def test_post_create_without_custom_fields_param
1420 def test_post_create_without_custom_fields_param
1423 @request.session[:user_id] = 2
1421 @request.session[:user_id] = 2
1424 assert_difference 'Issue.count' do
1422 assert_difference 'Issue.count' do
1425 post :create, :project_id => 1,
1423 post :create, :project_id => 1,
1426 :issue => {:tracker_id => 1,
1424 :issue => {:tracker_id => 1,
1427 :subject => 'This is the test_new issue',
1425 :subject => 'This is the test_new issue',
1428 :description => 'This is the description',
1426 :description => 'This is the description',
1429 :priority_id => 5}
1427 :priority_id => 5}
1430 end
1428 end
1431 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1429 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1432 end
1430 end
1433
1431
1434 def test_post_create_with_multi_custom_field
1432 def test_post_create_with_multi_custom_field
1435 field = IssueCustomField.find_by_name('Database')
1433 field = IssueCustomField.find_by_name('Database')
1436 field.update_attribute(:multiple, true)
1434 field.update_attribute(:multiple, true)
1437
1435
1438 @request.session[:user_id] = 2
1436 @request.session[:user_id] = 2
1439 assert_difference 'Issue.count' do
1437 assert_difference 'Issue.count' do
1440 post :create, :project_id => 1,
1438 post :create, :project_id => 1,
1441 :issue => {:tracker_id => 1,
1439 :issue => {:tracker_id => 1,
1442 :subject => 'This is the test_new issue',
1440 :subject => 'This is the test_new issue',
1443 :description => 'This is the description',
1441 :description => 'This is the description',
1444 :priority_id => 5,
1442 :priority_id => 5,
1445 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1443 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1446 end
1444 end
1447 assert_response 302
1445 assert_response 302
1448 issue = Issue.first(:order => 'id DESC')
1446 issue = Issue.first(:order => 'id DESC')
1449 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1447 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1450 end
1448 end
1451
1449
1452 def test_post_create_with_empty_multi_custom_field
1450 def test_post_create_with_empty_multi_custom_field
1453 field = IssueCustomField.find_by_name('Database')
1451 field = IssueCustomField.find_by_name('Database')
1454 field.update_attribute(:multiple, true)
1452 field.update_attribute(:multiple, true)
1455
1453
1456 @request.session[:user_id] = 2
1454 @request.session[:user_id] = 2
1457 assert_difference 'Issue.count' do
1455 assert_difference 'Issue.count' do
1458 post :create, :project_id => 1,
1456 post :create, :project_id => 1,
1459 :issue => {:tracker_id => 1,
1457 :issue => {:tracker_id => 1,
1460 :subject => 'This is the test_new issue',
1458 :subject => 'This is the test_new issue',
1461 :description => 'This is the description',
1459 :description => 'This is the description',
1462 :priority_id => 5,
1460 :priority_id => 5,
1463 :custom_field_values => {'1' => ['']}}
1461 :custom_field_values => {'1' => ['']}}
1464 end
1462 end
1465 assert_response 302
1463 assert_response 302
1466 issue = Issue.first(:order => 'id DESC')
1464 issue = Issue.first(:order => 'id DESC')
1467 assert_equal [''], issue.custom_field_value(1).sort
1465 assert_equal [''], issue.custom_field_value(1).sort
1468 end
1466 end
1469
1467
1470 def test_post_create_with_multi_user_custom_field
1468 def test_post_create_with_multi_user_custom_field
1471 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1469 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1472 :tracker_ids => [1], :is_for_all => true)
1470 :tracker_ids => [1], :is_for_all => true)
1473
1471
1474 @request.session[:user_id] = 2
1472 @request.session[:user_id] = 2
1475 assert_difference 'Issue.count' do
1473 assert_difference 'Issue.count' do
1476 post :create, :project_id => 1,
1474 post :create, :project_id => 1,
1477 :issue => {:tracker_id => 1,
1475 :issue => {:tracker_id => 1,
1478 :subject => 'This is the test_new issue',
1476 :subject => 'This is the test_new issue',
1479 :description => 'This is the description',
1477 :description => 'This is the description',
1480 :priority_id => 5,
1478 :priority_id => 5,
1481 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1479 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1482 end
1480 end
1483 assert_response 302
1481 assert_response 302
1484 issue = Issue.first(:order => 'id DESC')
1482 issue = Issue.first(:order => 'id DESC')
1485 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1483 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1486 end
1484 end
1487
1485
1488 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1486 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1489 field = IssueCustomField.find_by_name('Database')
1487 field = IssueCustomField.find_by_name('Database')
1490 field.update_attribute(:is_required, true)
1488 field.update_attribute(:is_required, true)
1491
1489
1492 @request.session[:user_id] = 2
1490 @request.session[:user_id] = 2
1493 assert_no_difference 'Issue.count' do
1491 assert_no_difference 'Issue.count' do
1494 post :create, :project_id => 1,
1492 post :create, :project_id => 1,
1495 :issue => {:tracker_id => 1,
1493 :issue => {:tracker_id => 1,
1496 :subject => 'This is the test_new issue',
1494 :subject => 'This is the test_new issue',
1497 :description => 'This is the description',
1495 :description => 'This is the description',
1498 :priority_id => 5}
1496 :priority_id => 5}
1499 end
1497 end
1500 assert_response :success
1498 assert_response :success
1501 assert_template 'new'
1499 assert_template 'new'
1502 issue = assigns(:issue)
1500 issue = assigns(:issue)
1503 assert_not_nil issue
1501 assert_not_nil issue
1504 assert_error_tag :content => /Database can't be blank/
1502 assert_error_tag :content => /Database can't be blank/
1505 end
1503 end
1506
1504
1507 def test_post_create_with_watchers
1505 def test_post_create_with_watchers
1508 @request.session[:user_id] = 2
1506 @request.session[:user_id] = 2
1509 ActionMailer::Base.deliveries.clear
1507 ActionMailer::Base.deliveries.clear
1510
1508
1511 assert_difference 'Watcher.count', 2 do
1509 assert_difference 'Watcher.count', 2 do
1512 post :create, :project_id => 1,
1510 post :create, :project_id => 1,
1513 :issue => {:tracker_id => 1,
1511 :issue => {:tracker_id => 1,
1514 :subject => 'This is a new issue with watchers',
1512 :subject => 'This is a new issue with watchers',
1515 :description => 'This is the description',
1513 :description => 'This is the description',
1516 :priority_id => 5,
1514 :priority_id => 5,
1517 :watcher_user_ids => ['2', '3']}
1515 :watcher_user_ids => ['2', '3']}
1518 end
1516 end
1519 issue = Issue.find_by_subject('This is a new issue with watchers')
1517 issue = Issue.find_by_subject('This is a new issue with watchers')
1520 assert_not_nil issue
1518 assert_not_nil issue
1521 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1519 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1522
1520
1523 # Watchers added
1521 # Watchers added
1524 assert_equal [2, 3], issue.watcher_user_ids.sort
1522 assert_equal [2, 3], issue.watcher_user_ids.sort
1525 assert issue.watched_by?(User.find(3))
1523 assert issue.watched_by?(User.find(3))
1526 # Watchers notified
1524 # Watchers notified
1527 mail = ActionMailer::Base.deliveries.last
1525 mail = ActionMailer::Base.deliveries.last
1528 assert_not_nil mail
1526 assert_not_nil mail
1529 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1527 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1530 end
1528 end
1531
1529
1532 def test_post_create_subissue
1530 def test_post_create_subissue
1533 @request.session[:user_id] = 2
1531 @request.session[:user_id] = 2
1534
1532
1535 assert_difference 'Issue.count' do
1533 assert_difference 'Issue.count' do
1536 post :create, :project_id => 1,
1534 post :create, :project_id => 1,
1537 :issue => {:tracker_id => 1,
1535 :issue => {:tracker_id => 1,
1538 :subject => 'This is a child issue',
1536 :subject => 'This is a child issue',
1539 :parent_issue_id => 2}
1537 :parent_issue_id => 2}
1540 end
1538 end
1541 issue = Issue.find_by_subject('This is a child issue')
1539 issue = Issue.find_by_subject('This is a child issue')
1542 assert_not_nil issue
1540 assert_not_nil issue
1543 assert_equal Issue.find(2), issue.parent
1541 assert_equal Issue.find(2), issue.parent
1544 end
1542 end
1545
1543
1546 def test_post_create_subissue_with_non_numeric_parent_id
1544 def test_post_create_subissue_with_non_numeric_parent_id
1547 @request.session[:user_id] = 2
1545 @request.session[:user_id] = 2
1548
1546
1549 assert_difference 'Issue.count' do
1547 assert_difference 'Issue.count' do
1550 post :create, :project_id => 1,
1548 post :create, :project_id => 1,
1551 :issue => {:tracker_id => 1,
1549 :issue => {:tracker_id => 1,
1552 :subject => 'This is a child issue',
1550 :subject => 'This is a child issue',
1553 :parent_issue_id => 'ABC'}
1551 :parent_issue_id => 'ABC'}
1554 end
1552 end
1555 issue = Issue.find_by_subject('This is a child issue')
1553 issue = Issue.find_by_subject('This is a child issue')
1556 assert_not_nil issue
1554 assert_not_nil issue
1557 assert_nil issue.parent
1555 assert_nil issue.parent
1558 end
1556 end
1559
1557
1560 def test_post_create_private
1558 def test_post_create_private
1561 @request.session[:user_id] = 2
1559 @request.session[:user_id] = 2
1562
1560
1563 assert_difference 'Issue.count' do
1561 assert_difference 'Issue.count' do
1564 post :create, :project_id => 1,
1562 post :create, :project_id => 1,
1565 :issue => {:tracker_id => 1,
1563 :issue => {:tracker_id => 1,
1566 :subject => 'This is a private issue',
1564 :subject => 'This is a private issue',
1567 :is_private => '1'}
1565 :is_private => '1'}
1568 end
1566 end
1569 issue = Issue.first(:order => 'id DESC')
1567 issue = Issue.first(:order => 'id DESC')
1570 assert issue.is_private?
1568 assert issue.is_private?
1571 end
1569 end
1572
1570
1573 def test_post_create_private_with_set_own_issues_private_permission
1571 def test_post_create_private_with_set_own_issues_private_permission
1574 role = Role.find(1)
1572 role = Role.find(1)
1575 role.remove_permission! :set_issues_private
1573 role.remove_permission! :set_issues_private
1576 role.add_permission! :set_own_issues_private
1574 role.add_permission! :set_own_issues_private
1577
1575
1578 @request.session[:user_id] = 2
1576 @request.session[:user_id] = 2
1579
1577
1580 assert_difference 'Issue.count' do
1578 assert_difference 'Issue.count' do
1581 post :create, :project_id => 1,
1579 post :create, :project_id => 1,
1582 :issue => {:tracker_id => 1,
1580 :issue => {:tracker_id => 1,
1583 :subject => 'This is a private issue',
1581 :subject => 'This is a private issue',
1584 :is_private => '1'}
1582 :is_private => '1'}
1585 end
1583 end
1586 issue = Issue.first(:order => 'id DESC')
1584 issue = Issue.first(:order => 'id DESC')
1587 assert issue.is_private?
1585 assert issue.is_private?
1588 end
1586 end
1589
1587
1590 def test_post_create_should_send_a_notification
1588 def test_post_create_should_send_a_notification
1591 ActionMailer::Base.deliveries.clear
1589 ActionMailer::Base.deliveries.clear
1592 @request.session[:user_id] = 2
1590 @request.session[:user_id] = 2
1593 assert_difference 'Issue.count' do
1591 assert_difference 'Issue.count' do
1594 post :create, :project_id => 1,
1592 post :create, :project_id => 1,
1595 :issue => {:tracker_id => 3,
1593 :issue => {:tracker_id => 3,
1596 :subject => 'This is the test_new issue',
1594 :subject => 'This is the test_new issue',
1597 :description => 'This is the description',
1595 :description => 'This is the description',
1598 :priority_id => 5,
1596 :priority_id => 5,
1599 :estimated_hours => '',
1597 :estimated_hours => '',
1600 :custom_field_values => {'2' => 'Value for field 2'}}
1598 :custom_field_values => {'2' => 'Value for field 2'}}
1601 end
1599 end
1602 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1600 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1603
1601
1604 assert_equal 1, ActionMailer::Base.deliveries.size
1602 assert_equal 1, ActionMailer::Base.deliveries.size
1605 end
1603 end
1606
1604
1607 def test_post_create_should_preserve_fields_values_on_validation_failure
1605 def test_post_create_should_preserve_fields_values_on_validation_failure
1608 @request.session[:user_id] = 2
1606 @request.session[:user_id] = 2
1609 post :create, :project_id => 1,
1607 post :create, :project_id => 1,
1610 :issue => {:tracker_id => 1,
1608 :issue => {:tracker_id => 1,
1611 # empty subject
1609 # empty subject
1612 :subject => '',
1610 :subject => '',
1613 :description => 'This is a description',
1611 :description => 'This is a description',
1614 :priority_id => 6,
1612 :priority_id => 6,
1615 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1613 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1616 assert_response :success
1614 assert_response :success
1617 assert_template 'new'
1615 assert_template 'new'
1618
1616
1619 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1617 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1620 :content => 'This is a description'
1618 :content => 'This is a description'
1621 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1619 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1622 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1620 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1623 :value => '6' },
1621 :value => '6' },
1624 :content => 'High' }
1622 :content => 'High' }
1625 # Custom fields
1623 # Custom fields
1626 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1624 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1627 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1625 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1628 :value => 'Oracle' },
1626 :value => 'Oracle' },
1629 :content => 'Oracle' }
1627 :content => 'Oracle' }
1630 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1628 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1631 :value => 'Value for field 2'}
1629 :value => 'Value for field 2'}
1632 end
1630 end
1633
1631
1634 def test_post_create_should_ignore_non_safe_attributes
1632 def test_post_create_should_ignore_non_safe_attributes
1635 @request.session[:user_id] = 2
1633 @request.session[:user_id] = 2
1636 assert_nothing_raised do
1634 assert_nothing_raised do
1637 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1635 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1638 end
1636 end
1639 end
1637 end
1640
1638
1641 def test_post_create_with_attachment
1639 def test_post_create_with_attachment
1642 set_tmp_attachments_directory
1640 set_tmp_attachments_directory
1643 @request.session[:user_id] = 2
1641 @request.session[:user_id] = 2
1644
1642
1645 assert_difference 'Issue.count' do
1643 assert_difference 'Issue.count' do
1646 assert_difference 'Attachment.count' do
1644 assert_difference 'Attachment.count' do
1647 post :create, :project_id => 1,
1645 post :create, :project_id => 1,
1648 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1646 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1649 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1647 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1650 end
1648 end
1651 end
1649 end
1652
1650
1653 issue = Issue.first(:order => 'id DESC')
1651 issue = Issue.first(:order => 'id DESC')
1654 attachment = Attachment.first(:order => 'id DESC')
1652 attachment = Attachment.first(:order => 'id DESC')
1655
1653
1656 assert_equal issue, attachment.container
1654 assert_equal issue, attachment.container
1657 assert_equal 2, attachment.author_id
1655 assert_equal 2, attachment.author_id
1658 assert_equal 'testfile.txt', attachment.filename
1656 assert_equal 'testfile.txt', attachment.filename
1659 assert_equal 'text/plain', attachment.content_type
1657 assert_equal 'text/plain', attachment.content_type
1660 assert_equal 'test file', attachment.description
1658 assert_equal 'test file', attachment.description
1661 assert_equal 59, attachment.filesize
1659 assert_equal 59, attachment.filesize
1662 assert File.exists?(attachment.diskfile)
1660 assert File.exists?(attachment.diskfile)
1663 assert_equal 59, File.size(attachment.diskfile)
1661 assert_equal 59, File.size(attachment.diskfile)
1664 end
1662 end
1665
1663
1666 def test_post_create_with_failure_should_save_attachments
1664 def test_post_create_with_failure_should_save_attachments
1667 set_tmp_attachments_directory
1665 set_tmp_attachments_directory
1668 @request.session[:user_id] = 2
1666 @request.session[:user_id] = 2
1669
1667
1670 assert_no_difference 'Issue.count' do
1668 assert_no_difference 'Issue.count' do
1671 assert_difference 'Attachment.count' do
1669 assert_difference 'Attachment.count' do
1672 post :create, :project_id => 1,
1670 post :create, :project_id => 1,
1673 :issue => { :tracker_id => '1', :subject => '' },
1671 :issue => { :tracker_id => '1', :subject => '' },
1674 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1672 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1675 assert_response :success
1673 assert_response :success
1676 assert_template 'new'
1674 assert_template 'new'
1677 end
1675 end
1678 end
1676 end
1679
1677
1680 attachment = Attachment.first(:order => 'id DESC')
1678 attachment = Attachment.first(:order => 'id DESC')
1681 assert_equal 'testfile.txt', attachment.filename
1679 assert_equal 'testfile.txt', attachment.filename
1682 assert File.exists?(attachment.diskfile)
1680 assert File.exists?(attachment.diskfile)
1683 assert_nil attachment.container
1681 assert_nil attachment.container
1684
1682
1685 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1683 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1686 assert_tag 'span', :content => /testfile.txt/
1684 assert_tag 'span', :content => /testfile.txt/
1687 end
1685 end
1688
1686
1689 def test_post_create_with_failure_should_keep_saved_attachments
1687 def test_post_create_with_failure_should_keep_saved_attachments
1690 set_tmp_attachments_directory
1688 set_tmp_attachments_directory
1691 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1689 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1692 @request.session[:user_id] = 2
1690 @request.session[:user_id] = 2
1693
1691
1694 assert_no_difference 'Issue.count' do
1692 assert_no_difference 'Issue.count' do
1695 assert_no_difference 'Attachment.count' do
1693 assert_no_difference 'Attachment.count' do
1696 post :create, :project_id => 1,
1694 post :create, :project_id => 1,
1697 :issue => { :tracker_id => '1', :subject => '' },
1695 :issue => { :tracker_id => '1', :subject => '' },
1698 :attachments => {'p0' => {'token' => attachment.token}}
1696 :attachments => {'p0' => {'token' => attachment.token}}
1699 assert_response :success
1697 assert_response :success
1700 assert_template 'new'
1698 assert_template 'new'
1701 end
1699 end
1702 end
1700 end
1703
1701
1704 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1702 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1705 assert_tag 'span', :content => /testfile.txt/
1703 assert_tag 'span', :content => /testfile.txt/
1706 end
1704 end
1707
1705
1708 def test_post_create_should_attach_saved_attachments
1706 def test_post_create_should_attach_saved_attachments
1709 set_tmp_attachments_directory
1707 set_tmp_attachments_directory
1710 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1708 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1711 @request.session[:user_id] = 2
1709 @request.session[:user_id] = 2
1712
1710
1713 assert_difference 'Issue.count' do
1711 assert_difference 'Issue.count' do
1714 assert_no_difference 'Attachment.count' do
1712 assert_no_difference 'Attachment.count' do
1715 post :create, :project_id => 1,
1713 post :create, :project_id => 1,
1716 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
1714 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
1717 :attachments => {'p0' => {'token' => attachment.token}}
1715 :attachments => {'p0' => {'token' => attachment.token}}
1718 assert_response 302
1716 assert_response 302
1719 end
1717 end
1720 end
1718 end
1721
1719
1722 issue = Issue.first(:order => 'id DESC')
1720 issue = Issue.first(:order => 'id DESC')
1723 assert_equal 1, issue.attachments.count
1721 assert_equal 1, issue.attachments.count
1724
1722
1725 attachment.reload
1723 attachment.reload
1726 assert_equal issue, attachment.container
1724 assert_equal issue, attachment.container
1727 end
1725 end
1728
1726
1729 context "without workflow privilege" do
1727 context "without workflow privilege" do
1730 setup do
1728 setup do
1731 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1729 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1732 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1730 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1733 end
1731 end
1734
1732
1735 context "#new" do
1733 context "#new" do
1736 should "propose default status only" do
1734 should "propose default status only" do
1737 get :new, :project_id => 1
1735 get :new, :project_id => 1
1738 assert_response :success
1736 assert_response :success
1739 assert_template 'new'
1737 assert_template 'new'
1740 assert_tag :tag => 'select',
1738 assert_tag :tag => 'select',
1741 :attributes => {:name => 'issue[status_id]'},
1739 :attributes => {:name => 'issue[status_id]'},
1742 :children => {:count => 1},
1740 :children => {:count => 1},
1743 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1741 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1744 end
1742 end
1745
1743
1746 should "accept default status" do
1744 should "accept default status" do
1747 assert_difference 'Issue.count' do
1745 assert_difference 'Issue.count' do
1748 post :create, :project_id => 1,
1746 post :create, :project_id => 1,
1749 :issue => {:tracker_id => 1,
1747 :issue => {:tracker_id => 1,
1750 :subject => 'This is an issue',
1748 :subject => 'This is an issue',
1751 :status_id => 1}
1749 :status_id => 1}
1752 end
1750 end
1753 issue = Issue.last(:order => 'id')
1751 issue = Issue.last(:order => 'id')
1754 assert_equal IssueStatus.default, issue.status
1752 assert_equal IssueStatus.default, issue.status
1755 end
1753 end
1756
1754
1757 should "ignore unauthorized status" do
1755 should "ignore unauthorized status" do
1758 assert_difference 'Issue.count' do
1756 assert_difference 'Issue.count' do
1759 post :create, :project_id => 1,
1757 post :create, :project_id => 1,
1760 :issue => {:tracker_id => 1,
1758 :issue => {:tracker_id => 1,
1761 :subject => 'This is an issue',
1759 :subject => 'This is an issue',
1762 :status_id => 3}
1760 :status_id => 3}
1763 end
1761 end
1764 issue = Issue.last(:order => 'id')
1762 issue = Issue.last(:order => 'id')
1765 assert_equal IssueStatus.default, issue.status
1763 assert_equal IssueStatus.default, issue.status
1766 end
1764 end
1767 end
1765 end
1768
1766
1769 context "#update" do
1767 context "#update" do
1770 should "ignore status change" do
1768 should "ignore status change" do
1771 assert_difference 'Journal.count' do
1769 assert_difference 'Journal.count' do
1772 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1770 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1773 end
1771 end
1774 assert_equal 1, Issue.find(1).status_id
1772 assert_equal 1, Issue.find(1).status_id
1775 end
1773 end
1776
1774
1777 should "ignore attributes changes" do
1775 should "ignore attributes changes" do
1778 assert_difference 'Journal.count' do
1776 assert_difference 'Journal.count' do
1779 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1777 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1780 end
1778 end
1781 issue = Issue.find(1)
1779 issue = Issue.find(1)
1782 assert_equal "Can't print recipes", issue.subject
1780 assert_equal "Can't print recipes", issue.subject
1783 assert_nil issue.assigned_to
1781 assert_nil issue.assigned_to
1784 end
1782 end
1785 end
1783 end
1786 end
1784 end
1787
1785
1788 context "with workflow privilege" do
1786 context "with workflow privilege" do
1789 setup do
1787 setup do
1790 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1788 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1791 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1789 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1792 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1790 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1793 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1791 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1794 end
1792 end
1795
1793
1796 context "#update" do
1794 context "#update" do
1797 should "accept authorized status" do
1795 should "accept authorized status" do
1798 assert_difference 'Journal.count' do
1796 assert_difference 'Journal.count' do
1799 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1797 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1800 end
1798 end
1801 assert_equal 3, Issue.find(1).status_id
1799 assert_equal 3, Issue.find(1).status_id
1802 end
1800 end
1803
1801
1804 should "ignore unauthorized status" do
1802 should "ignore unauthorized status" do
1805 assert_difference 'Journal.count' do
1803 assert_difference 'Journal.count' do
1806 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1804 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1807 end
1805 end
1808 assert_equal 1, Issue.find(1).status_id
1806 assert_equal 1, Issue.find(1).status_id
1809 end
1807 end
1810
1808
1811 should "accept authorized attributes changes" do
1809 should "accept authorized attributes changes" do
1812 assert_difference 'Journal.count' do
1810 assert_difference 'Journal.count' do
1813 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1811 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1814 end
1812 end
1815 issue = Issue.find(1)
1813 issue = Issue.find(1)
1816 assert_equal 2, issue.assigned_to_id
1814 assert_equal 2, issue.assigned_to_id
1817 end
1815 end
1818
1816
1819 should "ignore unauthorized attributes changes" do
1817 should "ignore unauthorized attributes changes" do
1820 assert_difference 'Journal.count' do
1818 assert_difference 'Journal.count' do
1821 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1819 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1822 end
1820 end
1823 issue = Issue.find(1)
1821 issue = Issue.find(1)
1824 assert_equal "Can't print recipes", issue.subject
1822 assert_equal "Can't print recipes", issue.subject
1825 end
1823 end
1826 end
1824 end
1827
1825
1828 context "and :edit_issues permission" do
1826 context "and :edit_issues permission" do
1829 setup do
1827 setup do
1830 Role.anonymous.add_permission! :add_issues, :edit_issues
1828 Role.anonymous.add_permission! :add_issues, :edit_issues
1831 end
1829 end
1832
1830
1833 should "accept authorized status" do
1831 should "accept authorized status" do
1834 assert_difference 'Journal.count' do
1832 assert_difference 'Journal.count' do
1835 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1833 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1836 end
1834 end
1837 assert_equal 3, Issue.find(1).status_id
1835 assert_equal 3, Issue.find(1).status_id
1838 end
1836 end
1839
1837
1840 should "ignore unauthorized status" do
1838 should "ignore unauthorized status" do
1841 assert_difference 'Journal.count' do
1839 assert_difference 'Journal.count' do
1842 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1840 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1843 end
1841 end
1844 assert_equal 1, Issue.find(1).status_id
1842 assert_equal 1, Issue.find(1).status_id
1845 end
1843 end
1846
1844
1847 should "accept authorized attributes changes" do
1845 should "accept authorized attributes changes" do
1848 assert_difference 'Journal.count' do
1846 assert_difference 'Journal.count' do
1849 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1847 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1850 end
1848 end
1851 issue = Issue.find(1)
1849 issue = Issue.find(1)
1852 assert_equal "changed", issue.subject
1850 assert_equal "changed", issue.subject
1853 assert_equal 2, issue.assigned_to_id
1851 assert_equal 2, issue.assigned_to_id
1854 end
1852 end
1855 end
1853 end
1856 end
1854 end
1857
1855
1858 def test_new_as_copy
1856 def test_new_as_copy
1859 @request.session[:user_id] = 2
1857 @request.session[:user_id] = 2
1860 get :new, :project_id => 1, :copy_from => 1
1858 get :new, :project_id => 1, :copy_from => 1
1861
1859
1862 assert_response :success
1860 assert_response :success
1863 assert_template 'new'
1861 assert_template 'new'
1864
1862
1865 assert_not_nil assigns(:issue)
1863 assert_not_nil assigns(:issue)
1866 orig = Issue.find(1)
1864 orig = Issue.find(1)
1867 assert_equal 1, assigns(:issue).project_id
1865 assert_equal 1, assigns(:issue).project_id
1868 assert_equal orig.subject, assigns(:issue).subject
1866 assert_equal orig.subject, assigns(:issue).subject
1869 assert assigns(:issue).copy?
1867 assert assigns(:issue).copy?
1870
1868
1871 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1869 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1872 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1870 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1873 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1871 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1874 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1872 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1875 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1873 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1876 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1874 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1877 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1875 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1878 end
1876 end
1879
1877
1880 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1878 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1881 @request.session[:user_id] = 2
1879 @request.session[:user_id] = 2
1882 issue = Issue.find(3)
1880 issue = Issue.find(3)
1883 assert issue.attachments.count > 0
1881 assert issue.attachments.count > 0
1884 get :new, :project_id => 1, :copy_from => 3
1882 get :new, :project_id => 1, :copy_from => 3
1885
1883
1886 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1884 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1887 end
1885 end
1888
1886
1889 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1887 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1890 @request.session[:user_id] = 2
1888 @request.session[:user_id] = 2
1891 issue = Issue.find(3)
1889 issue = Issue.find(3)
1892 issue.attachments.delete_all
1890 issue.attachments.delete_all
1893 get :new, :project_id => 1, :copy_from => 3
1891 get :new, :project_id => 1, :copy_from => 3
1894
1892
1895 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1893 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1896 end
1894 end
1897
1895
1898 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1896 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1899 @request.session[:user_id] = 2
1897 @request.session[:user_id] = 2
1900 get :new, :project_id => 1, :copy_from => 99999
1898 get :new, :project_id => 1, :copy_from => 99999
1901 assert_response 404
1899 assert_response 404
1902 end
1900 end
1903
1901
1904 def test_create_as_copy_on_different_project
1902 def test_create_as_copy_on_different_project
1905 @request.session[:user_id] = 2
1903 @request.session[:user_id] = 2
1906 assert_difference 'Issue.count' do
1904 assert_difference 'Issue.count' do
1907 post :create, :project_id => 1, :copy_from => 1,
1905 post :create, :project_id => 1, :copy_from => 1,
1908 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1906 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1909
1907
1910 assert_not_nil assigns(:issue)
1908 assert_not_nil assigns(:issue)
1911 assert assigns(:issue).copy?
1909 assert assigns(:issue).copy?
1912 end
1910 end
1913 issue = Issue.first(:order => 'id DESC')
1911 issue = Issue.first(:order => 'id DESC')
1914 assert_redirected_to "/issues/#{issue.id}"
1912 assert_redirected_to "/issues/#{issue.id}"
1915
1913
1916 assert_equal 2, issue.project_id
1914 assert_equal 2, issue.project_id
1917 assert_equal 3, issue.tracker_id
1915 assert_equal 3, issue.tracker_id
1918 assert_equal 'Copy', issue.subject
1916 assert_equal 'Copy', issue.subject
1919 end
1917 end
1920
1918
1921 def test_create_as_copy_should_copy_attachments
1919 def test_create_as_copy_should_copy_attachments
1922 @request.session[:user_id] = 2
1920 @request.session[:user_id] = 2
1923 issue = Issue.find(3)
1921 issue = Issue.find(3)
1924 count = issue.attachments.count
1922 count = issue.attachments.count
1925 assert count > 0
1923 assert count > 0
1926
1924
1927 assert_difference 'Issue.count' do
1925 assert_difference 'Issue.count' do
1928 assert_difference 'Attachment.count', count do
1926 assert_difference 'Attachment.count', count do
1929 assert_no_difference 'Journal.count' do
1927 assert_no_difference 'Journal.count' do
1930 post :create, :project_id => 1, :copy_from => 3,
1928 post :create, :project_id => 1, :copy_from => 3,
1931 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1929 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1932 :copy_attachments => '1'
1930 :copy_attachments => '1'
1933 end
1931 end
1934 end
1932 end
1935 end
1933 end
1936 copy = Issue.first(:order => 'id DESC')
1934 copy = Issue.first(:order => 'id DESC')
1937 assert_equal count, copy.attachments.count
1935 assert_equal count, copy.attachments.count
1938 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
1936 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
1939 end
1937 end
1940
1938
1941 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
1939 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
1942 @request.session[:user_id] = 2
1940 @request.session[:user_id] = 2
1943 issue = Issue.find(3)
1941 issue = Issue.find(3)
1944 count = issue.attachments.count
1942 count = issue.attachments.count
1945 assert count > 0
1943 assert count > 0
1946
1944
1947 assert_difference 'Issue.count' do
1945 assert_difference 'Issue.count' do
1948 assert_no_difference 'Attachment.count' do
1946 assert_no_difference 'Attachment.count' do
1949 assert_no_difference 'Journal.count' do
1947 assert_no_difference 'Journal.count' do
1950 post :create, :project_id => 1, :copy_from => 3,
1948 post :create, :project_id => 1, :copy_from => 3,
1951 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
1949 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
1952 end
1950 end
1953 end
1951 end
1954 end
1952 end
1955 copy = Issue.first(:order => 'id DESC')
1953 copy = Issue.first(:order => 'id DESC')
1956 assert_equal 0, copy.attachments.count
1954 assert_equal 0, copy.attachments.count
1957 end
1955 end
1958
1956
1959 def test_create_as_copy_with_attachments_should_add_new_files
1957 def test_create_as_copy_with_attachments_should_add_new_files
1960 @request.session[:user_id] = 2
1958 @request.session[:user_id] = 2
1961 issue = Issue.find(3)
1959 issue = Issue.find(3)
1962 count = issue.attachments.count
1960 count = issue.attachments.count
1963 assert count > 0
1961 assert count > 0
1964
1962
1965 assert_difference 'Issue.count' do
1963 assert_difference 'Issue.count' do
1966 assert_difference 'Attachment.count', count + 1 do
1964 assert_difference 'Attachment.count', count + 1 do
1967 assert_no_difference 'Journal.count' do
1965 assert_no_difference 'Journal.count' do
1968 post :create, :project_id => 1, :copy_from => 3,
1966 post :create, :project_id => 1, :copy_from => 3,
1969 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1967 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1970 :copy_attachments => '1',
1968 :copy_attachments => '1',
1971 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1969 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1972 end
1970 end
1973 end
1971 end
1974 end
1972 end
1975 copy = Issue.first(:order => 'id DESC')
1973 copy = Issue.first(:order => 'id DESC')
1976 assert_equal count + 1, copy.attachments.count
1974 assert_equal count + 1, copy.attachments.count
1977 end
1975 end
1978
1976
1979 def test_create_as_copy_with_failure
1977 def test_create_as_copy_with_failure
1980 @request.session[:user_id] = 2
1978 @request.session[:user_id] = 2
1981 post :create, :project_id => 1, :copy_from => 1,
1979 post :create, :project_id => 1, :copy_from => 1,
1982 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
1980 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
1983
1981
1984 assert_response :success
1982 assert_response :success
1985 assert_template 'new'
1983 assert_template 'new'
1986
1984
1987 assert_not_nil assigns(:issue)
1985 assert_not_nil assigns(:issue)
1988 assert assigns(:issue).copy?
1986 assert assigns(:issue).copy?
1989
1987
1990 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1988 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1991 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1989 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1992 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1990 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1993 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
1991 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
1994 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1992 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1995 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
1993 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
1996 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1994 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1997 end
1995 end
1998
1996
1999 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
1997 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2000 @request.session[:user_id] = 2
1998 @request.session[:user_id] = 2
2001 assert !User.find(2).member_of?(Project.find(4))
1999 assert !User.find(2).member_of?(Project.find(4))
2002
2000
2003 assert_difference 'Issue.count' do
2001 assert_difference 'Issue.count' do
2004 post :create, :project_id => 1, :copy_from => 1,
2002 post :create, :project_id => 1, :copy_from => 1,
2005 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2003 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2006 end
2004 end
2007 issue = Issue.first(:order => 'id DESC')
2005 issue = Issue.first(:order => 'id DESC')
2008 assert_equal 1, issue.project_id
2006 assert_equal 1, issue.project_id
2009 end
2007 end
2010
2008
2011 def test_get_edit
2009 def test_get_edit
2012 @request.session[:user_id] = 2
2010 @request.session[:user_id] = 2
2013 get :edit, :id => 1
2011 get :edit, :id => 1
2014 assert_response :success
2012 assert_response :success
2015 assert_template 'edit'
2013 assert_template 'edit'
2016 assert_not_nil assigns(:issue)
2014 assert_not_nil assigns(:issue)
2017 assert_equal Issue.find(1), assigns(:issue)
2015 assert_equal Issue.find(1), assigns(:issue)
2018
2016
2019 # Be sure we don't display inactive IssuePriorities
2017 # Be sure we don't display inactive IssuePriorities
2020 assert ! IssuePriority.find(15).active?
2018 assert ! IssuePriority.find(15).active?
2021 assert_no_tag :option, :attributes => {:value => '15'},
2019 assert_no_tag :option, :attributes => {:value => '15'},
2022 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2020 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2023 end
2021 end
2024
2022
2025 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2023 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2026 @request.session[:user_id] = 2
2024 @request.session[:user_id] = 2
2027 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2025 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2028
2026
2029 get :edit, :id => 1
2027 get :edit, :id => 1
2030 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2028 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2031 end
2029 end
2032
2030
2033 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2031 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2034 @request.session[:user_id] = 2
2032 @request.session[:user_id] = 2
2035 Role.find_by_name('Manager').remove_permission! :log_time
2033 Role.find_by_name('Manager').remove_permission! :log_time
2036
2034
2037 get :edit, :id => 1
2035 get :edit, :id => 1
2038 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2036 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2039 end
2037 end
2040
2038
2041 def test_get_edit_with_params
2039 def test_get_edit_with_params
2042 @request.session[:user_id] = 2
2040 @request.session[:user_id] = 2
2043 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2041 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2044 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2042 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2045 assert_response :success
2043 assert_response :success
2046 assert_template 'edit'
2044 assert_template 'edit'
2047
2045
2048 issue = assigns(:issue)
2046 issue = assigns(:issue)
2049 assert_not_nil issue
2047 assert_not_nil issue
2050
2048
2051 assert_equal 5, issue.status_id
2049 assert_equal 5, issue.status_id
2052 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2050 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2053 :child => { :tag => 'option',
2051 :child => { :tag => 'option',
2054 :content => 'Closed',
2052 :content => 'Closed',
2055 :attributes => { :selected => 'selected' } }
2053 :attributes => { :selected => 'selected' } }
2056
2054
2057 assert_equal 7, issue.priority_id
2055 assert_equal 7, issue.priority_id
2058 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2056 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2059 :child => { :tag => 'option',
2057 :child => { :tag => 'option',
2060 :content => 'Urgent',
2058 :content => 'Urgent',
2061 :attributes => { :selected => 'selected' } }
2059 :attributes => { :selected => 'selected' } }
2062
2060
2063 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2061 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2064 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2062 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2065 :child => { :tag => 'option',
2063 :child => { :tag => 'option',
2066 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2064 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2067 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2065 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2068 end
2066 end
2069
2067
2070 def test_get_edit_with_multi_custom_field
2068 def test_get_edit_with_multi_custom_field
2071 field = CustomField.find(1)
2069 field = CustomField.find(1)
2072 field.update_attribute :multiple, true
2070 field.update_attribute :multiple, true
2073 issue = Issue.find(1)
2071 issue = Issue.find(1)
2074 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2072 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2075 issue.save!
2073 issue.save!
2076
2074
2077 @request.session[:user_id] = 2
2075 @request.session[:user_id] = 2
2078 get :edit, :id => 1
2076 get :edit, :id => 1
2079 assert_response :success
2077 assert_response :success
2080 assert_template 'edit'
2078 assert_template 'edit'
2081
2079
2082 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2080 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2083 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2081 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2084 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2082 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2085 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2083 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2086 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2084 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2087 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2085 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2088 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2086 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2089 end
2087 end
2090
2088
2091 def test_update_edit_form
2089 def test_update_edit_form
2092 @request.session[:user_id] = 2
2090 @request.session[:user_id] = 2
2093 xhr :put, :new, :project_id => 1,
2091 xhr :put, :new, :project_id => 1,
2094 :id => 1,
2092 :id => 1,
2095 :issue => {:tracker_id => 2,
2093 :issue => {:tracker_id => 2,
2096 :subject => 'This is the test_new issue',
2094 :subject => 'This is the test_new issue',
2097 :description => 'This is the description',
2095 :description => 'This is the description',
2098 :priority_id => 5}
2096 :priority_id => 5}
2099 assert_response :success
2097 assert_response :success
2100 assert_template 'attributes'
2098 assert_template 'attributes'
2101
2099
2102 issue = assigns(:issue)
2100 issue = assigns(:issue)
2103 assert_kind_of Issue, issue
2101 assert_kind_of Issue, issue
2104 assert_equal 1, issue.id
2102 assert_equal 1, issue.id
2105 assert_equal 1, issue.project_id
2103 assert_equal 1, issue.project_id
2106 assert_equal 2, issue.tracker_id
2104 assert_equal 2, issue.tracker_id
2107 assert_equal 'This is the test_new issue', issue.subject
2105 assert_equal 'This is the test_new issue', issue.subject
2108 end
2106 end
2109
2107
2110 def test_update_edit_form_with_project_change
2108 def test_update_edit_form_with_project_change
2111 @request.session[:user_id] = 2
2109 @request.session[:user_id] = 2
2112 xhr :put, :new, :project_id => 1,
2110 xhr :put, :new, :project_id => 1,
2113 :id => 1,
2111 :id => 1,
2114 :project_change => '1',
2112 :project_change => '1',
2115 :issue => {:project_id => 2,
2113 :issue => {:project_id => 2,
2116 :tracker_id => 2,
2114 :tracker_id => 2,
2117 :subject => 'This is the test_new issue',
2115 :subject => 'This is the test_new issue',
2118 :description => 'This is the description',
2116 :description => 'This is the description',
2119 :priority_id => 5}
2117 :priority_id => 5}
2120 assert_response :success
2118 assert_response :success
2121 assert_template 'form'
2119 assert_template 'form'
2122
2120
2123 issue = assigns(:issue)
2121 issue = assigns(:issue)
2124 assert_kind_of Issue, issue
2122 assert_kind_of Issue, issue
2125 assert_equal 1, issue.id
2123 assert_equal 1, issue.id
2126 assert_equal 2, issue.project_id
2124 assert_equal 2, issue.project_id
2127 assert_equal 2, issue.tracker_id
2125 assert_equal 2, issue.tracker_id
2128 assert_equal 'This is the test_new issue', issue.subject
2126 assert_equal 'This is the test_new issue', issue.subject
2129 end
2127 end
2130
2128
2131 def test_update_using_invalid_http_verbs
2129 def test_update_using_invalid_http_verbs
2132 @request.session[:user_id] = 2
2130 @request.session[:user_id] = 2
2133 subject = 'Updated by an invalid http verb'
2131 subject = 'Updated by an invalid http verb'
2134
2132
2135 get :update, :id => 1, :issue => {:subject => subject}
2133 get :update, :id => 1, :issue => {:subject => subject}
2136 assert_not_equal subject, Issue.find(1).subject
2134 assert_not_equal subject, Issue.find(1).subject
2137
2135
2138 post :update, :id => 1, :issue => {:subject => subject}
2136 post :update, :id => 1, :issue => {:subject => subject}
2139 assert_not_equal subject, Issue.find(1).subject
2137 assert_not_equal subject, Issue.find(1).subject
2140
2138
2141 delete :update, :id => 1, :issue => {:subject => subject}
2139 delete :update, :id => 1, :issue => {:subject => subject}
2142 assert_not_equal subject, Issue.find(1).subject
2140 assert_not_equal subject, Issue.find(1).subject
2143 end
2141 end
2144
2142
2145 def test_put_update_without_custom_fields_param
2143 def test_put_update_without_custom_fields_param
2146 @request.session[:user_id] = 2
2144 @request.session[:user_id] = 2
2147 ActionMailer::Base.deliveries.clear
2145 ActionMailer::Base.deliveries.clear
2148
2146
2149 issue = Issue.find(1)
2147 issue = Issue.find(1)
2150 assert_equal '125', issue.custom_value_for(2).value
2148 assert_equal '125', issue.custom_value_for(2).value
2151 old_subject = issue.subject
2149 old_subject = issue.subject
2152 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2150 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2153
2151
2154 assert_difference('Journal.count') do
2152 assert_difference('Journal.count') do
2155 assert_difference('JournalDetail.count', 2) do
2153 assert_difference('JournalDetail.count', 2) do
2156 put :update, :id => 1, :issue => {:subject => new_subject,
2154 put :update, :id => 1, :issue => {:subject => new_subject,
2157 :priority_id => '6',
2155 :priority_id => '6',
2158 :category_id => '1' # no change
2156 :category_id => '1' # no change
2159 }
2157 }
2160 end
2158 end
2161 end
2159 end
2162 assert_redirected_to :action => 'show', :id => '1'
2160 assert_redirected_to :action => 'show', :id => '1'
2163 issue.reload
2161 issue.reload
2164 assert_equal new_subject, issue.subject
2162 assert_equal new_subject, issue.subject
2165 # Make sure custom fields were not cleared
2163 # Make sure custom fields were not cleared
2166 assert_equal '125', issue.custom_value_for(2).value
2164 assert_equal '125', issue.custom_value_for(2).value
2167
2165
2168 mail = ActionMailer::Base.deliveries.last
2166 mail = ActionMailer::Base.deliveries.last
2169 assert_not_nil mail
2167 assert_not_nil mail
2170 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2168 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2171 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
2169 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
2172 end
2170 end
2173
2171
2174 def test_put_update_with_project_change
2172 def test_put_update_with_project_change
2175 @request.session[:user_id] = 2
2173 @request.session[:user_id] = 2
2176 ActionMailer::Base.deliveries.clear
2174 ActionMailer::Base.deliveries.clear
2177
2175
2178 assert_difference('Journal.count') do
2176 assert_difference('Journal.count') do
2179 assert_difference('JournalDetail.count', 3) do
2177 assert_difference('JournalDetail.count', 3) do
2180 put :update, :id => 1, :issue => {:project_id => '2',
2178 put :update, :id => 1, :issue => {:project_id => '2',
2181 :tracker_id => '1', # no change
2179 :tracker_id => '1', # no change
2182 :priority_id => '6',
2180 :priority_id => '6',
2183 :category_id => '3'
2181 :category_id => '3'
2184 }
2182 }
2185 end
2183 end
2186 end
2184 end
2187 assert_redirected_to :action => 'show', :id => '1'
2185 assert_redirected_to :action => 'show', :id => '1'
2188 issue = Issue.find(1)
2186 issue = Issue.find(1)
2189 assert_equal 2, issue.project_id
2187 assert_equal 2, issue.project_id
2190 assert_equal 1, issue.tracker_id
2188 assert_equal 1, issue.tracker_id
2191 assert_equal 6, issue.priority_id
2189 assert_equal 6, issue.priority_id
2192 assert_equal 3, issue.category_id
2190 assert_equal 3, issue.category_id
2193
2191
2194 mail = ActionMailer::Base.deliveries.last
2192 mail = ActionMailer::Base.deliveries.last
2195 assert_not_nil mail
2193 assert_not_nil mail
2196 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2194 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2197 assert mail.body.include?("Project changed from eCookbook to OnlineStore")
2195 assert mail.body.include?("Project changed from eCookbook to OnlineStore")
2198 end
2196 end
2199
2197
2200 def test_put_update_with_tracker_change
2198 def test_put_update_with_tracker_change
2201 @request.session[:user_id] = 2
2199 @request.session[:user_id] = 2
2202 ActionMailer::Base.deliveries.clear
2200 ActionMailer::Base.deliveries.clear
2203
2201
2204 assert_difference('Journal.count') do
2202 assert_difference('Journal.count') do
2205 assert_difference('JournalDetail.count', 2) do
2203 assert_difference('JournalDetail.count', 2) do
2206 put :update, :id => 1, :issue => {:project_id => '1',
2204 put :update, :id => 1, :issue => {:project_id => '1',
2207 :tracker_id => '2',
2205 :tracker_id => '2',
2208 :priority_id => '6'
2206 :priority_id => '6'
2209 }
2207 }
2210 end
2208 end
2211 end
2209 end
2212 assert_redirected_to :action => 'show', :id => '1'
2210 assert_redirected_to :action => 'show', :id => '1'
2213 issue = Issue.find(1)
2211 issue = Issue.find(1)
2214 assert_equal 1, issue.project_id
2212 assert_equal 1, issue.project_id
2215 assert_equal 2, issue.tracker_id
2213 assert_equal 2, issue.tracker_id
2216 assert_equal 6, issue.priority_id
2214 assert_equal 6, issue.priority_id
2217 assert_equal 1, issue.category_id
2215 assert_equal 1, issue.category_id
2218
2216
2219 mail = ActionMailer::Base.deliveries.last
2217 mail = ActionMailer::Base.deliveries.last
2220 assert_not_nil mail
2218 assert_not_nil mail
2221 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2219 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2222 assert mail.body.include?("Tracker changed from Bug to Feature request")
2220 assert mail.body.include?("Tracker changed from Bug to Feature request")
2223 end
2221 end
2224
2222
2225 def test_put_update_with_custom_field_change
2223 def test_put_update_with_custom_field_change
2226 @request.session[:user_id] = 2
2224 @request.session[:user_id] = 2
2227 issue = Issue.find(1)
2225 issue = Issue.find(1)
2228 assert_equal '125', issue.custom_value_for(2).value
2226 assert_equal '125', issue.custom_value_for(2).value
2229
2227
2230 assert_difference('Journal.count') do
2228 assert_difference('Journal.count') do
2231 assert_difference('JournalDetail.count', 3) do
2229 assert_difference('JournalDetail.count', 3) do
2232 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2230 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2233 :priority_id => '6',
2231 :priority_id => '6',
2234 :category_id => '1', # no change
2232 :category_id => '1', # no change
2235 :custom_field_values => { '2' => 'New custom value' }
2233 :custom_field_values => { '2' => 'New custom value' }
2236 }
2234 }
2237 end
2235 end
2238 end
2236 end
2239 assert_redirected_to :action => 'show', :id => '1'
2237 assert_redirected_to :action => 'show', :id => '1'
2240 issue.reload
2238 issue.reload
2241 assert_equal 'New custom value', issue.custom_value_for(2).value
2239 assert_equal 'New custom value', issue.custom_value_for(2).value
2242
2240
2243 mail = ActionMailer::Base.deliveries.last
2241 mail = ActionMailer::Base.deliveries.last
2244 assert_not_nil mail
2242 assert_not_nil mail
2245 assert mail.body.include?("Searchable field changed from 125 to New custom value")
2243 assert mail.body.include?("Searchable field changed from 125 to New custom value")
2246 end
2244 end
2247
2245
2248 def test_put_update_with_multi_custom_field_change
2246 def test_put_update_with_multi_custom_field_change
2249 field = CustomField.find(1)
2247 field = CustomField.find(1)
2250 field.update_attribute :multiple, true
2248 field.update_attribute :multiple, true
2251 issue = Issue.find(1)
2249 issue = Issue.find(1)
2252 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2250 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2253 issue.save!
2251 issue.save!
2254
2252
2255 @request.session[:user_id] = 2
2253 @request.session[:user_id] = 2
2256 assert_difference('Journal.count') do
2254 assert_difference('Journal.count') do
2257 assert_difference('JournalDetail.count', 3) do
2255 assert_difference('JournalDetail.count', 3) do
2258 put :update, :id => 1,
2256 put :update, :id => 1,
2259 :issue => {
2257 :issue => {
2260 :subject => 'Custom field change',
2258 :subject => 'Custom field change',
2261 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2259 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2262 }
2260 }
2263 end
2261 end
2264 end
2262 end
2265 assert_redirected_to :action => 'show', :id => '1'
2263 assert_redirected_to :action => 'show', :id => '1'
2266 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2264 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2267 end
2265 end
2268
2266
2269 def test_put_update_with_status_and_assignee_change
2267 def test_put_update_with_status_and_assignee_change
2270 issue = Issue.find(1)
2268 issue = Issue.find(1)
2271 assert_equal 1, issue.status_id
2269 assert_equal 1, issue.status_id
2272 @request.session[:user_id] = 2
2270 @request.session[:user_id] = 2
2273 assert_difference('TimeEntry.count', 0) do
2271 assert_difference('TimeEntry.count', 0) do
2274 put :update,
2272 put :update,
2275 :id => 1,
2273 :id => 1,
2276 :issue => { :status_id => 2, :assigned_to_id => 3 },
2274 :issue => { :status_id => 2, :assigned_to_id => 3 },
2277 :notes => 'Assigned to dlopper',
2275 :notes => 'Assigned to dlopper',
2278 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2276 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2279 end
2277 end
2280 assert_redirected_to :action => 'show', :id => '1'
2278 assert_redirected_to :action => 'show', :id => '1'
2281 issue.reload
2279 issue.reload
2282 assert_equal 2, issue.status_id
2280 assert_equal 2, issue.status_id
2283 j = Journal.find(:first, :order => 'id DESC')
2281 j = Journal.find(:first, :order => 'id DESC')
2284 assert_equal 'Assigned to dlopper', j.notes
2282 assert_equal 'Assigned to dlopper', j.notes
2285 assert_equal 2, j.details.size
2283 assert_equal 2, j.details.size
2286
2284
2287 mail = ActionMailer::Base.deliveries.last
2285 mail = ActionMailer::Base.deliveries.last
2288 assert mail.body.include?("Status changed from New to Assigned")
2286 assert mail.body.include?("Status changed from New to Assigned")
2289 # subject should contain the new status
2287 # subject should contain the new status
2290 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2288 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2291 end
2289 end
2292
2290
2293 def test_put_update_with_note_only
2291 def test_put_update_with_note_only
2294 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2292 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2295 # anonymous user
2293 # anonymous user
2296 put :update,
2294 put :update,
2297 :id => 1,
2295 :id => 1,
2298 :notes => notes
2296 :notes => notes
2299 assert_redirected_to :action => 'show', :id => '1'
2297 assert_redirected_to :action => 'show', :id => '1'
2300 j = Journal.find(:first, :order => 'id DESC')
2298 j = Journal.find(:first, :order => 'id DESC')
2301 assert_equal notes, j.notes
2299 assert_equal notes, j.notes
2302 assert_equal 0, j.details.size
2300 assert_equal 0, j.details.size
2303 assert_equal User.anonymous, j.user
2301 assert_equal User.anonymous, j.user
2304
2302
2305 mail = ActionMailer::Base.deliveries.last
2303 mail = ActionMailer::Base.deliveries.last
2306 assert mail.body.include?(notes)
2304 assert mail.body.include?(notes)
2307 end
2305 end
2308
2306
2309 def test_put_update_with_note_and_spent_time
2307 def test_put_update_with_note_and_spent_time
2310 @request.session[:user_id] = 2
2308 @request.session[:user_id] = 2
2311 spent_hours_before = Issue.find(1).spent_hours
2309 spent_hours_before = Issue.find(1).spent_hours
2312 assert_difference('TimeEntry.count') do
2310 assert_difference('TimeEntry.count') do
2313 put :update,
2311 put :update,
2314 :id => 1,
2312 :id => 1,
2315 :notes => '2.5 hours added',
2313 :notes => '2.5 hours added',
2316 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2314 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2317 end
2315 end
2318 assert_redirected_to :action => 'show', :id => '1'
2316 assert_redirected_to :action => 'show', :id => '1'
2319
2317
2320 issue = Issue.find(1)
2318 issue = Issue.find(1)
2321
2319
2322 j = Journal.find(:first, :order => 'id DESC')
2320 j = Journal.find(:first, :order => 'id DESC')
2323 assert_equal '2.5 hours added', j.notes
2321 assert_equal '2.5 hours added', j.notes
2324 assert_equal 0, j.details.size
2322 assert_equal 0, j.details.size
2325
2323
2326 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2324 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2327 assert_not_nil t
2325 assert_not_nil t
2328 assert_equal 2.5, t.hours
2326 assert_equal 2.5, t.hours
2329 assert_equal spent_hours_before + 2.5, issue.spent_hours
2327 assert_equal spent_hours_before + 2.5, issue.spent_hours
2330 end
2328 end
2331
2329
2332 def test_put_update_with_attachment_only
2330 def test_put_update_with_attachment_only
2333 set_tmp_attachments_directory
2331 set_tmp_attachments_directory
2334
2332
2335 # Delete all fixtured journals, a race condition can occur causing the wrong
2333 # Delete all fixtured journals, a race condition can occur causing the wrong
2336 # journal to get fetched in the next find.
2334 # journal to get fetched in the next find.
2337 Journal.delete_all
2335 Journal.delete_all
2338
2336
2339 # anonymous user
2337 # anonymous user
2340 assert_difference 'Attachment.count' do
2338 assert_difference 'Attachment.count' do
2341 put :update, :id => 1,
2339 put :update, :id => 1,
2342 :notes => '',
2340 :notes => '',
2343 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2341 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2344 end
2342 end
2345
2343
2346 assert_redirected_to :action => 'show', :id => '1'
2344 assert_redirected_to :action => 'show', :id => '1'
2347 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2345 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2348 assert j.notes.blank?
2346 assert j.notes.blank?
2349 assert_equal 1, j.details.size
2347 assert_equal 1, j.details.size
2350 assert_equal 'testfile.txt', j.details.first.value
2348 assert_equal 'testfile.txt', j.details.first.value
2351 assert_equal User.anonymous, j.user
2349 assert_equal User.anonymous, j.user
2352
2350
2353 attachment = Attachment.first(:order => 'id DESC')
2351 attachment = Attachment.first(:order => 'id DESC')
2354 assert_equal Issue.find(1), attachment.container
2352 assert_equal Issue.find(1), attachment.container
2355 assert_equal User.anonymous, attachment.author
2353 assert_equal User.anonymous, attachment.author
2356 assert_equal 'testfile.txt', attachment.filename
2354 assert_equal 'testfile.txt', attachment.filename
2357 assert_equal 'text/plain', attachment.content_type
2355 assert_equal 'text/plain', attachment.content_type
2358 assert_equal 'test file', attachment.description
2356 assert_equal 'test file', attachment.description
2359 assert_equal 59, attachment.filesize
2357 assert_equal 59, attachment.filesize
2360 assert File.exists?(attachment.diskfile)
2358 assert File.exists?(attachment.diskfile)
2361 assert_equal 59, File.size(attachment.diskfile)
2359 assert_equal 59, File.size(attachment.diskfile)
2362
2360
2363 mail = ActionMailer::Base.deliveries.last
2361 mail = ActionMailer::Base.deliveries.last
2364 assert mail.body.include?('testfile.txt')
2362 assert mail.body.include?('testfile.txt')
2365 end
2363 end
2366
2364
2367 def test_put_update_with_failure_should_save_attachments
2365 def test_put_update_with_failure_should_save_attachments
2368 set_tmp_attachments_directory
2366 set_tmp_attachments_directory
2369 @request.session[:user_id] = 2
2367 @request.session[:user_id] = 2
2370
2368
2371 assert_no_difference 'Journal.count' do
2369 assert_no_difference 'Journal.count' do
2372 assert_difference 'Attachment.count' do
2370 assert_difference 'Attachment.count' do
2373 put :update, :id => 1,
2371 put :update, :id => 1,
2374 :issue => { :subject => '' },
2372 :issue => { :subject => '' },
2375 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2373 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2376 assert_response :success
2374 assert_response :success
2377 assert_template 'edit'
2375 assert_template 'edit'
2378 end
2376 end
2379 end
2377 end
2380
2378
2381 attachment = Attachment.first(:order => 'id DESC')
2379 attachment = Attachment.first(:order => 'id DESC')
2382 assert_equal 'testfile.txt', attachment.filename
2380 assert_equal 'testfile.txt', attachment.filename
2383 assert File.exists?(attachment.diskfile)
2381 assert File.exists?(attachment.diskfile)
2384 assert_nil attachment.container
2382 assert_nil attachment.container
2385
2383
2386 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2384 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2387 assert_tag 'span', :content => /testfile.txt/
2385 assert_tag 'span', :content => /testfile.txt/
2388 end
2386 end
2389
2387
2390 def test_put_update_with_failure_should_keep_saved_attachments
2388 def test_put_update_with_failure_should_keep_saved_attachments
2391 set_tmp_attachments_directory
2389 set_tmp_attachments_directory
2392 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2390 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2393 @request.session[:user_id] = 2
2391 @request.session[:user_id] = 2
2394
2392
2395 assert_no_difference 'Journal.count' do
2393 assert_no_difference 'Journal.count' do
2396 assert_no_difference 'Attachment.count' do
2394 assert_no_difference 'Attachment.count' do
2397 put :update, :id => 1,
2395 put :update, :id => 1,
2398 :issue => { :subject => '' },
2396 :issue => { :subject => '' },
2399 :attachments => {'p0' => {'token' => attachment.token}}
2397 :attachments => {'p0' => {'token' => attachment.token}}
2400 assert_response :success
2398 assert_response :success
2401 assert_template 'edit'
2399 assert_template 'edit'
2402 end
2400 end
2403 end
2401 end
2404
2402
2405 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2403 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2406 assert_tag 'span', :content => /testfile.txt/
2404 assert_tag 'span', :content => /testfile.txt/
2407 end
2405 end
2408
2406
2409 def test_put_update_should_attach_saved_attachments
2407 def test_put_update_should_attach_saved_attachments
2410 set_tmp_attachments_directory
2408 set_tmp_attachments_directory
2411 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2409 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2412 @request.session[:user_id] = 2
2410 @request.session[:user_id] = 2
2413
2411
2414 assert_difference 'Journal.count' do
2412 assert_difference 'Journal.count' do
2415 assert_difference 'JournalDetail.count' do
2413 assert_difference 'JournalDetail.count' do
2416 assert_no_difference 'Attachment.count' do
2414 assert_no_difference 'Attachment.count' do
2417 put :update, :id => 1,
2415 put :update, :id => 1,
2418 :notes => 'Attachment added',
2416 :notes => 'Attachment added',
2419 :attachments => {'p0' => {'token' => attachment.token}}
2417 :attachments => {'p0' => {'token' => attachment.token}}
2420 assert_redirected_to '/issues/1'
2418 assert_redirected_to '/issues/1'
2421 end
2419 end
2422 end
2420 end
2423 end
2421 end
2424
2422
2425 attachment.reload
2423 attachment.reload
2426 assert_equal Issue.find(1), attachment.container
2424 assert_equal Issue.find(1), attachment.container
2427
2425
2428 journal = Journal.first(:order => 'id DESC')
2426 journal = Journal.first(:order => 'id DESC')
2429 assert_equal 1, journal.details.size
2427 assert_equal 1, journal.details.size
2430 assert_equal 'testfile.txt', journal.details.first.value
2428 assert_equal 'testfile.txt', journal.details.first.value
2431 end
2429 end
2432
2430
2433 def test_put_update_with_attachment_that_fails_to_save
2431 def test_put_update_with_attachment_that_fails_to_save
2434 set_tmp_attachments_directory
2432 set_tmp_attachments_directory
2435
2433
2436 # Delete all fixtured journals, a race condition can occur causing the wrong
2434 # Delete all fixtured journals, a race condition can occur causing the wrong
2437 # journal to get fetched in the next find.
2435 # journal to get fetched in the next find.
2438 Journal.delete_all
2436 Journal.delete_all
2439
2437
2440 # Mock out the unsaved attachment
2438 # Mock out the unsaved attachment
2441 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2439 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2442
2440
2443 # anonymous user
2441 # anonymous user
2444 put :update,
2442 put :update,
2445 :id => 1,
2443 :id => 1,
2446 :notes => '',
2444 :notes => '',
2447 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2445 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2448 assert_redirected_to :action => 'show', :id => '1'
2446 assert_redirected_to :action => 'show', :id => '1'
2449 assert_equal '1 file(s) could not be saved.', flash[:warning]
2447 assert_equal '1 file(s) could not be saved.', flash[:warning]
2450 end
2448 end
2451
2449
2452 def test_put_update_with_no_change
2450 def test_put_update_with_no_change
2453 issue = Issue.find(1)
2451 issue = Issue.find(1)
2454 issue.journals.clear
2452 issue.journals.clear
2455 ActionMailer::Base.deliveries.clear
2453 ActionMailer::Base.deliveries.clear
2456
2454
2457 put :update,
2455 put :update,
2458 :id => 1,
2456 :id => 1,
2459 :notes => ''
2457 :notes => ''
2460 assert_redirected_to :action => 'show', :id => '1'
2458 assert_redirected_to :action => 'show', :id => '1'
2461
2459
2462 issue.reload
2460 issue.reload
2463 assert issue.journals.empty?
2461 assert issue.journals.empty?
2464 # No email should be sent
2462 # No email should be sent
2465 assert ActionMailer::Base.deliveries.empty?
2463 assert ActionMailer::Base.deliveries.empty?
2466 end
2464 end
2467
2465
2468 def test_put_update_should_send_a_notification
2466 def test_put_update_should_send_a_notification
2469 @request.session[:user_id] = 2
2467 @request.session[:user_id] = 2
2470 ActionMailer::Base.deliveries.clear
2468 ActionMailer::Base.deliveries.clear
2471 issue = Issue.find(1)
2469 issue = Issue.find(1)
2472 old_subject = issue.subject
2470 old_subject = issue.subject
2473 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2471 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2474
2472
2475 put :update, :id => 1, :issue => {:subject => new_subject,
2473 put :update, :id => 1, :issue => {:subject => new_subject,
2476 :priority_id => '6',
2474 :priority_id => '6',
2477 :category_id => '1' # no change
2475 :category_id => '1' # no change
2478 }
2476 }
2479 assert_equal 1, ActionMailer::Base.deliveries.size
2477 assert_equal 1, ActionMailer::Base.deliveries.size
2480 end
2478 end
2481
2479
2482 def test_put_update_with_invalid_spent_time_hours_only
2480 def test_put_update_with_invalid_spent_time_hours_only
2483 @request.session[:user_id] = 2
2481 @request.session[:user_id] = 2
2484 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2482 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2485
2483
2486 assert_no_difference('Journal.count') do
2484 assert_no_difference('Journal.count') do
2487 put :update,
2485 put :update,
2488 :id => 1,
2486 :id => 1,
2489 :notes => notes,
2487 :notes => notes,
2490 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2488 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2491 end
2489 end
2492 assert_response :success
2490 assert_response :success
2493 assert_template 'edit'
2491 assert_template 'edit'
2494
2492
2495 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2493 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2496 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2494 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2497 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2495 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2498 end
2496 end
2499
2497
2500 def test_put_update_with_invalid_spent_time_comments_only
2498 def test_put_update_with_invalid_spent_time_comments_only
2501 @request.session[:user_id] = 2
2499 @request.session[:user_id] = 2
2502 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2500 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2503
2501
2504 assert_no_difference('Journal.count') do
2502 assert_no_difference('Journal.count') do
2505 put :update,
2503 put :update,
2506 :id => 1,
2504 :id => 1,
2507 :notes => notes,
2505 :notes => notes,
2508 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2506 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2509 end
2507 end
2510 assert_response :success
2508 assert_response :success
2511 assert_template 'edit'
2509 assert_template 'edit'
2512
2510
2513 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2511 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2514 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2512 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2515 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2513 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2516 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2514 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2517 end
2515 end
2518
2516
2519 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2517 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2520 issue = Issue.find(2)
2518 issue = Issue.find(2)
2521 @request.session[:user_id] = 2
2519 @request.session[:user_id] = 2
2522
2520
2523 put :update,
2521 put :update,
2524 :id => issue.id,
2522 :id => issue.id,
2525 :issue => {
2523 :issue => {
2526 :fixed_version_id => 4
2524 :fixed_version_id => 4
2527 }
2525 }
2528
2526
2529 assert_response :redirect
2527 assert_response :redirect
2530 issue.reload
2528 issue.reload
2531 assert_equal 4, issue.fixed_version_id
2529 assert_equal 4, issue.fixed_version_id
2532 assert_not_equal issue.project_id, issue.fixed_version.project_id
2530 assert_not_equal issue.project_id, issue.fixed_version.project_id
2533 end
2531 end
2534
2532
2535 def test_put_update_should_redirect_back_using_the_back_url_parameter
2533 def test_put_update_should_redirect_back_using_the_back_url_parameter
2536 issue = Issue.find(2)
2534 issue = Issue.find(2)
2537 @request.session[:user_id] = 2
2535 @request.session[:user_id] = 2
2538
2536
2539 put :update,
2537 put :update,
2540 :id => issue.id,
2538 :id => issue.id,
2541 :issue => {
2539 :issue => {
2542 :fixed_version_id => 4
2540 :fixed_version_id => 4
2543 },
2541 },
2544 :back_url => '/issues'
2542 :back_url => '/issues'
2545
2543
2546 assert_response :redirect
2544 assert_response :redirect
2547 assert_redirected_to '/issues'
2545 assert_redirected_to '/issues'
2548 end
2546 end
2549
2547
2550 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2548 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2551 issue = Issue.find(2)
2549 issue = Issue.find(2)
2552 @request.session[:user_id] = 2
2550 @request.session[:user_id] = 2
2553
2551
2554 put :update,
2552 put :update,
2555 :id => issue.id,
2553 :id => issue.id,
2556 :issue => {
2554 :issue => {
2557 :fixed_version_id => 4
2555 :fixed_version_id => 4
2558 },
2556 },
2559 :back_url => 'http://google.com'
2557 :back_url => 'http://google.com'
2560
2558
2561 assert_response :redirect
2559 assert_response :redirect
2562 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2560 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2563 end
2561 end
2564
2562
2565 def test_get_bulk_edit
2563 def test_get_bulk_edit
2566 @request.session[:user_id] = 2
2564 @request.session[:user_id] = 2
2567 get :bulk_edit, :ids => [1, 2]
2565 get :bulk_edit, :ids => [1, 2]
2568 assert_response :success
2566 assert_response :success
2569 assert_template 'bulk_edit'
2567 assert_template 'bulk_edit'
2570
2568
2571 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2569 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2572 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2570 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2573
2571
2574 # Project specific custom field, date type
2572 # Project specific custom field, date type
2575 field = CustomField.find(9)
2573 field = CustomField.find(9)
2576 assert !field.is_for_all?
2574 assert !field.is_for_all?
2577 assert_equal 'date', field.field_format
2575 assert_equal 'date', field.field_format
2578 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2576 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2579
2577
2580 # System wide custom field
2578 # System wide custom field
2581 assert CustomField.find(1).is_for_all?
2579 assert CustomField.find(1).is_for_all?
2582 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2580 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2583
2581
2584 # Be sure we don't display inactive IssuePriorities
2582 # Be sure we don't display inactive IssuePriorities
2585 assert ! IssuePriority.find(15).active?
2583 assert ! IssuePriority.find(15).active?
2586 assert_no_tag :option, :attributes => {:value => '15'},
2584 assert_no_tag :option, :attributes => {:value => '15'},
2587 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2585 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2588 end
2586 end
2589
2587
2590 def test_get_bulk_edit_on_different_projects
2588 def test_get_bulk_edit_on_different_projects
2591 @request.session[:user_id] = 2
2589 @request.session[:user_id] = 2
2592 get :bulk_edit, :ids => [1, 2, 6]
2590 get :bulk_edit, :ids => [1, 2, 6]
2593 assert_response :success
2591 assert_response :success
2594 assert_template 'bulk_edit'
2592 assert_template 'bulk_edit'
2595
2593
2596 # Can not set issues from different projects as children of an issue
2594 # Can not set issues from different projects as children of an issue
2597 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2595 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2598
2596
2599 # Project specific custom field, date type
2597 # Project specific custom field, date type
2600 field = CustomField.find(9)
2598 field = CustomField.find(9)
2601 assert !field.is_for_all?
2599 assert !field.is_for_all?
2602 assert !field.project_ids.include?(Issue.find(6).project_id)
2600 assert !field.project_ids.include?(Issue.find(6).project_id)
2603 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2601 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2604 end
2602 end
2605
2603
2606 def test_get_bulk_edit_with_user_custom_field
2604 def test_get_bulk_edit_with_user_custom_field
2607 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2605 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2608
2606
2609 @request.session[:user_id] = 2
2607 @request.session[:user_id] = 2
2610 get :bulk_edit, :ids => [1, 2]
2608 get :bulk_edit, :ids => [1, 2]
2611 assert_response :success
2609 assert_response :success
2612 assert_template 'bulk_edit'
2610 assert_template 'bulk_edit'
2613
2611
2614 assert_tag :select,
2612 assert_tag :select,
2615 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2613 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2616 :children => {
2614 :children => {
2617 :only => {:tag => 'option'},
2615 :only => {:tag => 'option'},
2618 :count => Project.find(1).users.count + 1
2616 :count => Project.find(1).users.count + 1
2619 }
2617 }
2620 end
2618 end
2621
2619
2622 def test_get_bulk_edit_with_version_custom_field
2620 def test_get_bulk_edit_with_version_custom_field
2623 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2621 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2624
2622
2625 @request.session[:user_id] = 2
2623 @request.session[:user_id] = 2
2626 get :bulk_edit, :ids => [1, 2]
2624 get :bulk_edit, :ids => [1, 2]
2627 assert_response :success
2625 assert_response :success
2628 assert_template 'bulk_edit'
2626 assert_template 'bulk_edit'
2629
2627
2630 assert_tag :select,
2628 assert_tag :select,
2631 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2629 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2632 :children => {
2630 :children => {
2633 :only => {:tag => 'option'},
2631 :only => {:tag => 'option'},
2634 :count => Project.find(1).shared_versions.count + 1
2632 :count => Project.find(1).shared_versions.count + 1
2635 }
2633 }
2636 end
2634 end
2637
2635
2638 def test_get_bulk_edit_with_multi_custom_field
2636 def test_get_bulk_edit_with_multi_custom_field
2639 field = CustomField.find(1)
2637 field = CustomField.find(1)
2640 field.update_attribute :multiple, true
2638 field.update_attribute :multiple, true
2641
2639
2642 @request.session[:user_id] = 2
2640 @request.session[:user_id] = 2
2643 get :bulk_edit, :ids => [1, 2]
2641 get :bulk_edit, :ids => [1, 2]
2644 assert_response :success
2642 assert_response :success
2645 assert_template 'bulk_edit'
2643 assert_template 'bulk_edit'
2646
2644
2647 assert_tag :select,
2645 assert_tag :select,
2648 :attributes => {:name => "issue[custom_field_values][1][]"},
2646 :attributes => {:name => "issue[custom_field_values][1][]"},
2649 :children => {
2647 :children => {
2650 :only => {:tag => 'option'},
2648 :only => {:tag => 'option'},
2651 :count => 3
2649 :count => 3
2652 }
2650 }
2653 end
2651 end
2654
2652
2655 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
2653 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
2656 Workflow.delete_all
2654 Workflow.delete_all
2657 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
2655 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
2658 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2656 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2659 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2657 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2660 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2658 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2661 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2659 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2662 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2660 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2663 @request.session[:user_id] = 2
2661 @request.session[:user_id] = 2
2664 get :bulk_edit, :ids => [1, 2]
2662 get :bulk_edit, :ids => [1, 2]
2665
2663
2666 assert_response :success
2664 assert_response :success
2667 statuses = assigns(:available_statuses)
2665 statuses = assigns(:available_statuses)
2668 assert_not_nil statuses
2666 assert_not_nil statuses
2669 assert_equal [1, 3], statuses.map(&:id).sort
2667 assert_equal [1, 3], statuses.map(&:id).sort
2670
2668
2671 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
2669 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
2672 :children => {:count => 3} # 2 statuses + "no change" option
2670 :children => {:count => 3} # 2 statuses + "no change" option
2673 end
2671 end
2674
2672
2675 def test_bulk_edit_should_propose_target_project_open_shared_versions
2673 def test_bulk_edit_should_propose_target_project_open_shared_versions
2676 @request.session[:user_id] = 2
2674 @request.session[:user_id] = 2
2677 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2675 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2678 assert_response :success
2676 assert_response :success
2679 assert_template 'bulk_edit'
2677 assert_template 'bulk_edit'
2680 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
2678 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
2681 assert_tag 'select',
2679 assert_tag 'select',
2682 :attributes => {:name => 'issue[fixed_version_id]'},
2680 :attributes => {:name => 'issue[fixed_version_id]'},
2683 :descendant => {:tag => 'option', :content => '2.0'}
2681 :descendant => {:tag => 'option', :content => '2.0'}
2684 end
2682 end
2685
2683
2686 def test_bulk_edit_should_propose_target_project_categories
2684 def test_bulk_edit_should_propose_target_project_categories
2687 @request.session[:user_id] = 2
2685 @request.session[:user_id] = 2
2688 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2686 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2689 assert_response :success
2687 assert_response :success
2690 assert_template 'bulk_edit'
2688 assert_template 'bulk_edit'
2691 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
2689 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
2692 assert_tag 'select',
2690 assert_tag 'select',
2693 :attributes => {:name => 'issue[category_id]'},
2691 :attributes => {:name => 'issue[category_id]'},
2694 :descendant => {:tag => 'option', :content => 'Recipes'}
2692 :descendant => {:tag => 'option', :content => 'Recipes'}
2695 end
2693 end
2696
2694
2697 def test_bulk_update
2695 def test_bulk_update
2698 @request.session[:user_id] = 2
2696 @request.session[:user_id] = 2
2699 # update issues priority
2697 # update issues priority
2700 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2698 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2701 :issue => {:priority_id => 7,
2699 :issue => {:priority_id => 7,
2702 :assigned_to_id => '',
2700 :assigned_to_id => '',
2703 :custom_field_values => {'2' => ''}}
2701 :custom_field_values => {'2' => ''}}
2704
2702
2705 assert_response 302
2703 assert_response 302
2706 # check that the issues were updated
2704 # check that the issues were updated
2707 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2705 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2708
2706
2709 issue = Issue.find(1)
2707 issue = Issue.find(1)
2710 journal = issue.journals.find(:first, :order => 'created_on DESC')
2708 journal = issue.journals.find(:first, :order => 'created_on DESC')
2711 assert_equal '125', issue.custom_value_for(2).value
2709 assert_equal '125', issue.custom_value_for(2).value
2712 assert_equal 'Bulk editing', journal.notes
2710 assert_equal 'Bulk editing', journal.notes
2713 assert_equal 1, journal.details.size
2711 assert_equal 1, journal.details.size
2714 end
2712 end
2715
2713
2716 def test_bulk_update_with_group_assignee
2714 def test_bulk_update_with_group_assignee
2717 group = Group.find(11)
2715 group = Group.find(11)
2718 project = Project.find(1)
2716 project = Project.find(1)
2719 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2717 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2720
2718
2721 @request.session[:user_id] = 2
2719 @request.session[:user_id] = 2
2722 # update issues assignee
2720 # update issues assignee
2723 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2721 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2724 :issue => {:priority_id => '',
2722 :issue => {:priority_id => '',
2725 :assigned_to_id => group.id,
2723 :assigned_to_id => group.id,
2726 :custom_field_values => {'2' => ''}}
2724 :custom_field_values => {'2' => ''}}
2727
2725
2728 assert_response 302
2726 assert_response 302
2729 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2727 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2730 end
2728 end
2731
2729
2732 def test_bulk_update_on_different_projects
2730 def test_bulk_update_on_different_projects
2733 @request.session[:user_id] = 2
2731 @request.session[:user_id] = 2
2734 # update issues priority
2732 # update issues priority
2735 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2733 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2736 :issue => {:priority_id => 7,
2734 :issue => {:priority_id => 7,
2737 :assigned_to_id => '',
2735 :assigned_to_id => '',
2738 :custom_field_values => {'2' => ''}}
2736 :custom_field_values => {'2' => ''}}
2739
2737
2740 assert_response 302
2738 assert_response 302
2741 # check that the issues were updated
2739 # check that the issues were updated
2742 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2740 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2743
2741
2744 issue = Issue.find(1)
2742 issue = Issue.find(1)
2745 journal = issue.journals.find(:first, :order => 'created_on DESC')
2743 journal = issue.journals.find(:first, :order => 'created_on DESC')
2746 assert_equal '125', issue.custom_value_for(2).value
2744 assert_equal '125', issue.custom_value_for(2).value
2747 assert_equal 'Bulk editing', journal.notes
2745 assert_equal 'Bulk editing', journal.notes
2748 assert_equal 1, journal.details.size
2746 assert_equal 1, journal.details.size
2749 end
2747 end
2750
2748
2751 def test_bulk_update_on_different_projects_without_rights
2749 def test_bulk_update_on_different_projects_without_rights
2752 @request.session[:user_id] = 3
2750 @request.session[:user_id] = 3
2753 user = User.find(3)
2751 user = User.find(3)
2754 action = { :controller => "issues", :action => "bulk_update" }
2752 action = { :controller => "issues", :action => "bulk_update" }
2755 assert user.allowed_to?(action, Issue.find(1).project)
2753 assert user.allowed_to?(action, Issue.find(1).project)
2756 assert ! user.allowed_to?(action, Issue.find(6).project)
2754 assert ! user.allowed_to?(action, Issue.find(6).project)
2757 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2755 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2758 :issue => {:priority_id => 7,
2756 :issue => {:priority_id => 7,
2759 :assigned_to_id => '',
2757 :assigned_to_id => '',
2760 :custom_field_values => {'2' => ''}}
2758 :custom_field_values => {'2' => ''}}
2761 assert_response 403
2759 assert_response 403
2762 assert_not_equal "Bulk should fail", Journal.last.notes
2760 assert_not_equal "Bulk should fail", Journal.last.notes
2763 end
2761 end
2764
2762
2765 def test_bullk_update_should_send_a_notification
2763 def test_bullk_update_should_send_a_notification
2766 @request.session[:user_id] = 2
2764 @request.session[:user_id] = 2
2767 ActionMailer::Base.deliveries.clear
2765 ActionMailer::Base.deliveries.clear
2768 post(:bulk_update,
2766 post(:bulk_update,
2769 {
2767 {
2770 :ids => [1, 2],
2768 :ids => [1, 2],
2771 :notes => 'Bulk editing',
2769 :notes => 'Bulk editing',
2772 :issue => {
2770 :issue => {
2773 :priority_id => 7,
2771 :priority_id => 7,
2774 :assigned_to_id => '',
2772 :assigned_to_id => '',
2775 :custom_field_values => {'2' => ''}
2773 :custom_field_values => {'2' => ''}
2776 }
2774 }
2777 })
2775 })
2778
2776
2779 assert_response 302
2777 assert_response 302
2780 assert_equal 2, ActionMailer::Base.deliveries.size
2778 assert_equal 2, ActionMailer::Base.deliveries.size
2781 end
2779 end
2782
2780
2783 def test_bulk_update_project
2781 def test_bulk_update_project
2784 @request.session[:user_id] = 2
2782 @request.session[:user_id] = 2
2785 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2783 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2786 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2784 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2787 # Issues moved to project 2
2785 # Issues moved to project 2
2788 assert_equal 2, Issue.find(1).project_id
2786 assert_equal 2, Issue.find(1).project_id
2789 assert_equal 2, Issue.find(2).project_id
2787 assert_equal 2, Issue.find(2).project_id
2790 # No tracker change
2788 # No tracker change
2791 assert_equal 1, Issue.find(1).tracker_id
2789 assert_equal 1, Issue.find(1).tracker_id
2792 assert_equal 2, Issue.find(2).tracker_id
2790 assert_equal 2, Issue.find(2).tracker_id
2793 end
2791 end
2794
2792
2795 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2793 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2796 @request.session[:user_id] = 2
2794 @request.session[:user_id] = 2
2797 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2795 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2798 assert_redirected_to '/issues/1'
2796 assert_redirected_to '/issues/1'
2799 end
2797 end
2800
2798
2801 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2799 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2802 @request.session[:user_id] = 2
2800 @request.session[:user_id] = 2
2803 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2801 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2804 assert_redirected_to '/projects/onlinestore/issues'
2802 assert_redirected_to '/projects/onlinestore/issues'
2805 end
2803 end
2806
2804
2807 def test_bulk_update_tracker
2805 def test_bulk_update_tracker
2808 @request.session[:user_id] = 2
2806 @request.session[:user_id] = 2
2809 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2807 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2810 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2808 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2811 assert_equal 2, Issue.find(1).tracker_id
2809 assert_equal 2, Issue.find(1).tracker_id
2812 assert_equal 2, Issue.find(2).tracker_id
2810 assert_equal 2, Issue.find(2).tracker_id
2813 end
2811 end
2814
2812
2815 def test_bulk_update_status
2813 def test_bulk_update_status
2816 @request.session[:user_id] = 2
2814 @request.session[:user_id] = 2
2817 # update issues priority
2815 # update issues priority
2818 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2816 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2819 :issue => {:priority_id => '',
2817 :issue => {:priority_id => '',
2820 :assigned_to_id => '',
2818 :assigned_to_id => '',
2821 :status_id => '5'}
2819 :status_id => '5'}
2822
2820
2823 assert_response 302
2821 assert_response 302
2824 issue = Issue.find(1)
2822 issue = Issue.find(1)
2825 assert issue.closed?
2823 assert issue.closed?
2826 end
2824 end
2827
2825
2828 def test_bulk_update_priority
2826 def test_bulk_update_priority
2829 @request.session[:user_id] = 2
2827 @request.session[:user_id] = 2
2830 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2828 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2831
2829
2832 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2830 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2833 assert_equal 6, Issue.find(1).priority_id
2831 assert_equal 6, Issue.find(1).priority_id
2834 assert_equal 6, Issue.find(2).priority_id
2832 assert_equal 6, Issue.find(2).priority_id
2835 end
2833 end
2836
2834
2837 def test_bulk_update_with_notes
2835 def test_bulk_update_with_notes
2838 @request.session[:user_id] = 2
2836 @request.session[:user_id] = 2
2839 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2837 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2840
2838
2841 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2839 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2842 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2840 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2843 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2841 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2844 end
2842 end
2845
2843
2846 def test_bulk_update_parent_id
2844 def test_bulk_update_parent_id
2847 @request.session[:user_id] = 2
2845 @request.session[:user_id] = 2
2848 post :bulk_update, :ids => [1, 3],
2846 post :bulk_update, :ids => [1, 3],
2849 :notes => 'Bulk editing parent',
2847 :notes => 'Bulk editing parent',
2850 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2848 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2851
2849
2852 assert_response 302
2850 assert_response 302
2853 parent = Issue.find(2)
2851 parent = Issue.find(2)
2854 assert_equal parent.id, Issue.find(1).parent_id
2852 assert_equal parent.id, Issue.find(1).parent_id
2855 assert_equal parent.id, Issue.find(3).parent_id
2853 assert_equal parent.id, Issue.find(3).parent_id
2856 assert_equal [1, 3], parent.children.collect(&:id).sort
2854 assert_equal [1, 3], parent.children.collect(&:id).sort
2857 end
2855 end
2858
2856
2859 def test_bulk_update_custom_field
2857 def test_bulk_update_custom_field
2860 @request.session[:user_id] = 2
2858 @request.session[:user_id] = 2
2861 # update issues priority
2859 # update issues priority
2862 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2860 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2863 :issue => {:priority_id => '',
2861 :issue => {:priority_id => '',
2864 :assigned_to_id => '',
2862 :assigned_to_id => '',
2865 :custom_field_values => {'2' => '777'}}
2863 :custom_field_values => {'2' => '777'}}
2866
2864
2867 assert_response 302
2865 assert_response 302
2868
2866
2869 issue = Issue.find(1)
2867 issue = Issue.find(1)
2870 journal = issue.journals.find(:first, :order => 'created_on DESC')
2868 journal = issue.journals.find(:first, :order => 'created_on DESC')
2871 assert_equal '777', issue.custom_value_for(2).value
2869 assert_equal '777', issue.custom_value_for(2).value
2872 assert_equal 1, journal.details.size
2870 assert_equal 1, journal.details.size
2873 assert_equal '125', journal.details.first.old_value
2871 assert_equal '125', journal.details.first.old_value
2874 assert_equal '777', journal.details.first.value
2872 assert_equal '777', journal.details.first.value
2875 end
2873 end
2876
2874
2877 def test_bulk_update_multi_custom_field
2875 def test_bulk_update_multi_custom_field
2878 field = CustomField.find(1)
2876 field = CustomField.find(1)
2879 field.update_attribute :multiple, true
2877 field.update_attribute :multiple, true
2880
2878
2881 @request.session[:user_id] = 2
2879 @request.session[:user_id] = 2
2882 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
2880 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
2883 :issue => {:priority_id => '',
2881 :issue => {:priority_id => '',
2884 :assigned_to_id => '',
2882 :assigned_to_id => '',
2885 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
2883 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
2886
2884
2887 assert_response 302
2885 assert_response 302
2888
2886
2889 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
2887 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
2890 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
2888 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
2891 # the custom field is not associated with the issue tracker
2889 # the custom field is not associated with the issue tracker
2892 assert_nil Issue.find(2).custom_field_value(1)
2890 assert_nil Issue.find(2).custom_field_value(1)
2893 end
2891 end
2894
2892
2895 def test_bulk_update_unassign
2893 def test_bulk_update_unassign
2896 assert_not_nil Issue.find(2).assigned_to
2894 assert_not_nil Issue.find(2).assigned_to
2897 @request.session[:user_id] = 2
2895 @request.session[:user_id] = 2
2898 # unassign issues
2896 # unassign issues
2899 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2897 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2900 assert_response 302
2898 assert_response 302
2901 # check that the issues were updated
2899 # check that the issues were updated
2902 assert_nil Issue.find(2).assigned_to
2900 assert_nil Issue.find(2).assigned_to
2903 end
2901 end
2904
2902
2905 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2903 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2906 @request.session[:user_id] = 2
2904 @request.session[:user_id] = 2
2907
2905
2908 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2906 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2909
2907
2910 assert_response :redirect
2908 assert_response :redirect
2911 issues = Issue.find([1,2])
2909 issues = Issue.find([1,2])
2912 issues.each do |issue|
2910 issues.each do |issue|
2913 assert_equal 4, issue.fixed_version_id
2911 assert_equal 4, issue.fixed_version_id
2914 assert_not_equal issue.project_id, issue.fixed_version.project_id
2912 assert_not_equal issue.project_id, issue.fixed_version.project_id
2915 end
2913 end
2916 end
2914 end
2917
2915
2918 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2916 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2919 @request.session[:user_id] = 2
2917 @request.session[:user_id] = 2
2920 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2918 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2921
2919
2922 assert_response :redirect
2920 assert_response :redirect
2923 assert_redirected_to '/issues'
2921 assert_redirected_to '/issues'
2924 end
2922 end
2925
2923
2926 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2924 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2927 @request.session[:user_id] = 2
2925 @request.session[:user_id] = 2
2928 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
2926 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
2929
2927
2930 assert_response :redirect
2928 assert_response :redirect
2931 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
2929 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
2932 end
2930 end
2933
2931
2934 def test_bulk_copy_to_another_project
2932 def test_bulk_copy_to_another_project
2935 @request.session[:user_id] = 2
2933 @request.session[:user_id] = 2
2936 assert_difference 'Issue.count', 2 do
2934 assert_difference 'Issue.count', 2 do
2937 assert_no_difference 'Project.find(1).issues.count' do
2935 assert_no_difference 'Project.find(1).issues.count' do
2938 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
2936 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
2939 end
2937 end
2940 end
2938 end
2941 assert_redirected_to '/projects/ecookbook/issues'
2939 assert_redirected_to '/projects/ecookbook/issues'
2942 end
2940 end
2943
2941
2944 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
2942 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
2945 @request.session[:user_id] = 2
2943 @request.session[:user_id] = 2
2946 issue_before_move = Issue.find(1)
2944 issue_before_move = Issue.find(1)
2947 assert_difference 'Issue.count', 1 do
2945 assert_difference 'Issue.count', 1 do
2948 assert_no_difference 'Project.find(1).issues.count' do
2946 assert_no_difference 'Project.find(1).issues.count' do
2949 post :bulk_update, :ids => [1], :copy => '1',
2947 post :bulk_update, :ids => [1], :copy => '1',
2950 :issue => {
2948 :issue => {
2951 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
2949 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
2952 :status_id => '', :start_date => '', :due_date => ''
2950 :status_id => '', :start_date => '', :due_date => ''
2953 }
2951 }
2954 end
2952 end
2955 end
2953 end
2956 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
2954 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
2957 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
2955 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
2958 assert_equal issue_before_move.status_id, issue_after_move.status_id
2956 assert_equal issue_before_move.status_id, issue_after_move.status_id
2959 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
2957 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
2960 end
2958 end
2961
2959
2962 def test_bulk_copy_should_allow_changing_the_issue_attributes
2960 def test_bulk_copy_should_allow_changing_the_issue_attributes
2963 # Fixes random test failure with Mysql
2961 # Fixes random test failure with Mysql
2964 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2962 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2965 # doesn't return the expected results
2963 # doesn't return the expected results
2966 Issue.delete_all("project_id=2")
2964 Issue.delete_all("project_id=2")
2967
2965
2968 @request.session[:user_id] = 2
2966 @request.session[:user_id] = 2
2969 assert_difference 'Issue.count', 2 do
2967 assert_difference 'Issue.count', 2 do
2970 assert_no_difference 'Project.find(1).issues.count' do
2968 assert_no_difference 'Project.find(1).issues.count' do
2971 post :bulk_update, :ids => [1, 2], :copy => '1',
2969 post :bulk_update, :ids => [1, 2], :copy => '1',
2972 :issue => {
2970 :issue => {
2973 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
2971 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
2974 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2972 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2975 }
2973 }
2976 end
2974 end
2977 end
2975 end
2978
2976
2979 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2977 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2980 assert_equal 2, copied_issues.size
2978 assert_equal 2, copied_issues.size
2981 copied_issues.each do |issue|
2979 copied_issues.each do |issue|
2982 assert_equal 2, issue.project_id, "Project is incorrect"
2980 assert_equal 2, issue.project_id, "Project is incorrect"
2983 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
2981 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
2984 assert_equal 3, issue.status_id, "Status is incorrect"
2982 assert_equal 3, issue.status_id, "Status is incorrect"
2985 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
2983 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
2986 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
2984 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
2987 end
2985 end
2988 end
2986 end
2989
2987
2990 def test_bulk_copy_should_allow_adding_a_note
2988 def test_bulk_copy_should_allow_adding_a_note
2991 @request.session[:user_id] = 2
2989 @request.session[:user_id] = 2
2992 assert_difference 'Issue.count', 1 do
2990 assert_difference 'Issue.count', 1 do
2993 post :bulk_update, :ids => [1], :copy => '1',
2991 post :bulk_update, :ids => [1], :copy => '1',
2994 :notes => 'Copying one issue',
2992 :notes => 'Copying one issue',
2995 :issue => {
2993 :issue => {
2996 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
2994 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
2997 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2995 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2998 }
2996 }
2999 end
2997 end
3000
2998
3001 issue = Issue.first(:order => 'id DESC')
2999 issue = Issue.first(:order => 'id DESC')
3002 assert_equal 1, issue.journals.size
3000 assert_equal 1, issue.journals.size
3003 journal = issue.journals.first
3001 journal = issue.journals.first
3004 assert_equal 0, journal.details.size
3002 assert_equal 0, journal.details.size
3005 assert_equal 'Copying one issue', journal.notes
3003 assert_equal 'Copying one issue', journal.notes
3006 end
3004 end
3007
3005
3008 def test_bulk_copy_to_another_project_should_follow_when_needed
3006 def test_bulk_copy_to_another_project_should_follow_when_needed
3009 @request.session[:user_id] = 2
3007 @request.session[:user_id] = 2
3010 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3008 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3011 issue = Issue.first(:order => 'id DESC')
3009 issue = Issue.first(:order => 'id DESC')
3012 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3010 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3013 end
3011 end
3014
3012
3015 def test_destroy_issue_with_no_time_entries
3013 def test_destroy_issue_with_no_time_entries
3016 assert_nil TimeEntry.find_by_issue_id(2)
3014 assert_nil TimeEntry.find_by_issue_id(2)
3017 @request.session[:user_id] = 2
3015 @request.session[:user_id] = 2
3018
3016
3019 assert_difference 'Issue.count', -1 do
3017 assert_difference 'Issue.count', -1 do
3020 delete :destroy, :id => 2
3018 delete :destroy, :id => 2
3021 end
3019 end
3022 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3020 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3023 assert_nil Issue.find_by_id(2)
3021 assert_nil Issue.find_by_id(2)
3024 end
3022 end
3025
3023
3026 def test_destroy_issues_with_time_entries
3024 def test_destroy_issues_with_time_entries
3027 @request.session[:user_id] = 2
3025 @request.session[:user_id] = 2
3028
3026
3029 assert_no_difference 'Issue.count' do
3027 assert_no_difference 'Issue.count' do
3030 delete :destroy, :ids => [1, 3]
3028 delete :destroy, :ids => [1, 3]
3031 end
3029 end
3032 assert_response :success
3030 assert_response :success
3033 assert_template 'destroy'
3031 assert_template 'destroy'
3034 assert_not_nil assigns(:hours)
3032 assert_not_nil assigns(:hours)
3035 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3033 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3036 assert_tag 'form',
3034 assert_tag 'form',
3037 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3035 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3038 end
3036 end
3039
3037
3040 def test_destroy_issues_and_destroy_time_entries
3038 def test_destroy_issues_and_destroy_time_entries
3041 @request.session[:user_id] = 2
3039 @request.session[:user_id] = 2
3042
3040
3043 assert_difference 'Issue.count', -2 do
3041 assert_difference 'Issue.count', -2 do
3044 assert_difference 'TimeEntry.count', -3 do
3042 assert_difference 'TimeEntry.count', -3 do
3045 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3043 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3046 end
3044 end
3047 end
3045 end
3048 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3046 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3049 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3047 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3050 assert_nil TimeEntry.find_by_id([1, 2])
3048 assert_nil TimeEntry.find_by_id([1, 2])
3051 end
3049 end
3052
3050
3053 def test_destroy_issues_and_assign_time_entries_to_project
3051 def test_destroy_issues_and_assign_time_entries_to_project
3054 @request.session[:user_id] = 2
3052 @request.session[:user_id] = 2
3055
3053
3056 assert_difference 'Issue.count', -2 do
3054 assert_difference 'Issue.count', -2 do
3057 assert_no_difference 'TimeEntry.count' do
3055 assert_no_difference 'TimeEntry.count' do
3058 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3056 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3059 end
3057 end
3060 end
3058 end
3061 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3059 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3062 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3060 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3063 assert_nil TimeEntry.find(1).issue_id
3061 assert_nil TimeEntry.find(1).issue_id
3064 assert_nil TimeEntry.find(2).issue_id
3062 assert_nil TimeEntry.find(2).issue_id
3065 end
3063 end
3066
3064
3067 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3065 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3068 @request.session[:user_id] = 2
3066 @request.session[:user_id] = 2
3069
3067
3070 assert_difference 'Issue.count', -2 do
3068 assert_difference 'Issue.count', -2 do
3071 assert_no_difference 'TimeEntry.count' do
3069 assert_no_difference 'TimeEntry.count' do
3072 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3070 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3073 end
3071 end
3074 end
3072 end
3075 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3073 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3076 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3074 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3077 assert_equal 2, TimeEntry.find(1).issue_id
3075 assert_equal 2, TimeEntry.find(1).issue_id
3078 assert_equal 2, TimeEntry.find(2).issue_id
3076 assert_equal 2, TimeEntry.find(2).issue_id
3079 end
3077 end
3080
3078
3081 def test_destroy_issues_from_different_projects
3079 def test_destroy_issues_from_different_projects
3082 @request.session[:user_id] = 2
3080 @request.session[:user_id] = 2
3083
3081
3084 assert_difference 'Issue.count', -3 do
3082 assert_difference 'Issue.count', -3 do
3085 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3083 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3086 end
3084 end
3087 assert_redirected_to :controller => 'issues', :action => 'index'
3085 assert_redirected_to :controller => 'issues', :action => 'index'
3088 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3086 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3089 end
3087 end
3090
3088
3091 def test_destroy_parent_and_child_issues
3089 def test_destroy_parent_and_child_issues
3092 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
3090 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
3093 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
3091 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
3094 assert child.is_descendant_of?(parent.reload)
3092 assert child.is_descendant_of?(parent.reload)
3095
3093
3096 @request.session[:user_id] = 2
3094 @request.session[:user_id] = 2
3097 assert_difference 'Issue.count', -2 do
3095 assert_difference 'Issue.count', -2 do
3098 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3096 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3099 end
3097 end
3100 assert_response 302
3098 assert_response 302
3101 end
3099 end
3102
3100
3103 def test_default_search_scope
3101 def test_default_search_scope
3104 get :index
3102 get :index
3105 assert_tag :div, :attributes => {:id => 'quick-search'},
3103 assert_tag :div, :attributes => {:id => 'quick-search'},
3106 :child => {:tag => 'form',
3104 :child => {:tag => 'form',
3107 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3105 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3108 end
3106 end
3109 end
3107 end
General Comments 0
You need to be logged in to leave comments. Login now