##// END OF EJS Templates
Error raised on project settings after project wiki is deleted (#18429)....
Jean-Philippe Lang -
r13278:552926772ad5
parent child
Show More
@@ -1,253 +1,253
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class ProjectsController < ApplicationController
19 19 menu_item :overview
20 20 menu_item :settings, :only => :settings
21 21
22 22 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ]
23 23 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
24 24 before_filter :authorize_global, :only => [:new, :create]
25 25 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
26 26 accept_rss_auth :index
27 27 accept_api_auth :index, :show, :create, :update, :destroy
28 28
29 29 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
30 30 if controller.request.post?
31 31 controller.send :expire_action, :controller => 'welcome', :action => 'robots'
32 32 end
33 33 end
34 34
35 35 helper :custom_fields
36 36 helper :issues
37 37 helper :queries
38 38 helper :repositories
39 39 helper :members
40 40
41 41 # Lists visible projects
42 42 def index
43 43 scope = Project.visible.sorted
44 44
45 45 respond_to do |format|
46 46 format.html {
47 47 unless params[:closed]
48 48 scope = scope.active
49 49 end
50 50 @projects = scope.to_a
51 51 }
52 52 format.api {
53 53 @offset, @limit = api_offset_and_limit
54 54 @project_count = scope.count
55 55 @projects = scope.offset(@offset).limit(@limit).to_a
56 56 }
57 57 format.atom {
58 58 projects = scope.reorder(:created_on => :desc).limit(Setting.feeds_limit.to_i).to_a
59 59 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
60 60 }
61 61 end
62 62 end
63 63
64 64 def new
65 65 @issue_custom_fields = IssueCustomField.sorted.to_a
66 66 @trackers = Tracker.sorted.to_a
67 67 @project = Project.new
68 68 @project.safe_attributes = params[:project]
69 69 end
70 70
71 71 def create
72 72 @issue_custom_fields = IssueCustomField.sorted.to_a
73 73 @trackers = Tracker.sorted.to_a
74 74 @project = Project.new
75 75 @project.safe_attributes = params[:project]
76 76
77 77 if validate_parent_id && @project.save
78 78 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
79 79 unless User.current.admin?
80 80 @project.add_default_member(User.current)
81 81 end
82 82 respond_to do |format|
83 83 format.html {
84 84 flash[:notice] = l(:notice_successful_create)
85 85 if params[:continue]
86 86 attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
87 87 redirect_to new_project_path(attrs)
88 88 else
89 89 redirect_to settings_project_path(@project)
90 90 end
91 91 }
92 92 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
93 93 end
94 94 else
95 95 respond_to do |format|
96 96 format.html { render :action => 'new' }
97 97 format.api { render_validation_errors(@project) }
98 98 end
99 99 end
100 100 end
101 101
102 102 def copy
103 103 @issue_custom_fields = IssueCustomField.sorted.to_a
104 104 @trackers = Tracker.sorted.to_a
105 105 @source_project = Project.find(params[:id])
106 106 if request.get?
107 107 @project = Project.copy_from(@source_project)
108 108 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
109 109 else
110 110 Mailer.with_deliveries(params[:notifications] == '1') do
111 111 @project = Project.new
112 112 @project.safe_attributes = params[:project]
113 113 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
114 114 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
115 115 flash[:notice] = l(:notice_successful_create)
116 116 redirect_to settings_project_path(@project)
117 117 elsif !@project.new_record?
118 118 # Project was created
119 119 # But some objects were not copied due to validation failures
120 120 # (eg. issues from disabled trackers)
121 121 # TODO: inform about that
122 122 redirect_to settings_project_path(@project)
123 123 end
124 124 end
125 125 end
126 126 rescue ActiveRecord::RecordNotFound
127 127 # source_project not found
128 128 render_404
129 129 end
130 130
131 131 # Show @project
132 132 def show
133 133 # try to redirect to the requested menu item
134 134 if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
135 135 return
136 136 end
137 137
138 138 @users_by_role = @project.users_by_role
139 139 @subprojects = @project.children.visible.to_a
140 140 @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").to_a
141 141 @trackers = @project.rolled_up_trackers
142 142
143 143 cond = @project.project_condition(Setting.display_subprojects_issues?)
144 144
145 145 @open_issues_by_tracker = Issue.visible.open.where(cond).group(:tracker).count
146 146 @total_issues_by_tracker = Issue.visible.where(cond).group(:tracker).count
147 147
148 148 if User.current.allowed_to?(:view_time_entries, @project)
149 149 @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f
150 150 end
151 151
152 152 @key = User.current.rss_key
153 153
154 154 respond_to do |format|
155 155 format.html
156 156 format.api
157 157 end
158 158 end
159 159
160 160 def settings
161 161 @issue_custom_fields = IssueCustomField.sorted.to_a
162 162 @issue_category ||= IssueCategory.new
163 163 @member ||= @project.members.new
164 164 @trackers = Tracker.sorted.to_a
165 @wiki ||= @project.wiki
165 @wiki ||= @project.wiki || Wiki.new(:project => @project)
166 166 end
167 167
168 168 def edit
169 169 end
170 170
171 171 def update
172 172 @project.safe_attributes = params[:project]
173 173 if validate_parent_id && @project.save
174 174 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
175 175 respond_to do |format|
176 176 format.html {
177 177 flash[:notice] = l(:notice_successful_update)
178 178 redirect_to settings_project_path(@project)
179 179 }
180 180 format.api { render_api_ok }
181 181 end
182 182 else
183 183 respond_to do |format|
184 184 format.html {
185 185 settings
186 186 render :action => 'settings'
187 187 }
188 188 format.api { render_validation_errors(@project) }
189 189 end
190 190 end
191 191 end
192 192
193 193 def modules
194 194 @project.enabled_module_names = params[:enabled_module_names]
195 195 flash[:notice] = l(:notice_successful_update)
196 196 redirect_to settings_project_path(@project, :tab => 'modules')
197 197 end
198 198
199 199 def archive
200 200 unless @project.archive
201 201 flash[:error] = l(:error_can_not_archive_project)
202 202 end
203 203 redirect_to admin_projects_path(:status => params[:status])
204 204 end
205 205
206 206 def unarchive
207 207 unless @project.active?
208 208 @project.unarchive
209 209 end
210 210 redirect_to admin_projects_path(:status => params[:status])
211 211 end
212 212
213 213 def close
214 214 @project.close
215 215 redirect_to project_path(@project)
216 216 end
217 217
218 218 def reopen
219 219 @project.reopen
220 220 redirect_to project_path(@project)
221 221 end
222 222
223 223 # Delete @project
224 224 def destroy
225 225 @project_to_destroy = @project
226 226 if api_request? || params[:confirm]
227 227 @project_to_destroy.destroy
228 228 respond_to do |format|
229 229 format.html { redirect_to admin_projects_path }
230 230 format.api { render_api_ok }
231 231 end
232 232 end
233 233 # hide project in layout
234 234 @project = nil
235 235 end
236 236
237 237 private
238 238
239 239 # Validates parent_id param according to user's permissions
240 240 # TODO: move it to Project model in a validation that depends on User.current
241 241 def validate_parent_id
242 242 return true if User.current.admin?
243 243 parent_id = params[:project] && params[:project][:parent_id]
244 244 if parent_id || @project.new_record?
245 245 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
246 246 unless @project.allowed_parents.include?(parent)
247 247 @project.errors.add :parent_id, :invalid
248 248 return false
249 249 end
250 250 end
251 251 true
252 252 end
253 253 end
@@ -1,609 +1,623
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class ProjectsControllerTest < ActionController::TestCase
21 21 fixtures :projects, :versions, :users, :roles, :members,
22 22 :member_roles, :issues, :journals, :journal_details,
23 23 :trackers, :projects_trackers, :issue_statuses,
24 24 :enabled_modules, :enumerations, :boards, :messages,
25 25 :attachments, :custom_fields, :custom_values, :time_entries
26 26
27 27 def setup
28 28 @request.session[:user_id] = nil
29 29 Setting.default_language = 'en'
30 30 end
31 31
32 32 def test_index_by_anonymous_should_not_show_private_projects
33 33 get :index
34 34 assert_response :success
35 35 assert_template 'index'
36 36 projects = assigns(:projects)
37 37 assert_not_nil projects
38 38 assert projects.all?(&:is_public?)
39 39
40 40 assert_select 'ul' do
41 41 assert_select 'li' do
42 42 assert_select 'a', :text => 'eCookbook'
43 43 assert_select 'ul' do
44 44 assert_select 'a', :text => 'Child of private child'
45 45 end
46 46 end
47 47 end
48 48 assert_select 'a', :text => /Private child of eCookbook/, :count => 0
49 49 end
50 50
51 51 def test_index_atom
52 52 get :index, :format => 'atom'
53 53 assert_response :success
54 54 assert_template 'common/feed'
55 55 assert_select 'feed>title', :text => 'Redmine: Latest projects'
56 56 assert_select 'feed>entry', :count => Project.visible(User.current).count
57 57 end
58 58
59 59 test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
60 60 @request.session[:user_id] = 3
61 61 get :index
62 62 assert_template 'index'
63 63 assert_select 'a[href=?]', '/time_entries'
64 64 end
65 65
66 66 test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do
67 67 Role.find(2).remove_permission! :view_time_entries
68 68 Role.non_member.remove_permission! :view_time_entries
69 69 Role.anonymous.remove_permission! :view_time_entries
70 70 @request.session[:user_id] = 3
71 71
72 72 get :index
73 73 assert_template 'index'
74 74 assert_select 'a[href=?]', '/time_entries', 0
75 75 end
76 76
77 77 test "#new by admin user should accept get" do
78 78 @request.session[:user_id] = 1
79 79
80 80 get :new
81 81 assert_response :success
82 82 assert_template 'new'
83 83 end
84 84
85 85 test "#new by non-admin user with add_project permission should accept get" do
86 86 Role.non_member.add_permission! :add_project
87 87 @request.session[:user_id] = 9
88 88
89 89 get :new
90 90 assert_response :success
91 91 assert_template 'new'
92 92 assert_select 'select[name=?]', 'project[parent_id]', 0
93 93 end
94 94
95 95 test "#new by non-admin user with add_subprojects permission should accept get" do
96 96 Role.find(1).remove_permission! :add_project
97 97 Role.find(1).add_permission! :add_subprojects
98 98 @request.session[:user_id] = 2
99 99
100 100 get :new, :parent_id => 'ecookbook'
101 101 assert_response :success
102 102 assert_template 'new'
103 103
104 104 assert_select 'select[name=?]', 'project[parent_id]' do
105 105 # parent project selected
106 106 assert_select 'option[value="1"][selected=selected]'
107 107 # no empty value
108 108 assert_select 'option[value=""]', 0
109 109 end
110 110 end
111 111
112 112 test "#create by admin user should create a new project" do
113 113 @request.session[:user_id] = 1
114 114
115 115 post :create,
116 116 :project => {
117 117 :name => "blog",
118 118 :description => "weblog",
119 119 :homepage => 'http://weblog',
120 120 :identifier => "blog",
121 121 :is_public => 1,
122 122 :custom_field_values => { '3' => 'Beta' },
123 123 :tracker_ids => ['1', '3'],
124 124 # an issue custom field that is not for all project
125 125 :issue_custom_field_ids => ['9'],
126 126 :enabled_module_names => ['issue_tracking', 'news', 'repository']
127 127 }
128 128 assert_redirected_to '/projects/blog/settings'
129 129
130 130 project = Project.find_by_name('blog')
131 131 assert_kind_of Project, project
132 132 assert project.active?
133 133 assert_equal 'weblog', project.description
134 134 assert_equal 'http://weblog', project.homepage
135 135 assert_equal true, project.is_public?
136 136 assert_nil project.parent
137 137 assert_equal 'Beta', project.custom_value_for(3).value
138 138 assert_equal [1, 3], project.trackers.map(&:id).sort
139 139 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
140 140 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
141 141 end
142 142
143 143 test "#create by admin user should create a new subproject" do
144 144 @request.session[:user_id] = 1
145 145
146 146 assert_difference 'Project.count' do
147 147 post :create, :project => { :name => "blog",
148 148 :description => "weblog",
149 149 :identifier => "blog",
150 150 :is_public => 1,
151 151 :custom_field_values => { '3' => 'Beta' },
152 152 :parent_id => 1
153 153 }
154 154 assert_redirected_to '/projects/blog/settings'
155 155 end
156 156
157 157 project = Project.find_by_name('blog')
158 158 assert_kind_of Project, project
159 159 assert_equal Project.find(1), project.parent
160 160 end
161 161
162 162 test "#create by admin user should continue" do
163 163 @request.session[:user_id] = 1
164 164
165 165 assert_difference 'Project.count' do
166 166 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue'
167 167 end
168 168 assert_redirected_to '/projects/new'
169 169 end
170 170
171 171 test "#create by non-admin user with add_project permission should create a new project" do
172 172 Role.non_member.add_permission! :add_project
173 173 @request.session[:user_id] = 9
174 174
175 175 post :create, :project => { :name => "blog",
176 176 :description => "weblog",
177 177 :identifier => "blog",
178 178 :is_public => 1,
179 179 :custom_field_values => { '3' => 'Beta' },
180 180 :tracker_ids => ['1', '3'],
181 181 :enabled_module_names => ['issue_tracking', 'news', 'repository']
182 182 }
183 183
184 184 assert_redirected_to '/projects/blog/settings'
185 185
186 186 project = Project.find_by_name('blog')
187 187 assert_kind_of Project, project
188 188 assert_equal 'weblog', project.description
189 189 assert_equal true, project.is_public?
190 190 assert_equal [1, 3], project.trackers.map(&:id).sort
191 191 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
192 192
193 193 # User should be added as a project member
194 194 assert User.find(9).member_of?(project)
195 195 assert_equal 1, project.members.size
196 196 end
197 197
198 198 test "#create by non-admin user with add_project permission should fail with parent_id" do
199 199 Role.non_member.add_permission! :add_project
200 200 @request.session[:user_id] = 9
201 201
202 202 assert_no_difference 'Project.count' do
203 203 post :create, :project => { :name => "blog",
204 204 :description => "weblog",
205 205 :identifier => "blog",
206 206 :is_public => 1,
207 207 :custom_field_values => { '3' => 'Beta' },
208 208 :parent_id => 1
209 209 }
210 210 end
211 211 assert_response :success
212 212 project = assigns(:project)
213 213 assert_kind_of Project, project
214 214 assert_not_equal [], project.errors[:parent_id]
215 215 end
216 216
217 217 test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do
218 218 Role.find(1).remove_permission! :add_project
219 219 Role.find(1).add_permission! :add_subprojects
220 220 @request.session[:user_id] = 2
221 221
222 222 post :create, :project => { :name => "blog",
223 223 :description => "weblog",
224 224 :identifier => "blog",
225 225 :is_public => 1,
226 226 :custom_field_values => { '3' => 'Beta' },
227 227 :parent_id => 1
228 228 }
229 229 assert_redirected_to '/projects/blog/settings'
230 230 project = Project.find_by_name('blog')
231 231 end
232 232
233 233 test "#create by non-admin user with add_subprojects permission should fail without parent_id" do
234 234 Role.find(1).remove_permission! :add_project
235 235 Role.find(1).add_permission! :add_subprojects
236 236 @request.session[:user_id] = 2
237 237
238 238 assert_no_difference 'Project.count' do
239 239 post :create, :project => { :name => "blog",
240 240 :description => "weblog",
241 241 :identifier => "blog",
242 242 :is_public => 1,
243 243 :custom_field_values => { '3' => 'Beta' }
244 244 }
245 245 end
246 246 assert_response :success
247 247 project = assigns(:project)
248 248 assert_kind_of Project, project
249 249 assert_not_equal [], project.errors[:parent_id]
250 250 end
251 251
252 252 test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do
253 253 Role.find(1).remove_permission! :add_project
254 254 Role.find(1).add_permission! :add_subprojects
255 255 @request.session[:user_id] = 2
256 256
257 257 assert !User.find(2).member_of?(Project.find(6))
258 258 assert_no_difference 'Project.count' do
259 259 post :create, :project => { :name => "blog",
260 260 :description => "weblog",
261 261 :identifier => "blog",
262 262 :is_public => 1,
263 263 :custom_field_values => { '3' => 'Beta' },
264 264 :parent_id => 6
265 265 }
266 266 end
267 267 assert_response :success
268 268 project = assigns(:project)
269 269 assert_kind_of Project, project
270 270 assert_not_equal [], project.errors[:parent_id]
271 271 end
272 272
273 273 def test_create_subproject_with_inherit_members_should_inherit_members
274 274 Role.find_by_name('Manager').add_permission! :add_subprojects
275 275 parent = Project.find(1)
276 276 @request.session[:user_id] = 2
277 277
278 278 assert_difference 'Project.count' do
279 279 post :create, :project => {
280 280 :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1'
281 281 }
282 282 assert_response 302
283 283 end
284 284
285 285 project = Project.order('id desc').first
286 286 assert_equal 'inherited', project.name
287 287 assert_equal parent, project.parent
288 288 assert project.memberships.count > 0
289 289 assert_equal parent.memberships.count, project.memberships.count
290 290 end
291 291
292 292 def test_create_should_preserve_modules_on_validation_failure
293 293 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
294 294 @request.session[:user_id] = 1
295 295 assert_no_difference 'Project.count' do
296 296 post :create, :project => {
297 297 :name => "blog",
298 298 :identifier => "",
299 299 :enabled_module_names => %w(issue_tracking news)
300 300 }
301 301 end
302 302 assert_response :success
303 303 project = assigns(:project)
304 304 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
305 305 end
306 306 end
307 307
308 308 def test_show_by_id
309 309 get :show, :id => 1
310 310 assert_response :success
311 311 assert_template 'show'
312 312 assert_not_nil assigns(:project)
313 313 end
314 314
315 315 def test_show_by_identifier
316 316 get :show, :id => 'ecookbook'
317 317 assert_response :success
318 318 assert_template 'show'
319 319 assert_not_nil assigns(:project)
320 320 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
321 321
322 322 assert_select 'li', :text => /Development status/
323 323 end
324 324
325 325 def test_show_should_not_display_empty_sidebar
326 326 p = Project.find(1)
327 327 p.enabled_module_names = []
328 328 p.save!
329 329
330 330 get :show, :id => 'ecookbook'
331 331 assert_response :success
332 332 assert_select '#main.nosidebar'
333 333 end
334 334
335 335 def test_show_should_not_display_hidden_custom_fields
336 336 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
337 337 get :show, :id => 'ecookbook'
338 338 assert_response :success
339 339 assert_template 'show'
340 340 assert_not_nil assigns(:project)
341 341
342 342 assert_select 'li', :text => /Development status/, :count => 0
343 343 end
344 344
345 345 def test_show_should_not_fail_when_custom_values_are_nil
346 346 project = Project.find_by_identifier('ecookbook')
347 347 project.custom_values.first.update_attribute(:value, nil)
348 348 get :show, :id => 'ecookbook'
349 349 assert_response :success
350 350 assert_template 'show'
351 351 assert_not_nil assigns(:project)
352 352 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
353 353 end
354 354
355 355 def show_archived_project_should_be_denied
356 356 project = Project.find_by_identifier('ecookbook')
357 357 project.archive!
358 358
359 359 get :show, :id => 'ecookbook'
360 360 assert_response 403
361 361 assert_nil assigns(:project)
362 362 assert_select 'p', :text => /archived/
363 363 end
364 364
365 365 def test_show_should_not_show_private_subprojects_that_are_not_visible
366 366 get :show, :id => 'ecookbook'
367 367 assert_response :success
368 368 assert_template 'show'
369 369 assert_select 'a', :text => /Private child/, :count => 0
370 370 end
371 371
372 372 def test_show_should_show_private_subprojects_that_are_visible
373 373 @request.session[:user_id] = 2 # manager who is a member of the private subproject
374 374 get :show, :id => 'ecookbook'
375 375 assert_response :success
376 376 assert_template 'show'
377 377 assert_select 'a', :text => /Private child/
378 378 end
379 379
380 380 def test_settings
381 381 @request.session[:user_id] = 2 # manager
382 382 get :settings, :id => 1
383 383 assert_response :success
384 384 assert_template 'settings'
385 385 end
386 386
387 387 def test_settings_of_subproject
388 388 @request.session[:user_id] = 2
389 389 get :settings, :id => 'private-child'
390 390 assert_response :success
391 391 assert_template 'settings'
392 392
393 393 assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]'
394 394 end
395 395
396 396 def test_settings_should_be_denied_for_member_on_closed_project
397 397 Project.find(1).close
398 398 @request.session[:user_id] = 2 # manager
399 399
400 400 get :settings, :id => 1
401 401 assert_response 403
402 402 end
403 403
404 404 def test_settings_should_be_denied_for_anonymous_on_closed_project
405 405 Project.find(1).close
406 406
407 407 get :settings, :id => 1
408 408 assert_response 302
409 409 end
410 410
411 def test_setting_with_wiki_module_and_no_wiki
412 Project.find(1).wiki.destroy
413 Role.find(1).add_permission! :manage_wiki
414 @request.session[:user_id] = 2
415
416 get :settings, :id => 1
417 assert_response :success
418 assert_template 'settings'
419
420 assert_select 'form[action=?]', '/projects/ecookbook/wiki' do
421 assert_select 'input[name=?]', 'wiki[start_page]'
422 end
423 end
424
411 425 def test_update
412 426 @request.session[:user_id] = 2 # manager
413 427 post :update, :id => 1, :project => {:name => 'Test changed name',
414 428 :issue_custom_field_ids => ['']}
415 429 assert_redirected_to '/projects/ecookbook/settings'
416 430 project = Project.find(1)
417 431 assert_equal 'Test changed name', project.name
418 432 end
419 433
420 434 def test_update_with_failure
421 435 @request.session[:user_id] = 2 # manager
422 436 post :update, :id => 1, :project => {:name => ''}
423 437 assert_response :success
424 438 assert_template 'settings'
425 439 assert_select_error /name #{ESCAPED_CANT} be blank/i
426 440 end
427 441
428 442 def test_update_should_be_denied_for_member_on_closed_project
429 443 Project.find(1).close
430 444 @request.session[:user_id] = 2 # manager
431 445
432 446 post :update, :id => 1, :project => {:name => 'Closed'}
433 447 assert_response 403
434 448 assert_equal 'eCookbook', Project.find(1).name
435 449 end
436 450
437 451 def test_update_should_be_denied_for_anonymous_on_closed_project
438 452 Project.find(1).close
439 453
440 454 post :update, :id => 1, :project => {:name => 'Closed'}
441 455 assert_response 302
442 456 assert_equal 'eCookbook', Project.find(1).name
443 457 end
444 458
445 459 def test_modules
446 460 @request.session[:user_id] = 2
447 461 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
448 462
449 463 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
450 464 assert_redirected_to '/projects/ecookbook/settings/modules'
451 465 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
452 466 end
453 467
454 468 def test_destroy_leaf_project_without_confirmation_should_show_confirmation
455 469 @request.session[:user_id] = 1 # admin
456 470
457 471 assert_no_difference 'Project.count' do
458 472 delete :destroy, :id => 2
459 473 assert_response :success
460 474 assert_template 'destroy'
461 475 end
462 476 end
463 477
464 478 def test_destroy_without_confirmation_should_show_confirmation_with_subprojects
465 479 @request.session[:user_id] = 1 # admin
466 480
467 481 assert_no_difference 'Project.count' do
468 482 delete :destroy, :id => 1
469 483 assert_response :success
470 484 assert_template 'destroy'
471 485 end
472 486 assert_select 'strong',
473 487 :text => ['Private child of eCookbook',
474 488 'Child of private child, eCookbook Subproject 1',
475 489 'eCookbook Subproject 2'].join(', ')
476 490 end
477 491
478 492 def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects
479 493 @request.session[:user_id] = 1 # admin
480 494
481 495 assert_difference 'Project.count', -5 do
482 496 delete :destroy, :id => 1, :confirm => 1
483 497 assert_redirected_to '/admin/projects'
484 498 end
485 499 assert_nil Project.find_by_id(1)
486 500 end
487 501
488 502 def test_archive
489 503 @request.session[:user_id] = 1 # admin
490 504 post :archive, :id => 1
491 505 assert_redirected_to '/admin/projects'
492 506 assert !Project.find(1).active?
493 507 end
494 508
495 509 def test_archive_with_failure
496 510 @request.session[:user_id] = 1
497 511 Project.any_instance.stubs(:archive).returns(false)
498 512 post :archive, :id => 1
499 513 assert_redirected_to '/admin/projects'
500 514 assert_match /project cannot be archived/i, flash[:error]
501 515 end
502 516
503 517 def test_unarchive
504 518 @request.session[:user_id] = 1 # admin
505 519 Project.find(1).archive
506 520 post :unarchive, :id => 1
507 521 assert_redirected_to '/admin/projects'
508 522 assert Project.find(1).active?
509 523 end
510 524
511 525 def test_close
512 526 @request.session[:user_id] = 2
513 527 post :close, :id => 1
514 528 assert_redirected_to '/projects/ecookbook'
515 529 assert_equal Project::STATUS_CLOSED, Project.find(1).status
516 530 end
517 531
518 532 def test_reopen
519 533 Project.find(1).close
520 534 @request.session[:user_id] = 2
521 535 post :reopen, :id => 1
522 536 assert_redirected_to '/projects/ecookbook'
523 537 assert Project.find(1).active?
524 538 end
525 539
526 540 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
527 541 CustomField.delete_all
528 542 parent = nil
529 543 6.times do |i|
530 544 p = Project.generate_with_parent!(parent)
531 545 get :show, :id => p
532 546 assert_select '#header h1' do
533 547 assert_select 'a', :count => [i, 3].min
534 548 end
535 549
536 550 parent = p
537 551 end
538 552 end
539 553
540 554 def test_get_copy
541 555 @request.session[:user_id] = 1 # admin
542 556 get :copy, :id => 1
543 557 assert_response :success
544 558 assert_template 'copy'
545 559 assert assigns(:project)
546 560 assert_equal Project.find(1).description, assigns(:project).description
547 561 assert_nil assigns(:project).id
548 562
549 563 assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1
550 564 end
551 565
552 566 def test_get_copy_with_invalid_source_should_respond_with_404
553 567 @request.session[:user_id] = 1
554 568 get :copy, :id => 99
555 569 assert_response 404
556 570 end
557 571
558 572 def test_post_copy_should_copy_requested_items
559 573 @request.session[:user_id] = 1 # admin
560 574 CustomField.delete_all
561 575
562 576 assert_difference 'Project.count' do
563 577 post :copy, :id => 1,
564 578 :project => {
565 579 :name => 'Copy',
566 580 :identifier => 'unique-copy',
567 581 :tracker_ids => ['1', '2', '3', ''],
568 582 :enabled_module_names => %w(issue_tracking time_tracking)
569 583 },
570 584 :only => %w(issues versions)
571 585 end
572 586 project = Project.find('unique-copy')
573 587 source = Project.find(1)
574 588 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
575 589
576 590 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
577 591 assert_equal source.issues.count, project.issues.count, "All issues were not copied"
578 592 assert_equal 0, project.members.count
579 593 end
580 594
581 595 def test_post_copy_should_redirect_to_settings_when_successful
582 596 @request.session[:user_id] = 1 # admin
583 597 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
584 598 assert_response :redirect
585 599 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
586 600 end
587 601
588 602 def test_jump_should_redirect_to_active_tab
589 603 get :show, :id => 1, :jump => 'issues'
590 604 assert_redirected_to '/projects/ecookbook/issues'
591 605 end
592 606
593 607 def test_jump_should_not_redirect_to_inactive_tab
594 608 get :show, :id => 3, :jump => 'documents'
595 609 assert_response :success
596 610 assert_template 'show'
597 611 end
598 612
599 613 def test_jump_should_not_redirect_to_unknown_tab
600 614 get :show, :id => 3, :jump => 'foobar'
601 615 assert_response :success
602 616 assert_template 'show'
603 617 end
604 618
605 619 def test_body_should_have_project_css_class
606 620 get :show, :id => 1
607 621 assert_select 'body.project-ecookbook'
608 622 end
609 623 end
General Comments 0
You need to be logged in to leave comments. Login now