@@ -1,562 +1,569 | |||
|
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 |
|
20 | 20 | default_search_scope :issues |
|
21 | 21 | |
|
22 | before_filter :find_issue, :only => [:show, :edit, :reply] | |
|
22 | before_filter :find_issue, :only => [:show, :edit, :update, :reply] | |
|
23 | 23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] |
|
24 | 24 | before_filter :find_project, :only => [:new, :update_form, :preview] |
|
25 | 25 | before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] |
|
26 | 26 | before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] |
|
27 | 27 | accept_key_auth :index, :show, :changes |
|
28 | 28 | |
|
29 | 29 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
30 | 30 | |
|
31 | 31 | helper :journals |
|
32 | 32 | helper :projects |
|
33 | 33 | include ProjectsHelper |
|
34 | 34 | helper :custom_fields |
|
35 | 35 | include CustomFieldsHelper |
|
36 | 36 | helper :issue_relations |
|
37 | 37 | include IssueRelationsHelper |
|
38 | 38 | helper :watchers |
|
39 | 39 | include WatchersHelper |
|
40 | 40 | helper :attachments |
|
41 | 41 | include AttachmentsHelper |
|
42 | 42 | helper :queries |
|
43 | 43 | include QueriesHelper |
|
44 | 44 | helper :sort |
|
45 | 45 | include SortHelper |
|
46 | 46 | include IssuesHelper |
|
47 | 47 | helper :timelog |
|
48 | 48 | include Redmine::Export::PDF |
|
49 | 49 | |
|
50 | 50 | verify :method => [:post, :delete], |
|
51 | 51 | :only => :destroy, |
|
52 | 52 | :render => { :nothing => true, :status => :method_not_allowed } |
|
53 | 53 | |
|
54 | 54 | def index |
|
55 | 55 | retrieve_query |
|
56 | 56 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
57 | 57 | sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) |
|
58 | 58 | |
|
59 | 59 | if @query.valid? |
|
60 | 60 | limit = case params[:format] |
|
61 | 61 | when 'csv', 'pdf' |
|
62 | 62 | Setting.issues_export_limit.to_i |
|
63 | 63 | when 'atom' |
|
64 | 64 | Setting.feeds_limit.to_i |
|
65 | 65 | else |
|
66 | 66 | per_page_option |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | @issue_count = @query.issue_count |
|
70 | 70 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
71 | 71 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
72 | 72 | :order => sort_clause, |
|
73 | 73 | :offset => @issue_pages.current.offset, |
|
74 | 74 | :limit => limit) |
|
75 | 75 | @issue_count_by_group = @query.issue_count_by_group |
|
76 | 76 | |
|
77 | 77 | respond_to do |format| |
|
78 | 78 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
79 | 79 | format.xml { render :layout => false } |
|
80 | 80 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
81 | 81 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
82 | 82 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
83 | 83 | end |
|
84 | 84 | else |
|
85 | 85 | # Send html if the query is not valid |
|
86 | 86 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
87 | 87 | end |
|
88 | 88 | rescue ActiveRecord::RecordNotFound |
|
89 | 89 | render_404 |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def changes |
|
93 | 93 | retrieve_query |
|
94 | 94 | sort_init 'id', 'desc' |
|
95 | 95 | sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) |
|
96 | 96 | |
|
97 | 97 | if @query.valid? |
|
98 | 98 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
99 | 99 | :limit => 25) |
|
100 | 100 | end |
|
101 | 101 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
102 | 102 | render :layout => false, :content_type => 'application/atom+xml' |
|
103 | 103 | rescue ActiveRecord::RecordNotFound |
|
104 | 104 | render_404 |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | def show |
|
108 | 108 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
109 | 109 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
110 | 110 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
111 | 111 | @changesets = @issue.changesets.visible.all |
|
112 | 112 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
113 | 113 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
114 | 114 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
115 | 115 | @priorities = IssuePriority.all |
|
116 | 116 | @time_entry = TimeEntry.new |
|
117 | 117 | respond_to do |format| |
|
118 | 118 | format.html { render :template => 'issues/show.rhtml' } |
|
119 | 119 | format.xml { render :layout => false } |
|
120 | 120 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } |
|
121 | 121 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
122 | 122 | end |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | # Add a new issue |
|
126 | 126 | # The new issue will be created from an existing one if copy_from parameter is given |
|
127 | 127 | def new |
|
128 | 128 | @issue = Issue.new |
|
129 | 129 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
130 | 130 | @issue.project = @project |
|
131 | 131 | # Tracker must be set before custom field values |
|
132 | 132 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
133 | 133 | if @issue.tracker.nil? |
|
134 | 134 | render_error l(:error_no_tracker_in_project) |
|
135 | 135 | return |
|
136 | 136 | end |
|
137 | 137 | if params[:issue].is_a?(Hash) |
|
138 | 138 | @issue.safe_attributes = params[:issue] |
|
139 | 139 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) |
|
140 | 140 | end |
|
141 | 141 | @issue.author = User.current |
|
142 | 142 | |
|
143 | 143 | default_status = IssueStatus.default |
|
144 | 144 | unless default_status |
|
145 | 145 | render_error l(:error_no_default_issue_status) |
|
146 | 146 | return |
|
147 | 147 | end |
|
148 | 148 | @issue.status = default_status |
|
149 | 149 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq |
|
150 | 150 | |
|
151 | 151 | if request.get? || request.xhr? |
|
152 | 152 | @issue.start_date ||= Date.today |
|
153 | 153 | else |
|
154 | 154 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
155 | 155 | # Check that the user is allowed to apply the requested status |
|
156 | 156 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
157 | 157 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
158 | 158 | if @issue.save |
|
159 | 159 | attach_files(@issue, params[:attachments]) |
|
160 | 160 | flash[:notice] = l(:notice_successful_create) |
|
161 | 161 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
162 | 162 | respond_to do |format| |
|
163 | 163 | format.html { |
|
164 | 164 | redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } : |
|
165 | 165 | { :action => 'show', :id => @issue }) |
|
166 | 166 | } |
|
167 | 167 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } |
|
168 | 168 | end |
|
169 | 169 | return |
|
170 | 170 | else |
|
171 | 171 | respond_to do |format| |
|
172 | 172 | format.html { } |
|
173 | 173 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } |
|
174 | 174 | end |
|
175 | 175 | end |
|
176 | 176 | end |
|
177 | 177 | @priorities = IssuePriority.all |
|
178 | 178 | render :layout => !request.xhr? |
|
179 | 179 | end |
|
180 | 180 | |
|
181 | 181 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
182 | 182 | # TODO: make it configurable (at least per role) |
|
183 | 183 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
184 | 184 | |
|
185 | 185 | def edit |
|
186 | 186 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
187 | 187 | @priorities = IssuePriority.all |
|
188 | 188 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
189 | 189 | @time_entry = TimeEntry.new |
|
190 | 190 | |
|
191 | 191 | @notes = params[:notes] |
|
192 | 192 | journal = @issue.init_journal(User.current, @notes) |
|
193 | 193 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
194 | 194 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
195 | 195 | attrs = params[:issue].dup |
|
196 | 196 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
197 | 197 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
198 | 198 | @issue.safe_attributes = attrs |
|
199 | 199 | end |
|
200 | 200 | |
|
201 | 201 | if request.get? |
|
202 | 202 | # nop |
|
203 | 203 | else |
|
204 | 204 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
205 | 205 | @time_entry.attributes = params[:time_entry] |
|
206 | 206 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? |
|
207 | 207 | attachments = attach_files(@issue, params[:attachments]) |
|
208 | 208 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
209 | 209 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
210 | 210 | if @issue.save |
|
211 | 211 | # Log spend time |
|
212 | 212 | if User.current.allowed_to?(:log_time, @project) |
|
213 | 213 | @time_entry.save |
|
214 | 214 | end |
|
215 | 215 | if !journal.new_record? |
|
216 | 216 | # Only send notification if something was actually changed |
|
217 | 217 | flash[:notice] = l(:notice_successful_update) |
|
218 | 218 | end |
|
219 | 219 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
220 | 220 | respond_to do |format| |
|
221 | 221 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
222 | 222 | format.xml { head :ok } |
|
223 | 223 | end |
|
224 | 224 | return |
|
225 | 225 | end |
|
226 | 226 | end |
|
227 | 227 | # failure |
|
228 | 228 | respond_to do |format| |
|
229 | format.html { } | |
|
229 | format.html { render :action => 'edit' } | |
|
230 | 230 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } |
|
231 | 231 | end |
|
232 | 232 | end |
|
233 | 233 | rescue ActiveRecord::StaleObjectError |
|
234 | 234 | # Optimistic locking exception |
|
235 | 235 | flash.now[:error] = l(:notice_locking_conflict) |
|
236 | 236 | # Remove the previously added attachments if issue was not updated |
|
237 | 237 | attachments.each(&:destroy) |
|
238 | 238 | end |
|
239 | 239 | |
|
240 | #-- | |
|
241 | # Start converting to the Rails REST controllers | |
|
242 | #++ | |
|
243 | def update | |
|
244 | edit | |
|
245 | end | |
|
246 | ||
|
240 | 247 | def reply |
|
241 | 248 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
242 | 249 | if journal |
|
243 | 250 | user = journal.user |
|
244 | 251 | text = journal.notes |
|
245 | 252 | else |
|
246 | 253 | user = @issue.author |
|
247 | 254 | text = @issue.description |
|
248 | 255 | end |
|
249 | 256 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " |
|
250 | 257 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" |
|
251 | 258 | render(:update) { |page| |
|
252 | 259 | page.<< "$('notes').value = \"#{content}\";" |
|
253 | 260 | page.show 'update' |
|
254 | 261 | page << "Form.Element.focus('notes');" |
|
255 | 262 | page << "Element.scrollTo('update');" |
|
256 | 263 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
257 | 264 | } |
|
258 | 265 | end |
|
259 | 266 | |
|
260 | 267 | # Bulk edit a set of issues |
|
261 | 268 | def bulk_edit |
|
262 | 269 | if request.post? |
|
263 | 270 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} |
|
264 | 271 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} |
|
265 | 272 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] |
|
266 | 273 | |
|
267 | 274 | unsaved_issue_ids = [] |
|
268 | 275 | @issues.each do |issue| |
|
269 | 276 | journal = issue.init_journal(User.current, params[:notes]) |
|
270 | 277 | issue.safe_attributes = attributes |
|
271 | 278 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
272 | 279 | unless issue.save |
|
273 | 280 | # Keep unsaved issue ids to display them in flash error |
|
274 | 281 | unsaved_issue_ids << issue.id |
|
275 | 282 | end |
|
276 | 283 | end |
|
277 | 284 | if unsaved_issue_ids.empty? |
|
278 | 285 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
279 | 286 | else |
|
280 | 287 | flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size, |
|
281 | 288 | :total => @issues.size, |
|
282 | 289 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
283 | 290 | end |
|
284 | 291 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) |
|
285 | 292 | return |
|
286 | 293 | end |
|
287 | 294 | @available_statuses = Workflow.available_statuses(@project) |
|
288 | 295 | @custom_fields = @project.all_issue_custom_fields |
|
289 | 296 | end |
|
290 | 297 | |
|
291 | 298 | def move |
|
292 | 299 | @copy = params[:copy_options] && params[:copy_options][:copy] |
|
293 | 300 | @allowed_projects = [] |
|
294 | 301 | # find projects to which the user is allowed to move the issue |
|
295 | 302 | if User.current.admin? |
|
296 | 303 | # admin is allowed to move issues to any active (visible) project |
|
297 | 304 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current)) |
|
298 | 305 | else |
|
299 | 306 | User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} |
|
300 | 307 | end |
|
301 | 308 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
302 | 309 | @target_project ||= @project |
|
303 | 310 | @trackers = @target_project.trackers |
|
304 | 311 | @available_statuses = Workflow.available_statuses(@project) |
|
305 | 312 | if request.post? |
|
306 | 313 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
307 | 314 | unsaved_issue_ids = [] |
|
308 | 315 | moved_issues = [] |
|
309 | 316 | @issues.each do |issue| |
|
310 | 317 | changed_attributes = {} |
|
311 | 318 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| |
|
312 | 319 | unless params[valid_attribute].blank? |
|
313 | 320 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) |
|
314 | 321 | end |
|
315 | 322 | end |
|
316 | 323 | issue.init_journal(User.current) |
|
317 | 324 | call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) |
|
318 | 325 | if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) |
|
319 | 326 | moved_issues << r |
|
320 | 327 | else |
|
321 | 328 | unsaved_issue_ids << issue.id |
|
322 | 329 | end |
|
323 | 330 | end |
|
324 | 331 | if unsaved_issue_ids.empty? |
|
325 | 332 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
326 | 333 | else |
|
327 | 334 | flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size, |
|
328 | 335 | :total => @issues.size, |
|
329 | 336 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
330 | 337 | end |
|
331 | 338 | if params[:follow] |
|
332 | 339 | if @issues.size == 1 && moved_issues.size == 1 |
|
333 | 340 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first |
|
334 | 341 | else |
|
335 | 342 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) |
|
336 | 343 | end |
|
337 | 344 | else |
|
338 | 345 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
339 | 346 | end |
|
340 | 347 | return |
|
341 | 348 | end |
|
342 | 349 | render :layout => false if request.xhr? |
|
343 | 350 | end |
|
344 | 351 | |
|
345 | 352 | def destroy |
|
346 | 353 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
347 | 354 | if @hours > 0 |
|
348 | 355 | case params[:todo] |
|
349 | 356 | when 'destroy' |
|
350 | 357 | # nothing to do |
|
351 | 358 | when 'nullify' |
|
352 | 359 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
353 | 360 | when 'reassign' |
|
354 | 361 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
355 | 362 | if reassign_to.nil? |
|
356 | 363 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
357 | 364 | return |
|
358 | 365 | else |
|
359 | 366 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
360 | 367 | end |
|
361 | 368 | else |
|
362 | 369 | unless params[:format] == 'xml' |
|
363 | 370 | # display the destroy form if it's a user request |
|
364 | 371 | return |
|
365 | 372 | end |
|
366 | 373 | end |
|
367 | 374 | end |
|
368 | 375 | @issues.each(&:destroy) |
|
369 | 376 | respond_to do |format| |
|
370 | 377 | format.html { redirect_to :action => 'index', :project_id => @project } |
|
371 | 378 | format.xml { head :ok } |
|
372 | 379 | end |
|
373 | 380 | end |
|
374 | 381 | |
|
375 | 382 | def gantt |
|
376 | 383 | @gantt = Redmine::Helpers::Gantt.new(params) |
|
377 | 384 | retrieve_query |
|
378 | 385 | @query.group_by = nil |
|
379 | 386 | if @query.valid? |
|
380 | 387 | events = [] |
|
381 | 388 | # Issues that have start and due dates |
|
382 | 389 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
383 | 390 | :order => "start_date, due_date", |
|
384 | 391 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] |
|
385 | 392 | ) |
|
386 | 393 | # Issues that don't have a due date but that are assigned to a version with a date |
|
387 | 394 | events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version], |
|
388 | 395 | :order => "start_date, effective_date", |
|
389 | 396 | :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] |
|
390 | 397 | ) |
|
391 | 398 | # Versions |
|
392 | 399 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) |
|
393 | 400 | |
|
394 | 401 | @gantt.events = events |
|
395 | 402 | end |
|
396 | 403 | |
|
397 | 404 | basename = (@project ? "#{@project.identifier}-" : '') + 'gantt' |
|
398 | 405 | |
|
399 | 406 | respond_to do |format| |
|
400 | 407 | format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? } |
|
401 | 408 | format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image') |
|
402 | 409 | format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") } |
|
403 | 410 | end |
|
404 | 411 | end |
|
405 | 412 | |
|
406 | 413 | def calendar |
|
407 | 414 | if params[:year] and params[:year].to_i > 1900 |
|
408 | 415 | @year = params[:year].to_i |
|
409 | 416 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
410 | 417 | @month = params[:month].to_i |
|
411 | 418 | end |
|
412 | 419 | end |
|
413 | 420 | @year ||= Date.today.year |
|
414 | 421 | @month ||= Date.today.month |
|
415 | 422 | |
|
416 | 423 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
417 | 424 | retrieve_query |
|
418 | 425 | @query.group_by = nil |
|
419 | 426 | if @query.valid? |
|
420 | 427 | events = [] |
|
421 | 428 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
422 | 429 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
423 | 430 | ) |
|
424 | 431 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
425 | 432 | |
|
426 | 433 | @calendar.events = events |
|
427 | 434 | end |
|
428 | 435 | |
|
429 | 436 | render :layout => false if request.xhr? |
|
430 | 437 | end |
|
431 | 438 | |
|
432 | 439 | def context_menu |
|
433 | 440 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) |
|
434 | 441 | if (@issues.size == 1) |
|
435 | 442 | @issue = @issues.first |
|
436 | 443 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
437 | 444 | end |
|
438 | 445 | projects = @issues.collect(&:project).compact.uniq |
|
439 | 446 | @project = projects.first if projects.size == 1 |
|
440 | 447 | |
|
441 | 448 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), |
|
442 | 449 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
443 | 450 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), |
|
444 | 451 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
445 | 452 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
446 | 453 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) |
|
447 | 454 | } |
|
448 | 455 | if @project |
|
449 | 456 | @assignables = @project.assignable_users |
|
450 | 457 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
451 | 458 | @trackers = @project.trackers |
|
452 | 459 | end |
|
453 | 460 | |
|
454 | 461 | @priorities = IssuePriority.all.reverse |
|
455 | 462 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
456 | 463 | @back = params[:back_url] || request.env['HTTP_REFERER'] |
|
457 | 464 | |
|
458 | 465 | render :layout => false |
|
459 | 466 | end |
|
460 | 467 | |
|
461 | 468 | def update_form |
|
462 | 469 | if params[:id].blank? |
|
463 | 470 | @issue = Issue.new |
|
464 | 471 | @issue.project = @project |
|
465 | 472 | else |
|
466 | 473 | @issue = @project.issues.visible.find(params[:id]) |
|
467 | 474 | end |
|
468 | 475 | @issue.attributes = params[:issue] |
|
469 | 476 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq |
|
470 | 477 | @priorities = IssuePriority.all |
|
471 | 478 | |
|
472 | 479 | render :partial => 'attributes' |
|
473 | 480 | end |
|
474 | 481 | |
|
475 | 482 | def preview |
|
476 | 483 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
477 | 484 | @attachements = @issue.attachments if @issue |
|
478 | 485 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) |
|
479 | 486 | render :partial => 'common/preview' |
|
480 | 487 | end |
|
481 | 488 | |
|
482 | 489 | private |
|
483 | 490 | def find_issue |
|
484 | 491 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
485 | 492 | @project = @issue.project |
|
486 | 493 | rescue ActiveRecord::RecordNotFound |
|
487 | 494 | render_404 |
|
488 | 495 | end |
|
489 | 496 | |
|
490 | 497 | # Filter for bulk operations |
|
491 | 498 | def find_issues |
|
492 | 499 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
493 | 500 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
494 | 501 | projects = @issues.collect(&:project).compact.uniq |
|
495 | 502 | if projects.size == 1 |
|
496 | 503 | @project = projects.first |
|
497 | 504 | else |
|
498 | 505 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
499 | 506 | render_error 'Can not bulk edit/move/destroy issues from different projects' |
|
500 | 507 | return false |
|
501 | 508 | end |
|
502 | 509 | rescue ActiveRecord::RecordNotFound |
|
503 | 510 | render_404 |
|
504 | 511 | end |
|
505 | 512 | |
|
506 | 513 | def find_project |
|
507 | 514 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
508 | 515 | @project = Project.find(project_id) |
|
509 | 516 | rescue ActiveRecord::RecordNotFound |
|
510 | 517 | render_404 |
|
511 | 518 | end |
|
512 | 519 | |
|
513 | 520 | def find_optional_project |
|
514 | 521 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? |
|
515 | 522 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) |
|
516 | 523 | allowed ? true : deny_access |
|
517 | 524 | rescue ActiveRecord::RecordNotFound |
|
518 | 525 | render_404 |
|
519 | 526 | end |
|
520 | 527 | |
|
521 | 528 | # Retrieve query from session or build a new query |
|
522 | 529 | def retrieve_query |
|
523 | 530 | if !params[:query_id].blank? |
|
524 | 531 | cond = "project_id IS NULL" |
|
525 | 532 | cond << " OR project_id = #{@project.id}" if @project |
|
526 | 533 | @query = Query.find(params[:query_id], :conditions => cond) |
|
527 | 534 | @query.project = @project |
|
528 | 535 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
529 | 536 | sort_clear |
|
530 | 537 | else |
|
531 | 538 | if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
532 | 539 | # Give it a name, required to be valid |
|
533 | 540 | @query = Query.new(:name => "_") |
|
534 | 541 | @query.project = @project |
|
535 | 542 | if params[:fields] and params[:fields].is_a? Array |
|
536 | 543 | params[:fields].each do |field| |
|
537 | 544 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
538 | 545 | end |
|
539 | 546 | else |
|
540 | 547 | @query.available_filters.keys.each do |field| |
|
541 | 548 | @query.add_short_filter(field, params[field]) if params[field] |
|
542 | 549 | end |
|
543 | 550 | end |
|
544 | 551 | @query.group_by = params[:group_by] |
|
545 | 552 | @query.column_names = params[:query] && params[:query][:column_names] |
|
546 | 553 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} |
|
547 | 554 | else |
|
548 | 555 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
549 | 556 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
550 | 557 | @query.project = @project |
|
551 | 558 | end |
|
552 | 559 | end |
|
553 | 560 | end |
|
554 | 561 | |
|
555 | 562 | # Rescues an invalid query statement. Just in case... |
|
556 | 563 | def query_statement_invalid(exception) |
|
557 | 564 | logger.error "Query::StatementInvalid: #{exception.message}" if logger |
|
558 | 565 | session.delete(:query) |
|
559 | 566 | sort_clear |
|
560 | 567 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." |
|
561 | 568 | end |
|
562 | 569 | end |
@@ -1,55 +1,56 | |||
|
1 | 1 | <% labelled_tabular_form_for :issue, @issue, |
|
2 |
:url => {:action => ' |
|
|
2 | :url => {:action => 'update', :id => @issue}, | |
|
3 | 3 | :html => {:id => 'issue-form', |
|
4 | 4 | :class => nil, |
|
5 | :method => :put, | |
|
5 | 6 | :multipart => true} do |f| %> |
|
6 | 7 | <%= error_messages_for 'issue' %> |
|
7 | 8 | <%= error_messages_for 'time_entry' %> |
|
8 | 9 | <div class="box"> |
|
9 | 10 | <% if @edit_allowed || !@allowed_statuses.empty? %> |
|
10 | 11 | <fieldset class="tabular"><legend><%= l(:label_change_properties) %> |
|
11 | 12 | <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %> |
|
12 | 13 | <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small> |
|
13 | 14 | <% end %> |
|
14 | 15 | </legend> |
|
15 | 16 | <%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %> |
|
16 | 17 | </fieldset> |
|
17 | 18 | <% end %> |
|
18 | 19 | <% if authorize_for('timelog', 'edit') %> |
|
19 | 20 | <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend> |
|
20 | 21 | <% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %> |
|
21 | 22 | <div class="splitcontentleft"> |
|
22 | 23 | <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p> |
|
23 | 24 | </div> |
|
24 | 25 | <div class="splitcontentright"> |
|
25 | 26 | <p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p> |
|
26 | 27 | </div> |
|
27 | 28 | <p><%= time_entry.text_field :comments, :size => 60 %></p> |
|
28 | 29 | <% @time_entry.custom_field_values.each do |value| %> |
|
29 | 30 | <p><%= custom_field_tag_with_label :time_entry, value %></p> |
|
30 | 31 | <% end %> |
|
31 | 32 | <% end %> |
|
32 | 33 | </fieldset> |
|
33 | 34 | <% end %> |
|
34 | 35 | |
|
35 | 36 | <fieldset><legend><%= l(:field_notes) %></legend> |
|
36 | 37 | <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> |
|
37 | 38 | <%= wikitoolbar_for 'notes' %> |
|
38 | 39 | <%= call_hook(:view_issues_edit_notes_bottom, { :issue => @issue, :notes => @notes, :form => f }) %> |
|
39 | 40 | |
|
40 | 41 | <p><%=l(:label_attachment_plural)%><br /><%= render :partial => 'attachments/form' %></p> |
|
41 | 42 | </fieldset> |
|
42 | 43 | </div> |
|
43 | 44 | |
|
44 | 45 | <%= f.hidden_field :lock_version %> |
|
45 | 46 | <%= submit_tag l(:button_submit) %> |
|
46 | 47 | <%= link_to_remote l(:label_preview), |
|
47 | 48 | { :url => { :controller => 'issues', :action => 'preview', :project_id => @project, :id => @issue }, |
|
48 | 49 | :method => 'post', |
|
49 | 50 | :update => 'preview', |
|
50 | 51 | :with => 'Form.serialize("issue-form")', |
|
51 | 52 | :complete => "Element.scrollTo('preview')" |
|
52 | 53 | }, :accesskey => accesskey(:preview) %> |
|
53 | 54 | <% end %> |
|
54 | 55 | |
|
55 | 56 | <div id="preview" class="wiki"></div> |
@@ -1,194 +1,194 | |||
|
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/mime_type' |
|
6 | 6 | require 'redmine/core_ext' |
|
7 | 7 | require 'redmine/themes' |
|
8 | 8 | require 'redmine/hook' |
|
9 | 9 | require 'redmine/plugin' |
|
10 | 10 | require 'redmine/wiki_formatting' |
|
11 | 11 | require 'redmine/scm/base' |
|
12 | 12 | |
|
13 | 13 | begin |
|
14 | 14 | require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick) |
|
15 | 15 | rescue LoadError |
|
16 | 16 | # RMagick is not available |
|
17 | 17 | end |
|
18 | 18 | |
|
19 | 19 | if RUBY_VERSION < '1.9' |
|
20 | 20 | require 'faster_csv' |
|
21 | 21 | else |
|
22 | 22 | require 'csv' |
|
23 | 23 | FCSV = CSV |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | Redmine::Scm::Base.add "Subversion" |
|
27 | 27 | Redmine::Scm::Base.add "Darcs" |
|
28 | 28 | Redmine::Scm::Base.add "Mercurial" |
|
29 | 29 | Redmine::Scm::Base.add "Cvs" |
|
30 | 30 | Redmine::Scm::Base.add "Bazaar" |
|
31 | 31 | Redmine::Scm::Base.add "Git" |
|
32 | 32 | Redmine::Scm::Base.add "Filesystem" |
|
33 | 33 | |
|
34 | 34 | # Permissions |
|
35 | 35 | Redmine::AccessControl.map do |map| |
|
36 | 36 | map.permission :view_project, {:projects => [:show, :activity]}, :public => true |
|
37 | 37 | map.permission :search_project, {:search => :index}, :public => true |
|
38 | 38 | map.permission :add_project, {:projects => :add}, :require => :loggedin |
|
39 | 39 | map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member |
|
40 | 40 | map.permission :select_project_modules, {:projects => :modules}, :require => :member |
|
41 | 41 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member |
|
42 | 42 | map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :close_completed, :destroy]}, :require => :member |
|
43 | 43 | map.permission :add_subprojects, {:projects => :add}, :require => :member |
|
44 | 44 | |
|
45 | 45 | map.project_module :issue_tracking do |map| |
|
46 | 46 | # Issue categories |
|
47 | 47 | map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member |
|
48 | 48 | # Issues |
|
49 | 49 | map.permission :view_issues, {:projects => :roadmap, |
|
50 | 50 | :issues => [:index, :changes, :show, :context_menu], |
|
51 | 51 | :versions => [:show, :status_by], |
|
52 | 52 | :queries => :index, |
|
53 | 53 | :reports => [:issue_report, :issue_report_details]} |
|
54 | 54 | map.permission :add_issues, {:issues => [:new, :update_form]} |
|
55 | map.permission :edit_issues, {:issues => [:edit, :reply, :bulk_edit, :update_form]} | |
|
55 | map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]} | |
|
56 | 56 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} |
|
57 | map.permission :add_issue_notes, {:issues => [:edit, :reply]} | |
|
57 | map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]} | |
|
58 | 58 | map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin |
|
59 | 59 | map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin |
|
60 | 60 | map.permission :move_issues, {:issues => :move}, :require => :loggedin |
|
61 | 61 | map.permission :delete_issues, {:issues => :destroy}, :require => :member |
|
62 | 62 | # Queries |
|
63 | 63 | map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member |
|
64 | 64 | map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin |
|
65 | 65 | # Gantt & calendar |
|
66 | 66 | map.permission :view_gantt, :issues => :gantt |
|
67 | 67 | map.permission :view_calendar, :issues => :calendar |
|
68 | 68 | # Watchers |
|
69 | 69 | map.permission :view_issue_watchers, {} |
|
70 | 70 | map.permission :add_issue_watchers, {:watchers => :new} |
|
71 | 71 | map.permission :delete_issue_watchers, {:watchers => :destroy} |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | map.project_module :time_tracking do |map| |
|
75 | 75 | map.permission :log_time, {:timelog => :edit}, :require => :loggedin |
|
76 | 76 | map.permission :view_time_entries, :timelog => [:details, :report] |
|
77 | 77 | map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member |
|
78 | 78 | map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin |
|
79 | 79 | map.permission :manage_project_activities, {:projects => [:save_activities, :reset_activities]}, :require => :member |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | map.project_module :news do |map| |
|
83 | 83 | map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member |
|
84 | 84 | map.permission :view_news, {:news => [:index, :show]}, :public => true |
|
85 | 85 | map.permission :comment_news, {:news => :add_comment} |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | map.project_module :documents do |map| |
|
89 | 89 | map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin |
|
90 | 90 | map.permission :view_documents, :documents => [:index, :show, :download] |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | map.project_module :files do |map| |
|
94 | 94 | map.permission :manage_files, {:projects => :add_file}, :require => :loggedin |
|
95 | 95 | map.permission :view_files, :projects => :list_files, :versions => :download |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | map.project_module :wiki do |map| |
|
99 | 99 | map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member |
|
100 | 100 | map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member |
|
101 | 101 | map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member |
|
102 | 102 | map.permission :view_wiki_pages, :wiki => [:index, :special] |
|
103 | 103 | map.permission :export_wiki_pages, {} |
|
104 | 104 | map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate] |
|
105 | 105 | map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment] |
|
106 | 106 | map.permission :delete_wiki_pages_attachments, {} |
|
107 | 107 | map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | map.project_module :repository do |map| |
|
111 | 111 | map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member |
|
112 | 112 | map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph] |
|
113 | 113 | map.permission :view_changesets, :repositories => [:show, :revisions, :revision] |
|
114 | 114 | map.permission :commit_access, {} |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | map.project_module :boards do |map| |
|
118 | 118 | map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member |
|
119 | 119 | map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true |
|
120 | 120 | map.permission :add_messages, {:messages => [:new, :reply, :quote]} |
|
121 | 121 | map.permission :edit_messages, {:messages => :edit}, :require => :member |
|
122 | 122 | map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin |
|
123 | 123 | map.permission :delete_messages, {:messages => :destroy}, :require => :member |
|
124 | 124 | map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin |
|
125 | 125 | end |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | Redmine::MenuManager.map :top_menu do |menu| |
|
129 | 129 | menu.push :home, :home_path |
|
130 | 130 | menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? } |
|
131 | 131 | menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural |
|
132 | 132 | menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true |
|
133 | 133 | menu.push :help, Redmine::Info.help_url, :last => true |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | Redmine::MenuManager.map :account_menu do |menu| |
|
137 | 137 | menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? } |
|
138 | 138 | menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? } |
|
139 | 139 | menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? } |
|
140 | 140 | menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? } |
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | Redmine::MenuManager.map :application_menu do |menu| |
|
144 | 144 | # Empty |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | Redmine::MenuManager.map :admin_menu do |menu| |
|
148 | 148 | # Empty |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | Redmine::MenuManager.map :project_menu do |menu| |
|
152 | 152 | menu.push :overview, { :controller => 'projects', :action => 'show' } |
|
153 | 153 | menu.push :activity, { :controller => 'projects', :action => 'activity' } |
|
154 | 154 | menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, |
|
155 | 155 | :if => Proc.new { |p| p.shared_versions.any? } |
|
156 | 156 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural |
|
157 | 157 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, |
|
158 | 158 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } |
|
159 | 159 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural |
|
160 | 160 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural |
|
161 | 161 | menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, |
|
162 | 162 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } |
|
163 | 163 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, |
|
164 | 164 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural |
|
165 | 165 | menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural |
|
166 | 166 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, |
|
167 | 167 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } |
|
168 | 168 | menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | Redmine::Activity.map do |activity| |
|
172 | 172 | activity.register :issues, :class_name => %w(Issue Journal) |
|
173 | 173 | activity.register :changesets |
|
174 | 174 | activity.register :news |
|
175 | 175 | activity.register :documents, :class_name => %w(Document Attachment) |
|
176 | 176 | activity.register :files, :class_name => 'Attachment' |
|
177 | 177 | activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false |
|
178 | 178 | activity.register :messages, :default => false |
|
179 | 179 | activity.register :time_entries, :default => false |
|
180 | 180 | end |
|
181 | 181 | |
|
182 | 182 | Redmine::Search.map do |search| |
|
183 | 183 | search.register :issues |
|
184 | 184 | search.register :news |
|
185 | 185 | search.register :documents |
|
186 | 186 | search.register :changesets |
|
187 | 187 | search.register :wiki_pages |
|
188 | 188 | search.register :messages |
|
189 | 189 | search.register :projects |
|
190 | 190 | end |
|
191 | 191 | |
|
192 | 192 | Redmine::WikiFormatting.map do |format| |
|
193 | 193 | format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper |
|
194 | 194 | end |
@@ -1,1233 +1,1233 | |||
|
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_gantt |
|
235 | 235 | get :gantt, :project_id => 1 |
|
236 | 236 | assert_response :success |
|
237 | 237 | assert_template 'gantt.rhtml' |
|
238 | 238 | assert_not_nil assigns(:gantt) |
|
239 | 239 | events = assigns(:gantt).events |
|
240 | 240 | assert_not_nil events |
|
241 | 241 | # Issue with start and due dates |
|
242 | 242 | i = Issue.find(1) |
|
243 | 243 | assert_not_nil i.due_date |
|
244 | 244 | assert events.include?(Issue.find(1)) |
|
245 | 245 | # Issue with without due date but targeted to a version with date |
|
246 | 246 | i = Issue.find(2) |
|
247 | 247 | assert_nil i.due_date |
|
248 | 248 | assert events.include?(i) |
|
249 | 249 | end |
|
250 | 250 | |
|
251 | 251 | def test_cross_project_gantt |
|
252 | 252 | get :gantt |
|
253 | 253 | assert_response :success |
|
254 | 254 | assert_template 'gantt.rhtml' |
|
255 | 255 | assert_not_nil assigns(:gantt) |
|
256 | 256 | events = assigns(:gantt).events |
|
257 | 257 | assert_not_nil events |
|
258 | 258 | end |
|
259 | 259 | |
|
260 | 260 | def test_gantt_export_to_pdf |
|
261 | 261 | get :gantt, :project_id => 1, :format => 'pdf' |
|
262 | 262 | assert_response :success |
|
263 | 263 | assert_equal 'application/pdf', @response.content_type |
|
264 | 264 | assert @response.body.starts_with?('%PDF') |
|
265 | 265 | assert_not_nil assigns(:gantt) |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | def test_cross_project_gantt_export_to_pdf |
|
269 | 269 | get :gantt, :format => 'pdf' |
|
270 | 270 | assert_response :success |
|
271 | 271 | assert_equal 'application/pdf', @response.content_type |
|
272 | 272 | assert @response.body.starts_with?('%PDF') |
|
273 | 273 | assert_not_nil assigns(:gantt) |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | 276 | if Object.const_defined?(:Magick) |
|
277 | 277 | def test_gantt_image |
|
278 | 278 | get :gantt, :project_id => 1, :format => 'png' |
|
279 | 279 | assert_response :success |
|
280 | 280 | assert_equal 'image/png', @response.content_type |
|
281 | 281 | end |
|
282 | 282 | else |
|
283 | 283 | puts "RMagick not installed. Skipping tests !!!" |
|
284 | 284 | end |
|
285 | 285 | |
|
286 | 286 | def test_calendar |
|
287 | 287 | get :calendar, :project_id => 1 |
|
288 | 288 | assert_response :success |
|
289 | 289 | assert_template 'calendar' |
|
290 | 290 | assert_not_nil assigns(:calendar) |
|
291 | 291 | end |
|
292 | 292 | |
|
293 | 293 | def test_cross_project_calendar |
|
294 | 294 | get :calendar |
|
295 | 295 | assert_response :success |
|
296 | 296 | assert_template 'calendar' |
|
297 | 297 | assert_not_nil assigns(:calendar) |
|
298 | 298 | end |
|
299 | 299 | |
|
300 | 300 | def test_changes |
|
301 | 301 | get :changes, :project_id => 1 |
|
302 | 302 | assert_response :success |
|
303 | 303 | assert_not_nil assigns(:journals) |
|
304 | 304 | assert_equal 'application/atom+xml', @response.content_type |
|
305 | 305 | end |
|
306 | 306 | |
|
307 | 307 | def test_show_by_anonymous |
|
308 | 308 | get :show, :id => 1 |
|
309 | 309 | assert_response :success |
|
310 | 310 | assert_template 'show.rhtml' |
|
311 | 311 | assert_not_nil assigns(:issue) |
|
312 | 312 | assert_equal Issue.find(1), assigns(:issue) |
|
313 | 313 | |
|
314 | 314 | # anonymous role is allowed to add a note |
|
315 | 315 | assert_tag :tag => 'form', |
|
316 | 316 | :descendant => { :tag => 'fieldset', |
|
317 | 317 | :child => { :tag => 'legend', |
|
318 | 318 | :content => /Notes/ } } |
|
319 | 319 | end |
|
320 | 320 | |
|
321 | 321 | def test_show_by_manager |
|
322 | 322 | @request.session[:user_id] = 2 |
|
323 | 323 | get :show, :id => 1 |
|
324 | 324 | assert_response :success |
|
325 | 325 | |
|
326 | 326 | assert_tag :tag => 'form', |
|
327 | 327 | :descendant => { :tag => 'fieldset', |
|
328 | 328 | :child => { :tag => 'legend', |
|
329 | 329 | :content => /Change properties/ } }, |
|
330 | 330 | :descendant => { :tag => 'fieldset', |
|
331 | 331 | :child => { :tag => 'legend', |
|
332 | 332 | :content => /Log time/ } }, |
|
333 | 333 | :descendant => { :tag => 'fieldset', |
|
334 | 334 | :child => { :tag => 'legend', |
|
335 | 335 | :content => /Notes/ } } |
|
336 | 336 | end |
|
337 | 337 | |
|
338 | 338 | def test_show_should_deny_anonymous_access_without_permission |
|
339 | 339 | Role.anonymous.remove_permission!(:view_issues) |
|
340 | 340 | get :show, :id => 1 |
|
341 | 341 | assert_response :redirect |
|
342 | 342 | end |
|
343 | 343 | |
|
344 | 344 | def test_show_should_deny_non_member_access_without_permission |
|
345 | 345 | Role.non_member.remove_permission!(:view_issues) |
|
346 | 346 | @request.session[:user_id] = 9 |
|
347 | 347 | get :show, :id => 1 |
|
348 | 348 | assert_response 403 |
|
349 | 349 | end |
|
350 | 350 | |
|
351 | 351 | def test_show_should_deny_member_access_without_permission |
|
352 | 352 | Role.find(1).remove_permission!(:view_issues) |
|
353 | 353 | @request.session[:user_id] = 2 |
|
354 | 354 | get :show, :id => 1 |
|
355 | 355 | assert_response 403 |
|
356 | 356 | end |
|
357 | 357 | |
|
358 | 358 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
359 | 359 | Setting.cross_project_issue_relations = '1' |
|
360 | 360 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
361 | 361 | # Relation to a private project issue |
|
362 | 362 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
363 | 363 | |
|
364 | 364 | get :show, :id => 1 |
|
365 | 365 | assert_response :success |
|
366 | 366 | |
|
367 | 367 | assert_tag :div, :attributes => { :id => 'relations' }, |
|
368 | 368 | :descendant => { :tag => 'a', :content => /#2$/ } |
|
369 | 369 | assert_no_tag :div, :attributes => { :id => 'relations' }, |
|
370 | 370 | :descendant => { :tag => 'a', :content => /#4$/ } |
|
371 | 371 | end |
|
372 | 372 | |
|
373 | 373 | def test_show_atom |
|
374 | 374 | get :show, :id => 2, :format => 'atom' |
|
375 | 375 | assert_response :success |
|
376 | 376 | assert_template 'changes.rxml' |
|
377 | 377 | # Inline image |
|
378 | 378 | assert @response.body.include?("<img src=\"http://test.host/attachments/download/10\" alt=\"\" />"), "Body did not match. Body: #{@response.body}" |
|
379 | 379 | end |
|
380 | 380 | |
|
381 | 381 | def test_show_export_to_pdf |
|
382 | 382 | get :show, :id => 3, :format => 'pdf' |
|
383 | 383 | assert_response :success |
|
384 | 384 | assert_equal 'application/pdf', @response.content_type |
|
385 | 385 | assert @response.body.starts_with?('%PDF') |
|
386 | 386 | assert_not_nil assigns(:issue) |
|
387 | 387 | end |
|
388 | 388 | |
|
389 | 389 | def test_get_new |
|
390 | 390 | @request.session[:user_id] = 2 |
|
391 | 391 | get :new, :project_id => 1, :tracker_id => 1 |
|
392 | 392 | assert_response :success |
|
393 | 393 | assert_template 'new' |
|
394 | 394 | |
|
395 | 395 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
|
396 | 396 | :value => 'Default string' } |
|
397 | 397 | end |
|
398 | 398 | |
|
399 | 399 | def test_get_new_without_tracker_id |
|
400 | 400 | @request.session[:user_id] = 2 |
|
401 | 401 | get :new, :project_id => 1 |
|
402 | 402 | assert_response :success |
|
403 | 403 | assert_template 'new' |
|
404 | 404 | |
|
405 | 405 | issue = assigns(:issue) |
|
406 | 406 | assert_not_nil issue |
|
407 | 407 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
408 | 408 | end |
|
409 | 409 | |
|
410 | 410 | def test_get_new_with_no_default_status_should_display_an_error |
|
411 | 411 | @request.session[:user_id] = 2 |
|
412 | 412 | IssueStatus.delete_all |
|
413 | 413 | |
|
414 | 414 | get :new, :project_id => 1 |
|
415 | 415 | assert_response 500 |
|
416 | 416 | assert_not_nil flash[:error] |
|
417 | 417 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
418 | 418 | :content => /No default issue/ |
|
419 | 419 | end |
|
420 | 420 | |
|
421 | 421 | def test_get_new_with_no_tracker_should_display_an_error |
|
422 | 422 | @request.session[:user_id] = 2 |
|
423 | 423 | Tracker.delete_all |
|
424 | 424 | |
|
425 | 425 | get :new, :project_id => 1 |
|
426 | 426 | assert_response 500 |
|
427 | 427 | assert_not_nil flash[:error] |
|
428 | 428 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
429 | 429 | :content => /No tracker/ |
|
430 | 430 | end |
|
431 | 431 | |
|
432 | 432 | def test_update_new_form |
|
433 | 433 | @request.session[:user_id] = 2 |
|
434 | 434 | xhr :post, :update_form, :project_id => 1, |
|
435 | 435 | :issue => {:tracker_id => 2, |
|
436 | 436 | :subject => 'This is the test_new issue', |
|
437 | 437 | :description => 'This is the description', |
|
438 | 438 | :priority_id => 5} |
|
439 | 439 | assert_response :success |
|
440 | 440 | assert_template 'attributes' |
|
441 | 441 | |
|
442 | 442 | issue = assigns(:issue) |
|
443 | 443 | assert_kind_of Issue, issue |
|
444 | 444 | assert_equal 1, issue.project_id |
|
445 | 445 | assert_equal 2, issue.tracker_id |
|
446 | 446 | assert_equal 'This is the test_new issue', issue.subject |
|
447 | 447 | end |
|
448 | 448 | |
|
449 | 449 | def test_post_new |
|
450 | 450 | @request.session[:user_id] = 2 |
|
451 | 451 | assert_difference 'Issue.count' do |
|
452 | 452 | post :new, :project_id => 1, |
|
453 | 453 | :issue => {:tracker_id => 3, |
|
454 | 454 | :subject => 'This is the test_new issue', |
|
455 | 455 | :description => 'This is the description', |
|
456 | 456 | :priority_id => 5, |
|
457 | 457 | :estimated_hours => '', |
|
458 | 458 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
459 | 459 | end |
|
460 | 460 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
461 | 461 | |
|
462 | 462 | issue = Issue.find_by_subject('This is the test_new issue') |
|
463 | 463 | assert_not_nil issue |
|
464 | 464 | assert_equal 2, issue.author_id |
|
465 | 465 | assert_equal 3, issue.tracker_id |
|
466 | 466 | assert_nil issue.estimated_hours |
|
467 | 467 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
468 | 468 | assert_not_nil v |
|
469 | 469 | assert_equal 'Value for field 2', v.value |
|
470 | 470 | end |
|
471 | 471 | |
|
472 | 472 | def test_post_new_and_continue |
|
473 | 473 | @request.session[:user_id] = 2 |
|
474 | 474 | post :new, :project_id => 1, |
|
475 | 475 | :issue => {:tracker_id => 3, |
|
476 | 476 | :subject => 'This is first issue', |
|
477 | 477 | :priority_id => 5}, |
|
478 | 478 | :continue => '' |
|
479 | 479 | assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3 |
|
480 | 480 | end |
|
481 | 481 | |
|
482 | 482 | def test_post_new_without_custom_fields_param |
|
483 | 483 | @request.session[:user_id] = 2 |
|
484 | 484 | assert_difference 'Issue.count' do |
|
485 | 485 | post :new, :project_id => 1, |
|
486 | 486 | :issue => {:tracker_id => 1, |
|
487 | 487 | :subject => 'This is the test_new issue', |
|
488 | 488 | :description => 'This is the description', |
|
489 | 489 | :priority_id => 5} |
|
490 | 490 | end |
|
491 | 491 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
492 | 492 | end |
|
493 | 493 | |
|
494 | 494 | def test_post_new_with_required_custom_field_and_without_custom_fields_param |
|
495 | 495 | field = IssueCustomField.find_by_name('Database') |
|
496 | 496 | field.update_attribute(:is_required, true) |
|
497 | 497 | |
|
498 | 498 | @request.session[:user_id] = 2 |
|
499 | 499 | post :new, :project_id => 1, |
|
500 | 500 | :issue => {:tracker_id => 1, |
|
501 | 501 | :subject => 'This is the test_new issue', |
|
502 | 502 | :description => 'This is the description', |
|
503 | 503 | :priority_id => 5} |
|
504 | 504 | assert_response :success |
|
505 | 505 | assert_template 'new' |
|
506 | 506 | issue = assigns(:issue) |
|
507 | 507 | assert_not_nil issue |
|
508 | 508 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
509 | 509 | end |
|
510 | 510 | |
|
511 | 511 | def test_post_new_with_watchers |
|
512 | 512 | @request.session[:user_id] = 2 |
|
513 | 513 | ActionMailer::Base.deliveries.clear |
|
514 | 514 | |
|
515 | 515 | assert_difference 'Watcher.count', 2 do |
|
516 | 516 | post :new, :project_id => 1, |
|
517 | 517 | :issue => {:tracker_id => 1, |
|
518 | 518 | :subject => 'This is a new issue with watchers', |
|
519 | 519 | :description => 'This is the description', |
|
520 | 520 | :priority_id => 5, |
|
521 | 521 | :watcher_user_ids => ['2', '3']} |
|
522 | 522 | end |
|
523 | 523 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
524 | 524 | assert_not_nil issue |
|
525 | 525 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
526 | 526 | |
|
527 | 527 | # Watchers added |
|
528 | 528 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
529 | 529 | assert issue.watched_by?(User.find(3)) |
|
530 | 530 | # Watchers notified |
|
531 | 531 | mail = ActionMailer::Base.deliveries.last |
|
532 | 532 | assert_kind_of TMail::Mail, mail |
|
533 | 533 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
534 | 534 | end |
|
535 | 535 | |
|
536 | 536 | def test_post_new_should_send_a_notification |
|
537 | 537 | ActionMailer::Base.deliveries.clear |
|
538 | 538 | @request.session[:user_id] = 2 |
|
539 | 539 | assert_difference 'Issue.count' do |
|
540 | 540 | post :new, :project_id => 1, |
|
541 | 541 | :issue => {:tracker_id => 3, |
|
542 | 542 | :subject => 'This is the test_new issue', |
|
543 | 543 | :description => 'This is the description', |
|
544 | 544 | :priority_id => 5, |
|
545 | 545 | :estimated_hours => '', |
|
546 | 546 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
547 | 547 | end |
|
548 | 548 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
549 | 549 | |
|
550 | 550 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
551 | 551 | end |
|
552 | 552 | |
|
553 | 553 | def test_post_should_preserve_fields_values_on_validation_failure |
|
554 | 554 | @request.session[:user_id] = 2 |
|
555 | 555 | post :new, :project_id => 1, |
|
556 | 556 | :issue => {:tracker_id => 1, |
|
557 | 557 | # empty subject |
|
558 | 558 | :subject => '', |
|
559 | 559 | :description => 'This is a description', |
|
560 | 560 | :priority_id => 6, |
|
561 | 561 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
562 | 562 | assert_response :success |
|
563 | 563 | assert_template 'new' |
|
564 | 564 | |
|
565 | 565 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
|
566 | 566 | :content => 'This is a description' |
|
567 | 567 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
568 | 568 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
569 | 569 | :value => '6' }, |
|
570 | 570 | :content => 'High' } |
|
571 | 571 | # Custom fields |
|
572 | 572 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
573 | 573 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
574 | 574 | :value => 'Oracle' }, |
|
575 | 575 | :content => 'Oracle' } |
|
576 | 576 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
577 | 577 | :value => 'Value for field 2'} |
|
578 | 578 | end |
|
579 | 579 | |
|
580 | 580 | def test_post_new_should_ignore_non_safe_attributes |
|
581 | 581 | @request.session[:user_id] = 2 |
|
582 | 582 | assert_nothing_raised do |
|
583 | 583 | post :new, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
|
584 | 584 | end |
|
585 | 585 | end |
|
586 | 586 | |
|
587 | 587 | def test_copy_issue |
|
588 | 588 | @request.session[:user_id] = 2 |
|
589 | 589 | get :new, :project_id => 1, :copy_from => 1 |
|
590 | 590 | assert_template 'new' |
|
591 | 591 | assert_not_nil assigns(:issue) |
|
592 | 592 | orig = Issue.find(1) |
|
593 | 593 | assert_equal orig.subject, assigns(:issue).subject |
|
594 | 594 | end |
|
595 | 595 | |
|
596 | 596 | def test_get_edit |
|
597 | 597 | @request.session[:user_id] = 2 |
|
598 | 598 | get :edit, :id => 1 |
|
599 | 599 | assert_response :success |
|
600 | 600 | assert_template 'edit' |
|
601 | 601 | assert_not_nil assigns(:issue) |
|
602 | 602 | assert_equal Issue.find(1), assigns(:issue) |
|
603 | 603 | end |
|
604 | 604 | |
|
605 | 605 | def test_get_edit_with_params |
|
606 | 606 | @request.session[:user_id] = 2 |
|
607 | 607 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } |
|
608 | 608 | assert_response :success |
|
609 | 609 | assert_template 'edit' |
|
610 | 610 | |
|
611 | 611 | issue = assigns(:issue) |
|
612 | 612 | assert_not_nil issue |
|
613 | 613 | |
|
614 | 614 | assert_equal 5, issue.status_id |
|
615 | 615 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
616 | 616 | :child => { :tag => 'option', |
|
617 | 617 | :content => 'Closed', |
|
618 | 618 | :attributes => { :selected => 'selected' } } |
|
619 | 619 | |
|
620 | 620 | assert_equal 7, issue.priority_id |
|
621 | 621 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
622 | 622 | :child => { :tag => 'option', |
|
623 | 623 | :content => 'Urgent', |
|
624 | 624 | :attributes => { :selected => 'selected' } } |
|
625 | 625 | end |
|
626 | 626 | |
|
627 | 627 | def test_update_edit_form |
|
628 | 628 | @request.session[:user_id] = 2 |
|
629 | 629 | xhr :post, :update_form, :project_id => 1, |
|
630 | 630 | :id => 1, |
|
631 | 631 | :issue => {:tracker_id => 2, |
|
632 | 632 | :subject => 'This is the test_new issue', |
|
633 | 633 | :description => 'This is the description', |
|
634 | 634 | :priority_id => 5} |
|
635 | 635 | assert_response :success |
|
636 | 636 | assert_template 'attributes' |
|
637 | 637 | |
|
638 | 638 | issue = assigns(:issue) |
|
639 | 639 | assert_kind_of Issue, issue |
|
640 | 640 | assert_equal 1, issue.id |
|
641 | 641 | assert_equal 1, issue.project_id |
|
642 | 642 | assert_equal 2, issue.tracker_id |
|
643 | 643 | assert_equal 'This is the test_new issue', issue.subject |
|
644 | 644 | end |
|
645 | 645 | |
|
646 | 646 | def test_reply_to_issue |
|
647 | 647 | @request.session[:user_id] = 2 |
|
648 | 648 | get :reply, :id => 1 |
|
649 | 649 | assert_response :success |
|
650 | 650 | assert_select_rjs :show, "update" |
|
651 | 651 | end |
|
652 | 652 | |
|
653 | 653 | def test_reply_to_note |
|
654 | 654 | @request.session[:user_id] = 2 |
|
655 | 655 | get :reply, :id => 1, :journal_id => 2 |
|
656 | 656 | assert_response :success |
|
657 | 657 | assert_select_rjs :show, "update" |
|
658 | 658 | end |
|
659 | 659 | |
|
660 |
def test_p |
|
|
660 | def test_put_update_without_custom_fields_param | |
|
661 | 661 | @request.session[:user_id] = 2 |
|
662 | 662 | ActionMailer::Base.deliveries.clear |
|
663 | 663 | |
|
664 | 664 | issue = Issue.find(1) |
|
665 | 665 | assert_equal '125', issue.custom_value_for(2).value |
|
666 | 666 | old_subject = issue.subject |
|
667 | 667 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
668 | 668 | |
|
669 | 669 | assert_difference('Journal.count') do |
|
670 | 670 | assert_difference('JournalDetail.count', 2) do |
|
671 |
p |
|
|
671 | put :update, :id => 1, :issue => {:subject => new_subject, | |
|
672 | 672 | :priority_id => '6', |
|
673 | 673 | :category_id => '1' # no change |
|
674 | 674 | } |
|
675 | 675 | end |
|
676 | 676 | end |
|
677 | 677 | assert_redirected_to :action => 'show', :id => '1' |
|
678 | 678 | issue.reload |
|
679 | 679 | assert_equal new_subject, issue.subject |
|
680 | 680 | # Make sure custom fields were not cleared |
|
681 | 681 | assert_equal '125', issue.custom_value_for(2).value |
|
682 | 682 | |
|
683 | 683 | mail = ActionMailer::Base.deliveries.last |
|
684 | 684 | assert_kind_of TMail::Mail, mail |
|
685 | 685 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
686 | 686 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
|
687 | 687 | end |
|
688 | 688 | |
|
689 |
def test_p |
|
|
689 | def test_put_update_with_custom_field_change | |
|
690 | 690 | @request.session[:user_id] = 2 |
|
691 | 691 | issue = Issue.find(1) |
|
692 | 692 | assert_equal '125', issue.custom_value_for(2).value |
|
693 | 693 | |
|
694 | 694 | assert_difference('Journal.count') do |
|
695 | 695 | assert_difference('JournalDetail.count', 3) do |
|
696 |
p |
|
|
696 | put :update, :id => 1, :issue => {:subject => 'Custom field change', | |
|
697 | 697 | :priority_id => '6', |
|
698 | 698 | :category_id => '1', # no change |
|
699 | 699 | :custom_field_values => { '2' => 'New custom value' } |
|
700 | 700 | } |
|
701 | 701 | end |
|
702 | 702 | end |
|
703 | 703 | assert_redirected_to :action => 'show', :id => '1' |
|
704 | 704 | issue.reload |
|
705 | 705 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
706 | 706 | |
|
707 | 707 | mail = ActionMailer::Base.deliveries.last |
|
708 | 708 | assert_kind_of TMail::Mail, mail |
|
709 | 709 | assert mail.body.include?("Searchable field changed from 125 to New custom value") |
|
710 | 710 | end |
|
711 | 711 | |
|
712 |
def test_p |
|
|
712 | def test_put_update_with_status_and_assignee_change | |
|
713 | 713 | issue = Issue.find(1) |
|
714 | 714 | assert_equal 1, issue.status_id |
|
715 | 715 | @request.session[:user_id] = 2 |
|
716 | 716 | assert_difference('TimeEntry.count', 0) do |
|
717 |
p |
|
|
717 | put :update, | |
|
718 | 718 | :id => 1, |
|
719 | 719 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
720 | 720 | :notes => 'Assigned to dlopper', |
|
721 | 721 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
722 | 722 | end |
|
723 | 723 | assert_redirected_to :action => 'show', :id => '1' |
|
724 | 724 | issue.reload |
|
725 | 725 | assert_equal 2, issue.status_id |
|
726 | 726 | j = Journal.find(:first, :order => 'id DESC') |
|
727 | 727 | assert_equal 'Assigned to dlopper', j.notes |
|
728 | 728 | assert_equal 2, j.details.size |
|
729 | 729 | |
|
730 | 730 | mail = ActionMailer::Base.deliveries.last |
|
731 | 731 | assert mail.body.include?("Status changed from New to Assigned") |
|
732 | 732 | # subject should contain the new status |
|
733 | 733 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
734 | 734 | end |
|
735 | 735 | |
|
736 |
def test_p |
|
|
736 | def test_put_update_with_note_only | |
|
737 | 737 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
738 | 738 | # anonymous user |
|
739 |
p |
|
|
739 | put :update, | |
|
740 | 740 | :id => 1, |
|
741 | 741 | :notes => notes |
|
742 | 742 | assert_redirected_to :action => 'show', :id => '1' |
|
743 | 743 | j = Journal.find(:first, :order => 'id DESC') |
|
744 | 744 | assert_equal notes, j.notes |
|
745 | 745 | assert_equal 0, j.details.size |
|
746 | 746 | assert_equal User.anonymous, j.user |
|
747 | 747 | |
|
748 | 748 | mail = ActionMailer::Base.deliveries.last |
|
749 | 749 | assert mail.body.include?(notes) |
|
750 | 750 | end |
|
751 | 751 | |
|
752 |
def test_p |
|
|
752 | def test_put_update_with_note_and_spent_time | |
|
753 | 753 | @request.session[:user_id] = 2 |
|
754 | 754 | spent_hours_before = Issue.find(1).spent_hours |
|
755 | 755 | assert_difference('TimeEntry.count') do |
|
756 |
p |
|
|
756 | put :update, | |
|
757 | 757 | :id => 1, |
|
758 | 758 | :notes => '2.5 hours added', |
|
759 | 759 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first } |
|
760 | 760 | end |
|
761 | 761 | assert_redirected_to :action => 'show', :id => '1' |
|
762 | 762 | |
|
763 | 763 | issue = Issue.find(1) |
|
764 | 764 | |
|
765 | 765 | j = Journal.find(:first, :order => 'id DESC') |
|
766 | 766 | assert_equal '2.5 hours added', j.notes |
|
767 | 767 | assert_equal 0, j.details.size |
|
768 | 768 | |
|
769 | 769 | t = issue.time_entries.find(:first, :order => 'id DESC') |
|
770 | 770 | assert_not_nil t |
|
771 | 771 | assert_equal 2.5, t.hours |
|
772 | 772 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
773 | 773 | end |
|
774 | 774 | |
|
775 |
def test_p |
|
|
775 | def test_put_update_with_attachment_only | |
|
776 | 776 | set_tmp_attachments_directory |
|
777 | 777 | |
|
778 | 778 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
779 | 779 | # journal to get fetched in the next find. |
|
780 | 780 | Journal.delete_all |
|
781 | 781 | |
|
782 | 782 | # anonymous user |
|
783 |
p |
|
|
783 | put :update, | |
|
784 | 784 | :id => 1, |
|
785 | 785 | :notes => '', |
|
786 | 786 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
787 | 787 | assert_redirected_to :action => 'show', :id => '1' |
|
788 | 788 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
789 | 789 | assert j.notes.blank? |
|
790 | 790 | assert_equal 1, j.details.size |
|
791 | 791 | assert_equal 'testfile.txt', j.details.first.value |
|
792 | 792 | assert_equal User.anonymous, j.user |
|
793 | 793 | |
|
794 | 794 | mail = ActionMailer::Base.deliveries.last |
|
795 | 795 | assert mail.body.include?('testfile.txt') |
|
796 | 796 | end |
|
797 | 797 | |
|
798 |
def test_p |
|
|
798 | def test_put_update_with_no_change | |
|
799 | 799 | issue = Issue.find(1) |
|
800 | 800 | issue.journals.clear |
|
801 | 801 | ActionMailer::Base.deliveries.clear |
|
802 | 802 | |
|
803 |
p |
|
|
803 | put :update, | |
|
804 | 804 | :id => 1, |
|
805 | 805 | :notes => '' |
|
806 | 806 | assert_redirected_to :action => 'show', :id => '1' |
|
807 | 807 | |
|
808 | 808 | issue.reload |
|
809 | 809 | assert issue.journals.empty? |
|
810 | 810 | # No email should be sent |
|
811 | 811 | assert ActionMailer::Base.deliveries.empty? |
|
812 | 812 | end |
|
813 | 813 | |
|
814 |
def test_p |
|
|
814 | def test_put_update_should_send_a_notification | |
|
815 | 815 | @request.session[:user_id] = 2 |
|
816 | 816 | ActionMailer::Base.deliveries.clear |
|
817 | 817 | issue = Issue.find(1) |
|
818 | 818 | old_subject = issue.subject |
|
819 | 819 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
820 | 820 | |
|
821 |
p |
|
|
821 | put :update, :id => 1, :issue => {:subject => new_subject, | |
|
822 | 822 | :priority_id => '6', |
|
823 | 823 | :category_id => '1' # no change |
|
824 | 824 | } |
|
825 | 825 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
826 | 826 | end |
|
827 | 827 | |
|
828 |
def test_p |
|
|
828 | def test_put_update_with_invalid_spent_time | |
|
829 | 829 | @request.session[:user_id] = 2 |
|
830 | 830 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
831 | 831 | |
|
832 | 832 | assert_no_difference('Journal.count') do |
|
833 |
p |
|
|
833 | put :update, | |
|
834 | 834 | :id => 1, |
|
835 | 835 | :notes => notes, |
|
836 | 836 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
837 | 837 | end |
|
838 | 838 | assert_response :success |
|
839 | 839 | assert_template 'edit' |
|
840 | 840 | |
|
841 | 841 | assert_tag :textarea, :attributes => { :name => 'notes' }, |
|
842 | 842 | :content => notes |
|
843 | 843 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } |
|
844 | 844 | end |
|
845 | 845 | |
|
846 |
def test_p |
|
|
846 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
|
847 | 847 | issue = Issue.find(2) |
|
848 | 848 | @request.session[:user_id] = 2 |
|
849 | 849 | |
|
850 |
p |
|
|
850 | put :update, | |
|
851 | 851 | :id => issue.id, |
|
852 | 852 | :issue => { |
|
853 | 853 | :fixed_version_id => 4 |
|
854 | 854 | } |
|
855 | 855 | |
|
856 | 856 | assert_response :redirect |
|
857 | 857 | issue.reload |
|
858 | 858 | assert_equal 4, issue.fixed_version_id |
|
859 | 859 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
860 | 860 | end |
|
861 | 861 | |
|
862 |
def test_p |
|
|
862 | def test_put_update_should_redirect_back_using_the_back_url_parameter | |
|
863 | 863 | issue = Issue.find(2) |
|
864 | 864 | @request.session[:user_id] = 2 |
|
865 | 865 | |
|
866 |
p |
|
|
866 | put :update, | |
|
867 | 867 | :id => issue.id, |
|
868 | 868 | :issue => { |
|
869 | 869 | :fixed_version_id => 4 |
|
870 | 870 | }, |
|
871 | 871 | :back_url => '/issues' |
|
872 | 872 | |
|
873 | 873 | assert_response :redirect |
|
874 | 874 | assert_redirected_to '/issues' |
|
875 | 875 | end |
|
876 | 876 | |
|
877 |
def test_p |
|
|
877 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
|
878 | 878 | issue = Issue.find(2) |
|
879 | 879 | @request.session[:user_id] = 2 |
|
880 | 880 | |
|
881 |
p |
|
|
881 | put :update, | |
|
882 | 882 | :id => issue.id, |
|
883 | 883 | :issue => { |
|
884 | 884 | :fixed_version_id => 4 |
|
885 | 885 | }, |
|
886 | 886 | :back_url => 'http://google.com' |
|
887 | 887 | |
|
888 | 888 | assert_response :redirect |
|
889 | 889 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
|
890 | 890 | end |
|
891 | 891 | |
|
892 | 892 | def test_get_bulk_edit |
|
893 | 893 | @request.session[:user_id] = 2 |
|
894 | 894 | get :bulk_edit, :ids => [1, 2] |
|
895 | 895 | assert_response :success |
|
896 | 896 | assert_template 'bulk_edit' |
|
897 | 897 | |
|
898 | 898 | # Project specific custom field, date type |
|
899 | 899 | field = CustomField.find(9) |
|
900 | 900 | assert !field.is_for_all? |
|
901 | 901 | assert_equal 'date', field.field_format |
|
902 | 902 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
|
903 | 903 | |
|
904 | 904 | # System wide custom field |
|
905 | 905 | assert CustomField.find(1).is_for_all? |
|
906 | 906 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
|
907 | 907 | end |
|
908 | 908 | |
|
909 | 909 | def test_bulk_edit |
|
910 | 910 | @request.session[:user_id] = 2 |
|
911 | 911 | # update issues priority |
|
912 | 912 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing', |
|
913 | 913 | :issue => {:priority_id => 7, |
|
914 | 914 | :assigned_to_id => '', |
|
915 | 915 | :custom_field_values => {'2' => ''}} |
|
916 | 916 | |
|
917 | 917 | assert_response 302 |
|
918 | 918 | # check that the issues were updated |
|
919 | 919 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
920 | 920 | |
|
921 | 921 | issue = Issue.find(1) |
|
922 | 922 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
923 | 923 | assert_equal '125', issue.custom_value_for(2).value |
|
924 | 924 | assert_equal 'Bulk editing', journal.notes |
|
925 | 925 | assert_equal 1, journal.details.size |
|
926 | 926 | end |
|
927 | 927 | |
|
928 | 928 | def test_bullk_edit_should_send_a_notification |
|
929 | 929 | @request.session[:user_id] = 2 |
|
930 | 930 | ActionMailer::Base.deliveries.clear |
|
931 | 931 | post(:bulk_edit, |
|
932 | 932 | { |
|
933 | 933 | :ids => [1, 2], |
|
934 | 934 | :notes => 'Bulk editing', |
|
935 | 935 | :issue => { |
|
936 | 936 | :priority_id => 7, |
|
937 | 937 | :assigned_to_id => '', |
|
938 | 938 | :custom_field_values => {'2' => ''} |
|
939 | 939 | } |
|
940 | 940 | }) |
|
941 | 941 | |
|
942 | 942 | assert_response 302 |
|
943 | 943 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
944 | 944 | end |
|
945 | 945 | |
|
946 | 946 | def test_bulk_edit_status |
|
947 | 947 | @request.session[:user_id] = 2 |
|
948 | 948 | # update issues priority |
|
949 | 949 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing status', |
|
950 | 950 | :issue => {:priority_id => '', |
|
951 | 951 | :assigned_to_id => '', |
|
952 | 952 | :status_id => '5'} |
|
953 | 953 | |
|
954 | 954 | assert_response 302 |
|
955 | 955 | issue = Issue.find(1) |
|
956 | 956 | assert issue.closed? |
|
957 | 957 | end |
|
958 | 958 | |
|
959 | 959 | def test_bulk_edit_custom_field |
|
960 | 960 | @request.session[:user_id] = 2 |
|
961 | 961 | # update issues priority |
|
962 | 962 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing custom field', |
|
963 | 963 | :issue => {:priority_id => '', |
|
964 | 964 | :assigned_to_id => '', |
|
965 | 965 | :custom_field_values => {'2' => '777'}} |
|
966 | 966 | |
|
967 | 967 | assert_response 302 |
|
968 | 968 | |
|
969 | 969 | issue = Issue.find(1) |
|
970 | 970 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
971 | 971 | assert_equal '777', issue.custom_value_for(2).value |
|
972 | 972 | assert_equal 1, journal.details.size |
|
973 | 973 | assert_equal '125', journal.details.first.old_value |
|
974 | 974 | assert_equal '777', journal.details.first.value |
|
975 | 975 | end |
|
976 | 976 | |
|
977 | 977 | def test_bulk_unassign |
|
978 | 978 | assert_not_nil Issue.find(2).assigned_to |
|
979 | 979 | @request.session[:user_id] = 2 |
|
980 | 980 | # unassign issues |
|
981 | 981 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
|
982 | 982 | assert_response 302 |
|
983 | 983 | # check that the issues were updated |
|
984 | 984 | assert_nil Issue.find(2).assigned_to |
|
985 | 985 | end |
|
986 | 986 | |
|
987 | 987 | def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject |
|
988 | 988 | @request.session[:user_id] = 2 |
|
989 | 989 | |
|
990 | 990 | post :bulk_edit, :ids => [1,2], :issue => {:fixed_version_id => 4} |
|
991 | 991 | |
|
992 | 992 | assert_response :redirect |
|
993 | 993 | issues = Issue.find([1,2]) |
|
994 | 994 | issues.each do |issue| |
|
995 | 995 | assert_equal 4, issue.fixed_version_id |
|
996 | 996 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
997 | 997 | end |
|
998 | 998 | end |
|
999 | 999 | |
|
1000 | 1000 | def test_post_bulk_edit_should_redirect_back_using_the_back_url_parameter |
|
1001 | 1001 | @request.session[:user_id] = 2 |
|
1002 | 1002 | post :bulk_edit, :ids => [1,2], :back_url => '/issues' |
|
1003 | 1003 | |
|
1004 | 1004 | assert_response :redirect |
|
1005 | 1005 | assert_redirected_to '/issues' |
|
1006 | 1006 | end |
|
1007 | 1007 | |
|
1008 | 1008 | def test_post_bulk_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
1009 | 1009 | @request.session[:user_id] = 2 |
|
1010 | 1010 | post :bulk_edit, :ids => [1,2], :back_url => 'http://google.com' |
|
1011 | 1011 | |
|
1012 | 1012 | assert_response :redirect |
|
1013 | 1013 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
|
1014 | 1014 | end |
|
1015 | 1015 | |
|
1016 | 1016 | def test_move_one_issue_to_another_project |
|
1017 | 1017 | @request.session[:user_id] = 2 |
|
1018 | 1018 | post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' |
|
1019 | 1019 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1020 | 1020 | assert_equal 2, Issue.find(1).project_id |
|
1021 | 1021 | end |
|
1022 | 1022 | |
|
1023 | 1023 | def test_move_one_issue_to_another_project_should_follow_when_needed |
|
1024 | 1024 | @request.session[:user_id] = 2 |
|
1025 | 1025 | post :move, :id => 1, :new_project_id => 2, :follow => '1' |
|
1026 | 1026 | assert_redirected_to '/issues/1' |
|
1027 | 1027 | end |
|
1028 | 1028 | |
|
1029 | 1029 | def test_bulk_move_to_another_project |
|
1030 | 1030 | @request.session[:user_id] = 2 |
|
1031 | 1031 | post :move, :ids => [1, 2], :new_project_id => 2 |
|
1032 | 1032 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1033 | 1033 | # Issues moved to project 2 |
|
1034 | 1034 | assert_equal 2, Issue.find(1).project_id |
|
1035 | 1035 | assert_equal 2, Issue.find(2).project_id |
|
1036 | 1036 | # No tracker change |
|
1037 | 1037 | assert_equal 1, Issue.find(1).tracker_id |
|
1038 | 1038 | assert_equal 2, Issue.find(2).tracker_id |
|
1039 | 1039 | end |
|
1040 | 1040 | |
|
1041 | 1041 | def test_bulk_move_to_another_tracker |
|
1042 | 1042 | @request.session[:user_id] = 2 |
|
1043 | 1043 | post :move, :ids => [1, 2], :new_tracker_id => 2 |
|
1044 | 1044 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1045 | 1045 | assert_equal 2, Issue.find(1).tracker_id |
|
1046 | 1046 | assert_equal 2, Issue.find(2).tracker_id |
|
1047 | 1047 | end |
|
1048 | 1048 | |
|
1049 | 1049 | def test_bulk_copy_to_another_project |
|
1050 | 1050 | @request.session[:user_id] = 2 |
|
1051 | 1051 | assert_difference 'Issue.count', 2 do |
|
1052 | 1052 | assert_no_difference 'Project.find(1).issues.count' do |
|
1053 | 1053 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} |
|
1054 | 1054 | end |
|
1055 | 1055 | end |
|
1056 | 1056 | assert_redirected_to 'projects/ecookbook/issues' |
|
1057 | 1057 | end |
|
1058 | 1058 | |
|
1059 | 1059 | context "#move via bulk copy" do |
|
1060 | 1060 | should "allow not changing the issue's attributes" do |
|
1061 | 1061 | @request.session[:user_id] = 2 |
|
1062 | 1062 | issue_before_move = Issue.find(1) |
|
1063 | 1063 | assert_difference 'Issue.count', 1 do |
|
1064 | 1064 | assert_no_difference 'Project.find(1).issues.count' do |
|
1065 | 1065 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' |
|
1066 | 1066 | end |
|
1067 | 1067 | end |
|
1068 | 1068 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) |
|
1069 | 1069 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id |
|
1070 | 1070 | assert_equal issue_before_move.status_id, issue_after_move.status_id |
|
1071 | 1071 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id |
|
1072 | 1072 | end |
|
1073 | 1073 | |
|
1074 | 1074 | should "allow changing the issue's attributes" do |
|
1075 | 1075 | @request.session[:user_id] = 2 |
|
1076 | 1076 | assert_difference 'Issue.count', 2 do |
|
1077 | 1077 | assert_no_difference 'Project.find(1).issues.count' do |
|
1078 | 1078 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
1079 | 1079 | end |
|
1080 | 1080 | end |
|
1081 | 1081 | |
|
1082 | 1082 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) |
|
1083 | 1083 | assert_equal 2, copied_issues.size |
|
1084 | 1084 | copied_issues.each do |issue| |
|
1085 | 1085 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
1086 | 1086 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
1087 | 1087 | assert_equal 3, issue.status_id, "Status is incorrect" |
|
1088 | 1088 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
1089 | 1089 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
1090 | 1090 | end |
|
1091 | 1091 | end |
|
1092 | 1092 | end |
|
1093 | 1093 | |
|
1094 | 1094 | def test_copy_to_another_project_should_follow_when_needed |
|
1095 | 1095 | @request.session[:user_id] = 2 |
|
1096 | 1096 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' |
|
1097 | 1097 | issue = Issue.first(:order => 'id DESC') |
|
1098 | 1098 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
1099 | 1099 | end |
|
1100 | 1100 | |
|
1101 | 1101 | def test_context_menu_one_issue |
|
1102 | 1102 | @request.session[:user_id] = 2 |
|
1103 | 1103 | get :context_menu, :ids => [1] |
|
1104 | 1104 | assert_response :success |
|
1105 | 1105 | assert_template 'context_menu' |
|
1106 | 1106 | assert_tag :tag => 'a', :content => 'Edit', |
|
1107 | 1107 | :attributes => { :href => '/issues/1/edit', |
|
1108 | 1108 | :class => 'icon-edit' } |
|
1109 | 1109 | assert_tag :tag => 'a', :content => 'Closed', |
|
1110 | 1110 | :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5', |
|
1111 | 1111 | :class => '' } |
|
1112 | 1112 | assert_tag :tag => 'a', :content => 'Immediate', |
|
1113 | 1113 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8', |
|
1114 | 1114 | :class => '' } |
|
1115 | 1115 | # Versions |
|
1116 | 1116 | assert_tag :tag => 'a', :content => '2.0', |
|
1117 | 1117 | :attributes => { :href => '/issues/bulk_edit?fixed_version_id=3&ids%5B%5D=1', |
|
1118 | 1118 | :class => '' } |
|
1119 | 1119 | assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0', |
|
1120 | 1120 | :attributes => { :href => '/issues/bulk_edit?fixed_version_id=4&ids%5B%5D=1', |
|
1121 | 1121 | :class => '' } |
|
1122 | 1122 | |
|
1123 | 1123 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
1124 | 1124 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1', |
|
1125 | 1125 | :class => '' } |
|
1126 | 1126 | assert_tag :tag => 'a', :content => 'Duplicate', |
|
1127 | 1127 | :attributes => { :href => '/projects/ecookbook/issues/1/copy', |
|
1128 | 1128 | :class => 'icon-duplicate' } |
|
1129 | 1129 | assert_tag :tag => 'a', :content => 'Copy', |
|
1130 | 1130 | :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1', |
|
1131 | 1131 | :class => 'icon-copy' } |
|
1132 | 1132 | assert_tag :tag => 'a', :content => 'Move', |
|
1133 | 1133 | :attributes => { :href => '/issues/move?ids%5B%5D=1', |
|
1134 | 1134 | :class => 'icon-move' } |
|
1135 | 1135 | assert_tag :tag => 'a', :content => 'Delete', |
|
1136 | 1136 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', |
|
1137 | 1137 | :class => 'icon-del' } |
|
1138 | 1138 | end |
|
1139 | 1139 | |
|
1140 | 1140 | def test_context_menu_one_issue_by_anonymous |
|
1141 | 1141 | get :context_menu, :ids => [1] |
|
1142 | 1142 | assert_response :success |
|
1143 | 1143 | assert_template 'context_menu' |
|
1144 | 1144 | assert_tag :tag => 'a', :content => 'Delete', |
|
1145 | 1145 | :attributes => { :href => '#', |
|
1146 | 1146 | :class => 'icon-del disabled' } |
|
1147 | 1147 | end |
|
1148 | 1148 | |
|
1149 | 1149 | def test_context_menu_multiple_issues_of_same_project |
|
1150 | 1150 | @request.session[:user_id] = 2 |
|
1151 | 1151 | get :context_menu, :ids => [1, 2] |
|
1152 | 1152 | assert_response :success |
|
1153 | 1153 | assert_template 'context_menu' |
|
1154 | 1154 | assert_tag :tag => 'a', :content => 'Edit', |
|
1155 | 1155 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', |
|
1156 | 1156 | :class => 'icon-edit' } |
|
1157 | 1157 | assert_tag :tag => 'a', :content => 'Immediate', |
|
1158 | 1158 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8', |
|
1159 | 1159 | :class => '' } |
|
1160 | 1160 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
1161 | 1161 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2', |
|
1162 | 1162 | :class => '' } |
|
1163 | 1163 | assert_tag :tag => 'a', :content => 'Copy', |
|
1164 | 1164 | :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1&ids%5B%5D=2', |
|
1165 | 1165 | :class => 'icon-copy' } |
|
1166 | 1166 | assert_tag :tag => 'a', :content => 'Move', |
|
1167 | 1167 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', |
|
1168 | 1168 | :class => 'icon-move' } |
|
1169 | 1169 | assert_tag :tag => 'a', :content => 'Delete', |
|
1170 | 1170 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', |
|
1171 | 1171 | :class => 'icon-del' } |
|
1172 | 1172 | end |
|
1173 | 1173 | |
|
1174 | 1174 | def test_context_menu_multiple_issues_of_different_project |
|
1175 | 1175 | @request.session[:user_id] = 2 |
|
1176 | 1176 | get :context_menu, :ids => [1, 2, 4] |
|
1177 | 1177 | assert_response :success |
|
1178 | 1178 | assert_template 'context_menu' |
|
1179 | 1179 | assert_tag :tag => 'a', :content => 'Delete', |
|
1180 | 1180 | :attributes => { :href => '#', |
|
1181 | 1181 | :class => 'icon-del disabled' } |
|
1182 | 1182 | end |
|
1183 | 1183 | |
|
1184 | 1184 | def test_destroy_issue_with_no_time_entries |
|
1185 | 1185 | assert_nil TimeEntry.find_by_issue_id(2) |
|
1186 | 1186 | @request.session[:user_id] = 2 |
|
1187 | 1187 | post :destroy, :id => 2 |
|
1188 | 1188 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1189 | 1189 | assert_nil Issue.find_by_id(2) |
|
1190 | 1190 | end |
|
1191 | 1191 | |
|
1192 | 1192 | def test_destroy_issues_with_time_entries |
|
1193 | 1193 | @request.session[:user_id] = 2 |
|
1194 | 1194 | post :destroy, :ids => [1, 3] |
|
1195 | 1195 | assert_response :success |
|
1196 | 1196 | assert_template 'destroy' |
|
1197 | 1197 | assert_not_nil assigns(:hours) |
|
1198 | 1198 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
1199 | 1199 | end |
|
1200 | 1200 | |
|
1201 | 1201 | def test_destroy_issues_and_destroy_time_entries |
|
1202 | 1202 | @request.session[:user_id] = 2 |
|
1203 | 1203 | post :destroy, :ids => [1, 3], :todo => 'destroy' |
|
1204 | 1204 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1205 | 1205 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1206 | 1206 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
1207 | 1207 | end |
|
1208 | 1208 | |
|
1209 | 1209 | def test_destroy_issues_and_assign_time_entries_to_project |
|
1210 | 1210 | @request.session[:user_id] = 2 |
|
1211 | 1211 | post :destroy, :ids => [1, 3], :todo => 'nullify' |
|
1212 | 1212 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1213 | 1213 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1214 | 1214 | assert_nil TimeEntry.find(1).issue_id |
|
1215 | 1215 | assert_nil TimeEntry.find(2).issue_id |
|
1216 | 1216 | end |
|
1217 | 1217 | |
|
1218 | 1218 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
1219 | 1219 | @request.session[:user_id] = 2 |
|
1220 | 1220 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
1221 | 1221 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1222 | 1222 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1223 | 1223 | assert_equal 2, TimeEntry.find(1).issue_id |
|
1224 | 1224 | assert_equal 2, TimeEntry.find(2).issue_id |
|
1225 | 1225 | end |
|
1226 | 1226 | |
|
1227 | 1227 | def test_default_search_scope |
|
1228 | 1228 | get :index |
|
1229 | 1229 | assert_tag :div, :attributes => {:id => 'quick-search'}, |
|
1230 | 1230 | :child => {:tag => 'form', |
|
1231 | 1231 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |
|
1232 | 1232 | end |
|
1233 | 1233 | end |
General Comments 0
You need to be logged in to leave comments.
Login now