##// END OF EJS Templates
Fixed: activity atom feed broken by r1701 (#1703)....
Jean-Philippe Lang -
r1710:6034067d8623
parent child
Show More
@@ -1,365 +1,365
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 47 # Lists visible projects
48 48 def index
49 49 projects = Project.find :all,
50 50 :conditions => Project.visible_by(User.current),
51 51 :include => :parent
52 52 respond_to do |format|
53 53 format.html {
54 54 @project_tree = projects.group_by {|p| p.parent || p}
55 55 @project_tree.keys.each {|p| @project_tree[p] -= [p]}
56 56 }
57 57 format.atom {
58 58 render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
59 59 :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
60 60 }
61 61 end
62 62 end
63 63
64 64 # Add a new project
65 65 def add
66 66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
67 67 @trackers = Tracker.all
68 68 @root_projects = Project.find(:all,
69 69 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
70 70 :order => 'name')
71 71 @project = Project.new(params[:project])
72 72 if request.get?
73 73 @project.trackers = Tracker.all
74 74 @project.is_public = Setting.default_projects_public?
75 75 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
76 76 else
77 77 @project.enabled_module_names = params[:enabled_modules]
78 78 if @project.save
79 79 flash[:notice] = l(:notice_successful_create)
80 80 redirect_to :controller => 'admin', :action => 'projects'
81 81 end
82 82 end
83 83 end
84 84
85 85 # Show @project
86 86 def show
87 87 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
88 88 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
89 89 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
90 90 @trackers = @project.rolled_up_trackers
91 91
92 92 cond = @project.project_condition(Setting.display_subprojects_issues?)
93 93 Issue.visible_by(User.current) do
94 94 @open_issues_by_tracker = Issue.count(:group => :tracker,
95 95 :include => [:project, :status, :tracker],
96 96 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
97 97 @total_issues_by_tracker = Issue.count(:group => :tracker,
98 98 :include => [:project, :status, :tracker],
99 99 :conditions => cond)
100 100 end
101 101 TimeEntry.visible_by(User.current) do
102 102 @total_hours = TimeEntry.sum(:hours,
103 103 :include => :project,
104 104 :conditions => cond).to_f
105 105 end
106 106 @key = User.current.rss_key
107 107 end
108 108
109 109 def settings
110 110 @root_projects = Project.find(:all,
111 111 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
112 112 :order => 'name')
113 113 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
114 114 @issue_category ||= IssueCategory.new
115 115 @member ||= @project.members.new
116 116 @trackers = Tracker.all
117 117 @repository ||= @project.repository
118 118 @wiki ||= @project.wiki
119 119 end
120 120
121 121 # Edit @project
122 122 def edit
123 123 if request.post?
124 124 @project.attributes = params[:project]
125 125 if @project.save
126 126 flash[:notice] = l(:notice_successful_update)
127 127 redirect_to :action => 'settings', :id => @project
128 128 else
129 129 settings
130 130 render :action => 'settings'
131 131 end
132 132 end
133 133 end
134 134
135 135 def modules
136 136 @project.enabled_module_names = params[:enabled_modules]
137 137 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
138 138 end
139 139
140 140 def archive
141 141 @project.archive if request.post? && @project.active?
142 142 redirect_to :controller => 'admin', :action => 'projects'
143 143 end
144 144
145 145 def unarchive
146 146 @project.unarchive if request.post? && !@project.active?
147 147 redirect_to :controller => 'admin', :action => 'projects'
148 148 end
149 149
150 150 # Delete @project
151 151 def destroy
152 152 @project_to_destroy = @project
153 153 if request.post? and params[:confirm]
154 154 @project_to_destroy.destroy
155 155 redirect_to :controller => 'admin', :action => 'projects'
156 156 end
157 157 # hide project in layout
158 158 @project = nil
159 159 end
160 160
161 161 # Add a new issue category to @project
162 162 def add_issue_category
163 163 @category = @project.issue_categories.build(params[:category])
164 164 if request.post? and @category.save
165 165 respond_to do |format|
166 166 format.html do
167 167 flash[:notice] = l(:notice_successful_create)
168 168 redirect_to :action => 'settings', :tab => 'categories', :id => @project
169 169 end
170 170 format.js do
171 171 # IE doesn't support the replace_html rjs method for select box options
172 172 render(:update) {|page| page.replace "issue_category_id",
173 173 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]')
174 174 }
175 175 end
176 176 end
177 177 end
178 178 end
179 179
180 180 # Add a new version to @project
181 181 def add_version
182 182 @version = @project.versions.build(params[:version])
183 183 if request.post? and @version.save
184 184 flash[:notice] = l(:notice_successful_create)
185 185 redirect_to :action => 'settings', :tab => 'versions', :id => @project
186 186 end
187 187 end
188 188
189 189 def add_file
190 190 if request.post?
191 191 @version = @project.versions.find_by_id(params[:version_id])
192 192 attachments = attach_files(@version, params[:attachments])
193 193 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
194 194 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
195 195 end
196 196 @versions = @project.versions.sort
197 197 end
198 198
199 199 def list_files
200 200 sort_init "#{Attachment.table_name}.filename", "asc"
201 201 sort_update
202 202 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
203 203 render :layout => !request.xhr?
204 204 end
205 205
206 206 # Show changelog for @project
207 207 def changelog
208 208 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
209 209 retrieve_selected_tracker_ids(@trackers)
210 210 @versions = @project.versions.sort
211 211 end
212 212
213 213 def roadmap
214 214 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
215 215 retrieve_selected_tracker_ids(@trackers)
216 216 @versions = @project.versions.sort
217 217 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
218 218 end
219 219
220 220 def activity
221 221 @days = Setting.activity_days_default.to_i
222 222
223 223 if params[:from]
224 224 begin; @date_to = params[:from].to_date; rescue; end
225 225 end
226 226
227 227 @date_to ||= Date.today + 1
228 228 @date_from = @date_to - @days
229 229 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
230 230
231 231 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects)
232 232 @activity.scope_select {|t| !params["show_#{t}"].nil?}
233 233 @activity.default_scope! if @activity.scope.empty?
234 234
235 235 events = @activity.events(@date_from, @date_to)
236 236
237 237 respond_to do |format|
238 238 format.html {
239 239 @events_by_day = events.group_by(&:event_date)
240 240 render :layout => false if request.xhr?
241 241 }
242 242 format.atom {
243 title = (@scope.size == 1) ? l("label_#{@scope.first.singularize}_plural") : l(:label_activity)
243 title = (@activity.scope.size == 1) ? l("label_#{@activity.scope.first.singularize}_plural") : l(:label_activity)
244 244 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
245 245 }
246 246 end
247 247 end
248 248
249 249 def calendar
250 250 @trackers = @project.rolled_up_trackers
251 251 retrieve_selected_tracker_ids(@trackers)
252 252
253 253 if params[:year] and params[:year].to_i > 1900
254 254 @year = params[:year].to_i
255 255 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
256 256 @month = params[:month].to_i
257 257 end
258 258 end
259 259 @year ||= Date.today.year
260 260 @month ||= Date.today.month
261 261 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
262 262 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
263 263 events = []
264 264 @project.issues_with_subprojects(@with_subprojects) do
265 265 events += Issue.find(:all,
266 266 :include => [:tracker, :status, :assigned_to, :priority, :project],
267 267 :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]
268 268 ) unless @selected_tracker_ids.empty?
269 269 events += Version.find(:all, :include => :project,
270 270 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
271 271 end
272 272 @calendar.events = events
273 273
274 274 render :layout => false if request.xhr?
275 275 end
276 276
277 277 def gantt
278 278 @trackers = @project.rolled_up_trackers
279 279 retrieve_selected_tracker_ids(@trackers)
280 280
281 281 if params[:year] and params[:year].to_i >0
282 282 @year_from = params[:year].to_i
283 283 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
284 284 @month_from = params[:month].to_i
285 285 else
286 286 @month_from = 1
287 287 end
288 288 else
289 289 @month_from ||= Date.today.month
290 290 @year_from ||= Date.today.year
291 291 end
292 292
293 293 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
294 294 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
295 295 months = (params[:months] || User.current.pref[:gantt_months]).to_i
296 296 @months = (months > 0 && months < 25) ? months : 6
297 297
298 298 # Save gantt paramters as user preference (zoom and months count)
299 299 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
300 300 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
301 301 User.current.preference.save
302 302 end
303 303
304 304 @date_from = Date.civil(@year_from, @month_from, 1)
305 305 @date_to = (@date_from >> @months) - 1
306 306 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
307 307
308 308 @events = []
309 309 @project.issues_with_subprojects(@with_subprojects) do
310 310 # Issues that have start and due dates
311 311 @events += Issue.find(:all,
312 312 :order => "start_date, due_date",
313 313 :include => [:tracker, :status, :assigned_to, :priority, :project],
314 314 :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]
315 315 ) unless @selected_tracker_ids.empty?
316 316 # Issues that don't have a due date but that are assigned to a version with a date
317 317 @events += Issue.find(:all,
318 318 :order => "start_date, effective_date",
319 319 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
320 320 :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]
321 321 ) unless @selected_tracker_ids.empty?
322 322 @events += Version.find(:all, :include => :project,
323 323 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
324 324 end
325 325 @events.sort! {|x,y| x.start_date <=> y.start_date }
326 326
327 327 if params[:format]=='pdf'
328 328 @options_for_rfpdf ||= {}
329 329 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
330 330 render :template => "projects/gantt.rfpdf", :layout => false
331 331 elsif params[:format]=='png' && respond_to?('gantt_image')
332 332 image = gantt_image(@events, @date_from, @months, @zoom)
333 333 image.format = 'PNG'
334 334 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
335 335 else
336 336 render :template => "projects/gantt.rhtml"
337 337 end
338 338 end
339 339
340 340 private
341 341 # Find project of id params[:id]
342 342 # if not found, redirect to project list
343 343 # Used as a before_filter
344 344 def find_project
345 345 @project = Project.find(params[:id])
346 346 rescue ActiveRecord::RecordNotFound
347 347 render_404
348 348 end
349 349
350 350 def find_optional_project
351 351 return true unless params[:id]
352 352 @project = Project.find(params[:id])
353 353 authorize
354 354 rescue ActiveRecord::RecordNotFound
355 355 render_404
356 356 end
357 357
358 358 def retrieve_selected_tracker_ids(selectable_trackers)
359 359 if ids = params[:tracker_ids]
360 360 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
361 361 else
362 362 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
363 363 end
364 364 end
365 365 end
@@ -1,313 +1,319
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 38 assert_template 'index'
39 39 assert_not_nil assigns(:project_tree)
40 40 # Root project as hash key
41 41 assert assigns(:project_tree).keys.include?(Project.find(1))
42 42 # Subproject in corresponding value
43 43 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
44 44 end
45 45
46 46 def test_index_atom
47 47 get :index, :format => 'atom'
48 48 assert_response :success
49 49 assert_template 'common/feed.atom.rxml'
50 50 assert_select 'feed>title', :text => 'Redmine: Latest projects'
51 51 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
52 52 end
53 53
54 54 def test_show_by_id
55 55 get :show, :id => 1
56 56 assert_response :success
57 57 assert_template 'show'
58 58 assert_not_nil assigns(:project)
59 59 end
60 60
61 61 def test_show_by_identifier
62 62 get :show, :id => 'ecookbook'
63 63 assert_response :success
64 64 assert_template 'show'
65 65 assert_not_nil assigns(:project)
66 66 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
67 67 end
68 68
69 69 def test_private_subprojects_hidden
70 70 get :show, :id => 'ecookbook'
71 71 assert_response :success
72 72 assert_template 'show'
73 73 assert_no_tag :tag => 'a', :content => /Private child/
74 74 end
75 75
76 76 def test_private_subprojects_visible
77 77 @request.session[:user_id] = 2 # manager who is a member of the private subproject
78 78 get :show, :id => 'ecookbook'
79 79 assert_response :success
80 80 assert_template 'show'
81 81 assert_tag :tag => 'a', :content => /Private child/
82 82 end
83 83
84 84 def test_settings
85 85 @request.session[:user_id] = 2 # manager
86 86 get :settings, :id => 1
87 87 assert_response :success
88 88 assert_template 'settings'
89 89 end
90 90
91 91 def test_edit
92 92 @request.session[:user_id] = 2 # manager
93 93 post :edit, :id => 1, :project => {:name => 'Test changed name',
94 94 :issue_custom_field_ids => ['']}
95 95 assert_redirected_to 'projects/settings/ecookbook'
96 96 project = Project.find(1)
97 97 assert_equal 'Test changed name', project.name
98 98 end
99 99
100 100 def test_get_destroy
101 101 @request.session[:user_id] = 1 # admin
102 102 get :destroy, :id => 1
103 103 assert_response :success
104 104 assert_template 'destroy'
105 105 assert_not_nil Project.find_by_id(1)
106 106 end
107 107
108 108 def test_post_destroy
109 109 @request.session[:user_id] = 1 # admin
110 110 post :destroy, :id => 1, :confirm => 1
111 111 assert_redirected_to 'admin/projects'
112 112 assert_nil Project.find_by_id(1)
113 113 end
114 114
115 115 def test_list_files
116 116 get :list_files, :id => 1
117 117 assert_response :success
118 118 assert_template 'list_files'
119 119 assert_not_nil assigns(:versions)
120 120 end
121 121
122 122 def test_changelog
123 123 get :changelog, :id => 1
124 124 assert_response :success
125 125 assert_template 'changelog'
126 126 assert_not_nil assigns(:versions)
127 127 end
128 128
129 129 def test_roadmap
130 130 get :roadmap, :id => 1
131 131 assert_response :success
132 132 assert_template 'roadmap'
133 133 assert_not_nil assigns(:versions)
134 134 # Version with no date set appears
135 135 assert assigns(:versions).include?(Version.find(3))
136 136 # Completed version doesn't appear
137 137 assert !assigns(:versions).include?(Version.find(1))
138 138 end
139 139
140 140 def test_roadmap_with_completed_versions
141 141 get :roadmap, :id => 1, :completed => 1
142 142 assert_response :success
143 143 assert_template 'roadmap'
144 144 assert_not_nil assigns(:versions)
145 145 # Version with no date set appears
146 146 assert assigns(:versions).include?(Version.find(3))
147 147 # Completed version appears
148 148 assert assigns(:versions).include?(Version.find(1))
149 149 end
150 150
151 151 def test_project_activity
152 152 get :activity, :id => 1, :with_subprojects => 0
153 153 assert_response :success
154 154 assert_template 'activity'
155 155 assert_not_nil assigns(:events_by_day)
156 156
157 157 assert_tag :tag => "h3",
158 158 :content => /#{2.days.ago.to_date.day}/,
159 159 :sibling => { :tag => "dl",
160 160 :child => { :tag => "dt",
161 161 :attributes => { :class => /issue-edit/ },
162 162 :child => { :tag => "a",
163 163 :content => /(#{IssueStatus.find(2).name})/,
164 164 }
165 165 }
166 166 }
167 167 end
168 168
169 169 def test_previous_project_activity
170 170 get :activity, :id => 1, :from => 3.days.ago.to_date
171 171 assert_response :success
172 172 assert_template 'activity'
173 173 assert_not_nil assigns(:events_by_day)
174 174
175 175 assert_tag :tag => "h3",
176 176 :content => /#{3.day.ago.to_date.day}/,
177 177 :sibling => { :tag => "dl",
178 178 :child => { :tag => "dt",
179 179 :attributes => { :class => /issue/ },
180 180 :child => { :tag => "a",
181 181 :content => /#{Issue.find(1).subject}/,
182 182 }
183 183 }
184 184 }
185 185 end
186 186
187 187 def test_global_activity
188 188 get :activity
189 189 assert_response :success
190 190 assert_template 'activity'
191 191 assert_not_nil assigns(:events_by_day)
192 192
193 193 assert_tag :tag => "h3",
194 194 :content => /#{5.day.ago.to_date.day}/,
195 195 :sibling => { :tag => "dl",
196 196 :child => { :tag => "dt",
197 197 :attributes => { :class => /issue/ },
198 198 :child => { :tag => "a",
199 199 :content => /#{Issue.find(5).subject}/,
200 200 }
201 201 }
202 202 }
203 203 end
204 204
205 def test_activity_atom_feed
206 get :activity, :format => 'atom'
207 assert_response :success
208 assert_template 'common/feed.atom.rxml'
209 end
210
205 211 def test_calendar
206 212 get :calendar, :id => 1
207 213 assert_response :success
208 214 assert_template 'calendar'
209 215 assert_not_nil assigns(:calendar)
210 216 end
211 217
212 218 def test_calendar_with_subprojects_should_not_show_private_subprojects
213 219 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
214 220 assert_response :success
215 221 assert_template 'calendar'
216 222 assert_not_nil assigns(:calendar)
217 223 assert_no_tag :tag => 'a', :content => /#6/
218 224 end
219 225
220 226 def test_calendar_with_subprojects_should_show_private_subprojects
221 227 @request.session[:user_id] = 2
222 228 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
223 229 assert_response :success
224 230 assert_template 'calendar'
225 231 assert_not_nil assigns(:calendar)
226 232 assert_tag :tag => 'a', :content => /#6/
227 233 end
228 234
229 235 def test_gantt
230 236 get :gantt, :id => 1
231 237 assert_response :success
232 238 assert_template 'gantt.rhtml'
233 239 events = assigns(:events)
234 240 assert_not_nil events
235 241 # Issue with start and due dates
236 242 i = Issue.find(1)
237 243 assert_not_nil i.due_date
238 244 assert events.include?(Issue.find(1))
239 245 # Issue with without due date but targeted to a version with date
240 246 i = Issue.find(2)
241 247 assert_nil i.due_date
242 248 assert events.include?(i)
243 249 end
244 250
245 251 def test_gantt_with_subprojects_should_not_show_private_subprojects
246 252 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
247 253 assert_response :success
248 254 assert_template 'gantt.rhtml'
249 255 assert_not_nil assigns(:events)
250 256 assert_no_tag :tag => 'a', :content => /#6/
251 257 end
252 258
253 259 def test_gantt_with_subprojects_should_show_private_subprojects
254 260 @request.session[:user_id] = 2
255 261 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
256 262 assert_response :success
257 263 assert_template 'gantt.rhtml'
258 264 assert_not_nil assigns(:events)
259 265 assert_tag :tag => 'a', :content => /#6/
260 266 end
261 267
262 268 def test_gantt_export_to_pdf
263 269 get :gantt, :id => 1, :format => 'pdf'
264 270 assert_response :success
265 271 assert_template 'gantt.rfpdf'
266 272 assert_equal 'application/pdf', @response.content_type
267 273 assert_not_nil assigns(:events)
268 274 end
269 275
270 276 def test_archive
271 277 @request.session[:user_id] = 1 # admin
272 278 post :archive, :id => 1
273 279 assert_redirected_to 'admin/projects'
274 280 assert !Project.find(1).active?
275 281 end
276 282
277 283 def test_unarchive
278 284 @request.session[:user_id] = 1 # admin
279 285 Project.find(1).archive
280 286 post :unarchive, :id => 1
281 287 assert_redirected_to 'admin/projects'
282 288 assert Project.find(1).active?
283 289 end
284 290
285 291 def test_project_menu
286 292 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
287 293 Redmine::MenuManager.map :project_menu do |menu|
288 294 menu.push :foo, { :controller => 'projects', :action => 'show' }, :cation => 'Foo'
289 295 menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
290 296 menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
291 297 end
292 298
293 299 get :show, :id => 1
294 300 assert_tag :div, :attributes => { :id => 'main-menu' },
295 301 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo' } }
296 302
297 303 assert_tag :div, :attributes => { :id => 'main-menu' },
298 304 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar' },
299 305 :before => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' } } }
300 306
301 307 assert_tag :div, :attributes => { :id => 'main-menu' },
302 308 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' },
303 309 :before => { :tag => 'li', :child => { :tag => 'a', :content => 'Activity' } } }
304 310
305 311 # Remove the menu items
306 312 Redmine::MenuManager.map :project_menu do |menu|
307 313 menu.delete :foo
308 314 menu.delete :bar
309 315 menu.delete :hello
310 316 end
311 317 end
312 318 end
313 319 end
General Comments 0
You need to be logged in to leave comments. Login now