Chris@0
|
1 # Redmine - project management software
|
Chris@1115
|
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@441
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@441
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'projects_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class ProjectsController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class ProjectsControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
|
Chris@0
|
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
|
Chris@0
|
27 :attachments, :custom_fields, :custom_values, :time_entries
|
Chris@0
|
28
|
Chris@0
|
29 def setup
|
Chris@0
|
30 @controller = ProjectsController.new
|
Chris@0
|
31 @request = ActionController::TestRequest.new
|
Chris@0
|
32 @response = ActionController::TestResponse.new
|
Chris@0
|
33 @request.session[:user_id] = nil
|
Chris@0
|
34 Setting.default_language = 'en'
|
Chris@0
|
35 end
|
Chris@441
|
36
|
Chris@0
|
37 def test_index
|
Chris@0
|
38 get :index
|
Chris@0
|
39 assert_response :success
|
Chris@0
|
40 assert_template 'index'
|
Chris@0
|
41 assert_not_nil assigns(:projects)
|
Chris@441
|
42
|
Chris@0
|
43 assert_tag :ul, :child => {:tag => 'li',
|
Chris@0
|
44 :descendant => {:tag => 'a', :content => 'eCookbook'},
|
Chris@0
|
45 :child => { :tag => 'ul',
|
Chris@0
|
46 :descendant => { :tag => 'a',
|
Chris@0
|
47 :content => 'Child of private child'
|
Chris@0
|
48 }
|
Chris@0
|
49 }
|
Chris@0
|
50 }
|
Chris@441
|
51
|
Chris@0
|
52 assert_no_tag :a, :content => /Private child of eCookbook/
|
Chris@0
|
53 end
|
Chris@441
|
54
|
Chris@0
|
55 def test_index_atom
|
Chris@0
|
56 get :index, :format => 'atom'
|
Chris@0
|
57 assert_response :success
|
Chris@1115
|
58 assert_template 'common/feed'
|
Chris@0
|
59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
|
Chris@441
|
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
|
Chris@0
|
61 end
|
Chris@441
|
62
|
Chris@0
|
63 context "#index" do
|
Chris@0
|
64 context "by non-admin user with view_time_entries permission" do
|
Chris@0
|
65 setup do
|
Chris@0
|
66 @request.session[:user_id] = 3
|
Chris@0
|
67 end
|
Chris@0
|
68 should "show overall spent time link" do
|
Chris@0
|
69 get :index
|
Chris@0
|
70 assert_template 'index'
|
Chris@0
|
71 assert_tag :a, :attributes => {:href => '/time_entries'}
|
Chris@0
|
72 end
|
Chris@0
|
73 end
|
Chris@441
|
74
|
Chris@0
|
75 context "by non-admin user without view_time_entries permission" do
|
Chris@0
|
76 setup do
|
Chris@0
|
77 Role.find(2).remove_permission! :view_time_entries
|
Chris@0
|
78 Role.non_member.remove_permission! :view_time_entries
|
Chris@0
|
79 Role.anonymous.remove_permission! :view_time_entries
|
Chris@0
|
80 @request.session[:user_id] = 3
|
Chris@0
|
81 end
|
Chris@0
|
82 should "not show overall spent time link" do
|
Chris@0
|
83 get :index
|
Chris@0
|
84 assert_template 'index'
|
Chris@0
|
85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
|
Chris@0
|
86 end
|
Chris@441
|
87 end
|
Chris@0
|
88 end
|
Chris@441
|
89
|
chris@22
|
90 context "#new" do
|
Chris@0
|
91 context "by admin user" do
|
Chris@0
|
92 setup do
|
Chris@0
|
93 @request.session[:user_id] = 1
|
Chris@0
|
94 end
|
Chris@441
|
95
|
Chris@0
|
96 should "accept get" do
|
chris@22
|
97 get :new
|
Chris@0
|
98 assert_response :success
|
chris@22
|
99 assert_template 'new'
|
chris@22
|
100 end
|
chris@22
|
101
|
chris@22
|
102 end
|
chris@22
|
103
|
chris@22
|
104 context "by non-admin user with add_project permission" do
|
chris@22
|
105 setup do
|
chris@22
|
106 Role.non_member.add_permission! :add_project
|
chris@22
|
107 @request.session[:user_id] = 9
|
chris@22
|
108 end
|
chris@22
|
109
|
chris@22
|
110 should "accept get" do
|
chris@22
|
111 get :new
|
chris@22
|
112 assert_response :success
|
chris@22
|
113 assert_template 'new'
|
chris@22
|
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
|
chris@22
|
115 end
|
chris@22
|
116 end
|
chris@22
|
117
|
chris@22
|
118 context "by non-admin user with add_subprojects permission" do
|
chris@22
|
119 setup do
|
chris@22
|
120 Role.find(1).remove_permission! :add_project
|
chris@22
|
121 Role.find(1).add_permission! :add_subprojects
|
chris@22
|
122 @request.session[:user_id] = 2
|
Chris@0
|
123 end
|
Chris@441
|
124
|
chris@22
|
125 should "accept get" do
|
chris@22
|
126 get :new, :parent_id => 'ecookbook'
|
chris@22
|
127 assert_response :success
|
chris@22
|
128 assert_template 'new'
|
chris@22
|
129 # parent project selected
|
chris@22
|
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
|
chris@22
|
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
|
chris@22
|
132 # no empty value
|
chris@22
|
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
|
chris@22
|
134 :child => {:tag => 'option', :attributes => {:value => ''}}
|
chris@22
|
135 end
|
chris@22
|
136 end
|
Chris@441
|
137
|
chris@22
|
138 end
|
chris@22
|
139
|
chris@22
|
140 context "POST :create" do
|
chris@22
|
141 context "by admin user" do
|
chris@22
|
142 setup do
|
chris@22
|
143 @request.session[:user_id] = 1
|
chris@22
|
144 end
|
Chris@441
|
145
|
chris@22
|
146 should "create a new project" do
|
Chris@119
|
147 post :create,
|
Chris@119
|
148 :project => {
|
Chris@441
|
149 :name => "blog",
|
Chris@119
|
150 :description => "weblog",
|
Chris@119
|
151 :homepage => 'http://weblog',
|
Chris@119
|
152 :identifier => "blog",
|
Chris@119
|
153 :is_public => 1,
|
Chris@119
|
154 :custom_field_values => { '3' => 'Beta' },
|
Chris@119
|
155 :tracker_ids => ['1', '3'],
|
Chris@119
|
156 # an issue custom field that is not for all project
|
Chris@119
|
157 :issue_custom_field_ids => ['9'],
|
Chris@119
|
158 :enabled_module_names => ['issue_tracking', 'news', 'repository']
|
Chris@119
|
159 }
|
Chris@0
|
160 assert_redirected_to '/projects/blog/settings'
|
Chris@441
|
161
|
Chris@0
|
162 project = Project.find_by_name('blog')
|
Chris@0
|
163 assert_kind_of Project, project
|
Chris@119
|
164 assert project.active?
|
Chris@441
|
165 assert_equal 'weblog', project.description
|
Chris@119
|
166 assert_equal 'http://weblog', project.homepage
|
Chris@0
|
167 assert_equal true, project.is_public?
|
Chris@0
|
168 assert_nil project.parent
|
Chris@119
|
169 assert_equal 'Beta', project.custom_value_for(3).value
|
Chris@119
|
170 assert_equal [1, 3], project.trackers.map(&:id).sort
|
Chris@119
|
171 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
|
Chris@119
|
172 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
|
Chris@0
|
173 end
|
Chris@441
|
174
|
chris@22
|
175 should "create a new subproject" do
|
Chris@441
|
176 post :create, :project => { :name => "blog",
|
Chris@0
|
177 :description => "weblog",
|
Chris@0
|
178 :identifier => "blog",
|
Chris@0
|
179 :is_public => 1,
|
Chris@0
|
180 :custom_field_values => { '3' => 'Beta' },
|
Chris@0
|
181 :parent_id => 1
|
Chris@0
|
182 }
|
Chris@0
|
183 assert_redirected_to '/projects/blog/settings'
|
Chris@441
|
184
|
Chris@0
|
185 project = Project.find_by_name('blog')
|
Chris@0
|
186 assert_kind_of Project, project
|
Chris@0
|
187 assert_equal Project.find(1), project.parent
|
Chris@0
|
188 end
|
Chris@909
|
189
|
Chris@909
|
190 should "continue" do
|
Chris@909
|
191 assert_difference 'Project.count' do
|
Chris@909
|
192 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue'
|
Chris@909
|
193 end
|
Chris@909
|
194 assert_redirected_to '/projects/new?'
|
Chris@909
|
195 end
|
Chris@0
|
196 end
|
Chris@441
|
197
|
Chris@0
|
198 context "by non-admin user with add_project permission" do
|
Chris@0
|
199 setup do
|
Chris@0
|
200 Role.non_member.add_permission! :add_project
|
Chris@0
|
201 @request.session[:user_id] = 9
|
Chris@0
|
202 end
|
Chris@441
|
203
|
chris@22
|
204 should "accept create a Project" do
|
Chris@441
|
205 post :create, :project => { :name => "blog",
|
Chris@0
|
206 :description => "weblog",
|
Chris@0
|
207 :identifier => "blog",
|
Chris@0
|
208 :is_public => 1,
|
Chris@119
|
209 :custom_field_values => { '3' => 'Beta' },
|
Chris@119
|
210 :tracker_ids => ['1', '3'],
|
Chris@119
|
211 :enabled_module_names => ['issue_tracking', 'news', 'repository']
|
Chris@0
|
212 }
|
Chris@441
|
213
|
Chris@0
|
214 assert_redirected_to '/projects/blog/settings'
|
Chris@441
|
215
|
Chris@0
|
216 project = Project.find_by_name('blog')
|
Chris@0
|
217 assert_kind_of Project, project
|
Chris@441
|
218 assert_equal 'weblog', project.description
|
Chris@0
|
219 assert_equal true, project.is_public?
|
Chris@119
|
220 assert_equal [1, 3], project.trackers.map(&:id).sort
|
Chris@119
|
221 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
|
Chris@441
|
222
|
Chris@0
|
223 # User should be added as a project member
|
Chris@0
|
224 assert User.find(9).member_of?(project)
|
Chris@0
|
225 assert_equal 1, project.members.size
|
Chris@0
|
226 end
|
Chris@441
|
227
|
Chris@0
|
228 should "fail with parent_id" do
|
Chris@0
|
229 assert_no_difference 'Project.count' do
|
Chris@441
|
230 post :create, :project => { :name => "blog",
|
Chris@0
|
231 :description => "weblog",
|
Chris@0
|
232 :identifier => "blog",
|
Chris@0
|
233 :is_public => 1,
|
Chris@0
|
234 :custom_field_values => { '3' => 'Beta' },
|
Chris@0
|
235 :parent_id => 1
|
Chris@0
|
236 }
|
Chris@0
|
237 end
|
Chris@0
|
238 assert_response :success
|
Chris@0
|
239 project = assigns(:project)
|
Chris@0
|
240 assert_kind_of Project, project
|
Chris@909
|
241 assert_not_nil project.errors[:parent_id]
|
Chris@0
|
242 end
|
Chris@0
|
243 end
|
Chris@441
|
244
|
Chris@0
|
245 context "by non-admin user with add_subprojects permission" do
|
Chris@0
|
246 setup do
|
Chris@0
|
247 Role.find(1).remove_permission! :add_project
|
Chris@0
|
248 Role.find(1).add_permission! :add_subprojects
|
Chris@0
|
249 @request.session[:user_id] = 2
|
Chris@0
|
250 end
|
Chris@441
|
251
|
chris@22
|
252 should "create a project with a parent_id" do
|
Chris@441
|
253 post :create, :project => { :name => "blog",
|
Chris@0
|
254 :description => "weblog",
|
Chris@0
|
255 :identifier => "blog",
|
Chris@0
|
256 :is_public => 1,
|
Chris@0
|
257 :custom_field_values => { '3' => 'Beta' },
|
Chris@0
|
258 :parent_id => 1
|
Chris@0
|
259 }
|
Chris@0
|
260 assert_redirected_to '/projects/blog/settings'
|
Chris@0
|
261 project = Project.find_by_name('blog')
|
Chris@0
|
262 end
|
Chris@441
|
263
|
Chris@0
|
264 should "fail without parent_id" do
|
Chris@0
|
265 assert_no_difference 'Project.count' do
|
Chris@441
|
266 post :create, :project => { :name => "blog",
|
Chris@0
|
267 :description => "weblog",
|
Chris@0
|
268 :identifier => "blog",
|
Chris@0
|
269 :is_public => 1,
|
Chris@0
|
270 :custom_field_values => { '3' => 'Beta' }
|
Chris@0
|
271 }
|
Chris@0
|
272 end
|
Chris@0
|
273 assert_response :success
|
Chris@0
|
274 project = assigns(:project)
|
Chris@0
|
275 assert_kind_of Project, project
|
Chris@909
|
276 assert_not_nil project.errors[:parent_id]
|
Chris@0
|
277 end
|
Chris@441
|
278
|
Chris@0
|
279 should "fail with unauthorized parent_id" do
|
Chris@0
|
280 assert !User.find(2).member_of?(Project.find(6))
|
Chris@0
|
281 assert_no_difference 'Project.count' do
|
Chris@441
|
282 post :create, :project => { :name => "blog",
|
Chris@0
|
283 :description => "weblog",
|
Chris@0
|
284 :identifier => "blog",
|
Chris@0
|
285 :is_public => 1,
|
Chris@0
|
286 :custom_field_values => { '3' => 'Beta' },
|
Chris@0
|
287 :parent_id => 6
|
Chris@0
|
288 }
|
Chris@0
|
289 end
|
Chris@0
|
290 assert_response :success
|
Chris@0
|
291 project = assigns(:project)
|
Chris@0
|
292 assert_kind_of Project, project
|
Chris@909
|
293 assert_not_nil project.errors[:parent_id]
|
Chris@0
|
294 end
|
Chris@0
|
295 end
|
Chris@0
|
296 end
|
Chris@441
|
297
|
Chris@441
|
298 def test_create_should_preserve_modules_on_validation_failure
|
Chris@441
|
299 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
|
Chris@441
|
300 @request.session[:user_id] = 1
|
Chris@441
|
301 assert_no_difference 'Project.count' do
|
Chris@441
|
302 post :create, :project => {
|
Chris@441
|
303 :name => "blog",
|
Chris@441
|
304 :identifier => "",
|
Chris@441
|
305 :enabled_module_names => %w(issue_tracking news)
|
Chris@441
|
306 }
|
Chris@441
|
307 end
|
Chris@441
|
308 assert_response :success
|
Chris@441
|
309 project = assigns(:project)
|
Chris@441
|
310 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
|
Chris@441
|
311 end
|
Chris@441
|
312 end
|
Chris@441
|
313
|
Chris@0
|
314 def test_show_by_id
|
Chris@0
|
315 get :show, :id => 1
|
Chris@0
|
316 assert_response :success
|
Chris@0
|
317 assert_template 'show'
|
Chris@0
|
318 assert_not_nil assigns(:project)
|
Chris@0
|
319 end
|
Chris@0
|
320
|
Chris@0
|
321 def test_show_by_identifier
|
Chris@0
|
322 get :show, :id => 'ecookbook'
|
Chris@0
|
323 assert_response :success
|
Chris@0
|
324 assert_template 'show'
|
Chris@0
|
325 assert_not_nil assigns(:project)
|
Chris@0
|
326 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
|
Chris@441
|
327
|
chris@37
|
328 assert_tag 'li', :content => /Development status/
|
chris@37
|
329 end
|
chris@37
|
330
|
chris@37
|
331 def test_show_should_not_display_hidden_custom_fields
|
chris@37
|
332 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
|
chris@37
|
333 get :show, :id => 'ecookbook'
|
chris@37
|
334 assert_response :success
|
chris@37
|
335 assert_template 'show'
|
chris@37
|
336 assert_not_nil assigns(:project)
|
Chris@441
|
337
|
chris@37
|
338 assert_no_tag 'li', :content => /Development status/
|
Chris@0
|
339 end
|
Chris@441
|
340
|
Chris@0
|
341 def test_show_should_not_fail_when_custom_values_are_nil
|
Chris@0
|
342 project = Project.find_by_identifier('ecookbook')
|
Chris@0
|
343 project.custom_values.first.update_attribute(:value, nil)
|
Chris@0
|
344 get :show, :id => 'ecookbook'
|
Chris@0
|
345 assert_response :success
|
Chris@0
|
346 assert_template 'show'
|
Chris@0
|
347 assert_not_nil assigns(:project)
|
Chris@0
|
348 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
|
Chris@0
|
349 end
|
Chris@441
|
350
|
chris@37
|
351 def show_archived_project_should_be_denied
|
chris@37
|
352 project = Project.find_by_identifier('ecookbook')
|
chris@37
|
353 project.archive!
|
Chris@441
|
354
|
chris@37
|
355 get :show, :id => 'ecookbook'
|
chris@37
|
356 assert_response 403
|
chris@37
|
357 assert_nil assigns(:project)
|
chris@37
|
358 assert_tag :tag => 'p', :content => /archived/
|
chris@37
|
359 end
|
Chris@441
|
360
|
Chris@0
|
361 def test_private_subprojects_hidden
|
Chris@0
|
362 get :show, :id => 'ecookbook'
|
Chris@0
|
363 assert_response :success
|
Chris@0
|
364 assert_template 'show'
|
Chris@0
|
365 assert_no_tag :tag => 'a', :content => /Private child/
|
Chris@0
|
366 end
|
Chris@0
|
367
|
Chris@0
|
368 def test_private_subprojects_visible
|
Chris@0
|
369 @request.session[:user_id] = 2 # manager who is a member of the private subproject
|
Chris@0
|
370 get :show, :id => 'ecookbook'
|
Chris@0
|
371 assert_response :success
|
Chris@0
|
372 assert_template 'show'
|
Chris@0
|
373 assert_tag :tag => 'a', :content => /Private child/
|
Chris@0
|
374 end
|
Chris@441
|
375
|
Chris@0
|
376 def test_settings
|
Chris@0
|
377 @request.session[:user_id] = 2 # manager
|
Chris@0
|
378 get :settings, :id => 1
|
Chris@0
|
379 assert_response :success
|
Chris@0
|
380 assert_template 'settings'
|
Chris@0
|
381 end
|
Chris@441
|
382
|
Chris@1115
|
383 def test_settings_should_be_denied_for_member_on_closed_project
|
Chris@1115
|
384 Project.find(1).close
|
Chris@1115
|
385 @request.session[:user_id] = 2 # manager
|
Chris@1115
|
386
|
Chris@1115
|
387 get :settings, :id => 1
|
Chris@1115
|
388 assert_response 403
|
Chris@1115
|
389 end
|
Chris@1115
|
390
|
Chris@1115
|
391 def test_settings_should_be_denied_for_anonymous_on_closed_project
|
Chris@1115
|
392 Project.find(1).close
|
Chris@1115
|
393
|
Chris@1115
|
394 get :settings, :id => 1
|
Chris@1115
|
395 assert_response 302
|
Chris@1115
|
396 end
|
Chris@1115
|
397
|
chris@22
|
398 def test_update
|
Chris@0
|
399 @request.session[:user_id] = 2 # manager
|
chris@22
|
400 post :update, :id => 1, :project => {:name => 'Test changed name',
|
Chris@0
|
401 :issue_custom_field_ids => ['']}
|
chris@37
|
402 assert_redirected_to '/projects/ecookbook/settings'
|
Chris@0
|
403 project = Project.find(1)
|
Chris@0
|
404 assert_equal 'Test changed name', project.name
|
Chris@0
|
405 end
|
Chris@119
|
406
|
Chris@1115
|
407 def test_update_with_failure
|
Chris@1115
|
408 @request.session[:user_id] = 2 # manager
|
Chris@1115
|
409 post :update, :id => 1, :project => {:name => ''}
|
Chris@1115
|
410 assert_response :success
|
Chris@1115
|
411 assert_template 'settings'
|
Chris@1115
|
412 assert_error_tag :content => /name can't be blank/i
|
Chris@1115
|
413 end
|
Chris@1115
|
414
|
Chris@1115
|
415 def test_update_should_be_denied_for_member_on_closed_project
|
Chris@1115
|
416 Project.find(1).close
|
Chris@1115
|
417 @request.session[:user_id] = 2 # manager
|
Chris@1115
|
418
|
Chris@1115
|
419 post :update, :id => 1, :project => {:name => 'Closed'}
|
Chris@1115
|
420 assert_response 403
|
Chris@1115
|
421 assert_equal 'eCookbook', Project.find(1).name
|
Chris@1115
|
422 end
|
Chris@1115
|
423
|
Chris@1115
|
424 def test_update_should_be_denied_for_anonymous_on_closed_project
|
Chris@1115
|
425 Project.find(1).close
|
Chris@1115
|
426
|
Chris@1115
|
427 post :update, :id => 1, :project => {:name => 'Closed'}
|
Chris@1115
|
428 assert_response 302
|
Chris@1115
|
429 assert_equal 'eCookbook', Project.find(1).name
|
Chris@1115
|
430 end
|
Chris@1115
|
431
|
Chris@119
|
432 def test_modules
|
Chris@119
|
433 @request.session[:user_id] = 2
|
Chris@119
|
434 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
|
Chris@441
|
435
|
Chris@119
|
436 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
|
Chris@119
|
437 assert_redirected_to '/projects/ecookbook/settings/modules'
|
Chris@119
|
438 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
|
Chris@119
|
439 end
|
Chris@119
|
440
|
Chris@1115
|
441 def test_destroy_without_confirmation
|
Chris@0
|
442 @request.session[:user_id] = 1 # admin
|
Chris@1115
|
443 delete :destroy, :id => 1
|
Chris@0
|
444 assert_response :success
|
Chris@0
|
445 assert_template 'destroy'
|
Chris@0
|
446 assert_not_nil Project.find_by_id(1)
|
Chris@1115
|
447 assert_tag :tag => 'strong',
|
Chris@1115
|
448 :content => ['Private child of eCookbook',
|
Chris@1115
|
449 'Child of private child, eCookbook Subproject 1',
|
Chris@1115
|
450 'eCookbook Subproject 2'].join(', ')
|
Chris@0
|
451 end
|
Chris@0
|
452
|
Chris@1115
|
453 def test_destroy
|
Chris@0
|
454 @request.session[:user_id] = 1 # admin
|
Chris@1115
|
455 delete :destroy, :id => 1, :confirm => 1
|
chris@37
|
456 assert_redirected_to '/admin/projects'
|
Chris@0
|
457 assert_nil Project.find_by_id(1)
|
Chris@0
|
458 end
|
Chris@441
|
459
|
Chris@0
|
460 def test_archive
|
Chris@0
|
461 @request.session[:user_id] = 1 # admin
|
Chris@0
|
462 post :archive, :id => 1
|
chris@37
|
463 assert_redirected_to '/admin/projects'
|
Chris@0
|
464 assert !Project.find(1).active?
|
Chris@0
|
465 end
|
Chris@441
|
466
|
Chris@1115
|
467 def test_archive_with_failure
|
Chris@1115
|
468 @request.session[:user_id] = 1
|
Chris@1115
|
469 Project.any_instance.stubs(:archive).returns(false)
|
Chris@1115
|
470 post :archive, :id => 1
|
Chris@1115
|
471 assert_redirected_to '/admin/projects'
|
Chris@1115
|
472 assert_match /project cannot be archived/i, flash[:error]
|
Chris@1115
|
473 end
|
Chris@1115
|
474
|
Chris@0
|
475 def test_unarchive
|
Chris@0
|
476 @request.session[:user_id] = 1 # admin
|
Chris@0
|
477 Project.find(1).archive
|
Chris@0
|
478 post :unarchive, :id => 1
|
chris@37
|
479 assert_redirected_to '/admin/projects'
|
Chris@0
|
480 assert Project.find(1).active?
|
Chris@0
|
481 end
|
Chris@441
|
482
|
Chris@1115
|
483 def test_close
|
Chris@1115
|
484 @request.session[:user_id] = 2
|
Chris@1115
|
485 post :close, :id => 1
|
Chris@1115
|
486 assert_redirected_to '/projects/ecookbook'
|
Chris@1115
|
487 assert_equal Project::STATUS_CLOSED, Project.find(1).status
|
Chris@1115
|
488 end
|
Chris@1115
|
489
|
Chris@1115
|
490 def test_reopen
|
Chris@1115
|
491 Project.find(1).close
|
Chris@1115
|
492 @request.session[:user_id] = 2
|
Chris@1115
|
493 post :reopen, :id => 1
|
Chris@1115
|
494 assert_redirected_to '/projects/ecookbook'
|
Chris@1115
|
495 assert Project.find(1).active?
|
Chris@1115
|
496 end
|
Chris@1115
|
497
|
Chris@0
|
498 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
|
Chris@0
|
499 CustomField.delete_all
|
Chris@0
|
500 parent = nil
|
Chris@0
|
501 6.times do |i|
|
Chris@0
|
502 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
|
Chris@0
|
503 p.set_parent!(parent)
|
Chris@0
|
504 get :show, :id => p
|
Chris@0
|
505 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
|
Chris@0
|
506 :children => { :count => [i, 3].min,
|
Chris@0
|
507 :only => { :tag => 'a' } }
|
Chris@441
|
508
|
Chris@0
|
509 parent = p
|
Chris@0
|
510 end
|
Chris@0
|
511 end
|
Chris@0
|
512
|
Chris@441
|
513 def test_get_copy
|
Chris@0
|
514 @request.session[:user_id] = 1 # admin
|
Chris@0
|
515 get :copy, :id => 1
|
Chris@0
|
516 assert_response :success
|
Chris@0
|
517 assert_template 'copy'
|
Chris@0
|
518 assert assigns(:project)
|
Chris@0
|
519 assert_equal Project.find(1).description, assigns(:project).description
|
Chris@0
|
520 assert_nil assigns(:project).id
|
Chris@441
|
521
|
Chris@441
|
522 assert_tag :tag => 'input',
|
Chris@441
|
523 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'}
|
Chris@0
|
524 end
|
Chris@0
|
525
|
Chris@1115
|
526 def test_get_copy_with_invalid_source_should_respond_with_404
|
Chris@1115
|
527 @request.session[:user_id] = 1
|
Chris@1115
|
528 get :copy, :id => 99
|
Chris@1115
|
529 assert_response 404
|
Chris@0
|
530 end
|
Chris@0
|
531
|
Chris@441
|
532 def test_post_copy_should_copy_requested_items
|
Chris@441
|
533 @request.session[:user_id] = 1 # admin
|
Chris@441
|
534 CustomField.delete_all
|
chris@37
|
535
|
Chris@441
|
536 assert_difference 'Project.count' do
|
Chris@441
|
537 post :copy, :id => 1,
|
Chris@441
|
538 :project => {
|
Chris@441
|
539 :name => 'Copy',
|
Chris@441
|
540 :identifier => 'unique-copy',
|
Chris@441
|
541 :tracker_ids => ['1', '2', '3', ''],
|
Chris@441
|
542 :enabled_module_names => %w(issue_tracking time_tracking)
|
Chris@441
|
543 },
|
Chris@441
|
544 :only => %w(issues versions)
|
chris@37
|
545 end
|
Chris@441
|
546 project = Project.find('unique-copy')
|
Chris@441
|
547 source = Project.find(1)
|
Chris@441
|
548 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
|
Chris@441
|
549
|
Chris@441
|
550 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
|
Chris@1115
|
551 assert_equal source.issues.count, project.issues.count, "All issues were not copied"
|
Chris@441
|
552 assert_equal 0, project.members.count
|
Chris@441
|
553 end
|
Chris@441
|
554
|
Chris@441
|
555 def test_post_copy_should_redirect_to_settings_when_successful
|
Chris@441
|
556 @request.session[:user_id] = 1 # admin
|
Chris@441
|
557 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
|
Chris@441
|
558 assert_response :redirect
|
Chris@441
|
559 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
|
chris@37
|
560 end
|
chris@37
|
561
|
Chris@0
|
562 def test_jump_should_redirect_to_active_tab
|
Chris@0
|
563 get :show, :id => 1, :jump => 'issues'
|
chris@37
|
564 assert_redirected_to '/projects/ecookbook/issues'
|
Chris@0
|
565 end
|
Chris@441
|
566
|
Chris@0
|
567 def test_jump_should_not_redirect_to_inactive_tab
|
Chris@0
|
568 get :show, :id => 3, :jump => 'documents'
|
Chris@0
|
569 assert_response :success
|
Chris@0
|
570 assert_template 'show'
|
Chris@0
|
571 end
|
Chris@441
|
572
|
Chris@0
|
573 def test_jump_should_not_redirect_to_unknown_tab
|
Chris@0
|
574 get :show, :id => 3, :jump => 'foobar'
|
Chris@0
|
575 assert_response :success
|
Chris@0
|
576 assert_template 'show'
|
Chris@0
|
577 end
|
Chris@0
|
578 end
|