comparison test/functional/projects_controller_test.rb @ 442:753f1380d6bc cannam

Merge from branch "redmine-1.2"
author Chris Cannam
date Mon, 06 Jun 2011 14:41:04 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
252:adc8466df404 442:753f1380d6bc
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2008 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__)
31 @request = ActionController::TestRequest.new 31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new 32 @response = ActionController::TestResponse.new
33 @request.session[:user_id] = nil 33 @request.session[:user_id] = nil
34 Setting.default_language = 'en' 34 Setting.default_language = 'en'
35 end 35 end
36 36
37 def test_index 37 def test_index
38 get :index 38 get :index
39 assert_response :success 39 assert_response :success
40 assert_template 'index' 40 assert_template 'index'
41 assert_not_nil assigns(:projects) 41 assert_not_nil assigns(:projects)
42 42
43 assert_tag :ul, :child => {:tag => 'li', 43 assert_tag :ul, :child => {:tag => 'li',
44 :descendant => {:tag => 'a', :content => 'eCookbook'}, 44 :descendant => {:tag => 'a', :content => 'eCookbook'},
45 :child => { :tag => 'ul', 45 :child => { :tag => 'ul',
46 :descendant => { :tag => 'a', 46 :descendant => { :tag => 'a',
47 :content => 'Child of private child' 47 :content => 'Child of private child'
48 } 48 }
49 } 49 }
50 } 50 }
51 51
52 assert_no_tag :a, :content => /Private child of eCookbook/ 52 assert_no_tag :a, :content => /Private child of eCookbook/
53 end 53 end
54 54
55 def test_index_atom 55 def test_index_atom
56 get :index, :format => 'atom' 56 get :index, :format => 'atom'
57 assert_response :success 57 assert_response :success
58 assert_template 'common/feed.atom.rxml' 58 assert_template 'common/feed.atom.rxml'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects' 59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) 60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
61 end 61 end
62 62
63 context "#index" do 63 context "#index" do
64 context "by non-admin user with view_time_entries permission" do 64 context "by non-admin user with view_time_entries permission" do
65 setup do 65 setup do
66 @request.session[:user_id] = 3 66 @request.session[:user_id] = 3
67 end 67 end
69 get :index 69 get :index
70 assert_template 'index' 70 assert_template 'index'
71 assert_tag :a, :attributes => {:href => '/time_entries'} 71 assert_tag :a, :attributes => {:href => '/time_entries'}
72 end 72 end
73 end 73 end
74 74
75 context "by non-admin user without view_time_entries permission" do 75 context "by non-admin user without view_time_entries permission" do
76 setup do 76 setup do
77 Role.find(2).remove_permission! :view_time_entries 77 Role.find(2).remove_permission! :view_time_entries
78 Role.non_member.remove_permission! :view_time_entries 78 Role.non_member.remove_permission! :view_time_entries
79 Role.anonymous.remove_permission! :view_time_entries 79 Role.anonymous.remove_permission! :view_time_entries
82 should "not show overall spent time link" do 82 should "not show overall spent time link" do
83 get :index 83 get :index
84 assert_template 'index' 84 assert_template 'index'
85 assert_no_tag :a, :attributes => {:href => '/time_entries'} 85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
86 end 86 end
87 end 87 end
88 end 88 end
89 89
90 context "#new" do 90 context "#new" do
91 context "by admin user" do 91 context "by admin user" do
92 setup do 92 setup do
93 @request.session[:user_id] = 1 93 @request.session[:user_id] = 1
94 end 94 end
95 95
96 should "accept get" do 96 should "accept get" do
97 get :new 97 get :new
98 assert_response :success 98 assert_response :success
99 assert_template 'new' 99 assert_template 'new'
100 end 100 end
119 setup do 119 setup do
120 Role.find(1).remove_permission! :add_project 120 Role.find(1).remove_permission! :add_project
121 Role.find(1).add_permission! :add_subprojects 121 Role.find(1).add_permission! :add_subprojects
122 @request.session[:user_id] = 2 122 @request.session[:user_id] = 2
123 end 123 end
124 124
125 should "accept get" do 125 should "accept get" do
126 get :new, :parent_id => 'ecookbook' 126 get :new, :parent_id => 'ecookbook'
127 assert_response :success 127 assert_response :success
128 assert_template 'new' 128 assert_template 'new'
129 # parent project selected 129 # parent project selected
132 # no empty value 132 # no empty value
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, 133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
134 :child => {:tag => 'option', :attributes => {:value => ''}} 134 :child => {:tag => 'option', :attributes => {:value => ''}}
135 end 135 end
136 end 136 end
137 137
138 end 138 end
139 139
140 context "POST :create" do 140 context "POST :create" do
141 context "by admin user" do 141 context "by admin user" do
142 setup do 142 setup do
143 @request.session[:user_id] = 1 143 @request.session[:user_id] = 1
144 end 144 end
145 145
146 should "create a new project" do 146 should "create a new project" do
147 post :create, 147 post :create,
148 :project => { 148 :project => {
149 :name => "blog", 149 :name => "blog",
150 :description => "weblog", 150 :description => "weblog",
151 :homepage => 'http://weblog', 151 :homepage => 'http://weblog',
152 :identifier => "blog", 152 :identifier => "blog",
153 :is_public => 1, 153 :is_public => 1,
154 :custom_field_values => { '3' => 'Beta' }, 154 :custom_field_values => { '3' => 'Beta' },
156 # an issue custom field that is not for all project 156 # an issue custom field that is not for all project
157 :issue_custom_field_ids => ['9'], 157 :issue_custom_field_ids => ['9'],
158 :enabled_module_names => ['issue_tracking', 'news', 'repository'] 158 :enabled_module_names => ['issue_tracking', 'news', 'repository']
159 } 159 }
160 assert_redirected_to '/projects/blog/settings' 160 assert_redirected_to '/projects/blog/settings'
161 161
162 project = Project.find_by_name('blog') 162 project = Project.find_by_name('blog')
163 assert_kind_of Project, project 163 assert_kind_of Project, project
164 assert project.active? 164 assert project.active?
165 assert_equal 'weblog', project.description 165 assert_equal 'weblog', project.description
166 assert_equal 'http://weblog', project.homepage 166 assert_equal 'http://weblog', project.homepage
167 assert_equal true, project.is_public? 167 assert_equal true, project.is_public?
168 assert_nil project.parent 168 assert_nil project.parent
169 assert_equal 'Beta', project.custom_value_for(3).value 169 assert_equal 'Beta', project.custom_value_for(3).value
170 assert_equal [1, 3], project.trackers.map(&:id).sort 170 assert_equal [1, 3], project.trackers.map(&:id).sort
171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort 171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
172 assert project.issue_custom_fields.include?(IssueCustomField.find(9)) 172 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
173 end 173 end
174 174
175 should "create a new subproject" do 175 should "create a new subproject" do
176 post :create, :project => { :name => "blog", 176 post :create, :project => { :name => "blog",
177 :description => "weblog", 177 :description => "weblog",
178 :identifier => "blog", 178 :identifier => "blog",
179 :is_public => 1, 179 :is_public => 1,
180 :custom_field_values => { '3' => 'Beta' }, 180 :custom_field_values => { '3' => 'Beta' },
181 :parent_id => 1 181 :parent_id => 1
182 } 182 }
183 assert_redirected_to '/projects/blog/settings' 183 assert_redirected_to '/projects/blog/settings'
184 184
185 project = Project.find_by_name('blog') 185 project = Project.find_by_name('blog')
186 assert_kind_of Project, project 186 assert_kind_of Project, project
187 assert_equal Project.find(1), project.parent 187 assert_equal Project.find(1), project.parent
188 end 188 end
189 end 189 end
190 190
191 context "by non-admin user with add_project permission" do 191 context "by non-admin user with add_project permission" do
192 setup do 192 setup do
193 Role.non_member.add_permission! :add_project 193 Role.non_member.add_permission! :add_project
194 @request.session[:user_id] = 9 194 @request.session[:user_id] = 9
195 end 195 end
196 196
197 should "accept create a Project" do 197 should "accept create a Project" do
198 post :create, :project => { :name => "blog", 198 post :create, :project => { :name => "blog",
199 :description => "weblog", 199 :description => "weblog",
200 :identifier => "blog", 200 :identifier => "blog",
201 :is_public => 1, 201 :is_public => 1,
202 :custom_field_values => { '3' => 'Beta' }, 202 :custom_field_values => { '3' => 'Beta' },
203 :tracker_ids => ['1', '3'], 203 :tracker_ids => ['1', '3'],
204 :enabled_module_names => ['issue_tracking', 'news', 'repository'] 204 :enabled_module_names => ['issue_tracking', 'news', 'repository']
205 } 205 }
206 206
207 assert_redirected_to '/projects/blog/settings' 207 assert_redirected_to '/projects/blog/settings'
208 208
209 project = Project.find_by_name('blog') 209 project = Project.find_by_name('blog')
210 assert_kind_of Project, project 210 assert_kind_of Project, project
211 assert_equal 'weblog', project.description 211 assert_equal 'weblog', project.description
212 assert_equal true, project.is_public? 212 assert_equal true, project.is_public?
213 assert_equal [1, 3], project.trackers.map(&:id).sort 213 assert_equal [1, 3], project.trackers.map(&:id).sort
214 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort 214 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
215 215
216 # User should be added as a project member 216 # User should be added as a project member
217 assert User.find(9).member_of?(project) 217 assert User.find(9).member_of?(project)
218 assert_equal 1, project.members.size 218 assert_equal 1, project.members.size
219 end 219 end
220 220
221 should "fail with parent_id" do 221 should "fail with parent_id" do
222 assert_no_difference 'Project.count' do 222 assert_no_difference 'Project.count' do
223 post :create, :project => { :name => "blog", 223 post :create, :project => { :name => "blog",
224 :description => "weblog", 224 :description => "weblog",
225 :identifier => "blog", 225 :identifier => "blog",
226 :is_public => 1, 226 :is_public => 1,
227 :custom_field_values => { '3' => 'Beta' }, 227 :custom_field_values => { '3' => 'Beta' },
228 :parent_id => 1 228 :parent_id => 1
232 project = assigns(:project) 232 project = assigns(:project)
233 assert_kind_of Project, project 233 assert_kind_of Project, project
234 assert_not_nil project.errors.on(:parent_id) 234 assert_not_nil project.errors.on(:parent_id)
235 end 235 end
236 end 236 end
237 237
238 context "by non-admin user with add_subprojects permission" do 238 context "by non-admin user with add_subprojects permission" do
239 setup do 239 setup do
240 Role.find(1).remove_permission! :add_project 240 Role.find(1).remove_permission! :add_project
241 Role.find(1).add_permission! :add_subprojects 241 Role.find(1).add_permission! :add_subprojects
242 @request.session[:user_id] = 2 242 @request.session[:user_id] = 2
243 end 243 end
244 244
245 should "create a project with a parent_id" do 245 should "create a project with a parent_id" do
246 post :create, :project => { :name => "blog", 246 post :create, :project => { :name => "blog",
247 :description => "weblog", 247 :description => "weblog",
248 :identifier => "blog", 248 :identifier => "blog",
249 :is_public => 1, 249 :is_public => 1,
250 :custom_field_values => { '3' => 'Beta' }, 250 :custom_field_values => { '3' => 'Beta' },
251 :parent_id => 1 251 :parent_id => 1
252 } 252 }
253 assert_redirected_to '/projects/blog/settings' 253 assert_redirected_to '/projects/blog/settings'
254 project = Project.find_by_name('blog') 254 project = Project.find_by_name('blog')
255 end 255 end
256 256
257 should "fail without parent_id" do 257 should "fail without parent_id" do
258 assert_no_difference 'Project.count' do 258 assert_no_difference 'Project.count' do
259 post :create, :project => { :name => "blog", 259 post :create, :project => { :name => "blog",
260 :description => "weblog", 260 :description => "weblog",
261 :identifier => "blog", 261 :identifier => "blog",
262 :is_public => 1, 262 :is_public => 1,
263 :custom_field_values => { '3' => 'Beta' } 263 :custom_field_values => { '3' => 'Beta' }
264 } 264 }
266 assert_response :success 266 assert_response :success
267 project = assigns(:project) 267 project = assigns(:project)
268 assert_kind_of Project, project 268 assert_kind_of Project, project
269 assert_not_nil project.errors.on(:parent_id) 269 assert_not_nil project.errors.on(:parent_id)
270 end 270 end
271 271
272 should "fail with unauthorized parent_id" do 272 should "fail with unauthorized parent_id" do
273 assert !User.find(2).member_of?(Project.find(6)) 273 assert !User.find(2).member_of?(Project.find(6))
274 assert_no_difference 'Project.count' do 274 assert_no_difference 'Project.count' do
275 post :create, :project => { :name => "blog", 275 post :create, :project => { :name => "blog",
276 :description => "weblog", 276 :description => "weblog",
277 :identifier => "blog", 277 :identifier => "blog",
278 :is_public => 1, 278 :is_public => 1,
279 :custom_field_values => { '3' => 'Beta' }, 279 :custom_field_values => { '3' => 'Beta' },
280 :parent_id => 6 280 :parent_id => 6
285 assert_kind_of Project, project 285 assert_kind_of Project, project
286 assert_not_nil project.errors.on(:parent_id) 286 assert_not_nil project.errors.on(:parent_id)
287 end 287 end
288 end 288 end
289 end 289 end
290 290
291 def test_create_should_preserve_modules_on_validation_failure
292 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
293 @request.session[:user_id] = 1
294 assert_no_difference 'Project.count' do
295 post :create, :project => {
296 :name => "blog",
297 :identifier => "",
298 :enabled_module_names => %w(issue_tracking news)
299 }
300 end
301 assert_response :success
302 project = assigns(:project)
303 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
304 end
305 end
306
291 def test_create_should_not_accept_get 307 def test_create_should_not_accept_get
292 @request.session[:user_id] = 1 308 @request.session[:user_id] = 1
293 get :create 309 get :create
294 assert_response :method_not_allowed 310 assert_response :method_not_allowed
295 end 311 end
296 312
297 def test_show_by_id 313 def test_show_by_id
298 get :show, :id => 1 314 get :show, :id => 1
299 assert_response :success 315 assert_response :success
300 assert_template 'show' 316 assert_template 'show'
301 assert_not_nil assigns(:project) 317 assert_not_nil assigns(:project)
305 get :show, :id => 'ecookbook' 321 get :show, :id => 'ecookbook'
306 assert_response :success 322 assert_response :success
307 assert_template 'show' 323 assert_template 'show'
308 assert_not_nil assigns(:project) 324 assert_not_nil assigns(:project)
309 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) 325 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
310 326
311 assert_tag 'li', :content => /Development status/ 327 assert_tag 'li', :content => /Development status/
312 end 328 end
313 329
314 def test_show_should_not_display_hidden_custom_fields 330 def test_show_should_not_display_hidden_custom_fields
315 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false 331 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
316 get :show, :id => 'ecookbook' 332 get :show, :id => 'ecookbook'
317 assert_response :success 333 assert_response :success
318 assert_template 'show' 334 assert_template 'show'
319 assert_not_nil assigns(:project) 335 assert_not_nil assigns(:project)
320 336
321 assert_no_tag 'li', :content => /Development status/ 337 assert_no_tag 'li', :content => /Development status/
322 end 338 end
323 339
324 def test_show_should_not_fail_when_custom_values_are_nil 340 def test_show_should_not_fail_when_custom_values_are_nil
325 project = Project.find_by_identifier('ecookbook') 341 project = Project.find_by_identifier('ecookbook')
326 project.custom_values.first.update_attribute(:value, nil) 342 project.custom_values.first.update_attribute(:value, nil)
327 get :show, :id => 'ecookbook' 343 get :show, :id => 'ecookbook'
328 assert_response :success 344 assert_response :success
329 assert_template 'show' 345 assert_template 'show'
330 assert_not_nil assigns(:project) 346 assert_not_nil assigns(:project)
331 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) 347 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
332 end 348 end
333 349
334 def show_archived_project_should_be_denied 350 def show_archived_project_should_be_denied
335 project = Project.find_by_identifier('ecookbook') 351 project = Project.find_by_identifier('ecookbook')
336 project.archive! 352 project.archive!
337 353
338 get :show, :id => 'ecookbook' 354 get :show, :id => 'ecookbook'
339 assert_response 403 355 assert_response 403
340 assert_nil assigns(:project) 356 assert_nil assigns(:project)
341 assert_tag :tag => 'p', :content => /archived/ 357 assert_tag :tag => 'p', :content => /archived/
342 end 358 end
343 359
344 def test_private_subprojects_hidden 360 def test_private_subprojects_hidden
345 get :show, :id => 'ecookbook' 361 get :show, :id => 'ecookbook'
346 assert_response :success 362 assert_response :success
347 assert_template 'show' 363 assert_template 'show'
348 assert_no_tag :tag => 'a', :content => /Private child/ 364 assert_no_tag :tag => 'a', :content => /Private child/
353 get :show, :id => 'ecookbook' 369 get :show, :id => 'ecookbook'
354 assert_response :success 370 assert_response :success
355 assert_template 'show' 371 assert_template 'show'
356 assert_tag :tag => 'a', :content => /Private child/ 372 assert_tag :tag => 'a', :content => /Private child/
357 end 373 end
358 374
359 def test_settings 375 def test_settings
360 @request.session[:user_id] = 2 # manager 376 @request.session[:user_id] = 2 # manager
361 get :settings, :id => 1 377 get :settings, :id => 1
362 assert_response :success 378 assert_response :success
363 assert_template 'settings' 379 assert_template 'settings'
364 end 380 end
365 381
366 def test_update 382 def test_update
367 @request.session[:user_id] = 2 # manager 383 @request.session[:user_id] = 2 # manager
368 post :update, :id => 1, :project => {:name => 'Test changed name', 384 post :update, :id => 1, :project => {:name => 'Test changed name',
369 :issue_custom_field_ids => ['']} 385 :issue_custom_field_ids => ['']}
370 assert_redirected_to '/projects/ecookbook/settings' 386 assert_redirected_to '/projects/ecookbook/settings'
373 end 389 end
374 390
375 def test_modules 391 def test_modules
376 @request.session[:user_id] = 2 392 @request.session[:user_id] = 2
377 Project.find(1).enabled_module_names = ['issue_tracking', 'news'] 393 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
378 394
379 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] 395 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
380 assert_redirected_to '/projects/ecookbook/settings/modules' 396 assert_redirected_to '/projects/ecookbook/settings/modules'
381 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort 397 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
382 end 398 end
383 399
384 def test_modules_should_not_allow_get 400 def test_modules_should_not_allow_get
385 @request.session[:user_id] = 1 401 @request.session[:user_id] = 1
386 get :modules, :id => 1 402 get :modules, :id => 1
387 assert_response :method_not_allowed 403 assert_response :method_not_allowed
388 end 404 end
389 405
390 def test_get_destroy 406 def test_get_destroy
391 @request.session[:user_id] = 1 # admin 407 @request.session[:user_id] = 1 # admin
392 get :destroy, :id => 1 408 get :destroy, :id => 1
393 assert_response :success 409 assert_response :success
394 assert_template 'destroy' 410 assert_template 'destroy'
399 @request.session[:user_id] = 1 # admin 415 @request.session[:user_id] = 1 # admin
400 post :destroy, :id => 1, :confirm => 1 416 post :destroy, :id => 1, :confirm => 1
401 assert_redirected_to '/admin/projects' 417 assert_redirected_to '/admin/projects'
402 assert_nil Project.find_by_id(1) 418 assert_nil Project.find_by_id(1)
403 end 419 end
404 420
405 def test_archive 421 def test_archive
406 @request.session[:user_id] = 1 # admin 422 @request.session[:user_id] = 1 # admin
407 post :archive, :id => 1 423 post :archive, :id => 1
408 assert_redirected_to '/admin/projects' 424 assert_redirected_to '/admin/projects'
409 assert !Project.find(1).active? 425 assert !Project.find(1).active?
410 end 426 end
411 427
412 def test_unarchive 428 def test_unarchive
413 @request.session[:user_id] = 1 # admin 429 @request.session[:user_id] = 1 # admin
414 Project.find(1).archive 430 Project.find(1).archive
415 post :unarchive, :id => 1 431 post :unarchive, :id => 1
416 assert_redirected_to '/admin/projects' 432 assert_redirected_to '/admin/projects'
417 assert Project.find(1).active? 433 assert Project.find(1).active?
418 end 434 end
419 435
420 def test_project_breadcrumbs_should_be_limited_to_3_ancestors 436 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
421 CustomField.delete_all 437 CustomField.delete_all
422 parent = nil 438 parent = nil
423 6.times do |i| 439 6.times do |i|
424 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") 440 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
425 p.set_parent!(parent) 441 p.set_parent!(parent)
426 get :show, :id => p 442 get :show, :id => p
427 assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, 443 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
428 :children => { :count => [i, 3].min, 444 :children => { :count => [i, 3].min,
429 :only => { :tag => 'a' } } 445 :only => { :tag => 'a' } }
430 446
431 parent = p 447 parent = p
432 end 448 end
433 end 449 end
434 450
435 def test_copy_with_project 451 def test_get_copy
436 @request.session[:user_id] = 1 # admin 452 @request.session[:user_id] = 1 # admin
437 get :copy, :id => 1 453 get :copy, :id => 1
438 assert_response :success 454 assert_response :success
439 assert_template 'copy' 455 assert_template 'copy'
440 assert assigns(:project) 456 assert assigns(:project)
441 assert_equal Project.find(1).description, assigns(:project).description 457 assert_equal Project.find(1).description, assigns(:project).description
442 assert_nil assigns(:project).id 458 assert_nil assigns(:project).id
443 end 459
444 460 assert_tag :tag => 'input',
445 def test_copy_without_project 461 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'}
462 end
463
464 def test_get_copy_without_project
446 @request.session[:user_id] = 1 # admin 465 @request.session[:user_id] = 1 # admin
447 get :copy 466 get :copy
448 assert_response :redirect 467 assert_response :redirect
449 assert_redirected_to :controller => 'admin', :action => 'projects' 468 assert_redirected_to :controller => 'admin', :action => 'projects'
450 end 469 end
451 470
452 context "POST :copy" do 471 def test_post_copy_should_copy_requested_items
453 should "TODO: test the rest of the method" 472 @request.session[:user_id] = 1 # admin
454 473 CustomField.delete_all
455 should "redirect to the project settings when successful" do 474
456 @request.session[:user_id] = 1 # admin 475 assert_difference 'Project.count' do
457 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} 476 post :copy, :id => 1,
458 assert_response :redirect 477 :project => {
459 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' 478 :name => 'Copy',
460 end 479 :identifier => 'unique-copy',
480 :tracker_ids => ['1', '2', '3', ''],
481 :enabled_module_names => %w(issue_tracking time_tracking)
482 },
483 :only => %w(issues versions)
484 end
485 project = Project.find('unique-copy')
486 source = Project.find(1)
487 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
488
489 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
490 # issues assigned to a closed version won't be copied
491 assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size,
492 project.issues.count, "All issues were not copied"
493 assert_equal 0, project.members.count
494 end
495
496 def test_post_copy_should_redirect_to_settings_when_successful
497 @request.session[:user_id] = 1 # admin
498 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
499 assert_response :redirect
500 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
461 end 501 end
462 502
463 def test_jump_should_redirect_to_active_tab 503 def test_jump_should_redirect_to_active_tab
464 get :show, :id => 1, :jump => 'issues' 504 get :show, :id => 1, :jump => 'issues'
465 assert_redirected_to '/projects/ecookbook/issues' 505 assert_redirected_to '/projects/ecookbook/issues'
466 end 506 end
467 507
468 def test_jump_should_not_redirect_to_inactive_tab 508 def test_jump_should_not_redirect_to_inactive_tab
469 get :show, :id => 3, :jump => 'documents' 509 get :show, :id => 3, :jump => 'documents'
470 assert_response :success 510 assert_response :success
471 assert_template 'show' 511 assert_template 'show'
472 end 512 end
473 513
474 def test_jump_should_not_redirect_to_unknown_tab 514 def test_jump_should_not_redirect_to_unknown_tab
475 get :show, :id => 3, :jump => 'foobar' 515 get :show, :id => 3, :jump => 'foobar'
476 assert_response :success 516 assert_response :success
477 assert_template 'show' 517 assert_template 'show'
478 end 518 end
484 stylesheet_link_tag(context[:project].identifier) if context[:project] 524 stylesheet_link_tag(context[:project].identifier) if context[:project]
485 end 525 end
486 end 526 end
487 # Don't use this hook now 527 # Don't use this hook now
488 Redmine::Hook.clear_listeners 528 Redmine::Hook.clear_listeners
489 529
490 def test_hook_response 530 def test_hook_response
491 Redmine::Hook.add_listener(ProjectBasedTemplate) 531 Redmine::Hook.add_listener(ProjectBasedTemplate)
492 get :show, :id => 1 532 get :show, :id => 1
493 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, 533 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
494 :parent => {:tag => 'head'} 534 :parent => {:tag => 'head'}
495 535
496 Redmine::Hook.clear_listeners 536 Redmine::Hook.clear_listeners
497 end 537 end
498 end 538 end