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