##// END OF EJS Templates
Moved ProjectsController#list to ProjectsController#index....
Jean-Philippe Lang -
r1450:744d8669260b
parent child
Show More
@@ -1,440 +1,435
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 layout 'base'
20 20 menu_item :overview
21 21 menu_item :activity, :only => :activity
22 22 menu_item :roadmap, :only => :roadmap
23 23 menu_item :files, :only => [:list_files, :add_file]
24 24 menu_item :settings, :only => :settings
25 25 menu_item :issues, :only => [:changelog]
26 26
27 27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
28 28 before_filter :find_optional_project, :only => :activity
29 29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
30 30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
31 31 accept_key_auth :activity, :calendar
32 32
33 33 helper :sort
34 34 include SortHelper
35 35 helper :custom_fields
36 36 include CustomFieldsHelper
37 37 helper :ifpdf
38 38 include IfpdfHelper
39 39 helper :issues
40 40 helper IssuesHelper
41 41 helper :queries
42 42 include QueriesHelper
43 43 helper :repositories
44 44 include RepositoriesHelper
45 45 include ProjectsHelper
46 46
47 def index
48 list
49 render :action => 'list' unless request.xhr?
50 end
51
52 47 # Lists visible projects
53 def list
48 def index
54 49 projects = Project.find :all,
55 50 :conditions => Project.visible_by(User.current),
56 51 :include => :parent
57 52 @project_tree = projects.group_by {|p| p.parent || p}
58 53 @project_tree.each_key {|p| @project_tree[p] -= [p]}
59 54 end
60 55
61 56 # Add a new project
62 57 def add
63 58 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
64 59 @trackers = Tracker.all
65 60 @root_projects = Project.find(:all,
66 61 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
67 62 :order => 'name')
68 63 @project = Project.new(params[:project])
69 64 if request.get?
70 65 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
71 66 @project.trackers = Tracker.all
72 67 @project.is_public = Setting.default_projects_public?
73 68 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
74 69 else
75 70 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
76 71 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
77 72 @project.custom_values = @custom_values
78 73 @project.enabled_module_names = params[:enabled_modules]
79 74 if @project.save
80 75 flash[:notice] = l(:notice_successful_create)
81 76 redirect_to :controller => 'admin', :action => 'projects'
82 77 end
83 78 end
84 79 end
85 80
86 81 # Show @project
87 82 def show
88 83 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
89 84 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
90 85 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
91 86 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
92 87 @trackers = @project.rolled_up_trackers
93 88
94 89 cond = @project.project_condition(Setting.display_subprojects_issues?)
95 90 Issue.visible_by(User.current) do
96 91 @open_issues_by_tracker = Issue.count(:group => :tracker,
97 92 :include => [:project, :status, :tracker],
98 93 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
99 94 @total_issues_by_tracker = Issue.count(:group => :tracker,
100 95 :include => [:project, :status, :tracker],
101 96 :conditions => cond)
102 97 end
103 98 TimeEntry.visible_by(User.current) do
104 99 @total_hours = TimeEntry.sum(:hours,
105 100 :include => :project,
106 101 :conditions => cond).to_f
107 102 end
108 103 @key = User.current.rss_key
109 104 end
110 105
111 106 def settings
112 107 @root_projects = Project.find(:all,
113 108 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
114 109 :order => 'name')
115 110 @custom_fields = IssueCustomField.find(:all)
116 111 @issue_category ||= IssueCategory.new
117 112 @member ||= @project.members.new
118 113 @trackers = Tracker.all
119 114 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
120 115 @repository ||= @project.repository
121 116 @wiki ||= @project.wiki
122 117 end
123 118
124 119 # Edit @project
125 120 def edit
126 121 if request.post?
127 122 if params[:custom_fields]
128 123 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
129 124 @project.custom_values = @custom_values
130 125 end
131 126 @project.attributes = params[:project]
132 127 if @project.save
133 128 flash[:notice] = l(:notice_successful_update)
134 129 redirect_to :action => 'settings', :id => @project
135 130 else
136 131 settings
137 132 render :action => 'settings'
138 133 end
139 134 end
140 135 end
141 136
142 137 def modules
143 138 @project.enabled_module_names = params[:enabled_modules]
144 139 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
145 140 end
146 141
147 142 def archive
148 143 @project.archive if request.post? && @project.active?
149 144 redirect_to :controller => 'admin', :action => 'projects'
150 145 end
151 146
152 147 def unarchive
153 148 @project.unarchive if request.post? && !@project.active?
154 149 redirect_to :controller => 'admin', :action => 'projects'
155 150 end
156 151
157 152 # Delete @project
158 153 def destroy
159 154 @project_to_destroy = @project
160 155 if request.post? and params[:confirm]
161 156 @project_to_destroy.destroy
162 157 redirect_to :controller => 'admin', :action => 'projects'
163 158 end
164 159 # hide project in layout
165 160 @project = nil
166 161 end
167 162
168 163 # Add a new issue category to @project
169 164 def add_issue_category
170 165 @category = @project.issue_categories.build(params[:category])
171 166 if request.post? and @category.save
172 167 respond_to do |format|
173 168 format.html do
174 169 flash[:notice] = l(:notice_successful_create)
175 170 redirect_to :action => 'settings', :tab => 'categories', :id => @project
176 171 end
177 172 format.js do
178 173 # IE doesn't support the replace_html rjs method for select box options
179 174 render(:update) {|page| page.replace "issue_category_id",
180 175 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
181 176 }
182 177 end
183 178 end
184 179 end
185 180 end
186 181
187 182 # Add a new version to @project
188 183 def add_version
189 184 @version = @project.versions.build(params[:version])
190 185 if request.post? and @version.save
191 186 flash[:notice] = l(:notice_successful_create)
192 187 redirect_to :action => 'settings', :tab => 'versions', :id => @project
193 188 end
194 189 end
195 190
196 191 def add_file
197 192 if request.post?
198 193 @version = @project.versions.find_by_id(params[:version_id])
199 194 attachments = attach_files(@version, params[:attachments])
200 195 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
201 196 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
202 197 end
203 198 @versions = @project.versions.sort
204 199 end
205 200
206 201 def list_files
207 202 sort_init "#{Attachment.table_name}.filename", "asc"
208 203 sort_update
209 204 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
210 205 render :layout => !request.xhr?
211 206 end
212 207
213 208 # Show changelog for @project
214 209 def changelog
215 210 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
216 211 retrieve_selected_tracker_ids(@trackers)
217 212 @versions = @project.versions.sort
218 213 end
219 214
220 215 def roadmap
221 216 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
222 217 retrieve_selected_tracker_ids(@trackers)
223 218 @versions = @project.versions.sort
224 219 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
225 220 end
226 221
227 222 def activity
228 223 @days = Setting.activity_days_default.to_i
229 224
230 225 if params[:from]
231 226 begin; @date_to = params[:from].to_date; rescue; end
232 227 end
233 228
234 229 @date_to ||= Date.today + 1
235 230 @date_from = @date_to - @days
236 231
237 232 @event_types = %w(issues news files documents changesets wiki_pages messages)
238 233 if @project
239 234 @event_types.delete('wiki_pages') unless @project.wiki
240 235 @event_types.delete('changesets') unless @project.repository
241 236 @event_types.delete('messages') unless @project.boards.any?
242 237 # only show what the user is allowed to view
243 238 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
244 239 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
245 240 end
246 241 @scope = @event_types.select {|t| params["show_#{t}"]}
247 242 # default events if none is specified in parameters
248 243 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
249 244
250 245 @events = []
251 246
252 247 if @scope.include?('issues')
253 248 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
254 249 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
255 250 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
256 251
257 252 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
258 253 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
259 254 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
260 255 end
261 256
262 257 if @scope.include?('news')
263 258 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
264 259 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
265 260 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
266 261 end
267 262
268 263 if @scope.include?('files')
269 264 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
270 265 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
271 266 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
272 267 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
273 268 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
274 269 :conditions => cond.conditions)
275 270 end
276 271
277 272 if @scope.include?('documents')
278 273 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
279 274 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
280 275 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
281 276
282 277 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
283 278 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
284 279 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
285 280 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
286 281 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
287 282 :conditions => cond.conditions)
288 283 end
289 284
290 285 if @scope.include?('wiki_pages')
291 286 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
292 287 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
293 288 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
294 289 "#{WikiContent.versioned_table_name}.id"
295 290 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
296 291 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
297 292 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
298 293
299 294 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
300 295 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
301 296 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
302 297 end
303 298
304 299 if @scope.include?('changesets')
305 300 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
306 301 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
307 302 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
308 303 end
309 304
310 305 if @scope.include?('messages')
311 306 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
312 307 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
313 308 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
314 309 end
315 310
316 311 @events_by_day = @events.group_by(&:event_date)
317 312
318 313 respond_to do |format|
319 314 format.html { render :layout => false if request.xhr? }
320 315 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
321 316 end
322 317 end
323 318
324 319 def calendar
325 320 @trackers = @project.rolled_up_trackers
326 321 retrieve_selected_tracker_ids(@trackers)
327 322
328 323 if params[:year] and params[:year].to_i > 1900
329 324 @year = params[:year].to_i
330 325 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
331 326 @month = params[:month].to_i
332 327 end
333 328 end
334 329 @year ||= Date.today.year
335 330 @month ||= Date.today.month
336 331 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
337 332 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
338 333 events = []
339 334 @project.issues_with_subprojects(@with_subprojects) do
340 335 events += Issue.find(:all,
341 336 :include => [:tracker, :status, :assigned_to, :priority, :project],
342 337 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
343 338 ) unless @selected_tracker_ids.empty?
344 339 events += Version.find(:all, :include => :project,
345 340 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
346 341 end
347 342 @calendar.events = events
348 343
349 344 render :layout => false if request.xhr?
350 345 end
351 346
352 347 def gantt
353 348 @trackers = @project.rolled_up_trackers
354 349 retrieve_selected_tracker_ids(@trackers)
355 350
356 351 if params[:year] and params[:year].to_i >0
357 352 @year_from = params[:year].to_i
358 353 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
359 354 @month_from = params[:month].to_i
360 355 else
361 356 @month_from = 1
362 357 end
363 358 else
364 359 @month_from ||= Date.today.month
365 360 @year_from ||= Date.today.year
366 361 end
367 362
368 363 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
369 364 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
370 365 months = (params[:months] || User.current.pref[:gantt_months]).to_i
371 366 @months = (months > 0 && months < 25) ? months : 6
372 367
373 368 # Save gantt paramters as user preference (zoom and months count)
374 369 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
375 370 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
376 371 User.current.preference.save
377 372 end
378 373
379 374 @date_from = Date.civil(@year_from, @month_from, 1)
380 375 @date_to = (@date_from >> @months) - 1
381 376 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
382 377
383 378 @events = []
384 379 @project.issues_with_subprojects(@with_subprojects) do
385 380 # Issues that have start and due dates
386 381 @events += Issue.find(:all,
387 382 :order => "start_date, due_date",
388 383 :include => [:tracker, :status, :assigned_to, :priority, :project],
389 384 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
390 385 ) unless @selected_tracker_ids.empty?
391 386 # Issues that don't have a due date but that are assigned to a version with a date
392 387 @events += Issue.find(:all,
393 388 :order => "start_date, effective_date",
394 389 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
395 390 :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
396 391 ) unless @selected_tracker_ids.empty?
397 392 @events += Version.find(:all, :include => :project,
398 393 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
399 394 end
400 395 @events.sort! {|x,y| x.start_date <=> y.start_date }
401 396
402 397 if params[:format]=='pdf'
403 398 @options_for_rfpdf ||= {}
404 399 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
405 400 render :template => "projects/gantt.rfpdf", :layout => false
406 401 elsif params[:format]=='png' && respond_to?('gantt_image')
407 402 image = gantt_image(@events, @date_from, @months, @zoom)
408 403 image.format = 'PNG'
409 404 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
410 405 else
411 406 render :template => "projects/gantt.rhtml"
412 407 end
413 408 end
414 409
415 410 private
416 411 # Find project of id params[:id]
417 412 # if not found, redirect to project list
418 413 # Used as a before_filter
419 414 def find_project
420 415 @project = Project.find(params[:id])
421 416 rescue ActiveRecord::RecordNotFound
422 417 render_404
423 418 end
424 419
425 420 def find_optional_project
426 421 return true unless params[:id]
427 422 @project = Project.find(params[:id])
428 423 authorize
429 424 rescue ActiveRecord::RecordNotFound
430 425 render_404
431 426 end
432 427
433 428 def retrieve_selected_tracker_ids(selectable_trackers)
434 429 if ids = params[:tracker_ids]
435 430 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
436 431 else
437 432 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
438 433 end
439 434 end
440 435 end
1 NO CONTENT: file renamed from app/views/projects/list.rhtml to app/views/projects/index.rhtml
@@ -1,313 +1,307
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'projects_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class ProjectsController; def rescue_action(e) raise e end; end
23 23
24 24 class ProjectsControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
26 26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
27 27
28 28 def setup
29 29 @controller = ProjectsController.new
30 30 @request = ActionController::TestRequest.new
31 31 @response = ActionController::TestResponse.new
32 32 @request.session[:user_id] = nil
33 33 end
34 34
35 35 def test_index
36 36 get :index
37 37 assert_response :success
38 assert_template 'list'
39 end
40
41 def test_list
42 get :list
43 assert_response :success
44 assert_template 'list'
38 assert_template 'index'
45 39 assert_not_nil assigns(:project_tree)
46 40 # Root project as hash key
47 41 assert assigns(:project_tree).has_key?(Project.find(1))
48 42 # Subproject in corresponding value
49 43 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
50 44 end
51 45
52 46 def test_show_by_id
53 47 get :show, :id => 1
54 48 assert_response :success
55 49 assert_template 'show'
56 50 assert_not_nil assigns(:project)
57 51 end
58 52
59 53 def test_show_by_identifier
60 54 get :show, :id => 'ecookbook'
61 55 assert_response :success
62 56 assert_template 'show'
63 57 assert_not_nil assigns(:project)
64 58 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
65 59 end
66 60
67 61 def test_private_subprojects_hidden
68 62 get :show, :id => 'ecookbook'
69 63 assert_response :success
70 64 assert_template 'show'
71 65 assert_no_tag :tag => 'a', :content => /Private child/
72 66 end
73 67
74 68 def test_private_subprojects_visible
75 69 @request.session[:user_id] = 2 # manager who is a member of the private subproject
76 70 get :show, :id => 'ecookbook'
77 71 assert_response :success
78 72 assert_template 'show'
79 73 assert_tag :tag => 'a', :content => /Private child/
80 74 end
81 75
82 76 def test_settings
83 77 @request.session[:user_id] = 2 # manager
84 78 get :settings, :id => 1
85 79 assert_response :success
86 80 assert_template 'settings'
87 81 end
88 82
89 83 def test_edit
90 84 @request.session[:user_id] = 2 # manager
91 85 post :edit, :id => 1, :project => {:name => 'Test changed name',
92 86 :custom_field_ids => ['']}
93 87 assert_redirected_to 'projects/settings/ecookbook'
94 88 project = Project.find(1)
95 89 assert_equal 'Test changed name', project.name
96 90 end
97 91
98 92 def test_get_destroy
99 93 @request.session[:user_id] = 1 # admin
100 94 get :destroy, :id => 1
101 95 assert_response :success
102 96 assert_template 'destroy'
103 97 assert_not_nil Project.find_by_id(1)
104 98 end
105 99
106 100 def test_post_destroy
107 101 @request.session[:user_id] = 1 # admin
108 102 post :destroy, :id => 1, :confirm => 1
109 103 assert_redirected_to 'admin/projects'
110 104 assert_nil Project.find_by_id(1)
111 105 end
112 106
113 107 def test_list_files
114 108 get :list_files, :id => 1
115 109 assert_response :success
116 110 assert_template 'list_files'
117 111 assert_not_nil assigns(:versions)
118 112 end
119 113
120 114 def test_changelog
121 115 get :changelog, :id => 1
122 116 assert_response :success
123 117 assert_template 'changelog'
124 118 assert_not_nil assigns(:versions)
125 119 end
126 120
127 121 def test_roadmap
128 122 get :roadmap, :id => 1
129 123 assert_response :success
130 124 assert_template 'roadmap'
131 125 assert_not_nil assigns(:versions)
132 126 # Version with no date set appears
133 127 assert assigns(:versions).include?(Version.find(3))
134 128 # Completed version doesn't appear
135 129 assert !assigns(:versions).include?(Version.find(1))
136 130 end
137 131
138 132 def test_roadmap_with_completed_versions
139 133 get :roadmap, :id => 1, :completed => 1
140 134 assert_response :success
141 135 assert_template 'roadmap'
142 136 assert_not_nil assigns(:versions)
143 137 # Version with no date set appears
144 138 assert assigns(:versions).include?(Version.find(3))
145 139 # Completed version appears
146 140 assert assigns(:versions).include?(Version.find(1))
147 141 end
148 142
149 143 def test_project_activity
150 144 get :activity, :id => 1, :with_subprojects => 0
151 145 assert_response :success
152 146 assert_template 'activity'
153 147 assert_not_nil assigns(:events_by_day)
154 148 assert_not_nil assigns(:events)
155 149
156 150 # subproject issue not included by default
157 151 assert !assigns(:events).include?(Issue.find(5))
158 152
159 153 assert_tag :tag => "h3",
160 154 :content => /#{2.days.ago.to_date.day}/,
161 155 :sibling => { :tag => "dl",
162 156 :child => { :tag => "dt",
163 157 :attributes => { :class => 'issue-edit' },
164 158 :child => { :tag => "a",
165 159 :content => /(#{IssueStatus.find(2).name})/,
166 160 }
167 161 }
168 162 }
169 163
170 164 get :activity, :id => 1, :from => 3.days.ago.to_date
171 165 assert_response :success
172 166 assert_template 'activity'
173 167 assert_not_nil assigns(:events_by_day)
174 168
175 169 assert_tag :tag => "h3",
176 170 :content => /#{3.day.ago.to_date.day}/,
177 171 :sibling => { :tag => "dl",
178 172 :child => { :tag => "dt",
179 173 :attributes => { :class => 'issue' },
180 174 :child => { :tag => "a",
181 175 :content => /#{Issue.find(1).subject}/,
182 176 }
183 177 }
184 178 }
185 179 end
186 180
187 181 def test_activity_with_subprojects
188 182 get :activity, :id => 1, :with_subprojects => 1
189 183 assert_response :success
190 184 assert_template 'activity'
191 185 assert_not_nil assigns(:events)
192 186
193 187 assert assigns(:events).include?(Issue.find(1))
194 188 assert !assigns(:events).include?(Issue.find(4))
195 189 # subproject issue
196 190 assert assigns(:events).include?(Issue.find(5))
197 191 end
198 192
199 193 def test_global_activity_anonymous
200 194 get :activity
201 195 assert_response :success
202 196 assert_template 'activity'
203 197 assert_not_nil assigns(:events)
204 198
205 199 assert assigns(:events).include?(Issue.find(1))
206 200 # Issue of a private project
207 201 assert !assigns(:events).include?(Issue.find(4))
208 202 end
209 203
210 204 def test_global_activity_logged_user
211 205 @request.session[:user_id] = 2 # manager
212 206 get :activity
213 207 assert_response :success
214 208 assert_template 'activity'
215 209 assert_not_nil assigns(:events)
216 210
217 211 assert assigns(:events).include?(Issue.find(1))
218 212 # Issue of a private project the user belongs to
219 213 assert assigns(:events).include?(Issue.find(4))
220 214 end
221 215
222 216
223 217 def test_global_activity_with_all_types
224 218 get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
225 219 assert_response :success
226 220 assert_template 'activity'
227 221 assert_not_nil assigns(:events)
228 222
229 223 assert assigns(:events).include?(Issue.find(1))
230 224 assert !assigns(:events).include?(Issue.find(4))
231 225 assert assigns(:events).include?(Message.find(5))
232 226 end
233 227
234 228 def test_calendar
235 229 get :calendar, :id => 1
236 230 assert_response :success
237 231 assert_template 'calendar'
238 232 assert_not_nil assigns(:calendar)
239 233 end
240 234
241 235 def test_calendar_with_subprojects_should_not_show_private_subprojects
242 236 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
243 237 assert_response :success
244 238 assert_template 'calendar'
245 239 assert_not_nil assigns(:calendar)
246 240 assert_no_tag :tag => 'a', :content => /#6/
247 241 end
248 242
249 243 def test_calendar_with_subprojects_should_show_private_subprojects
250 244 @request.session[:user_id] = 2
251 245 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
252 246 assert_response :success
253 247 assert_template 'calendar'
254 248 assert_not_nil assigns(:calendar)
255 249 assert_tag :tag => 'a', :content => /#6/
256 250 end
257 251
258 252 def test_gantt
259 253 get :gantt, :id => 1
260 254 assert_response :success
261 255 assert_template 'gantt.rhtml'
262 256 events = assigns(:events)
263 257 assert_not_nil events
264 258 # Issue with start and due dates
265 259 i = Issue.find(1)
266 260 assert_not_nil i.due_date
267 261 assert events.include?(Issue.find(1))
268 262 # Issue with without due date but targeted to a version with date
269 263 i = Issue.find(2)
270 264 assert_nil i.due_date
271 265 assert events.include?(i)
272 266 end
273 267
274 268 def test_gantt_with_subprojects_should_not_show_private_subprojects
275 269 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
276 270 assert_response :success
277 271 assert_template 'gantt.rhtml'
278 272 assert_not_nil assigns(:events)
279 273 assert_no_tag :tag => 'a', :content => /#6/
280 274 end
281 275
282 276 def test_gantt_with_subprojects_should_show_private_subprojects
283 277 @request.session[:user_id] = 2
284 278 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
285 279 assert_response :success
286 280 assert_template 'gantt.rhtml'
287 281 assert_not_nil assigns(:events)
288 282 assert_tag :tag => 'a', :content => /#6/
289 283 end
290 284
291 285 def test_gantt_export_to_pdf
292 286 get :gantt, :id => 1, :format => 'pdf'
293 287 assert_response :success
294 288 assert_template 'gantt.rfpdf'
295 289 assert_equal 'application/pdf', @response.content_type
296 290 assert_not_nil assigns(:events)
297 291 end
298 292
299 293 def test_archive
300 294 @request.session[:user_id] = 1 # admin
301 295 post :archive, :id => 1
302 296 assert_redirected_to 'admin/projects'
303 297 assert !Project.find(1).active?
304 298 end
305 299
306 300 def test_unarchive
307 301 @request.session[:user_id] = 1 # admin
308 302 Project.find(1).archive
309 303 post :unarchive, :id => 1
310 304 assert_redirected_to 'admin/projects'
311 305 assert Project.find(1).active?
312 306 end
313 307 end
General Comments 0
You need to be logged in to leave comments. Login now