comparison test/functional/projects_controller_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 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.
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 'projects_controller'
20
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
23 19
24 class ProjectsControllerTest < ActionController::TestCase 20 class ProjectsControllerTest < ActionController::TestCase
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, 21 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, 22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
27 :attachments, :custom_fields, :custom_values, :time_entries 23 :attachments, :custom_fields, :custom_values, :time_entries
28 24
29 def setup 25 def setup
30 @controller = ProjectsController.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
33 @request.session[:user_id] = nil 26 @request.session[:user_id] = nil
34 Setting.default_language = 'en' 27 Setting.default_language = 'en'
35 end 28 end
36 29
37 def test_index 30 def test_index_by_anonymous_should_not_show_private_projects
38 get :index 31 get :index
39 assert_response :success 32 assert_response :success
40 assert_template 'index' 33 assert_template 'index'
41 assert_not_nil assigns(:projects) 34 projects = assigns(:projects)
42 35 assert_not_nil projects
43 assert_tag :ul, :child => {:tag => 'li', 36 assert projects.all?(&:is_public?)
44 :descendant => {:tag => 'a', :content => 'eCookbook'}, 37
45 :child => { :tag => 'ul', 38 assert_select 'ul' do
46 :descendant => { :tag => 'a', 39 assert_select 'li' do
47 :content => 'Child of private child' 40 assert_select 'a', :text => 'eCookbook'
48 } 41 assert_select 'ul' do
49 } 42 assert_select 'a', :text => 'Child of private child'
50 } 43 end
51 44 end
52 assert_no_tag :a, :content => /Private child of eCookbook/ 45 end
46 assert_select 'a', :text => /Private child of eCookbook/, :count => 0
53 end 47 end
54 48
55 def test_index_atom 49 def test_index_atom
56 get :index, :format => 'atom' 50 get :index, :format => 'atom'
57 assert_response :success 51 assert_response :success
58 assert_template 'common/feed' 52 assert_template 'common/feed'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects' 53 assert_select 'feed>title', :text => 'Redmine: Latest projects'
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) 54 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
61 end 55 end
62 56
63 context "#index" do 57 test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
64 context "by non-admin user with view_time_entries permission" do 58 @request.session[:user_id] = 3
65 setup do 59 get :index
66 @request.session[:user_id] = 3 60 assert_template 'index'
67 end 61 assert_select 'a[href=?]', '/time_entries'
68 should "show overall spent time link" do 62 end
69 get :index 63
70 assert_template 'index' 64 test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do
71 assert_tag :a, :attributes => {:href => '/time_entries'} 65 Role.find(2).remove_permission! :view_time_entries
72 end 66 Role.non_member.remove_permission! :view_time_entries
73 end 67 Role.anonymous.remove_permission! :view_time_entries
74 68 @request.session[:user_id] = 3
75 context "by non-admin user without view_time_entries permission" do 69
76 setup do 70 get :index
77 Role.find(2).remove_permission! :view_time_entries 71 assert_template 'index'
78 Role.non_member.remove_permission! :view_time_entries 72 assert_select 'a[href=?]', '/time_entries', 0
79 Role.anonymous.remove_permission! :view_time_entries 73 end
80 @request.session[:user_id] = 3 74
81 end 75 test "#new by admin user should accept get" do
82 should "not show overall spent time link" do 76 @request.session[:user_id] = 1
83 get :index 77
84 assert_template 'index' 78 get :new
85 assert_no_tag :a, :attributes => {:href => '/time_entries'} 79 assert_response :success
86 end 80 assert_template 'new'
87 end 81 end
88 end 82
89 83 test "#new by non-admin user with add_project permission should accept get" do
90 context "#new" do 84 Role.non_member.add_permission! :add_project
91 context "by admin user" do 85 @request.session[:user_id] = 9
92 setup do 86
93 @request.session[:user_id] = 1 87 get :new
94 end 88 assert_response :success
95 89 assert_template 'new'
96 should "accept get" do 90 assert_select 'select[name=?]', 'project[parent_id]', 0
97 get :new 91 end
98 assert_response :success 92
99 assert_template 'new' 93 test "#new by non-admin user with add_subprojects permission should accept get" do
100 end 94 Role.find(1).remove_permission! :add_project
101 95 Role.find(1).add_permission! :add_subprojects
102 end 96 @request.session[:user_id] = 2
103 97
104 context "by non-admin user with add_project permission" do 98 get :new, :parent_id => 'ecookbook'
105 setup do 99 assert_response :success
106 Role.non_member.add_permission! :add_project 100 assert_template 'new'
107 @request.session[:user_id] = 9 101
108 end 102 assert_select 'select[name=?]', 'project[parent_id]' do
109 103 # parent project selected
110 should "accept get" do 104 assert_select 'option[value=1][selected=selected]'
111 get :new 105 # no empty value
112 assert_response :success 106 assert_select 'option[value=]', 0
113 assert_template 'new' 107 end
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} 108 end
115 end 109
116 end 110 test "#create by admin user should create a new project" do
117 111 @request.session[:user_id] = 1
118 context "by non-admin user with add_subprojects permission" do 112
119 setup do 113 post :create,
120 Role.find(1).remove_permission! :add_project 114 :project => {
121 Role.find(1).add_permission! :add_subprojects 115 :name => "blog",
122 @request.session[:user_id] = 2 116 :description => "weblog",
123 end 117 :homepage => 'http://weblog',
124 118 :identifier => "blog",
125 should "accept get" do 119 :is_public => 1,
126 get :new, :parent_id => 'ecookbook' 120 :custom_field_values => { '3' => 'Beta' },
127 assert_response :success 121 :tracker_ids => ['1', '3'],
128 assert_template 'new' 122 # an issue custom field that is not for all project
129 # parent project selected 123 :issue_custom_field_ids => ['9'],
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'}, 124 :enabled_module_names => ['issue_tracking', 'news', 'repository']
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} 125 }
132 # no empty value 126 assert_redirected_to '/projects/blog/settings'
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, 127
134 :child => {:tag => 'option', :attributes => {:value => ''}} 128 project = Project.find_by_name('blog')
135 end 129 assert_kind_of Project, project
136 end 130 assert project.active?
137 131 assert_equal 'weblog', project.description
138 end 132 assert_equal 'http://weblog', project.homepage
139 133 assert_equal true, project.is_public?
140 context "POST :create" do 134 assert_nil project.parent
141 context "by admin user" do 135 assert_equal 'Beta', project.custom_value_for(3).value
142 setup do 136 assert_equal [1, 3], project.trackers.map(&:id).sort
143 @request.session[:user_id] = 1 137 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
144 end 138 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
145 139 end
146 should "create a new project" do 140
147 post :create, 141 test "#create by admin user should create a new subproject" do
148 :project => { 142 @request.session[:user_id] = 1
149 :name => "blog", 143
150 :description => "weblog", 144 assert_difference 'Project.count' do
151 :homepage => 'http://weblog', 145 post :create, :project => { :name => "blog",
152 :identifier => "blog", 146 :description => "weblog",
153 :is_public => 1, 147 :identifier => "blog",
154 :custom_field_values => { '3' => 'Beta' }, 148 :is_public => 1,
155 :tracker_ids => ['1', '3'], 149 :custom_field_values => { '3' => 'Beta' },
156 # an issue custom field that is not for all project 150 :parent_id => 1
157 :issue_custom_field_ids => ['9'], 151 }
158 :enabled_module_names => ['issue_tracking', 'news', 'repository'] 152 assert_redirected_to '/projects/blog/settings'
159 } 153 end
160 assert_redirected_to '/projects/blog/settings' 154
161 155 project = Project.find_by_name('blog')
162 project = Project.find_by_name('blog') 156 assert_kind_of Project, project
163 assert_kind_of Project, project 157 assert_equal Project.find(1), project.parent
164 assert project.active? 158 end
165 assert_equal 'weblog', project.description 159
166 assert_equal 'http://weblog', project.homepage 160 test "#create by admin user should continue" do
167 assert_equal true, project.is_public? 161 @request.session[:user_id] = 1
168 assert_nil project.parent 162
169 assert_equal 'Beta', project.custom_value_for(3).value 163 assert_difference 'Project.count' do
170 assert_equal [1, 3], project.trackers.map(&:id).sort 164 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue'
171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort 165 end
172 assert project.issue_custom_fields.include?(IssueCustomField.find(9)) 166 assert_redirected_to '/projects/new'
173 end 167 end
174 168
175 should "create a new subproject" do 169 test "#create by non-admin user with add_project permission should create a new project" do
176 post :create, :project => { :name => "blog", 170 Role.non_member.add_permission! :add_project
177 :description => "weblog", 171 @request.session[:user_id] = 9
178 :identifier => "blog", 172
179 :is_public => 1, 173 post :create, :project => { :name => "blog",
180 :custom_field_values => { '3' => 'Beta' }, 174 :description => "weblog",
181 :parent_id => 1 175 :identifier => "blog",
182 } 176 :is_public => 1,
183 assert_redirected_to '/projects/blog/settings' 177 :custom_field_values => { '3' => 'Beta' },
184 178 :tracker_ids => ['1', '3'],
185 project = Project.find_by_name('blog') 179 :enabled_module_names => ['issue_tracking', 'news', 'repository']
186 assert_kind_of Project, project 180 }
187 assert_equal Project.find(1), project.parent 181
188 end 182 assert_redirected_to '/projects/blog/settings'
189 183
190 should "continue" do 184 project = Project.find_by_name('blog')
191 assert_difference 'Project.count' do 185 assert_kind_of Project, project
192 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' 186 assert_equal 'weblog', project.description
193 end 187 assert_equal true, project.is_public?
194 assert_redirected_to '/projects/new?' 188 assert_equal [1, 3], project.trackers.map(&:id).sort
195 end 189 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
196 end 190
197 191 # User should be added as a project member
198 context "by non-admin user with add_project permission" do 192 assert User.find(9).member_of?(project)
199 setup do 193 assert_equal 1, project.members.size
200 Role.non_member.add_permission! :add_project 194 end
201 @request.session[:user_id] = 9 195
202 end 196 test "#create by non-admin user with add_project permission should fail with parent_id" do
203 197 Role.non_member.add_permission! :add_project
204 should "accept create a Project" do 198 @request.session[:user_id] = 9
205 post :create, :project => { :name => "blog", 199
206 :description => "weblog", 200 assert_no_difference 'Project.count' do
207 :identifier => "blog", 201 post :create, :project => { :name => "blog",
208 :is_public => 1, 202 :description => "weblog",
209 :custom_field_values => { '3' => 'Beta' }, 203 :identifier => "blog",
210 :tracker_ids => ['1', '3'], 204 :is_public => 1,
211 :enabled_module_names => ['issue_tracking', 'news', 'repository'] 205 :custom_field_values => { '3' => 'Beta' },
212 } 206 :parent_id => 1
213 207 }
214 assert_redirected_to '/projects/blog/settings' 208 end
215 209 assert_response :success
216 project = Project.find_by_name('blog') 210 project = assigns(:project)
217 assert_kind_of Project, project 211 assert_kind_of Project, project
218 assert_equal 'weblog', project.description 212 assert_not_nil project.errors[:parent_id]
219 assert_equal true, project.is_public? 213 end
220 assert_equal [1, 3], project.trackers.map(&:id).sort 214
221 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort 215 test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do
222 216 Role.find(1).remove_permission! :add_project
223 # User should be added as a project member 217 Role.find(1).add_permission! :add_subprojects
224 assert User.find(9).member_of?(project) 218 @request.session[:user_id] = 2
225 assert_equal 1, project.members.size 219
226 end 220 post :create, :project => { :name => "blog",
227 221 :description => "weblog",
228 should "fail with parent_id" do 222 :identifier => "blog",
229 assert_no_difference 'Project.count' do 223 :is_public => 1,
230 post :create, :project => { :name => "blog", 224 :custom_field_values => { '3' => 'Beta' },
231 :description => "weblog", 225 :parent_id => 1
232 :identifier => "blog", 226 }
233 :is_public => 1, 227 assert_redirected_to '/projects/blog/settings'
234 :custom_field_values => { '3' => 'Beta' }, 228 project = Project.find_by_name('blog')
235 :parent_id => 1 229 end
236 } 230
237 end 231 test "#create by non-admin user with add_subprojects permission should fail without parent_id" do
238 assert_response :success 232 Role.find(1).remove_permission! :add_project
239 project = assigns(:project) 233 Role.find(1).add_permission! :add_subprojects
240 assert_kind_of Project, project 234 @request.session[:user_id] = 2
241 assert_not_nil project.errors[:parent_id] 235
242 end 236 assert_no_difference 'Project.count' do
243 end 237 post :create, :project => { :name => "blog",
244 238 :description => "weblog",
245 context "by non-admin user with add_subprojects permission" do 239 :identifier => "blog",
246 setup do 240 :is_public => 1,
247 Role.find(1).remove_permission! :add_project 241 :custom_field_values => { '3' => 'Beta' }
248 Role.find(1).add_permission! :add_subprojects 242 }
249 @request.session[:user_id] = 2 243 end
250 end 244 assert_response :success
251 245 project = assigns(:project)
252 should "create a project with a parent_id" do 246 assert_kind_of Project, project
253 post :create, :project => { :name => "blog", 247 assert_not_nil project.errors[:parent_id]
254 :description => "weblog", 248 end
255 :identifier => "blog", 249
256 :is_public => 1, 250 test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do
257 :custom_field_values => { '3' => 'Beta' }, 251 Role.find(1).remove_permission! :add_project
258 :parent_id => 1 252 Role.find(1).add_permission! :add_subprojects
259 } 253 @request.session[:user_id] = 2
260 assert_redirected_to '/projects/blog/settings' 254
261 project = Project.find_by_name('blog') 255 assert !User.find(2).member_of?(Project.find(6))
262 end 256 assert_no_difference 'Project.count' do
263 257 post :create, :project => { :name => "blog",
264 should "fail without parent_id" do 258 :description => "weblog",
265 assert_no_difference 'Project.count' do 259 :identifier => "blog",
266 post :create, :project => { :name => "blog", 260 :is_public => 1,
267 :description => "weblog", 261 :custom_field_values => { '3' => 'Beta' },
268 :identifier => "blog", 262 :parent_id => 6
269 :is_public => 1, 263 }
270 :custom_field_values => { '3' => 'Beta' } 264 end
271 } 265 assert_response :success
272 end 266 project = assigns(:project)
273 assert_response :success 267 assert_kind_of Project, project
274 project = assigns(:project) 268 assert_not_nil project.errors[:parent_id]
275 assert_kind_of Project, project 269 end
276 assert_not_nil project.errors[:parent_id] 270
277 end 271 def test_create_subproject_with_inherit_members_should_inherit_members
278 272 Role.find_by_name('Manager').add_permission! :add_subprojects
279 should "fail with unauthorized parent_id" do 273 parent = Project.find(1)
280 assert !User.find(2).member_of?(Project.find(6)) 274 @request.session[:user_id] = 2
281 assert_no_difference 'Project.count' do 275
282 post :create, :project => { :name => "blog", 276 assert_difference 'Project.count' do
283 :description => "weblog", 277 post :create, :project => {
284 :identifier => "blog", 278 :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1'
285 :is_public => 1, 279 }
286 :custom_field_values => { '3' => 'Beta' }, 280 assert_response 302
287 :parent_id => 6 281 end
288 } 282
289 end 283 project = Project.order('id desc').first
290 assert_response :success 284 assert_equal 'inherited', project.name
291 project = assigns(:project) 285 assert_equal parent, project.parent
292 assert_kind_of Project, project 286 assert project.memberships.count > 0
293 assert_not_nil project.errors[:parent_id] 287 assert_equal parent.memberships.count, project.memberships.count
294 end
295 end
296 end 288 end
297 289
298 def test_create_should_preserve_modules_on_validation_failure 290 def test_create_should_preserve_modules_on_validation_failure
299 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do 291 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
300 @request.session[:user_id] = 1 292 @request.session[:user_id] = 1
323 assert_response :success 315 assert_response :success
324 assert_template 'show' 316 assert_template 'show'
325 assert_not_nil assigns(:project) 317 assert_not_nil assigns(:project)
326 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) 318 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
327 319
328 assert_tag 'li', :content => /Development status/ 320 assert_select 'li', :text => /Development status/
329 end 321 end
330 322
331 def test_show_should_not_display_hidden_custom_fields 323 def test_show_should_not_display_hidden_custom_fields
332 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false 324 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
333 get :show, :id => 'ecookbook' 325 get :show, :id => 'ecookbook'
334 assert_response :success 326 assert_response :success
335 assert_template 'show' 327 assert_template 'show'
336 assert_not_nil assigns(:project) 328 assert_not_nil assigns(:project)
337 329
338 assert_no_tag 'li', :content => /Development status/ 330 assert_select 'li', :text => /Development status/, :count => 0
339 end 331 end
340 332
341 def test_show_should_not_fail_when_custom_values_are_nil 333 def test_show_should_not_fail_when_custom_values_are_nil
342 project = Project.find_by_identifier('ecookbook') 334 project = Project.find_by_identifier('ecookbook')
343 project.custom_values.first.update_attribute(:value, nil) 335 project.custom_values.first.update_attribute(:value, nil)
353 project.archive! 345 project.archive!
354 346
355 get :show, :id => 'ecookbook' 347 get :show, :id => 'ecookbook'
356 assert_response 403 348 assert_response 403
357 assert_nil assigns(:project) 349 assert_nil assigns(:project)
358 assert_tag :tag => 'p', :content => /archived/ 350 assert_select 'p', :text => /archived/
359 end 351 end
360 352
361 def test_private_subprojects_hidden 353 def test_show_should_not_show_private_subprojects_that_are_not_visible
362 get :show, :id => 'ecookbook' 354 get :show, :id => 'ecookbook'
363 assert_response :success 355 assert_response :success
364 assert_template 'show' 356 assert_template 'show'
365 assert_no_tag :tag => 'a', :content => /Private child/ 357 assert_select 'a', :text => /Private child/, :count => 0
366 end 358 end
367 359
368 def test_private_subprojects_visible 360 def test_show_should_show_private_subprojects_that_are_visible
369 @request.session[:user_id] = 2 # manager who is a member of the private subproject 361 @request.session[:user_id] = 2 # manager who is a member of the private subproject
370 get :show, :id => 'ecookbook' 362 get :show, :id => 'ecookbook'
371 assert_response :success 363 assert_response :success
372 assert_template 'show' 364 assert_template 'show'
373 assert_tag :tag => 'a', :content => /Private child/ 365 assert_select 'a', :text => /Private child/
374 end 366 end
375 367
376 def test_settings 368 def test_settings
377 @request.session[:user_id] = 2 # manager 369 @request.session[:user_id] = 2 # manager
378 get :settings, :id => 1 370 get :settings, :id => 1
379 assert_response :success 371 assert_response :success
380 assert_template 'settings' 372 assert_template 'settings'
373 end
374
375 def test_settings_of_subproject
376 @request.session[:user_id] = 2
377 get :settings, :id => 'private-child'
378 assert_response :success
379 assert_template 'settings'
380
381 assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]'
381 end 382 end
382 383
383 def test_settings_should_be_denied_for_member_on_closed_project 384 def test_settings_should_be_denied_for_member_on_closed_project
384 Project.find(1).close 385 Project.find(1).close
385 @request.session[:user_id] = 2 # manager 386 @request.session[:user_id] = 2 # manager
436 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] 437 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
437 assert_redirected_to '/projects/ecookbook/settings/modules' 438 assert_redirected_to '/projects/ecookbook/settings/modules'
438 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort 439 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
439 end 440 end
440 441
441 def test_destroy_without_confirmation 442 def test_destroy_leaf_project_without_confirmation_should_show_confirmation
442 @request.session[:user_id] = 1 # admin 443 @request.session[:user_id] = 1 # admin
443 delete :destroy, :id => 1 444
444 assert_response :success 445 assert_no_difference 'Project.count' do
445 assert_template 'destroy' 446 delete :destroy, :id => 2
446 assert_not_nil Project.find_by_id(1) 447 assert_response :success
447 assert_tag :tag => 'strong', 448 assert_template 'destroy'
448 :content => ['Private child of eCookbook', 449 end
450 end
451
452 def test_destroy_without_confirmation_should_show_confirmation_with_subprojects
453 @request.session[:user_id] = 1 # admin
454
455 assert_no_difference 'Project.count' do
456 delete :destroy, :id => 1
457 assert_response :success
458 assert_template 'destroy'
459 end
460 assert_select 'strong',
461 :text => ['Private child of eCookbook',
449 'Child of private child, eCookbook Subproject 1', 462 'Child of private child, eCookbook Subproject 1',
450 'eCookbook Subproject 2'].join(', ') 463 'eCookbook Subproject 2'].join(', ')
451 end 464 end
452 465
453 def test_destroy 466 def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects
454 @request.session[:user_id] = 1 # admin 467 @request.session[:user_id] = 1 # admin
455 delete :destroy, :id => 1, :confirm => 1 468
456 assert_redirected_to '/admin/projects' 469 assert_difference 'Project.count', -5 do
470 delete :destroy, :id => 1, :confirm => 1
471 assert_redirected_to '/admin/projects'
472 end
457 assert_nil Project.find_by_id(1) 473 assert_nil Project.find_by_id(1)
458 end 474 end
459 475
460 def test_archive 476 def test_archive
461 @request.session[:user_id] = 1 # admin 477 @request.session[:user_id] = 1 # admin
497 513
498 def test_project_breadcrumbs_should_be_limited_to_3_ancestors 514 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
499 CustomField.delete_all 515 CustomField.delete_all
500 parent = nil 516 parent = nil
501 6.times do |i| 517 6.times do |i|
502 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") 518 p = Project.generate_with_parent!(parent)
503 p.set_parent!(parent)
504 get :show, :id => p 519 get :show, :id => p
505 assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, 520 assert_select '#header h1' do
506 :children => { :count => [i, 3].min, 521 assert_select 'a', :count => [i, 3].min
507 :only => { :tag => 'a' } } 522 end
508 523
509 parent = p 524 parent = p
510 end 525 end
511 end 526 end
512 527
517 assert_template 'copy' 532 assert_template 'copy'
518 assert assigns(:project) 533 assert assigns(:project)
519 assert_equal Project.find(1).description, assigns(:project).description 534 assert_equal Project.find(1).description, assigns(:project).description
520 assert_nil assigns(:project).id 535 assert_nil assigns(:project).id
521 536
522 assert_tag :tag => 'input', 537 assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1
523 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'}
524 end 538 end
525 539
526 def test_get_copy_with_invalid_source_should_respond_with_404 540 def test_get_copy_with_invalid_source_should_respond_with_404
527 @request.session[:user_id] = 1 541 @request.session[:user_id] = 1
528 get :copy, :id => 99 542 get :copy, :id => 99