##// END OF EJS Templates
Refactor: move IssuesController#reply to JournalsController...
Eric Davis -
r3827:22c978ad9433
parent child
Show More
@@ -1,417 +1,394
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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 IssuesController < ApplicationController
19 19 menu_item :new_issue, :only => [:new, :create]
20 20 default_search_scope :issues
21 21
22 before_filter :find_issue, :only => [:show, :edit, :update, :reply]
22 before_filter :find_issue, :only => [:show, :edit, :update]
23 23 before_filter :find_issues, :only => [:bulk_edit, :move, :perform_move, :destroy]
24 24 before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete]
25 25 before_filter :authorize, :except => [:index, :changes, :preview, :context_menu]
26 26 before_filter :find_optional_project, :only => [:index, :changes]
27 27 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 28 before_filter :build_new_issue_from_params, :only => [:new, :create]
29 29 accept_key_auth :index, :show, :changes
30 30
31 31 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
32 32
33 33 helper :journals
34 34 helper :projects
35 35 include ProjectsHelper
36 36 helper :custom_fields
37 37 include CustomFieldsHelper
38 38 helper :issue_relations
39 39 include IssueRelationsHelper
40 40 helper :watchers
41 41 include WatchersHelper
42 42 helper :attachments
43 43 include AttachmentsHelper
44 44 helper :queries
45 45 include QueriesHelper
46 46 helper :sort
47 47 include SortHelper
48 48 include IssuesHelper
49 49 helper :timelog
50 50 include Redmine::Export::PDF
51 51
52 52 verify :method => [:post, :delete],
53 53 :only => :destroy,
54 54 :render => { :nothing => true, :status => :method_not_allowed }
55 55
56 56 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
57 57 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
58 58
59 59 def index
60 60 retrieve_query
61 61 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
62 62 sort_update(@query.sortable_columns)
63 63
64 64 if @query.valid?
65 65 limit = case params[:format]
66 66 when 'csv', 'pdf'
67 67 Setting.issues_export_limit.to_i
68 68 when 'atom'
69 69 Setting.feeds_limit.to_i
70 70 else
71 71 per_page_option
72 72 end
73 73
74 74 @issue_count = @query.issue_count
75 75 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
76 76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
77 77 :order => sort_clause,
78 78 :offset => @issue_pages.current.offset,
79 79 :limit => limit)
80 80 @issue_count_by_group = @query.issue_count_by_group
81 81
82 82 respond_to do |format|
83 83 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
84 84 format.xml { render :layout => false }
85 85 format.json { render :text => @issues.to_json, :layout => false }
86 86 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
87 87 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
88 88 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
89 89 end
90 90 else
91 91 # Send html if the query is not valid
92 92 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
93 93 end
94 94 rescue ActiveRecord::RecordNotFound
95 95 render_404
96 96 end
97 97
98 98 def changes
99 99 retrieve_query
100 100 sort_init 'id', 'desc'
101 101 sort_update(@query.sortable_columns)
102 102
103 103 if @query.valid?
104 104 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
105 105 :limit => 25)
106 106 end
107 107 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
108 108 render :layout => false, :content_type => 'application/atom+xml'
109 109 rescue ActiveRecord::RecordNotFound
110 110 render_404
111 111 end
112 112
113 113 def show
114 114 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
115 115 @journals.each_with_index {|j,i| j.indice = i+1}
116 116 @journals.reverse! if User.current.wants_comments_in_reverse_order?
117 117 @changesets = @issue.changesets.visible.all
118 118 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
119 119 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
120 120 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
121 121 @priorities = IssuePriority.all
122 122 @time_entry = TimeEntry.new
123 123 respond_to do |format|
124 124 format.html { render :template => 'issues/show.rhtml' }
125 125 format.xml { render :layout => false }
126 126 format.json { render :text => @issue.to_json, :layout => false }
127 127 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
128 128 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
129 129 end
130 130 end
131 131
132 132 # Add a new issue
133 133 # The new issue will be created from an existing one if copy_from parameter is given
134 134 def new
135 135 render :action => 'new', :layout => !request.xhr?
136 136 end
137 137
138 138 def create
139 139 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
140 140 if @issue.save
141 141 attachments = Attachment.attach_files(@issue, params[:attachments])
142 142 render_attachment_warning_if_needed(@issue)
143 143 flash[:notice] = l(:notice_successful_create)
144 144 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
145 145 respond_to do |format|
146 146 format.html {
147 147 redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
148 148 { :action => 'show', :id => @issue })
149 149 }
150 150 format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
151 151 format.json { render :text => @issue.to_json, :status => :created, :location => url_for(:controller => 'issues', :action => 'show'), :layout => false }
152 152 end
153 153 return
154 154 else
155 155 respond_to do |format|
156 156 format.html { render :action => 'new' }
157 157 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
158 158 format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false }
159 159 end
160 160 end
161 161 end
162 162
163 163 # Attributes that can be updated on workflow transition (without :edit permission)
164 164 # TODO: make it configurable (at least per role)
165 165 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
166 166
167 167 def edit
168 168 update_issue_from_params
169 169
170 170 @journal = @issue.current_journal
171 171
172 172 respond_to do |format|
173 173 format.html { }
174 174 format.xml { }
175 175 end
176 176 end
177 177
178 178 def update
179 179 update_issue_from_params
180 180
181 181 if @issue.save_issue_with_child_records(params, @time_entry)
182 182 render_attachment_warning_if_needed(@issue)
183 183 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
184 184
185 185 respond_to do |format|
186 186 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
187 187 format.xml { head :ok }
188 188 format.json { head :ok }
189 189 end
190 190 else
191 191 render_attachment_warning_if_needed(@issue)
192 192 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
193 193 @journal = @issue.current_journal
194 194
195 195 respond_to do |format|
196 196 format.html { render :action => 'edit' }
197 197 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
198 198 format.json { render :text => object_errors_to_json(@issue), :status => :unprocessable_entity, :layout => false }
199 199 end
200 200 end
201 201 end
202 202
203 def reply
204 journal = Journal.find(params[:journal_id]) if params[:journal_id]
205 if journal
206 user = journal.user
207 text = journal.notes
208 else
209 user = @issue.author
210 text = @issue.description
211 end
212 # Replaces pre blocks with [...]
213 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
214 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
215 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
216
217 render(:update) { |page|
218 page.<< "$('notes').value = \"#{escape_javascript content}\";"
219 page.show 'update'
220 page << "Form.Element.focus('notes');"
221 page << "Element.scrollTo('update');"
222 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
223 }
224 end
225
226 203 # Bulk edit a set of issues
227 204 def bulk_edit
228 205 @issues.sort!
229 206 if request.post?
230 207 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
231 208 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
232 209 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
233 210
234 211 unsaved_issue_ids = []
235 212 @issues.each do |issue|
236 213 issue.reload
237 214 journal = issue.init_journal(User.current, params[:notes])
238 215 issue.safe_attributes = attributes
239 216 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
240 217 unless issue.save
241 218 # Keep unsaved issue ids to display them in flash error
242 219 unsaved_issue_ids << issue.id
243 220 end
244 221 end
245 222 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
246 223 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
247 224 return
248 225 end
249 226 @available_statuses = Workflow.available_statuses(@project)
250 227 @custom_fields = @project.all_issue_custom_fields
251 228 end
252 229
253 230 def destroy
254 231 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
255 232 if @hours > 0
256 233 case params[:todo]
257 234 when 'destroy'
258 235 # nothing to do
259 236 when 'nullify'
260 237 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
261 238 when 'reassign'
262 239 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
263 240 if reassign_to.nil?
264 241 flash.now[:error] = l(:error_issue_not_found_in_project)
265 242 return
266 243 else
267 244 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
268 245 end
269 246 else
270 247 unless params[:format] == 'xml' || params[:format] == 'json'
271 248 # display the destroy form if it's a user request
272 249 return
273 250 end
274 251 end
275 252 end
276 253 @issues.each(&:destroy)
277 254 respond_to do |format|
278 255 format.html { redirect_to :action => 'index', :project_id => @project }
279 256 format.xml { head :ok }
280 257 format.json { head :ok }
281 258 end
282 259 end
283 260
284 261 def context_menu
285 262 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
286 263 if (@issues.size == 1)
287 264 @issue = @issues.first
288 265 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
289 266 end
290 267 projects = @issues.collect(&:project).compact.uniq
291 268 @project = projects.first if projects.size == 1
292 269
293 270 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
294 271 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
295 272 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
296 273 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
297 274 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
298 275 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
299 276 }
300 277 if @project
301 278 @assignables = @project.assignable_users
302 279 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
303 280 @trackers = @project.trackers
304 281 end
305 282
306 283 @priorities = IssuePriority.all.reverse
307 284 @statuses = IssueStatus.find(:all, :order => 'position')
308 285 @back = back_url
309 286
310 287 render :layout => false
311 288 end
312 289
313 290 def update_form
314 291 if params[:id].blank?
315 292 @issue = Issue.new
316 293 @issue.project = @project
317 294 else
318 295 @issue = @project.issues.visible.find(params[:id])
319 296 end
320 297 @issue.attributes = params[:issue]
321 298 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
322 299 @priorities = IssuePriority.all
323 300
324 301 render :partial => 'attributes'
325 302 end
326 303
327 304 def preview
328 305 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
329 306 if @issue
330 307 @attachements = @issue.attachments
331 308 @description = params[:issue] && params[:issue][:description]
332 309 if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n")
333 310 @description = nil
334 311 end
335 312 @notes = params[:notes]
336 313 else
337 314 @description = (params[:issue] ? params[:issue][:description] : nil)
338 315 end
339 316 render :layout => false
340 317 end
341 318
342 319 def auto_complete
343 320 @issues = []
344 321 q = params[:q].to_s
345 322 if q.match(/^\d+$/)
346 323 @issues << @project.issues.visible.find_by_id(q.to_i)
347 324 end
348 325 unless q.blank?
349 326 @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
350 327 end
351 328 render :layout => false
352 329 end
353 330
354 331 private
355 332 def find_issue
356 333 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
357 334 @project = @issue.project
358 335 rescue ActiveRecord::RecordNotFound
359 336 render_404
360 337 end
361 338
362 339 def find_project
363 340 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
364 341 @project = Project.find(project_id)
365 342 rescue ActiveRecord::RecordNotFound
366 343 render_404
367 344 end
368 345
369 346 # Used by #edit and #update to set some common instance variables
370 347 # from the params
371 348 # TODO: Refactor, not everything in here is needed by #edit
372 349 def update_issue_from_params
373 350 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
374 351 @priorities = IssuePriority.all
375 352 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
376 353 @time_entry = TimeEntry.new
377 354
378 355 @notes = params[:notes]
379 356 @issue.init_journal(User.current, @notes)
380 357 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
381 358 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
382 359 attrs = params[:issue].dup
383 360 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
384 361 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
385 362 @issue.safe_attributes = attrs
386 363 end
387 364
388 365 end
389 366
390 367 # TODO: Refactor, lots of extra code in here
391 368 def build_new_issue_from_params
392 369 @issue = Issue.new
393 370 @issue.copy_from(params[:copy_from]) if params[:copy_from]
394 371 @issue.project = @project
395 372 # Tracker must be set before custom field values
396 373 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
397 374 if @issue.tracker.nil?
398 375 render_error l(:error_no_tracker_in_project)
399 376 return false
400 377 end
401 378 if params[:issue].is_a?(Hash)
402 379 @issue.safe_attributes = params[:issue]
403 380 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
404 381 end
405 382 @issue.author = User.current
406 383 @issue.start_date ||= Date.today
407 384 @priorities = IssuePriority.all
408 385 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
409 386 end
410 387
411 388 def check_for_default_issue_status
412 389 if IssueStatus.default.nil?
413 390 render_error l(:error_no_default_issue_status)
414 391 return false
415 392 end
416 393 end
417 394 end
@@ -1,41 +1,73
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 JournalsController < ApplicationController
19 before_filter :find_journal
19 before_filter :find_journal, :only => [:edit]
20 before_filter :find_issue, :only => [:new]
21
22 def new
23 journal = Journal.find(params[:journal_id]) if params[:journal_id]
24 if journal
25 user = journal.user
26 text = journal.notes
27 else
28 user = @issue.author
29 text = @issue.description
30 end
31 # Replaces pre blocks with [...]
32 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
33 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
34 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
35
36 render(:update) { |page|
37 page.<< "$('notes').value = \"#{escape_javascript content}\";"
38 page.show 'update'
39 page << "Form.Element.focus('notes');"
40 page << "Element.scrollTo('update');"
41 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
42 }
43 end
20 44
21 45 def edit
22 46 if request.post?
23 47 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
24 48 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
25 49 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
26 50 respond_to do |format|
27 51 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
28 52 format.js { render :action => 'update' }
29 53 end
30 54 end
31 55 end
32 56
33 57 private
34 58 def find_journal
35 59 @journal = Journal.find(params[:id])
36 60 (render_403; return false) unless @journal.editable_by?(User.current)
37 61 @project = @journal.journalized.project
38 62 rescue ActiveRecord::RecordNotFound
39 63 render_404
40 64 end
65
66 # TODO: duplicated in IssuesController
67 def find_issue
68 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
69 @project = @issue.project
70 rescue ActiveRecord::RecordNotFound
71 render_404
72 end
41 73 end
@@ -1,42 +1,42
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 module JournalsHelper
19 19 def render_notes(issue, journal, options={})
20 20 content = ''
21 21 editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
22 22 links = []
23 23 if !journal.notes.blank?
24 24 links << link_to_remote(image_tag('comment.png'),
25 { :url => {:controller => 'issues', :action => 'reply', :id => issue, :journal_id => journal} },
25 { :url => {:controller => 'journals', :action => 'new', :id => issue, :journal_id => journal} },
26 26 :title => l(:button_quote)) if options[:reply_links]
27 27 links << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
28 28 { :controller => 'journals', :action => 'edit', :id => journal },
29 29 :title => l(:button_edit)) if editable
30 30 end
31 31 content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
32 32 content << textilizable(journal, :notes)
33 33 css_classes = "wiki"
34 34 css_classes << " editable" if editable
35 35 content_tag('div', content, :id => "journal-#{journal.id}-notes", :class => css_classes)
36 36 end
37 37
38 38 def link_to_in_place_notes_editor(text, field_id, url, options={})
39 39 onclick = "new Ajax.Request('#{url_for(url)}', {asynchronous:true, evalScripts:true, method:'get'}); return false;"
40 40 link_to text, '#', options.merge(:onclick => onclick)
41 41 end
42 42 end
@@ -1,294 +1,294
1 1 ActionController::Routing::Routes.draw do |map|
2 2 # Add your own custom routes here.
3 3 # The priority is based upon order of creation: first created -> highest priority.
4 4
5 5 # Here's a sample route:
6 6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 7 # Keep in mind you can assign values other than :controller and :action
8 8
9 9 map.home '', :controller => 'welcome'
10 10
11 11 map.signin 'login', :controller => 'account', :action => 'login'
12 12 map.signout 'logout', :controller => 'account', :action => 'logout'
13 13
14 14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
15 15 map.connect 'help/:ctrl/:page', :controller => 'help'
16 16
17 17 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
18 18 map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog'
19 19 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog'
20 20
21 21 map.with_options :controller => 'timelog' do |timelog|
22 22 timelog.connect 'projects/:project_id/time_entries', :action => 'details'
23 23
24 24 timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details|
25 25 time_details.connect 'time_entries'
26 26 time_details.connect 'time_entries.:format'
27 27 time_details.connect 'issues/:issue_id/time_entries'
28 28 time_details.connect 'issues/:issue_id/time_entries.:format'
29 29 time_details.connect 'projects/:project_id/time_entries.:format'
30 30 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries'
31 31 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format'
32 32 end
33 33 timelog.connect 'projects/:project_id/time_entries/report', :action => 'report'
34 34 timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report|
35 35 time_report.connect 'time_entries/report'
36 36 time_report.connect 'time_entries/report.:format'
37 37 time_report.connect 'projects/:project_id/time_entries/report.:format'
38 38 end
39 39
40 40 timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit|
41 41 time_edit.connect 'issues/:issue_id/time_entries/new'
42 42 end
43 43
44 44 timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post}
45 45 end
46 46
47 47 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
48 48 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
49 49 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
50 50 map.with_options :controller => 'wiki' do |wiki_routes|
51 51 wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
52 52 wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i
53 53 wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil
54 54 wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit'
55 55 wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename'
56 56 wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history'
57 57 wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
58 58 wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate'
59 59 end
60 60
61 61 wiki_routes.connect 'projects/:id/wiki/:page/:action',
62 62 :action => /edit|rename|destroy|preview|protect/,
63 63 :conditions => {:method => :post}
64 64 end
65 65
66 66 map.with_options :controller => 'messages' do |messages_routes|
67 67 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
68 68 messages_views.connect 'boards/:board_id/topics/new', :action => 'new'
69 69 messages_views.connect 'boards/:board_id/topics/:id', :action => 'show'
70 70 messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit'
71 71 end
72 72 messages_routes.with_options :conditions => {:method => :post} do |messages_actions|
73 73 messages_actions.connect 'boards/:board_id/topics/new', :action => 'new'
74 74 messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply'
75 75 messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/
76 76 end
77 77 end
78 78
79 79 map.with_options :controller => 'boards' do |board_routes|
80 80 board_routes.with_options :conditions => {:method => :get} do |board_views|
81 81 board_views.connect 'projects/:project_id/boards', :action => 'index'
82 82 board_views.connect 'projects/:project_id/boards/new', :action => 'new'
83 83 board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
84 84 board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show'
85 85 board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
86 86 end
87 87 board_routes.with_options :conditions => {:method => :post} do |board_actions|
88 88 board_actions.connect 'projects/:project_id/boards', :action => 'new'
89 89 board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
90 90 end
91 91 end
92 92
93 93 map.with_options :controller => 'documents' do |document_routes|
94 94 document_routes.with_options :conditions => {:method => :get} do |document_views|
95 95 document_views.connect 'projects/:project_id/documents', :action => 'index'
96 96 document_views.connect 'projects/:project_id/documents/new', :action => 'new'
97 97 document_views.connect 'documents/:id', :action => 'show'
98 98 document_views.connect 'documents/:id/edit', :action => 'edit'
99 99 end
100 100 document_routes.with_options :conditions => {:method => :post} do |document_actions|
101 101 document_actions.connect 'projects/:project_id/documents', :action => 'new'
102 102 document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
103 103 end
104 104 end
105 105
106 106 map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
107 107
108 108 map.with_options :controller => 'issues' do |issues_routes|
109 109 issues_routes.with_options :conditions => {:method => :get} do |issues_views|
110 110 issues_views.connect 'issues', :action => 'index'
111 111 issues_views.connect 'issues.:format', :action => 'index'
112 112 issues_views.connect 'projects/:project_id/issues', :action => 'index'
113 113 issues_views.connect 'projects/:project_id/issues.:format', :action => 'index'
114 114 issues_views.connect 'projects/:project_id/issues/new', :action => 'new'
115 115 issues_views.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
116 116 issues_views.connect 'projects/:project_id/issues/calendar', :controller => 'calendars', :action => 'show'
117 117 issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new'
118 118 issues_views.connect 'issues/:id', :action => 'show', :id => /\d+/
119 119 issues_views.connect 'issues/:id.:format', :action => 'show', :id => /\d+/
120 120 issues_views.connect 'issues/:id/edit', :action => 'edit', :id => /\d+/
121 121 end
122 122 issues_routes.with_options :conditions => {:method => :post} do |issues_actions|
123 123 issues_actions.connect 'issues', :action => 'index'
124 124 issues_actions.connect 'projects/:project_id/issues', :action => 'create'
125 125 issues_actions.connect 'projects/:project_id/issues/gantt', :controller => 'gantts', :action => 'show'
126 126 issues_actions.connect 'projects/:project_id/issues/calendar', :controller => 'calendars', :action => 'show'
127 issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/
127 issues_actions.connect 'issues/:id/quoted', :controller => 'journals', :action => 'new', :id => /\d+/
128 128 issues_actions.connect 'issues/:id/:action', :action => /edit|destroy/, :id => /\d+/
129 129 issues_actions.connect 'issues.:format', :action => 'create', :format => /xml/
130 130 end
131 131 issues_routes.with_options :conditions => {:method => :put} do |issues_actions|
132 132 issues_actions.connect 'issues/:id/edit', :action => 'update', :id => /\d+/
133 133 issues_actions.connect 'issues/:id.:format', :action => 'update', :id => /\d+/, :format => /xml/
134 134 end
135 135 issues_routes.with_options :conditions => {:method => :delete} do |issues_actions|
136 136 issues_actions.connect 'issues/:id.:format', :action => 'destroy', :id => /\d+/, :format => /xml/
137 137 end
138 138 issues_routes.connect 'issues/gantt', :controller => 'gantts', :action => 'show'
139 139 issues_routes.connect 'issues/calendar', :controller => 'calendars', :action => 'show'
140 140 issues_routes.connect 'issues/:action'
141 141 end
142 142
143 143 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
144 144 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
145 145 relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
146 146 end
147 147
148 148 map.with_options :controller => 'reports', :conditions => {:method => :get} do |reports|
149 149 reports.connect 'projects/:id/issues/report', :action => 'issue_report'
150 150 reports.connect 'projects/:id/issues/report/:detail', :action => 'issue_report_details'
151 151 end
152 152
153 153 map.with_options :controller => 'news' do |news_routes|
154 154 news_routes.with_options :conditions => {:method => :get} do |news_views|
155 155 news_views.connect 'news', :action => 'index'
156 156 news_views.connect 'projects/:project_id/news', :action => 'index'
157 157 news_views.connect 'projects/:project_id/news.:format', :action => 'index'
158 158 news_views.connect 'news.:format', :action => 'index'
159 159 news_views.connect 'projects/:project_id/news/new', :action => 'new'
160 160 news_views.connect 'news/:id', :action => 'show'
161 161 news_views.connect 'news/:id/edit', :action => 'edit'
162 162 end
163 163 news_routes.with_options do |news_actions|
164 164 news_actions.connect 'projects/:project_id/news', :action => 'new'
165 165 news_actions.connect 'news/:id/edit', :action => 'edit'
166 166 news_actions.connect 'news/:id/destroy', :action => 'destroy'
167 167 end
168 168 end
169 169
170 170 map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
171 171
172 172 map.with_options :controller => 'users' do |users|
173 173 users.with_options :conditions => {:method => :get} do |user_views|
174 174 user_views.connect 'users', :action => 'index'
175 175 user_views.connect 'users/:id', :action => 'show', :id => /\d+/
176 176 user_views.connect 'users/new', :action => 'add'
177 177 user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
178 178 end
179 179 users.with_options :conditions => {:method => :post} do |user_actions|
180 180 user_actions.connect 'users', :action => 'add'
181 181 user_actions.connect 'users/new', :action => 'add'
182 182 user_actions.connect 'users/:id/edit', :action => 'edit'
183 183 user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
184 184 user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
185 185 user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
186 186 end
187 187 end
188 188
189 189 map.with_options :controller => 'projects' do |projects|
190 190 projects.with_options :conditions => {:method => :get} do |project_views|
191 191 project_views.connect 'projects', :action => 'index'
192 192 project_views.connect 'projects.:format', :action => 'index'
193 193 project_views.connect 'projects/new', :action => 'add'
194 194 project_views.connect 'projects/:id', :action => 'show'
195 195 project_views.connect 'projects/:id.:format', :action => 'show'
196 196 project_views.connect 'projects/:id/:action', :action => /roadmap|destroy|settings/
197 197 project_views.connect 'projects/:id/files', :action => 'list_files'
198 198 project_views.connect 'projects/:id/files/new', :action => 'add_file'
199 199 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
200 200 end
201 201
202 202 projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity|
203 203 activity.connect 'projects/:id/activity'
204 204 activity.connect 'projects/:id/activity.:format'
205 205 activity.connect 'activity', :id => nil
206 206 activity.connect 'activity.:format', :id => nil
207 207 end
208 208
209 209 projects.with_options :conditions => {:method => :post} do |project_actions|
210 210 project_actions.connect 'projects/new', :action => 'add'
211 211 project_actions.connect 'projects', :action => 'add'
212 212 project_actions.connect 'projects.:format', :action => 'add', :format => /xml/
213 213 project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/
214 214 project_actions.connect 'projects/:id/files/new', :action => 'add_file'
215 215 project_actions.connect 'projects/:id/activities/save', :action => 'save_activities'
216 216 end
217 217
218 218 projects.with_options :conditions => {:method => :put} do |project_actions|
219 219 project_actions.conditions 'projects/:id.:format', :action => 'edit', :format => /xml/
220 220 end
221 221
222 222 projects.with_options :conditions => {:method => :delete} do |project_actions|
223 223 project_actions.conditions 'projects/:id.:format', :action => 'destroy', :format => /xml/
224 224 project_actions.conditions 'projects/:id/reset_activities', :action => 'reset_activities'
225 225 end
226 226 end
227 227
228 228 map.with_options :controller => 'versions' do |versions|
229 229 versions.connect 'projects/:project_id/versions/new', :action => 'new'
230 230 versions.with_options :conditions => {:method => :post} do |version_actions|
231 231 version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed'
232 232 end
233 233 end
234 234
235 235 map.with_options :controller => 'issue_categories' do |categories|
236 236 categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
237 237 end
238 238
239 239 map.with_options :controller => 'repositories' do |repositories|
240 240 repositories.with_options :conditions => {:method => :get} do |repository_views|
241 241 repository_views.connect 'projects/:id/repository', :action => 'show'
242 242 repository_views.connect 'projects/:id/repository/edit', :action => 'edit'
243 243 repository_views.connect 'projects/:id/repository/statistics', :action => 'stats'
244 244 repository_views.connect 'projects/:id/repository/revisions', :action => 'revisions'
245 245 repository_views.connect 'projects/:id/repository/revisions.:format', :action => 'revisions'
246 246 repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
247 247 repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
248 248 repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
249 249 repository_views.connect 'projects/:id/repository/revisions/:rev/raw/*path', :action => 'entry', :format => 'raw', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
250 250 repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9\.\-_]+/ }
251 251 repository_views.connect 'projects/:id/repository/raw/*path', :action => 'entry', :format => 'raw'
252 252 # TODO: why the following route is required?
253 253 repository_views.connect 'projects/:id/repository/entry/*path', :action => 'entry'
254 254 repository_views.connect 'projects/:id/repository/:action/*path'
255 255 end
256 256
257 257 repositories.connect 'projects/:id/repository/:action', :conditions => {:method => :post}
258 258 end
259 259
260 260 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
261 261 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
262 262 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
263 263
264 264 map.resources :groups
265 265
266 266 #left old routes at the bottom for backwards compat
267 267 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
268 268 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
269 269 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
270 270 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
271 271 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
272 272 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
273 273 map.connect 'projects/:project_id/news/:action', :controller => 'news'
274 274 map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/
275 275 map.with_options :controller => 'repositories' do |omap|
276 276 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
277 277 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
278 278 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
279 279 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
280 280 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
281 281 omap.connect 'repositories/revision/:id/:rev', :action => 'revision'
282 282 end
283 283
284 284 map.with_options :controller => 'sys' do |sys|
285 285 sys.connect 'sys/projects.:format', :action => 'projects', :conditions => {:method => :get}
286 286 sys.connect 'sys/projects/:id/repository.:format', :action => 'create_project_repository', :conditions => {:method => :post}
287 287 end
288 288
289 289 # Install the default route as the lowest priority.
290 290 map.connect ':controller/:action/:id'
291 291 map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
292 292 # Used for OpenID
293 293 map.root :controller => 'account', :action => 'login'
294 294 end
@@ -1,221 +1,221
1 1 require 'redmine/access_control'
2 2 require 'redmine/menu_manager'
3 3 require 'redmine/activity'
4 4 require 'redmine/search'
5 5 require 'redmine/custom_field_format'
6 6 require 'redmine/mime_type'
7 7 require 'redmine/core_ext'
8 8 require 'redmine/themes'
9 9 require 'redmine/hook'
10 10 require 'redmine/plugin'
11 11 require 'redmine/wiki_formatting'
12 12 require 'redmine/scm/base'
13 13
14 14 begin
15 15 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
16 16 rescue LoadError
17 17 # RMagick is not available
18 18 end
19 19
20 20 if RUBY_VERSION < '1.9'
21 21 require 'faster_csv'
22 22 else
23 23 require 'csv'
24 24 FCSV = CSV
25 25 end
26 26
27 27 Redmine::Scm::Base.add "Subversion"
28 28 Redmine::Scm::Base.add "Darcs"
29 29 Redmine::Scm::Base.add "Mercurial"
30 30 Redmine::Scm::Base.add "Cvs"
31 31 Redmine::Scm::Base.add "Bazaar"
32 32 Redmine::Scm::Base.add "Git"
33 33 Redmine::Scm::Base.add "Filesystem"
34 34
35 35 Redmine::CustomFieldFormat.map do |fields|
36 36 fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1)
37 37 fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2)
38 38 fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3)
39 39 fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4)
40 40 fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5)
41 41 fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6)
42 42 fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7)
43 43 end
44 44
45 45 # Permissions
46 46 Redmine::AccessControl.map do |map|
47 47 map.permission :view_project, {:projects => [:show, :activity]}, :public => true
48 48 map.permission :search_project, {:search => :index}, :public => true
49 49 map.permission :add_project, {:projects => :add}, :require => :loggedin
50 50 map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
51 51 map.permission :select_project_modules, {:projects => :modules}, :require => :member
52 52 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member
53 53 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :edit, :close_completed, :destroy]}, :require => :member
54 54 map.permission :add_subprojects, {:projects => :add}, :require => :member
55 55
56 56 map.project_module :issue_tracking do |map|
57 57 # Issue categories
58 58 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
59 59 # Issues
60 60 map.permission :view_issues, {:projects => :roadmap,
61 61 :issues => [:index, :changes, :show, :context_menu, :auto_complete],
62 62 :versions => [:show, :status_by],
63 63 :queries => :index,
64 64 :reports => [:issue_report, :issue_report_details]}
65 65 map.permission :add_issues, {:issues => [:new, :create, :update_form]}
66 map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]}
66 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :update_form], :journals => [:new]}
67 67 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
68 68 map.permission :manage_subtasks, {}
69 map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]}
69 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
70 70 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
71 71 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
72 72 map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
73 73 map.permission :delete_issues, {:issues => :destroy}, :require => :member
74 74 # Queries
75 75 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
76 76 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
77 77 # Gantt & calendar
78 78 map.permission :view_gantt, :gantts => :show
79 79 map.permission :view_calendar, :calendars => :show
80 80 # Watchers
81 81 map.permission :view_issue_watchers, {}
82 82 map.permission :add_issue_watchers, {:watchers => :new}
83 83 map.permission :delete_issue_watchers, {:watchers => :destroy}
84 84 end
85 85
86 86 map.project_module :time_tracking do |map|
87 87 map.permission :log_time, {:timelog => :edit}, :require => :loggedin
88 88 map.permission :view_time_entries, :timelog => [:details, :report]
89 89 map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member
90 90 map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin
91 91 map.permission :manage_project_activities, {:projects => [:save_activities, :reset_activities]}, :require => :member
92 92 end
93 93
94 94 map.project_module :news do |map|
95 95 map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
96 96 map.permission :view_news, {:news => [:index, :show]}, :public => true
97 97 map.permission :comment_news, {:news => :add_comment}
98 98 end
99 99
100 100 map.project_module :documents do |map|
101 101 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
102 102 map.permission :view_documents, :documents => [:index, :show, :download]
103 103 end
104 104
105 105 map.project_module :files do |map|
106 106 map.permission :manage_files, {:projects => :add_file}, :require => :loggedin
107 107 map.permission :view_files, :projects => :list_files, :versions => :download
108 108 end
109 109
110 110 map.project_module :wiki do |map|
111 111 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
112 112 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
113 113 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
114 114 map.permission :view_wiki_pages, :wiki => [:index, :special]
115 115 map.permission :export_wiki_pages, {}
116 116 map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
117 117 map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment]
118 118 map.permission :delete_wiki_pages_attachments, {}
119 119 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
120 120 end
121 121
122 122 map.project_module :repository do |map|
123 123 map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member
124 124 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
125 125 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
126 126 map.permission :commit_access, {}
127 127 end
128 128
129 129 map.project_module :boards do |map|
130 130 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
131 131 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
132 132 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
133 133 map.permission :edit_messages, {:messages => :edit}, :require => :member
134 134 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
135 135 map.permission :delete_messages, {:messages => :destroy}, :require => :member
136 136 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
137 137 end
138 138 end
139 139
140 140 Redmine::MenuManager.map :top_menu do |menu|
141 141 menu.push :home, :home_path
142 142 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
143 143 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
144 144 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
145 145 menu.push :help, Redmine::Info.help_url, :last => true
146 146 end
147 147
148 148 Redmine::MenuManager.map :account_menu do |menu|
149 149 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
150 150 menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
151 151 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
152 152 menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
153 153 end
154 154
155 155 Redmine::MenuManager.map :application_menu do |menu|
156 156 # Empty
157 157 end
158 158
159 159 Redmine::MenuManager.map :admin_menu do |menu|
160 160 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
161 161 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
162 162 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
163 163 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
164 164 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
165 165 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
166 166 :html => {:class => 'issue_statuses'}
167 167 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
168 168 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
169 169 :html => {:class => 'custom_fields'}
170 170 menu.push :enumerations, {:controller => 'enumerations'}
171 171 menu.push :settings, {:controller => 'settings'}
172 172 menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'},
173 173 :html => {:class => 'server_authentication'}
174 174 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
175 175 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
176 176 end
177 177
178 178 Redmine::MenuManager.map :project_menu do |menu|
179 179 menu.push :overview, { :controller => 'projects', :action => 'show' }
180 180 menu.push :activity, { :controller => 'projects', :action => 'activity' }
181 181 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
182 182 :if => Proc.new { |p| p.shared_versions.any? }
183 183 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
184 184 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
185 185 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
186 186 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
187 187 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
188 188 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
189 189 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
190 190 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
191 191 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
192 192 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural
193 193 menu.push :repository, { :controller => 'repositories', :action => 'show' },
194 194 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
195 195 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
196 196 end
197 197
198 198 Redmine::Activity.map do |activity|
199 199 activity.register :issues, :class_name => %w(Issue Journal)
200 200 activity.register :changesets
201 201 activity.register :news
202 202 activity.register :documents, :class_name => %w(Document Attachment)
203 203 activity.register :files, :class_name => 'Attachment'
204 204 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
205 205 activity.register :messages, :default => false
206 206 activity.register :time_entries, :default => false
207 207 end
208 208
209 209 Redmine::Search.map do |search|
210 210 search.register :issues
211 211 search.register :news
212 212 search.register :documents
213 213 search.register :changesets
214 214 search.register :wiki_pages
215 215 search.register :messages
216 216 search.register :projects
217 217 end
218 218
219 219 Redmine::WikiFormatting.map do |format|
220 220 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
221 221 end
@@ -1,1203 +1,1189
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < ActionController::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :member_roles,
30 30 :issues,
31 31 :issue_statuses,
32 32 :versions,
33 33 :trackers,
34 34 :projects_trackers,
35 35 :issue_categories,
36 36 :enabled_modules,
37 37 :enumerations,
38 38 :attachments,
39 39 :workflows,
40 40 :custom_fields,
41 41 :custom_values,
42 42 :custom_fields_projects,
43 43 :custom_fields_trackers,
44 44 :time_entries,
45 45 :journals,
46 46 :journal_details,
47 47 :queries
48 48
49 49 def setup
50 50 @controller = IssuesController.new
51 51 @request = ActionController::TestRequest.new
52 52 @response = ActionController::TestResponse.new
53 53 User.current = nil
54 54 end
55 55
56 56 def test_index
57 57 Setting.default_language = 'en'
58 58
59 59 get :index
60 60 assert_response :success
61 61 assert_template 'index.rhtml'
62 62 assert_not_nil assigns(:issues)
63 63 assert_nil assigns(:project)
64 64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 65 assert_tag :tag => 'a', :content => /Subproject issue/
66 66 # private projects hidden
67 67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 69 # project column
70 70 assert_tag :tag => 'th', :content => /Project/
71 71 end
72 72
73 73 def test_index_should_not_list_issues_when_module_disabled
74 74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 75 get :index
76 76 assert_response :success
77 77 assert_template 'index.rhtml'
78 78 assert_not_nil assigns(:issues)
79 79 assert_nil assigns(:project)
80 80 assert_no_tag :tag => 'a', :content => /Can't print recipes/
81 81 assert_tag :tag => 'a', :content => /Subproject issue/
82 82 end
83 83
84 84 def test_index_should_not_list_issues_when_module_disabled
85 85 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
86 86 get :index
87 87 assert_response :success
88 88 assert_template 'index.rhtml'
89 89 assert_not_nil assigns(:issues)
90 90 assert_nil assigns(:project)
91 91 assert_no_tag :tag => 'a', :content => /Can't print recipes/
92 92 assert_tag :tag => 'a', :content => /Subproject issue/
93 93 end
94 94
95 95 def test_index_with_project
96 96 Setting.display_subprojects_issues = 0
97 97 get :index, :project_id => 1
98 98 assert_response :success
99 99 assert_template 'index.rhtml'
100 100 assert_not_nil assigns(:issues)
101 101 assert_tag :tag => 'a', :content => /Can't print recipes/
102 102 assert_no_tag :tag => 'a', :content => /Subproject issue/
103 103 end
104 104
105 105 def test_index_with_project_and_subprojects
106 106 Setting.display_subprojects_issues = 1
107 107 get :index, :project_id => 1
108 108 assert_response :success
109 109 assert_template 'index.rhtml'
110 110 assert_not_nil assigns(:issues)
111 111 assert_tag :tag => 'a', :content => /Can't print recipes/
112 112 assert_tag :tag => 'a', :content => /Subproject issue/
113 113 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
114 114 end
115 115
116 116 def test_index_with_project_and_subprojects_should_show_private_subprojects
117 117 @request.session[:user_id] = 2
118 118 Setting.display_subprojects_issues = 1
119 119 get :index, :project_id => 1
120 120 assert_response :success
121 121 assert_template 'index.rhtml'
122 122 assert_not_nil assigns(:issues)
123 123 assert_tag :tag => 'a', :content => /Can't print recipes/
124 124 assert_tag :tag => 'a', :content => /Subproject issue/
125 125 assert_tag :tag => 'a', :content => /Issue of a private subproject/
126 126 end
127 127
128 128 def test_index_with_project_and_filter
129 129 get :index, :project_id => 1, :set_filter => 1
130 130 assert_response :success
131 131 assert_template 'index.rhtml'
132 132 assert_not_nil assigns(:issues)
133 133 end
134 134
135 135 def test_index_with_query
136 136 get :index, :project_id => 1, :query_id => 5
137 137 assert_response :success
138 138 assert_template 'index.rhtml'
139 139 assert_not_nil assigns(:issues)
140 140 assert_nil assigns(:issue_count_by_group)
141 141 end
142 142
143 143 def test_index_with_query_grouped_by_tracker
144 144 get :index, :project_id => 1, :query_id => 6
145 145 assert_response :success
146 146 assert_template 'index.rhtml'
147 147 assert_not_nil assigns(:issues)
148 148 assert_not_nil assigns(:issue_count_by_group)
149 149 end
150 150
151 151 def test_index_with_query_grouped_by_list_custom_field
152 152 get :index, :project_id => 1, :query_id => 9
153 153 assert_response :success
154 154 assert_template 'index.rhtml'
155 155 assert_not_nil assigns(:issues)
156 156 assert_not_nil assigns(:issue_count_by_group)
157 157 end
158 158
159 159 def test_index_sort_by_field_not_included_in_columns
160 160 Setting.issue_list_default_columns = %w(subject author)
161 161 get :index, :sort => 'tracker'
162 162 end
163 163
164 164 def test_index_csv_with_project
165 165 Setting.default_language = 'en'
166 166
167 167 get :index, :format => 'csv'
168 168 assert_response :success
169 169 assert_not_nil assigns(:issues)
170 170 assert_equal 'text/csv', @response.content_type
171 171 assert @response.body.starts_with?("#,")
172 172
173 173 get :index, :project_id => 1, :format => 'csv'
174 174 assert_response :success
175 175 assert_not_nil assigns(:issues)
176 176 assert_equal 'text/csv', @response.content_type
177 177 end
178 178
179 179 def test_index_pdf
180 180 get :index, :format => 'pdf'
181 181 assert_response :success
182 182 assert_not_nil assigns(:issues)
183 183 assert_equal 'application/pdf', @response.content_type
184 184
185 185 get :index, :project_id => 1, :format => 'pdf'
186 186 assert_response :success
187 187 assert_not_nil assigns(:issues)
188 188 assert_equal 'application/pdf', @response.content_type
189 189
190 190 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
191 191 assert_response :success
192 192 assert_not_nil assigns(:issues)
193 193 assert_equal 'application/pdf', @response.content_type
194 194 end
195 195
196 196 def test_index_pdf_with_query_grouped_by_list_custom_field
197 197 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
198 198 assert_response :success
199 199 assert_not_nil assigns(:issues)
200 200 assert_not_nil assigns(:issue_count_by_group)
201 201 assert_equal 'application/pdf', @response.content_type
202 202 end
203 203
204 204 def test_index_sort
205 205 get :index, :sort => 'tracker,id:desc'
206 206 assert_response :success
207 207
208 208 sort_params = @request.session['issues_index_sort']
209 209 assert sort_params.is_a?(String)
210 210 assert_equal 'tracker,id:desc', sort_params
211 211
212 212 issues = assigns(:issues)
213 213 assert_not_nil issues
214 214 assert !issues.empty?
215 215 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
216 216 end
217 217
218 218 def test_index_with_columns
219 219 columns = ['tracker', 'subject', 'assigned_to']
220 220 get :index, :set_filter => 1, :query => { 'column_names' => columns}
221 221 assert_response :success
222 222
223 223 # query should use specified columns
224 224 query = assigns(:query)
225 225 assert_kind_of Query, query
226 226 assert_equal columns, query.column_names.map(&:to_s)
227 227
228 228 # columns should be stored in session
229 229 assert_kind_of Hash, session[:query]
230 230 assert_kind_of Array, session[:query][:column_names]
231 231 assert_equal columns, session[:query][:column_names].map(&:to_s)
232 232 end
233 233
234 234 def test_changes
235 235 get :changes, :project_id => 1
236 236 assert_response :success
237 237 assert_not_nil assigns(:journals)
238 238 assert_equal 'application/atom+xml', @response.content_type
239 239 end
240 240
241 241 def test_show_by_anonymous
242 242 get :show, :id => 1
243 243 assert_response :success
244 244 assert_template 'show.rhtml'
245 245 assert_not_nil assigns(:issue)
246 246 assert_equal Issue.find(1), assigns(:issue)
247 247
248 248 # anonymous role is allowed to add a note
249 249 assert_tag :tag => 'form',
250 250 :descendant => { :tag => 'fieldset',
251 251 :child => { :tag => 'legend',
252 252 :content => /Notes/ } }
253 253 end
254 254
255 255 def test_show_by_manager
256 256 @request.session[:user_id] = 2
257 257 get :show, :id => 1
258 258 assert_response :success
259 259
260 260 assert_tag :tag => 'form',
261 261 :descendant => { :tag => 'fieldset',
262 262 :child => { :tag => 'legend',
263 263 :content => /Change properties/ } },
264 264 :descendant => { :tag => 'fieldset',
265 265 :child => { :tag => 'legend',
266 266 :content => /Log time/ } },
267 267 :descendant => { :tag => 'fieldset',
268 268 :child => { :tag => 'legend',
269 269 :content => /Notes/ } }
270 270 end
271 271
272 272 def test_show_should_deny_anonymous_access_without_permission
273 273 Role.anonymous.remove_permission!(:view_issues)
274 274 get :show, :id => 1
275 275 assert_response :redirect
276 276 end
277 277
278 278 def test_show_should_deny_non_member_access_without_permission
279 279 Role.non_member.remove_permission!(:view_issues)
280 280 @request.session[:user_id] = 9
281 281 get :show, :id => 1
282 282 assert_response 403
283 283 end
284 284
285 285 def test_show_should_deny_member_access_without_permission
286 286 Role.find(1).remove_permission!(:view_issues)
287 287 @request.session[:user_id] = 2
288 288 get :show, :id => 1
289 289 assert_response 403
290 290 end
291 291
292 292 def test_show_should_not_disclose_relations_to_invisible_issues
293 293 Setting.cross_project_issue_relations = '1'
294 294 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
295 295 # Relation to a private project issue
296 296 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
297 297
298 298 get :show, :id => 1
299 299 assert_response :success
300 300
301 301 assert_tag :div, :attributes => { :id => 'relations' },
302 302 :descendant => { :tag => 'a', :content => /#2$/ }
303 303 assert_no_tag :div, :attributes => { :id => 'relations' },
304 304 :descendant => { :tag => 'a', :content => /#4$/ }
305 305 end
306 306
307 307 def test_show_atom
308 308 get :show, :id => 2, :format => 'atom'
309 309 assert_response :success
310 310 assert_template 'changes.rxml'
311 311 # Inline image
312 312 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
313 313 end
314 314
315 315 def test_show_export_to_pdf
316 316 get :show, :id => 3, :format => 'pdf'
317 317 assert_response :success
318 318 assert_equal 'application/pdf', @response.content_type
319 319 assert @response.body.starts_with?('%PDF')
320 320 assert_not_nil assigns(:issue)
321 321 end
322 322
323 323 def test_get_new
324 324 @request.session[:user_id] = 2
325 325 get :new, :project_id => 1, :tracker_id => 1
326 326 assert_response :success
327 327 assert_template 'new'
328 328
329 329 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
330 330 :value => 'Default string' }
331 331 end
332 332
333 333 def test_get_new_without_tracker_id
334 334 @request.session[:user_id] = 2
335 335 get :new, :project_id => 1
336 336 assert_response :success
337 337 assert_template 'new'
338 338
339 339 issue = assigns(:issue)
340 340 assert_not_nil issue
341 341 assert_equal Project.find(1).trackers.first, issue.tracker
342 342 end
343 343
344 344 def test_get_new_with_no_default_status_should_display_an_error
345 345 @request.session[:user_id] = 2
346 346 IssueStatus.delete_all
347 347
348 348 get :new, :project_id => 1
349 349 assert_response 500
350 350 assert_not_nil flash[:error]
351 351 assert_tag :tag => 'div', :attributes => { :class => /error/ },
352 352 :content => /No default issue/
353 353 end
354 354
355 355 def test_get_new_with_no_tracker_should_display_an_error
356 356 @request.session[:user_id] = 2
357 357 Tracker.delete_all
358 358
359 359 get :new, :project_id => 1
360 360 assert_response 500
361 361 assert_not_nil flash[:error]
362 362 assert_tag :tag => 'div', :attributes => { :class => /error/ },
363 363 :content => /No tracker/
364 364 end
365 365
366 366 def test_update_new_form
367 367 @request.session[:user_id] = 2
368 368 xhr :post, :update_form, :project_id => 1,
369 369 :issue => {:tracker_id => 2,
370 370 :subject => 'This is the test_new issue',
371 371 :description => 'This is the description',
372 372 :priority_id => 5}
373 373 assert_response :success
374 374 assert_template 'attributes'
375 375
376 376 issue = assigns(:issue)
377 377 assert_kind_of Issue, issue
378 378 assert_equal 1, issue.project_id
379 379 assert_equal 2, issue.tracker_id
380 380 assert_equal 'This is the test_new issue', issue.subject
381 381 end
382 382
383 383 def test_post_create
384 384 @request.session[:user_id] = 2
385 385 assert_difference 'Issue.count' do
386 386 post :create, :project_id => 1,
387 387 :issue => {:tracker_id => 3,
388 388 :status_id => 2,
389 389 :subject => 'This is the test_new issue',
390 390 :description => 'This is the description',
391 391 :priority_id => 5,
392 392 :estimated_hours => '',
393 393 :custom_field_values => {'2' => 'Value for field 2'}}
394 394 end
395 395 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
396 396
397 397 issue = Issue.find_by_subject('This is the test_new issue')
398 398 assert_not_nil issue
399 399 assert_equal 2, issue.author_id
400 400 assert_equal 3, issue.tracker_id
401 401 assert_equal 2, issue.status_id
402 402 assert_nil issue.estimated_hours
403 403 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
404 404 assert_not_nil v
405 405 assert_equal 'Value for field 2', v.value
406 406 end
407 407
408 408 def test_post_create_and_continue
409 409 @request.session[:user_id] = 2
410 410 post :create, :project_id => 1,
411 411 :issue => {:tracker_id => 3,
412 412 :subject => 'This is first issue',
413 413 :priority_id => 5},
414 414 :continue => ''
415 415 assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3}
416 416 end
417 417
418 418 def test_post_create_without_custom_fields_param
419 419 @request.session[:user_id] = 2
420 420 assert_difference 'Issue.count' do
421 421 post :create, :project_id => 1,
422 422 :issue => {:tracker_id => 1,
423 423 :subject => 'This is the test_new issue',
424 424 :description => 'This is the description',
425 425 :priority_id => 5}
426 426 end
427 427 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
428 428 end
429 429
430 430 def test_post_create_with_required_custom_field_and_without_custom_fields_param
431 431 field = IssueCustomField.find_by_name('Database')
432 432 field.update_attribute(:is_required, true)
433 433
434 434 @request.session[:user_id] = 2
435 435 post :create, :project_id => 1,
436 436 :issue => {:tracker_id => 1,
437 437 :subject => 'This is the test_new issue',
438 438 :description => 'This is the description',
439 439 :priority_id => 5}
440 440 assert_response :success
441 441 assert_template 'new'
442 442 issue = assigns(:issue)
443 443 assert_not_nil issue
444 444 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
445 445 end
446 446
447 447 def test_post_create_with_watchers
448 448 @request.session[:user_id] = 2
449 449 ActionMailer::Base.deliveries.clear
450 450
451 451 assert_difference 'Watcher.count', 2 do
452 452 post :create, :project_id => 1,
453 453 :issue => {:tracker_id => 1,
454 454 :subject => 'This is a new issue with watchers',
455 455 :description => 'This is the description',
456 456 :priority_id => 5,
457 457 :watcher_user_ids => ['2', '3']}
458 458 end
459 459 issue = Issue.find_by_subject('This is a new issue with watchers')
460 460 assert_not_nil issue
461 461 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
462 462
463 463 # Watchers added
464 464 assert_equal [2, 3], issue.watcher_user_ids.sort
465 465 assert issue.watched_by?(User.find(3))
466 466 # Watchers notified
467 467 mail = ActionMailer::Base.deliveries.last
468 468 assert_kind_of TMail::Mail, mail
469 469 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
470 470 end
471 471
472 472 def test_post_create_subissue
473 473 @request.session[:user_id] = 2
474 474
475 475 assert_difference 'Issue.count' do
476 476 post :create, :project_id => 1,
477 477 :issue => {:tracker_id => 1,
478 478 :subject => 'This is a child issue',
479 479 :parent_issue_id => 2}
480 480 end
481 481 issue = Issue.find_by_subject('This is a child issue')
482 482 assert_not_nil issue
483 483 assert_equal Issue.find(2), issue.parent
484 484 end
485 485
486 486 def test_post_create_should_send_a_notification
487 487 ActionMailer::Base.deliveries.clear
488 488 @request.session[:user_id] = 2
489 489 assert_difference 'Issue.count' do
490 490 post :create, :project_id => 1,
491 491 :issue => {:tracker_id => 3,
492 492 :subject => 'This is the test_new issue',
493 493 :description => 'This is the description',
494 494 :priority_id => 5,
495 495 :estimated_hours => '',
496 496 :custom_field_values => {'2' => 'Value for field 2'}}
497 497 end
498 498 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
499 499
500 500 assert_equal 1, ActionMailer::Base.deliveries.size
501 501 end
502 502
503 503 def test_post_create_should_preserve_fields_values_on_validation_failure
504 504 @request.session[:user_id] = 2
505 505 post :create, :project_id => 1,
506 506 :issue => {:tracker_id => 1,
507 507 # empty subject
508 508 :subject => '',
509 509 :description => 'This is a description',
510 510 :priority_id => 6,
511 511 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
512 512 assert_response :success
513 513 assert_template 'new'
514 514
515 515 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
516 516 :content => 'This is a description'
517 517 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
518 518 :child => { :tag => 'option', :attributes => { :selected => 'selected',
519 519 :value => '6' },
520 520 :content => 'High' }
521 521 # Custom fields
522 522 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
523 523 :child => { :tag => 'option', :attributes => { :selected => 'selected',
524 524 :value => 'Oracle' },
525 525 :content => 'Oracle' }
526 526 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
527 527 :value => 'Value for field 2'}
528 528 end
529 529
530 530 def test_post_create_should_ignore_non_safe_attributes
531 531 @request.session[:user_id] = 2
532 532 assert_nothing_raised do
533 533 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
534 534 end
535 535 end
536 536
537 537 context "without workflow privilege" do
538 538 setup do
539 539 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
540 540 Role.anonymous.add_permission! :add_issues
541 541 end
542 542
543 543 context "#new" do
544 544 should "propose default status only" do
545 545 get :new, :project_id => 1
546 546 assert_response :success
547 547 assert_template 'new'
548 548 assert_tag :tag => 'select',
549 549 :attributes => {:name => 'issue[status_id]'},
550 550 :children => {:count => 1},
551 551 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
552 552 end
553 553
554 554 should "accept default status" do
555 555 assert_difference 'Issue.count' do
556 556 post :create, :project_id => 1,
557 557 :issue => {:tracker_id => 1,
558 558 :subject => 'This is an issue',
559 559 :status_id => 1}
560 560 end
561 561 issue = Issue.last(:order => 'id')
562 562 assert_equal IssueStatus.default, issue.status
563 563 end
564 564
565 565 should "ignore unauthorized status" do
566 566 assert_difference 'Issue.count' do
567 567 post :create, :project_id => 1,
568 568 :issue => {:tracker_id => 1,
569 569 :subject => 'This is an issue',
570 570 :status_id => 3}
571 571 end
572 572 issue = Issue.last(:order => 'id')
573 573 assert_equal IssueStatus.default, issue.status
574 574 end
575 575 end
576 576 end
577 577
578 578 def test_copy_issue
579 579 @request.session[:user_id] = 2
580 580 get :new, :project_id => 1, :copy_from => 1
581 581 assert_template 'new'
582 582 assert_not_nil assigns(:issue)
583 583 orig = Issue.find(1)
584 584 assert_equal orig.subject, assigns(:issue).subject
585 585 end
586 586
587 587 def test_get_edit
588 588 @request.session[:user_id] = 2
589 589 get :edit, :id => 1
590 590 assert_response :success
591 591 assert_template 'edit'
592 592 assert_not_nil assigns(:issue)
593 593 assert_equal Issue.find(1), assigns(:issue)
594 594 end
595 595
596 596 def test_get_edit_with_params
597 597 @request.session[:user_id] = 2
598 598 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
599 599 assert_response :success
600 600 assert_template 'edit'
601 601
602 602 issue = assigns(:issue)
603 603 assert_not_nil issue
604 604
605 605 assert_equal 5, issue.status_id
606 606 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
607 607 :child => { :tag => 'option',
608 608 :content => 'Closed',
609 609 :attributes => { :selected => 'selected' } }
610 610
611 611 assert_equal 7, issue.priority_id
612 612 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
613 613 :child => { :tag => 'option',
614 614 :content => 'Urgent',
615 615 :attributes => { :selected => 'selected' } }
616 616 end
617 617
618 618 def test_update_edit_form
619 619 @request.session[:user_id] = 2
620 620 xhr :post, :update_form, :project_id => 1,
621 621 :id => 1,
622 622 :issue => {:tracker_id => 2,
623 623 :subject => 'This is the test_new issue',
624 624 :description => 'This is the description',
625 625 :priority_id => 5}
626 626 assert_response :success
627 627 assert_template 'attributes'
628 628
629 629 issue = assigns(:issue)
630 630 assert_kind_of Issue, issue
631 631 assert_equal 1, issue.id
632 632 assert_equal 1, issue.project_id
633 633 assert_equal 2, issue.tracker_id
634 634 assert_equal 'This is the test_new issue', issue.subject
635 635 end
636 636
637 def test_reply_to_issue
638 @request.session[:user_id] = 2
639 get :reply, :id => 1
640 assert_response :success
641 assert_select_rjs :show, "update"
642 end
643
644 def test_reply_to_note
645 @request.session[:user_id] = 2
646 get :reply, :id => 1, :journal_id => 2
647 assert_response :success
648 assert_select_rjs :show, "update"
649 end
650
651 637 def test_update_using_invalid_http_verbs
652 638 @request.session[:user_id] = 2
653 639 subject = 'Updated by an invalid http verb'
654 640
655 641 get :update, :id => 1, :issue => {:subject => subject}
656 642 assert_not_equal subject, Issue.find(1).subject
657 643
658 644 post :update, :id => 1, :issue => {:subject => subject}
659 645 assert_not_equal subject, Issue.find(1).subject
660 646
661 647 delete :update, :id => 1, :issue => {:subject => subject}
662 648 assert_not_equal subject, Issue.find(1).subject
663 649 end
664 650
665 651 def test_put_update_without_custom_fields_param
666 652 @request.session[:user_id] = 2
667 653 ActionMailer::Base.deliveries.clear
668 654
669 655 issue = Issue.find(1)
670 656 assert_equal '125', issue.custom_value_for(2).value
671 657 old_subject = issue.subject
672 658 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
673 659
674 660 assert_difference('Journal.count') do
675 661 assert_difference('JournalDetail.count', 2) do
676 662 put :update, :id => 1, :issue => {:subject => new_subject,
677 663 :priority_id => '6',
678 664 :category_id => '1' # no change
679 665 }
680 666 end
681 667 end
682 668 assert_redirected_to :action => 'show', :id => '1'
683 669 issue.reload
684 670 assert_equal new_subject, issue.subject
685 671 # Make sure custom fields were not cleared
686 672 assert_equal '125', issue.custom_value_for(2).value
687 673
688 674 mail = ActionMailer::Base.deliveries.last
689 675 assert_kind_of TMail::Mail, mail
690 676 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
691 677 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
692 678 end
693 679
694 680 def test_put_update_with_custom_field_change
695 681 @request.session[:user_id] = 2
696 682 issue = Issue.find(1)
697 683 assert_equal '125', issue.custom_value_for(2).value
698 684
699 685 assert_difference('Journal.count') do
700 686 assert_difference('JournalDetail.count', 3) do
701 687 put :update, :id => 1, :issue => {:subject => 'Custom field change',
702 688 :priority_id => '6',
703 689 :category_id => '1', # no change
704 690 :custom_field_values => { '2' => 'New custom value' }
705 691 }
706 692 end
707 693 end
708 694 assert_redirected_to :action => 'show', :id => '1'
709 695 issue.reload
710 696 assert_equal 'New custom value', issue.custom_value_for(2).value
711 697
712 698 mail = ActionMailer::Base.deliveries.last
713 699 assert_kind_of TMail::Mail, mail
714 700 assert mail.body.include?("Searchable field changed from 125 to New custom value")
715 701 end
716 702
717 703 def test_put_update_with_status_and_assignee_change
718 704 issue = Issue.find(1)
719 705 assert_equal 1, issue.status_id
720 706 @request.session[:user_id] = 2
721 707 assert_difference('TimeEntry.count', 0) do
722 708 put :update,
723 709 :id => 1,
724 710 :issue => { :status_id => 2, :assigned_to_id => 3 },
725 711 :notes => 'Assigned to dlopper',
726 712 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
727 713 end
728 714 assert_redirected_to :action => 'show', :id => '1'
729 715 issue.reload
730 716 assert_equal 2, issue.status_id
731 717 j = Journal.find(:first, :order => 'id DESC')
732 718 assert_equal 'Assigned to dlopper', j.notes
733 719 assert_equal 2, j.details.size
734 720
735 721 mail = ActionMailer::Base.deliveries.last
736 722 assert mail.body.include?("Status changed from New to Assigned")
737 723 # subject should contain the new status
738 724 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
739 725 end
740 726
741 727 def test_put_update_with_note_only
742 728 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
743 729 # anonymous user
744 730 put :update,
745 731 :id => 1,
746 732 :notes => notes
747 733 assert_redirected_to :action => 'show', :id => '1'
748 734 j = Journal.find(:first, :order => 'id DESC')
749 735 assert_equal notes, j.notes
750 736 assert_equal 0, j.details.size
751 737 assert_equal User.anonymous, j.user
752 738
753 739 mail = ActionMailer::Base.deliveries.last
754 740 assert mail.body.include?(notes)
755 741 end
756 742
757 743 def test_put_update_with_note_and_spent_time
758 744 @request.session[:user_id] = 2
759 745 spent_hours_before = Issue.find(1).spent_hours
760 746 assert_difference('TimeEntry.count') do
761 747 put :update,
762 748 :id => 1,
763 749 :notes => '2.5 hours added',
764 750 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
765 751 end
766 752 assert_redirected_to :action => 'show', :id => '1'
767 753
768 754 issue = Issue.find(1)
769 755
770 756 j = Journal.find(:first, :order => 'id DESC')
771 757 assert_equal '2.5 hours added', j.notes
772 758 assert_equal 0, j.details.size
773 759
774 760 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
775 761 assert_not_nil t
776 762 assert_equal 2.5, t.hours
777 763 assert_equal spent_hours_before + 2.5, issue.spent_hours
778 764 end
779 765
780 766 def test_put_update_with_attachment_only
781 767 set_tmp_attachments_directory
782 768
783 769 # Delete all fixtured journals, a race condition can occur causing the wrong
784 770 # journal to get fetched in the next find.
785 771 Journal.delete_all
786 772
787 773 # anonymous user
788 774 put :update,
789 775 :id => 1,
790 776 :notes => '',
791 777 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
792 778 assert_redirected_to :action => 'show', :id => '1'
793 779 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
794 780 assert j.notes.blank?
795 781 assert_equal 1, j.details.size
796 782 assert_equal 'testfile.txt', j.details.first.value
797 783 assert_equal User.anonymous, j.user
798 784
799 785 mail = ActionMailer::Base.deliveries.last
800 786 assert mail.body.include?('testfile.txt')
801 787 end
802 788
803 789 def test_put_update_with_attachment_that_fails_to_save
804 790 set_tmp_attachments_directory
805 791
806 792 # Delete all fixtured journals, a race condition can occur causing the wrong
807 793 # journal to get fetched in the next find.
808 794 Journal.delete_all
809 795
810 796 # Mock out the unsaved attachment
811 797 Attachment.any_instance.stubs(:create).returns(Attachment.new)
812 798
813 799 # anonymous user
814 800 put :update,
815 801 :id => 1,
816 802 :notes => '',
817 803 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
818 804 assert_redirected_to :action => 'show', :id => '1'
819 805 assert_equal '1 file(s) could not be saved.', flash[:warning]
820 806
821 807 end if Object.const_defined?(:Mocha)
822 808
823 809 def test_put_update_with_no_change
824 810 issue = Issue.find(1)
825 811 issue.journals.clear
826 812 ActionMailer::Base.deliveries.clear
827 813
828 814 put :update,
829 815 :id => 1,
830 816 :notes => ''
831 817 assert_redirected_to :action => 'show', :id => '1'
832 818
833 819 issue.reload
834 820 assert issue.journals.empty?
835 821 # No email should be sent
836 822 assert ActionMailer::Base.deliveries.empty?
837 823 end
838 824
839 825 def test_put_update_should_send_a_notification
840 826 @request.session[:user_id] = 2
841 827 ActionMailer::Base.deliveries.clear
842 828 issue = Issue.find(1)
843 829 old_subject = issue.subject
844 830 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
845 831
846 832 put :update, :id => 1, :issue => {:subject => new_subject,
847 833 :priority_id => '6',
848 834 :category_id => '1' # no change
849 835 }
850 836 assert_equal 1, ActionMailer::Base.deliveries.size
851 837 end
852 838
853 839 def test_put_update_with_invalid_spent_time
854 840 @request.session[:user_id] = 2
855 841 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
856 842
857 843 assert_no_difference('Journal.count') do
858 844 put :update,
859 845 :id => 1,
860 846 :notes => notes,
861 847 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
862 848 end
863 849 assert_response :success
864 850 assert_template 'edit'
865 851
866 852 assert_tag :textarea, :attributes => { :name => 'notes' },
867 853 :content => notes
868 854 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
869 855 end
870 856
871 857 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
872 858 issue = Issue.find(2)
873 859 @request.session[:user_id] = 2
874 860
875 861 put :update,
876 862 :id => issue.id,
877 863 :issue => {
878 864 :fixed_version_id => 4
879 865 }
880 866
881 867 assert_response :redirect
882 868 issue.reload
883 869 assert_equal 4, issue.fixed_version_id
884 870 assert_not_equal issue.project_id, issue.fixed_version.project_id
885 871 end
886 872
887 873 def test_put_update_should_redirect_back_using_the_back_url_parameter
888 874 issue = Issue.find(2)
889 875 @request.session[:user_id] = 2
890 876
891 877 put :update,
892 878 :id => issue.id,
893 879 :issue => {
894 880 :fixed_version_id => 4
895 881 },
896 882 :back_url => '/issues'
897 883
898 884 assert_response :redirect
899 885 assert_redirected_to '/issues'
900 886 end
901 887
902 888 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
903 889 issue = Issue.find(2)
904 890 @request.session[:user_id] = 2
905 891
906 892 put :update,
907 893 :id => issue.id,
908 894 :issue => {
909 895 :fixed_version_id => 4
910 896 },
911 897 :back_url => 'http://google.com'
912 898
913 899 assert_response :redirect
914 900 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
915 901 end
916 902
917 903 def test_get_bulk_edit
918 904 @request.session[:user_id] = 2
919 905 get :bulk_edit, :ids => [1, 2]
920 906 assert_response :success
921 907 assert_template 'bulk_edit'
922 908
923 909 # Project specific custom field, date type
924 910 field = CustomField.find(9)
925 911 assert !field.is_for_all?
926 912 assert_equal 'date', field.field_format
927 913 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
928 914
929 915 # System wide custom field
930 916 assert CustomField.find(1).is_for_all?
931 917 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
932 918 end
933 919
934 920 def test_bulk_edit
935 921 @request.session[:user_id] = 2
936 922 # update issues priority
937 923 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing',
938 924 :issue => {:priority_id => 7,
939 925 :assigned_to_id => '',
940 926 :custom_field_values => {'2' => ''}}
941 927
942 928 assert_response 302
943 929 # check that the issues were updated
944 930 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
945 931
946 932 issue = Issue.find(1)
947 933 journal = issue.journals.find(:first, :order => 'created_on DESC')
948 934 assert_equal '125', issue.custom_value_for(2).value
949 935 assert_equal 'Bulk editing', journal.notes
950 936 assert_equal 1, journal.details.size
951 937 end
952 938
953 939 def test_bullk_edit_should_send_a_notification
954 940 @request.session[:user_id] = 2
955 941 ActionMailer::Base.deliveries.clear
956 942 post(:bulk_edit,
957 943 {
958 944 :ids => [1, 2],
959 945 :notes => 'Bulk editing',
960 946 :issue => {
961 947 :priority_id => 7,
962 948 :assigned_to_id => '',
963 949 :custom_field_values => {'2' => ''}
964 950 }
965 951 })
966 952
967 953 assert_response 302
968 954 assert_equal 2, ActionMailer::Base.deliveries.size
969 955 end
970 956
971 957 def test_bulk_edit_status
972 958 @request.session[:user_id] = 2
973 959 # update issues priority
974 960 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing status',
975 961 :issue => {:priority_id => '',
976 962 :assigned_to_id => '',
977 963 :status_id => '5'}
978 964
979 965 assert_response 302
980 966 issue = Issue.find(1)
981 967 assert issue.closed?
982 968 end
983 969
984 970 def test_bulk_edit_custom_field
985 971 @request.session[:user_id] = 2
986 972 # update issues priority
987 973 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing custom field',
988 974 :issue => {:priority_id => '',
989 975 :assigned_to_id => '',
990 976 :custom_field_values => {'2' => '777'}}
991 977
992 978 assert_response 302
993 979
994 980 issue = Issue.find(1)
995 981 journal = issue.journals.find(:first, :order => 'created_on DESC')
996 982 assert_equal '777', issue.custom_value_for(2).value
997 983 assert_equal 1, journal.details.size
998 984 assert_equal '125', journal.details.first.old_value
999 985 assert_equal '777', journal.details.first.value
1000 986 end
1001 987
1002 988 def test_bulk_unassign
1003 989 assert_not_nil Issue.find(2).assigned_to
1004 990 @request.session[:user_id] = 2
1005 991 # unassign issues
1006 992 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1007 993 assert_response 302
1008 994 # check that the issues were updated
1009 995 assert_nil Issue.find(2).assigned_to
1010 996 end
1011 997
1012 998 def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject
1013 999 @request.session[:user_id] = 2
1014 1000
1015 1001 post :bulk_edit, :ids => [1,2], :issue => {:fixed_version_id => 4}
1016 1002
1017 1003 assert_response :redirect
1018 1004 issues = Issue.find([1,2])
1019 1005 issues.each do |issue|
1020 1006 assert_equal 4, issue.fixed_version_id
1021 1007 assert_not_equal issue.project_id, issue.fixed_version.project_id
1022 1008 end
1023 1009 end
1024 1010
1025 1011 def test_post_bulk_edit_should_redirect_back_using_the_back_url_parameter
1026 1012 @request.session[:user_id] = 2
1027 1013 post :bulk_edit, :ids => [1,2], :back_url => '/issues'
1028 1014
1029 1015 assert_response :redirect
1030 1016 assert_redirected_to '/issues'
1031 1017 end
1032 1018
1033 1019 def test_post_bulk_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1034 1020 @request.session[:user_id] = 2
1035 1021 post :bulk_edit, :ids => [1,2], :back_url => 'http://google.com'
1036 1022
1037 1023 assert_response :redirect
1038 1024 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1039 1025 end
1040 1026
1041 1027 def test_context_menu_one_issue
1042 1028 @request.session[:user_id] = 2
1043 1029 get :context_menu, :ids => [1]
1044 1030 assert_response :success
1045 1031 assert_template 'context_menu'
1046 1032 assert_tag :tag => 'a', :content => 'Edit',
1047 1033 :attributes => { :href => '/issues/1/edit',
1048 1034 :class => 'icon-edit' }
1049 1035 assert_tag :tag => 'a', :content => 'Closed',
1050 1036 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
1051 1037 :class => '' }
1052 1038 assert_tag :tag => 'a', :content => 'Immediate',
1053 1039 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
1054 1040 :class => '' }
1055 1041 # Versions
1056 1042 assert_tag :tag => 'a', :content => '2.0',
1057 1043 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
1058 1044 :class => '' }
1059 1045 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
1060 1046 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
1061 1047 :class => '' }
1062 1048
1063 1049 assert_tag :tag => 'a', :content => 'Dave Lopper',
1064 1050 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
1065 1051 :class => '' }
1066 1052 assert_tag :tag => 'a', :content => 'Duplicate',
1067 1053 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
1068 1054 :class => 'icon-duplicate' }
1069 1055 assert_tag :tag => 'a', :content => 'Copy',
1070 1056 :attributes => { :href => '/issues/move/new?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1',
1071 1057 :class => 'icon-copy' }
1072 1058 assert_tag :tag => 'a', :content => 'Move',
1073 1059 :attributes => { :href => '/issues/move/new?ids%5B%5D=1',
1074 1060 :class => 'icon-move' }
1075 1061 assert_tag :tag => 'a', :content => 'Delete',
1076 1062 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
1077 1063 :class => 'icon-del' }
1078 1064 end
1079 1065
1080 1066 def test_context_menu_one_issue_by_anonymous
1081 1067 get :context_menu, :ids => [1]
1082 1068 assert_response :success
1083 1069 assert_template 'context_menu'
1084 1070 assert_tag :tag => 'a', :content => 'Delete',
1085 1071 :attributes => { :href => '#',
1086 1072 :class => 'icon-del disabled' }
1087 1073 end
1088 1074
1089 1075 def test_context_menu_multiple_issues_of_same_project
1090 1076 @request.session[:user_id] = 2
1091 1077 get :context_menu, :ids => [1, 2]
1092 1078 assert_response :success
1093 1079 assert_template 'context_menu'
1094 1080 assert_tag :tag => 'a', :content => 'Edit',
1095 1081 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
1096 1082 :class => 'icon-edit' }
1097 1083 assert_tag :tag => 'a', :content => 'Immediate',
1098 1084 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;issue%5Bpriority_id%5D=8',
1099 1085 :class => '' }
1100 1086 assert_tag :tag => 'a', :content => 'Dave Lopper',
1101 1087 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;issue%5Bassigned_to_id%5D=3',
1102 1088 :class => '' }
1103 1089 assert_tag :tag => 'a', :content => 'Copy',
1104 1090 :attributes => { :href => '/issues/move/new?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1105 1091 :class => 'icon-copy' }
1106 1092 assert_tag :tag => 'a', :content => 'Move',
1107 1093 :attributes => { :href => '/issues/move/new?ids%5B%5D=1&amp;ids%5B%5D=2',
1108 1094 :class => 'icon-move' }
1109 1095 assert_tag :tag => 'a', :content => 'Delete',
1110 1096 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
1111 1097 :class => 'icon-del' }
1112 1098 end
1113 1099
1114 1100 def test_context_menu_multiple_issues_of_different_project
1115 1101 @request.session[:user_id] = 2
1116 1102 get :context_menu, :ids => [1, 2, 4]
1117 1103 assert_response :success
1118 1104 assert_template 'context_menu'
1119 1105 assert_tag :tag => 'a', :content => 'Delete',
1120 1106 :attributes => { :href => '#',
1121 1107 :class => 'icon-del disabled' }
1122 1108 end
1123 1109
1124 1110 def test_preview_new_issue
1125 1111 @request.session[:user_id] = 2
1126 1112 post :preview, :project_id => '1', :issue => {:description => 'Foo'}
1127 1113 assert_response :success
1128 1114 assert_template 'preview'
1129 1115 assert_not_nil assigns(:description)
1130 1116 end
1131 1117
1132 1118 def test_preview_notes
1133 1119 @request.session[:user_id] = 2
1134 1120 post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo'
1135 1121 assert_response :success
1136 1122 assert_template 'preview'
1137 1123 assert_not_nil assigns(:notes)
1138 1124 end
1139 1125
1140 1126 def test_auto_complete_should_not_be_case_sensitive
1141 1127 get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe'
1142 1128 assert_response :success
1143 1129 assert_not_nil assigns(:issues)
1144 1130 assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
1145 1131 end
1146 1132
1147 1133 def test_auto_complete_should_return_issue_with_given_id
1148 1134 get :auto_complete, :project_id => 'subproject1', :q => '13'
1149 1135 assert_response :success
1150 1136 assert_not_nil assigns(:issues)
1151 1137 assert assigns(:issues).include?(Issue.find(13))
1152 1138 end
1153 1139
1154 1140 def test_destroy_issue_with_no_time_entries
1155 1141 assert_nil TimeEntry.find_by_issue_id(2)
1156 1142 @request.session[:user_id] = 2
1157 1143 post :destroy, :id => 2
1158 1144 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1159 1145 assert_nil Issue.find_by_id(2)
1160 1146 end
1161 1147
1162 1148 def test_destroy_issues_with_time_entries
1163 1149 @request.session[:user_id] = 2
1164 1150 post :destroy, :ids => [1, 3]
1165 1151 assert_response :success
1166 1152 assert_template 'destroy'
1167 1153 assert_not_nil assigns(:hours)
1168 1154 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1169 1155 end
1170 1156
1171 1157 def test_destroy_issues_and_destroy_time_entries
1172 1158 @request.session[:user_id] = 2
1173 1159 post :destroy, :ids => [1, 3], :todo => 'destroy'
1174 1160 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1175 1161 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1176 1162 assert_nil TimeEntry.find_by_id([1, 2])
1177 1163 end
1178 1164
1179 1165 def test_destroy_issues_and_assign_time_entries_to_project
1180 1166 @request.session[:user_id] = 2
1181 1167 post :destroy, :ids => [1, 3], :todo => 'nullify'
1182 1168 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1183 1169 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1184 1170 assert_nil TimeEntry.find(1).issue_id
1185 1171 assert_nil TimeEntry.find(2).issue_id
1186 1172 end
1187 1173
1188 1174 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1189 1175 @request.session[:user_id] = 2
1190 1176 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1191 1177 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1192 1178 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1193 1179 assert_equal 2, TimeEntry.find(1).issue_id
1194 1180 assert_equal 2, TimeEntry.find(2).issue_id
1195 1181 end
1196 1182
1197 1183 def test_default_search_scope
1198 1184 get :index
1199 1185 assert_tag :div, :attributes => {:id => 'quick-search'},
1200 1186 :child => {:tag => 'form',
1201 1187 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1202 1188 end
1203 1189 end
@@ -1,59 +1,73
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 'journals_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class JournalsController; def rescue_action(e) raise e end; end
23 23
24 24 class JournalsControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :members, :member_roles, :roles, :issues, :journals, :journal_details, :enabled_modules
26 26
27 27 def setup
28 28 @controller = JournalsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 def test_reply_to_issue
35 @request.session[:user_id] = 2
36 get :new, :id => 1
37 assert_response :success
38 assert_select_rjs :show, "update"
39 end
40
41 def test_reply_to_note
42 @request.session[:user_id] = 2
43 get :new, :id => 1, :journal_id => 2
44 assert_response :success
45 assert_select_rjs :show, "update"
46 end
47
34 48 def test_get_edit
35 49 @request.session[:user_id] = 1
36 50 xhr :get, :edit, :id => 2
37 51 assert_response :success
38 52 assert_select_rjs :insert, :after, 'journal-2-notes' do
39 53 assert_select 'form[id=journal-2-form]'
40 54 assert_select 'textarea'
41 55 end
42 56 end
43 57
44 58 def test_post_edit
45 59 @request.session[:user_id] = 1
46 60 xhr :post, :edit, :id => 2, :notes => 'Updated notes'
47 61 assert_response :success
48 62 assert_select_rjs :replace, 'journal-2-notes'
49 63 assert_equal 'Updated notes', Journal.find(2).notes
50 64 end
51 65
52 66 def test_post_edit_with_empty_notes
53 67 @request.session[:user_id] = 1
54 68 xhr :post, :edit, :id => 2, :notes => ''
55 69 assert_response :success
56 70 assert_select_rjs :remove, 'change-2'
57 71 assert_nil Journal.find_by_id(2)
58 72 end
59 73 end
@@ -1,281 +1,281
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2010 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
20 20 class RoutingTest < ActionController::IntegrationTest
21 21 context "activities" do
22 22 should_route :get, "/activity", :controller => 'projects', :action => 'activity', :id => nil
23 23 should_route :get, "/activity.atom", :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom'
24 24 end
25 25
26 26 context "attachments" do
27 27 should_route :get, "/attachments/1", :controller => 'attachments', :action => 'show', :id => '1'
28 28 should_route :get, "/attachments/1/filename.ext", :controller => 'attachments', :action => 'show', :id => '1', :filename => 'filename.ext'
29 29 should_route :get, "/attachments/download/1", :controller => 'attachments', :action => 'download', :id => '1'
30 30 should_route :get, "/attachments/download/1/filename.ext", :controller => 'attachments', :action => 'download', :id => '1', :filename => 'filename.ext'
31 31 end
32 32
33 33 context "boards" do
34 34 should_route :get, "/projects/world_domination/boards", :controller => 'boards', :action => 'index', :project_id => 'world_domination'
35 35 should_route :get, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
36 36 should_route :get, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44'
37 37 should_route :get, "/projects/world_domination/boards/44.atom", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44', :format => 'atom'
38 38 should_route :get, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
39 39
40 40 should_route :post, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
41 41 should_route :post, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
42 42 should_route :post, "/projects/world_domination/boards/44/destroy", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
43 43
44 44 end
45 45
46 46 context "documents" do
47 47 should_route :get, "/projects/567/documents", :controller => 'documents', :action => 'index', :project_id => '567'
48 48 should_route :get, "/projects/567/documents/new", :controller => 'documents', :action => 'new', :project_id => '567'
49 49 should_route :get, "/documents/22", :controller => 'documents', :action => 'show', :id => '22'
50 50 should_route :get, "/documents/22/edit", :controller => 'documents', :action => 'edit', :id => '22'
51 51
52 52 should_route :post, "/projects/567/documents/new", :controller => 'documents', :action => 'new', :project_id => '567'
53 53 should_route :post, "/documents/567/edit", :controller => 'documents', :action => 'edit', :id => '567'
54 54 should_route :post, "/documents/567/destroy", :controller => 'documents', :action => 'destroy', :id => '567'
55 55 end
56 56
57 57 context "issues" do
58 58 # REST actions
59 59 should_route :get, "/issues", :controller => 'issues', :action => 'index'
60 60 should_route :get, "/issues.pdf", :controller => 'issues', :action => 'index', :format => 'pdf'
61 61 should_route :get, "/issues.atom", :controller => 'issues', :action => 'index', :format => 'atom'
62 62 should_route :get, "/issues.xml", :controller => 'issues', :action => 'index', :format => 'xml'
63 63 should_route :get, "/projects/23/issues", :controller => 'issues', :action => 'index', :project_id => '23'
64 64 should_route :get, "/projects/23/issues.pdf", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
65 65 should_route :get, "/projects/23/issues.atom", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
66 66 should_route :get, "/projects/23/issues.xml", :controller => 'issues', :action => 'index', :project_id => '23', :format => 'xml'
67 67 should_route :get, "/issues/64", :controller => 'issues', :action => 'show', :id => '64'
68 68 should_route :get, "/issues/64.pdf", :controller => 'issues', :action => 'show', :id => '64', :format => 'pdf'
69 69 should_route :get, "/issues/64.atom", :controller => 'issues', :action => 'show', :id => '64', :format => 'atom'
70 70 should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml'
71 71
72 72 should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23'
73 73 should_route :post, "/projects/23/issues", :controller => 'issues', :action => 'create', :project_id => '23'
74 74 should_route :post, "/issues.xml", :controller => 'issues', :action => 'create', :format => 'xml'
75 75
76 76 should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
77 77 # TODO: Should use PUT
78 78 should_route :post, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64'
79 79 should_route :put, "/issues/1.xml", :controller => 'issues', :action => 'update', :id => '1', :format => 'xml'
80 80
81 81 # TODO: Should use DELETE
82 82 should_route :post, "/issues/64/destroy", :controller => 'issues', :action => 'destroy', :id => '64'
83 83 should_route :delete, "/issues/1.xml", :controller => 'issues', :action => 'destroy', :id => '1', :format => 'xml'
84 84
85 85 # Extra actions
86 86 should_route :get, "/projects/23/issues/64/copy", :controller => 'issues', :action => 'new', :project_id => '23', :copy_from => '64'
87 87
88 88 should_route :get, "/issues/move/new", :controller => 'issue_moves', :action => 'new'
89 89 should_route :post, "/issues/move", :controller => 'issue_moves', :action => 'create'
90 90
91 should_route :post, "/issues/1/quoted", :controller => 'issues', :action => 'reply', :id => '1'
91 should_route :post, "/issues/1/quoted", :controller => 'journals', :action => 'new', :id => '1'
92 92
93 93 should_route :get, "/issues/calendar", :controller => 'calendars', :action => 'show'
94 94 should_route :post, "/issues/calendar", :controller => 'calendars', :action => 'show'
95 95 should_route :get, "/projects/project-name/issues/calendar", :controller => 'calendars', :action => 'show', :project_id => 'project-name'
96 96 should_route :post, "/projects/project-name/issues/calendar", :controller => 'calendars', :action => 'show', :project_id => 'project-name'
97 97
98 98 should_route :get, "/issues/gantt", :controller => 'gantts', :action => 'show'
99 99 should_route :post, "/issues/gantt", :controller => 'gantts', :action => 'show'
100 100 should_route :get, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
101 101 should_route :post, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
102 102
103 103 should_route :get, "/issues/auto_complete", :controller => 'issues', :action => 'auto_complete'
104 104 end
105 105
106 106 context "issue categories" do
107 107 should_route :get, "/projects/test/issue_categories/new", :controller => 'issue_categories', :action => 'new', :project_id => 'test'
108 108
109 109 should_route :post, "/projects/test/issue_categories/new", :controller => 'issue_categories', :action => 'new', :project_id => 'test'
110 110 end
111 111
112 112 context "issue relations" do
113 113 should_route :post, "/issues/1/relations", :controller => 'issue_relations', :action => 'new', :issue_id => '1'
114 114 should_route :post, "/issues/1/relations/23/destroy", :controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'
115 115 end
116 116
117 117 context "issue reports" do
118 118 should_route :get, "/projects/567/issues/report", :controller => 'reports', :action => 'issue_report', :id => '567'
119 119 should_route :get, "/projects/567/issues/report/assigned_to", :controller => 'reports', :action => 'issue_report_details', :id => '567', :detail => 'assigned_to'
120 120 end
121 121
122 122 context "members" do
123 123 should_route :post, "/projects/5234/members/new", :controller => 'members', :action => 'new', :id => '5234'
124 124 end
125 125
126 126 context "messages" do
127 127 should_route :get, "/boards/22/topics/2", :controller => 'messages', :action => 'show', :id => '2', :board_id => '22'
128 128 should_route :get, "/boards/lala/topics/new", :controller => 'messages', :action => 'new', :board_id => 'lala'
129 129 should_route :get, "/boards/lala/topics/22/edit", :controller => 'messages', :action => 'edit', :id => '22', :board_id => 'lala'
130 130
131 131 should_route :post, "/boards/lala/topics/new", :controller => 'messages', :action => 'new', :board_id => 'lala'
132 132 should_route :post, "/boards/lala/topics/22/edit", :controller => 'messages', :action => 'edit', :id => '22', :board_id => 'lala'
133 133 should_route :post, "/boards/22/topics/555/replies", :controller => 'messages', :action => 'reply', :id => '555', :board_id => '22'
134 134 should_route :post, "/boards/22/topics/555/destroy", :controller => 'messages', :action => 'destroy', :id => '555', :board_id => '22'
135 135 end
136 136
137 137 context "news" do
138 138 should_route :get, "/news", :controller => 'news', :action => 'index'
139 139 should_route :get, "/news.atom", :controller => 'news', :action => 'index', :format => 'atom'
140 140 should_route :get, "/news.xml", :controller => 'news', :action => 'index', :format => 'xml'
141 141 should_route :get, "/news.json", :controller => 'news', :action => 'index', :format => 'json'
142 142 should_route :get, "/projects/567/news", :controller => 'news', :action => 'index', :project_id => '567'
143 143 should_route :get, "/projects/567/news.atom", :controller => 'news', :action => 'index', :format => 'atom', :project_id => '567'
144 144 should_route :get, "/projects/567/news.xml", :controller => 'news', :action => 'index', :format => 'xml', :project_id => '567'
145 145 should_route :get, "/projects/567/news.json", :controller => 'news', :action => 'index', :format => 'json', :project_id => '567'
146 146 should_route :get, "/news/2", :controller => 'news', :action => 'show', :id => '2'
147 147 should_route :get, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
148 148 should_route :get, "/news/234", :controller => 'news', :action => 'show', :id => '234'
149 149
150 150 should_route :post, "/projects/567/news/new", :controller => 'news', :action => 'new', :project_id => '567'
151 151 should_route :post, "/news/567/edit", :controller => 'news', :action => 'edit', :id => '567'
152 152 should_route :post, "/news/567/destroy", :controller => 'news', :action => 'destroy', :id => '567'
153 153 end
154 154
155 155 context "projects" do
156 156 should_route :get, "/projects", :controller => 'projects', :action => 'index'
157 157 should_route :get, "/projects.atom", :controller => 'projects', :action => 'index', :format => 'atom'
158 158 should_route :get, "/projects.xml", :controller => 'projects', :action => 'index', :format => 'xml'
159 159 should_route :get, "/projects/new", :controller => 'projects', :action => 'add'
160 160 should_route :get, "/projects/test", :controller => 'projects', :action => 'show', :id => 'test'
161 161 should_route :get, "/projects/1.xml", :controller => 'projects', :action => 'show', :id => '1', :format => 'xml'
162 162 should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223'
163 163 should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
164 164 should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567'
165 165 should_route :get, "/projects/33/files", :controller => 'projects', :action => 'list_files', :id => '33'
166 166 should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
167 167 should_route :get, "/projects/33/roadmap", :controller => 'projects', :action => 'roadmap', :id => '33'
168 168 should_route :get, "/projects/33/activity", :controller => 'projects', :action => 'activity', :id => '33'
169 169 should_route :get, "/projects/33/activity.atom", :controller => 'projects', :action => 'activity', :id => '33', :format => 'atom'
170 170
171 171 should_route :post, "/projects/new", :controller => 'projects', :action => 'add'
172 172 should_route :post, "/projects.xml", :controller => 'projects', :action => 'add', :format => 'xml'
173 173 should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'edit', :id => '4223'
174 174 should_route :post, "/projects/64/destroy", :controller => 'projects', :action => 'destroy', :id => '64'
175 175 should_route :post, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
176 176 should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64'
177 177 should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64'
178 178 should_route :post, "/projects/64/activities/save", :controller => 'projects', :action => 'save_activities', :id => '64'
179 179
180 180 should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml'
181 181
182 182 should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml'
183 183 should_route :delete, "/projects/64/reset_activities", :controller => 'projects', :action => 'reset_activities', :id => '64'
184 184 end
185 185
186 186 context "repositories" do
187 187 should_route :get, "/projects/redmine/repository", :controller => 'repositories', :action => 'show', :id => 'redmine'
188 188 should_route :get, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
189 189 should_route :get, "/projects/redmine/repository/revisions", :controller => 'repositories', :action => 'revisions', :id => 'redmine'
190 190 should_route :get, "/projects/redmine/repository/revisions.atom", :controller => 'repositories', :action => 'revisions', :id => 'redmine', :format => 'atom'
191 191 should_route :get, "/projects/redmine/repository/revisions/2457", :controller => 'repositories', :action => 'revision', :id => 'redmine', :rev => '2457'
192 192 should_route :get, "/projects/redmine/repository/revisions/2457/diff", :controller => 'repositories', :action => 'diff', :id => 'redmine', :rev => '2457'
193 193 should_route :get, "/projects/redmine/repository/revisions/2457/diff.diff", :controller => 'repositories', :action => 'diff', :id => 'redmine', :rev => '2457', :format => 'diff'
194 194 should_route :get, "/projects/redmine/repository/diff/path/to/file.c", :controller => 'repositories', :action => 'diff', :id => 'redmine', :path => %w[path to file.c]
195 195 should_route :get, "/projects/redmine/repository/revisions/2/diff/path/to/file.c", :controller => 'repositories', :action => 'diff', :id => 'redmine', :path => %w[path to file.c], :rev => '2'
196 196 should_route :get, "/projects/redmine/repository/browse/path/to/file.c", :controller => 'repositories', :action => 'browse', :id => 'redmine', :path => %w[path to file.c]
197 197 should_route :get, "/projects/redmine/repository/entry/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c]
198 198 should_route :get, "/projects/redmine/repository/revisions/2/entry/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :rev => '2'
199 199 should_route :get, "/projects/redmine/repository/raw/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :format => 'raw'
200 200 should_route :get, "/projects/redmine/repository/revisions/2/raw/path/to/file.c", :controller => 'repositories', :action => 'entry', :id => 'redmine', :path => %w[path to file.c], :rev => '2', :format => 'raw'
201 201 should_route :get, "/projects/redmine/repository/annotate/path/to/file.c", :controller => 'repositories', :action => 'annotate', :id => 'redmine', :path => %w[path to file.c]
202 202 should_route :get, "/projects/redmine/repository/changes/path/to/file.c", :controller => 'repositories', :action => 'changes', :id => 'redmine', :path => %w[path to file.c]
203 203 should_route :get, "/projects/redmine/repository/statistics", :controller => 'repositories', :action => 'stats', :id => 'redmine'
204 204
205 205
206 206 should_route :post, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
207 207 end
208 208
209 209 context "timelogs" do
210 210 should_route :get, "/issues/567/time_entries/new", :controller => 'timelog', :action => 'edit', :issue_id => '567'
211 211 should_route :get, "/projects/ecookbook/time_entries/new", :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook'
212 212 should_route :get, "/projects/ecookbook/issues/567/time_entries/new", :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567'
213 213 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
214 214 should_route :get, "/time_entries/report", :controller => 'timelog', :action => 'report'
215 215 should_route :get, "/projects/567/time_entries/report", :controller => 'timelog', :action => 'report', :project_id => '567'
216 216 should_route :get, "/projects/567/time_entries/report.csv", :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv'
217 217 should_route :get, "/time_entries", :controller => 'timelog', :action => 'details'
218 218 should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'details', :format => 'csv'
219 219 should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'details', :format => 'atom'
220 220 should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'details', :project_id => '567'
221 221 should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'details', :project_id => '567', :format => 'csv'
222 222 should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'details', :project_id => '567', :format => 'atom'
223 223 should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'details', :issue_id => '234'
224 224 should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'details', :issue_id => '234', :format => 'csv'
225 225 should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'details', :issue_id => '234', :format => 'atom'
226 226 should_route :get, "/projects/ecookbook/issues/123/time_entries", :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123'
227 227
228 228 should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55'
229 229 end
230 230
231 231 context "users" do
232 232 should_route :get, "/users", :controller => 'users', :action => 'index'
233 233 should_route :get, "/users/44", :controller => 'users', :action => 'show', :id => '44'
234 234 should_route :get, "/users/new", :controller => 'users', :action => 'add'
235 235 should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
236 236 should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
237 237
238 238 should_route :post, "/users/new", :controller => 'users', :action => 'add'
239 239 should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
240 240 should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
241 241 should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
242 242 should_route :post, "/users/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
243 243 end
244 244
245 245 context "versions" do
246 246 should_route :get, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
247 247
248 248 should_route :post, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
249 249 end
250 250
251 251 context "wiki (singular, project's pages)" do
252 252 should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :id => '567'
253 253 should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :id => '567', :page => 'lalala'
254 254 should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
255 255 should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :id => '1', :page => 'CookBook_documentation'
256 256 should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1'
257 257 should_route :get, "/projects/1/wiki/CookBook_documentation/annotate/2", :controller => 'wiki', :action => 'annotate', :id => '1', :page => 'CookBook_documentation', :version => '2'
258 258 should_route :get, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'
259 259 should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'page_index'
260 260 should_route :get, "/projects/567/wiki/Page_Index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'Page_Index'
261 261 should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index'
262 262 should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'special', :id => '567', :page => 'export'
263 263
264 264 should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
265 265 should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation'
266 266 should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :id => '22', :page => 'ladida'
267 267 should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :id => '22', :page => 'ladida'
268 268 should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :id => '22', :page => 'ladida'
269 269 end
270 270
271 271 context "wikis (plural, admin setup)" do
272 272 should_route :get, "/projects/ladida/wiki/destroy", :controller => 'wikis', :action => 'destroy', :id => 'ladida'
273 273
274 274 should_route :post, "/projects/ladida/wiki", :controller => 'wikis', :action => 'edit', :id => 'ladida'
275 275 should_route :post, "/projects/ladida/wiki/destroy", :controller => 'wikis', :action => 'destroy', :id => 'ladida'
276 276 end
277 277
278 278 context "administration panel" do
279 279 should_route :get, "/admin/projects", :controller => 'admin', :action => 'projects'
280 280 end
281 281 end
General Comments 0
You need to be logged in to leave comments. Login now