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