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