@@ -1,1321 +1,1321 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | require 'forwardable' |
|
21 | 21 | require 'cgi' |
|
22 | 22 | |
|
23 | 23 | module ApplicationHelper |
|
24 | 24 | include Redmine::WikiFormatting::Macros::Definitions |
|
25 | 25 | include Redmine::I18n |
|
26 | 26 | include GravatarHelper::PublicMethods |
|
27 | 27 | include Redmine::Pagination::Helper |
|
28 | 28 | |
|
29 | 29 | extend Forwardable |
|
30 | 30 | def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter |
|
31 | 31 | |
|
32 | 32 | # Return true if user is authorized for controller/action, otherwise false |
|
33 | 33 | def authorize_for(controller, action) |
|
34 | 34 | User.current.allowed_to?({:controller => controller, :action => action}, @project) |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | # Display a link if user is authorized |
|
38 | 38 | # |
|
39 | 39 | # @param [String] name Anchor text (passed to link_to) |
|
40 | 40 | # @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized |
|
41 | 41 | # @param [optional, Hash] html_options Options passed to link_to |
|
42 | 42 | # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to |
|
43 | 43 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) |
|
44 | 44 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | # Displays a link to user's account page if active |
|
48 | 48 | def link_to_user(user, options={}) |
|
49 | 49 | if user.is_a?(User) |
|
50 | 50 | name = h(user.name(options[:format])) |
|
51 | 51 | if user.active? || (User.current.admin? && user.logged?) |
|
52 | 52 | link_to name, user_path(user), :class => user.css_classes |
|
53 | 53 | else |
|
54 | 54 | name |
|
55 | 55 | end |
|
56 | 56 | else |
|
57 | 57 | h(user.to_s) |
|
58 | 58 | end |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | # Displays a link to +issue+ with its subject. |
|
62 | 62 | # Examples: |
|
63 | 63 | # |
|
64 | 64 | # link_to_issue(issue) # => Defect #6: This is the subject |
|
65 | 65 | # link_to_issue(issue, :truncate => 6) # => Defect #6: This i... |
|
66 | 66 | # link_to_issue(issue, :subject => false) # => Defect #6 |
|
67 | 67 | # link_to_issue(issue, :project => true) # => Foo - Defect #6 |
|
68 | 68 | # link_to_issue(issue, :subject => false, :tracker => false) # => #6 |
|
69 | 69 | # |
|
70 | 70 | def link_to_issue(issue, options={}) |
|
71 | 71 | title = nil |
|
72 | 72 | subject = nil |
|
73 | 73 | text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}" |
|
74 | 74 | if options[:subject] == false |
|
75 | 75 | title = issue.subject.truncate(60) |
|
76 | 76 | else |
|
77 | 77 | subject = issue.subject |
|
78 | 78 | if truncate_length = options[:truncate] |
|
79 | 79 | subject = subject.truncate(truncate_length) |
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | only_path = options[:only_path].nil? ? true : options[:only_path] |
|
83 | 83 | s = link_to(text, issue_url(issue, :only_path => only_path), |
|
84 | 84 | :class => issue.css_classes, :title => title) |
|
85 | 85 | s << h(": #{subject}") if subject |
|
86 | 86 | s = h("#{issue.project} - ") + s if options[:project] |
|
87 | 87 | s |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | # Generates a link to an attachment. |
|
91 | 91 | # Options: |
|
92 | 92 | # * :text - Link text (default to attachment filename) |
|
93 | 93 | # * :download - Force download (default: false) |
|
94 | 94 | def link_to_attachment(attachment, options={}) |
|
95 | 95 | text = options.delete(:text) || attachment.filename |
|
96 | 96 | route_method = options.delete(:download) ? :download_named_attachment_url : :named_attachment_url |
|
97 | 97 | html_options = options.slice!(:only_path) |
|
98 | 98 | options[:only_path] = true unless options.key?(:only_path) |
|
99 | 99 | url = send(route_method, attachment, attachment.filename, options) |
|
100 | 100 | link_to text, url, html_options |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | # Generates a link to a SCM revision |
|
104 | 104 | # Options: |
|
105 | 105 | # * :text - Link text (default to the formatted revision) |
|
106 | 106 | def link_to_revision(revision, repository, options={}) |
|
107 | 107 | if repository.is_a?(Project) |
|
108 | 108 | repository = repository.repository |
|
109 | 109 | end |
|
110 | 110 | text = options.delete(:text) || format_revision(revision) |
|
111 | 111 | rev = revision.respond_to?(:identifier) ? revision.identifier : revision |
|
112 | 112 | link_to( |
|
113 | 113 | h(text), |
|
114 | 114 | {:controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev}, |
|
115 | 115 | :title => l(:label_revision_id, format_revision(revision)), |
|
116 | 116 | :accesskey => options[:accesskey] |
|
117 | 117 | ) |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | # Generates a link to a message |
|
121 | 121 | def link_to_message(message, options={}, html_options = nil) |
|
122 | 122 | link_to( |
|
123 | 123 | message.subject.truncate(60), |
|
124 | 124 | board_message_url(message.board_id, message.parent_id || message.id, { |
|
125 | 125 | :r => (message.parent_id && message.id), |
|
126 | 126 | :anchor => (message.parent_id ? "message-#{message.id}" : nil), |
|
127 | 127 | :only_path => true |
|
128 | 128 | }.merge(options)), |
|
129 | 129 | html_options |
|
130 | 130 | ) |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | # Generates a link to a project if active |
|
134 | 134 | # Examples: |
|
135 | 135 | # |
|
136 | 136 | # link_to_project(project) # => link to the specified project overview |
|
137 | 137 | # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options |
|
138 | 138 | # link_to_project(project, {}, :class => "project") # => html options with default url (project overview) |
|
139 | 139 | # |
|
140 | 140 | def link_to_project(project, options={}, html_options = nil) |
|
141 | 141 | if project.archived? |
|
142 | 142 | h(project.name) |
|
143 | 143 | else |
|
144 | 144 | link_to project.name, |
|
145 | 145 | project_url(project, {:only_path => true}.merge(options)), |
|
146 | 146 | html_options |
|
147 | 147 | end |
|
148 | 148 | end |
|
149 | 149 | |
|
150 | 150 | # Generates a link to a project settings if active |
|
151 | 151 | def link_to_project_settings(project, options={}, html_options=nil) |
|
152 | 152 | if project.active? |
|
153 | 153 | link_to project.name, settings_project_path(project, options), html_options |
|
154 | 154 | elsif project.archived? |
|
155 | 155 | h(project.name) |
|
156 | 156 | else |
|
157 | 157 | link_to project.name, project_path(project, options), html_options |
|
158 | 158 | end |
|
159 | 159 | end |
|
160 | 160 | |
|
161 | 161 | # Generates a link to a version |
|
162 | 162 | def link_to_version(version, options = {}) |
|
163 | 163 | return '' unless version && version.is_a?(Version) |
|
164 | 164 | options = {:title => format_date(version.effective_date)}.merge(options) |
|
165 | 165 | link_to_if version.visible?, format_version_name(version), version_path(version), options |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | # Helper that formats object for html or text rendering |
|
169 | 169 | def format_object(object, html=true, &block) |
|
170 | 170 | if block_given? |
|
171 | 171 | object = yield object |
|
172 | 172 | end |
|
173 | 173 | case object.class.name |
|
174 | 174 | when 'Array' |
|
175 | 175 | object.map {|o| format_object(o, html)}.join(', ').html_safe |
|
176 | 176 | when 'Time' |
|
177 | 177 | format_time(object) |
|
178 | 178 | when 'Date' |
|
179 | 179 | format_date(object) |
|
180 | 180 | when 'Fixnum' |
|
181 | 181 | object.to_s |
|
182 | 182 | when 'Float' |
|
183 | 183 | sprintf "%.2f", object |
|
184 | 184 | when 'User' |
|
185 | 185 | html ? link_to_user(object) : object.to_s |
|
186 | 186 | when 'Project' |
|
187 | 187 | html ? link_to_project(object) : object.to_s |
|
188 | 188 | when 'Version' |
|
189 | 189 | html ? link_to_version(object) : object.to_s |
|
190 | 190 | when 'TrueClass' |
|
191 | 191 | l(:general_text_Yes) |
|
192 | 192 | when 'FalseClass' |
|
193 | 193 | l(:general_text_No) |
|
194 | 194 | when 'Issue' |
|
195 | 195 | object.visible? && html ? link_to_issue(object) : "##{object.id}" |
|
196 | 196 | when 'CustomValue', 'CustomFieldValue' |
|
197 | 197 | if object.custom_field |
|
198 | 198 | f = object.custom_field.format.formatted_custom_value(self, object, html) |
|
199 | 199 | if f.nil? || f.is_a?(String) |
|
200 | 200 | f |
|
201 | 201 | else |
|
202 | 202 | format_object(f, html, &block) |
|
203 | 203 | end |
|
204 | 204 | else |
|
205 | 205 | object.value.to_s |
|
206 | 206 | end |
|
207 | 207 | else |
|
208 | 208 | html ? h(object) : object.to_s |
|
209 | 209 | end |
|
210 | 210 | end |
|
211 | 211 | |
|
212 | 212 | def wiki_page_path(page, options={}) |
|
213 | 213 | url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}.merge(options)) |
|
214 | 214 | end |
|
215 | 215 | |
|
216 | 216 | def thumbnail_tag(attachment) |
|
217 | 217 | link_to image_tag(thumbnail_path(attachment)), |
|
218 | 218 | named_attachment_path(attachment, attachment.filename), |
|
219 | 219 | :title => attachment.filename |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def toggle_link(name, id, options={}) |
|
223 | 223 | onclick = "$('##{id}').toggle(); " |
|
224 | 224 | onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ") |
|
225 | 225 | onclick << "return false;" |
|
226 | 226 | link_to(name, "#", :onclick => onclick) |
|
227 | 227 | end |
|
228 | 228 | |
|
229 | 229 | def format_activity_title(text) |
|
230 | 230 | h(truncate_single_line_raw(text, 100)) |
|
231 | 231 | end |
|
232 | 232 | |
|
233 | 233 | def format_activity_day(date) |
|
234 | 234 | date == User.current.today ? l(:label_today).titleize : format_date(date) |
|
235 | 235 | end |
|
236 | 236 | |
|
237 | 237 | def format_activity_description(text) |
|
238 | 238 | h(text.to_s.truncate(120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...') |
|
239 | 239 | ).gsub(/[\r\n]+/, "<br />").html_safe |
|
240 | 240 | end |
|
241 | 241 | |
|
242 | 242 | def format_version_name(version) |
|
243 |
if |
|
|
243 | if version.project == @project | |
|
244 | 244 | h(version) |
|
245 | 245 | else |
|
246 | 246 | h("#{version.project} - #{version}") |
|
247 | 247 | end |
|
248 | 248 | end |
|
249 | 249 | |
|
250 | 250 | def due_date_distance_in_words(date) |
|
251 | 251 | if date |
|
252 | 252 | l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date)) |
|
253 | 253 | end |
|
254 | 254 | end |
|
255 | 255 | |
|
256 | 256 | # Renders a tree of projects as a nested set of unordered lists |
|
257 | 257 | # The given collection may be a subset of the whole project tree |
|
258 | 258 | # (eg. some intermediate nodes are private and can not be seen) |
|
259 | 259 | def render_project_nested_lists(projects, &block) |
|
260 | 260 | s = '' |
|
261 | 261 | if projects.any? |
|
262 | 262 | ancestors = [] |
|
263 | 263 | original_project = @project |
|
264 | 264 | projects.sort_by(&:lft).each do |project| |
|
265 | 265 | # set the project environment to please macros. |
|
266 | 266 | @project = project |
|
267 | 267 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) |
|
268 | 268 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" |
|
269 | 269 | else |
|
270 | 270 | ancestors.pop |
|
271 | 271 | s << "</li>" |
|
272 | 272 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
273 | 273 | ancestors.pop |
|
274 | 274 | s << "</ul></li>\n" |
|
275 | 275 | end |
|
276 | 276 | end |
|
277 | 277 | classes = (ancestors.empty? ? 'root' : 'child') |
|
278 | 278 | s << "<li class='#{classes}'><div class='#{classes}'>" |
|
279 | 279 | s << h(block_given? ? capture(project, &block) : project.name) |
|
280 | 280 | s << "</div>\n" |
|
281 | 281 | ancestors << project |
|
282 | 282 | end |
|
283 | 283 | s << ("</li></ul>\n" * ancestors.size) |
|
284 | 284 | @project = original_project |
|
285 | 285 | end |
|
286 | 286 | s.html_safe |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | def render_page_hierarchy(pages, node=nil, options={}) |
|
290 | 290 | content = '' |
|
291 | 291 | if pages[node] |
|
292 | 292 | content << "<ul class=\"pages-hierarchy\">\n" |
|
293 | 293 | pages[node].each do |page| |
|
294 | 294 | content << "<li>" |
|
295 | 295 | content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil}, |
|
296 | 296 | :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil)) |
|
297 | 297 | content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id] |
|
298 | 298 | content << "</li>\n" |
|
299 | 299 | end |
|
300 | 300 | content << "</ul>\n" |
|
301 | 301 | end |
|
302 | 302 | content.html_safe |
|
303 | 303 | end |
|
304 | 304 | |
|
305 | 305 | # Renders flash messages |
|
306 | 306 | def render_flash_messages |
|
307 | 307 | s = '' |
|
308 | 308 | flash.each do |k,v| |
|
309 | 309 | s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}") |
|
310 | 310 | end |
|
311 | 311 | s.html_safe |
|
312 | 312 | end |
|
313 | 313 | |
|
314 | 314 | # Renders tabs and their content |
|
315 | 315 | def render_tabs(tabs, selected=params[:tab]) |
|
316 | 316 | if tabs.any? |
|
317 | 317 | unless tabs.detect {|tab| tab[:name] == selected} |
|
318 | 318 | selected = nil |
|
319 | 319 | end |
|
320 | 320 | selected ||= tabs.first[:name] |
|
321 | 321 | render :partial => 'common/tabs', :locals => {:tabs => tabs, :selected_tab => selected} |
|
322 | 322 | else |
|
323 | 323 | content_tag 'p', l(:label_no_data), :class => "nodata" |
|
324 | 324 | end |
|
325 | 325 | end |
|
326 | 326 | |
|
327 | 327 | # Renders the project quick-jump box |
|
328 | 328 | def render_project_jump_box |
|
329 | 329 | return unless User.current.logged? |
|
330 | 330 | projects = User.current.projects.active.select(:id, :name, :identifier, :lft, :rgt).to_a |
|
331 | 331 | if projects.any? |
|
332 | 332 | options = |
|
333 | 333 | ("<option value=''>#{ l(:label_jump_to_a_project) }</option>" + |
|
334 | 334 | '<option value="" disabled="disabled">---</option>').html_safe |
|
335 | 335 | |
|
336 | 336 | options << project_tree_options_for_select(projects, :selected => @project) do |p| |
|
337 | 337 | { :value => project_path(:id => p, :jump => current_menu_item) } |
|
338 | 338 | end |
|
339 | 339 | |
|
340 | 340 | select_tag('project_quick_jump_box', options, :onchange => 'if (this.value != \'\') { window.location = this.value; }') |
|
341 | 341 | end |
|
342 | 342 | end |
|
343 | 343 | |
|
344 | 344 | def project_tree_options_for_select(projects, options = {}) |
|
345 | 345 | s = ''.html_safe |
|
346 | 346 | if blank_text = options[:include_blank] |
|
347 | 347 | if blank_text == true |
|
348 | 348 | blank_text = ' '.html_safe |
|
349 | 349 | end |
|
350 | 350 | s << content_tag('option', blank_text, :value => '') |
|
351 | 351 | end |
|
352 | 352 | project_tree(projects) do |project, level| |
|
353 | 353 | name_prefix = (level > 0 ? ' ' * 2 * level + '» ' : '').html_safe |
|
354 | 354 | tag_options = {:value => project.id} |
|
355 | 355 | if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project)) |
|
356 | 356 | tag_options[:selected] = 'selected' |
|
357 | 357 | else |
|
358 | 358 | tag_options[:selected] = nil |
|
359 | 359 | end |
|
360 | 360 | tag_options.merge!(yield(project)) if block_given? |
|
361 | 361 | s << content_tag('option', name_prefix + h(project), tag_options) |
|
362 | 362 | end |
|
363 | 363 | s.html_safe |
|
364 | 364 | end |
|
365 | 365 | |
|
366 | 366 | # Yields the given block for each project with its level in the tree |
|
367 | 367 | # |
|
368 | 368 | # Wrapper for Project#project_tree |
|
369 | 369 | def project_tree(projects, &block) |
|
370 | 370 | Project.project_tree(projects, &block) |
|
371 | 371 | end |
|
372 | 372 | |
|
373 | 373 | def principals_check_box_tags(name, principals) |
|
374 | 374 | s = '' |
|
375 | 375 | principals.each do |principal| |
|
376 | 376 | s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal}</label>\n" |
|
377 | 377 | end |
|
378 | 378 | s.html_safe |
|
379 | 379 | end |
|
380 | 380 | |
|
381 | 381 | # Returns a string for users/groups option tags |
|
382 | 382 | def principals_options_for_select(collection, selected=nil) |
|
383 | 383 | s = '' |
|
384 | 384 | if collection.include?(User.current) |
|
385 | 385 | s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id) |
|
386 | 386 | end |
|
387 | 387 | groups = '' |
|
388 | 388 | collection.sort.each do |element| |
|
389 | 389 | selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) || element.id.to_s == selected |
|
390 | 390 | (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>) |
|
391 | 391 | end |
|
392 | 392 | unless groups.empty? |
|
393 | 393 | s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>) |
|
394 | 394 | end |
|
395 | 395 | s.html_safe |
|
396 | 396 | end |
|
397 | 397 | |
|
398 | 398 | def option_tag(name, text, value, selected=nil, options={}) |
|
399 | 399 | content_tag 'option', value, options.merge(:value => value, :selected => (value == selected)) |
|
400 | 400 | end |
|
401 | 401 | |
|
402 | 402 | def truncate_single_line_raw(string, length) |
|
403 | 403 | string.to_s.truncate(length).gsub(%r{[\r\n]+}m, ' ') |
|
404 | 404 | end |
|
405 | 405 | |
|
406 | 406 | # Truncates at line break after 250 characters or options[:length] |
|
407 | 407 | def truncate_lines(string, options={}) |
|
408 | 408 | length = options[:length] || 250 |
|
409 | 409 | if string.to_s =~ /\A(.{#{length}}.*?)$/m |
|
410 | 410 | "#{$1}..." |
|
411 | 411 | else |
|
412 | 412 | string |
|
413 | 413 | end |
|
414 | 414 | end |
|
415 | 415 | |
|
416 | 416 | def anchor(text) |
|
417 | 417 | text.to_s.gsub(' ', '_') |
|
418 | 418 | end |
|
419 | 419 | |
|
420 | 420 | def html_hours(text) |
|
421 | 421 | text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe |
|
422 | 422 | end |
|
423 | 423 | |
|
424 | 424 | def authoring(created, author, options={}) |
|
425 | 425 | l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe |
|
426 | 426 | end |
|
427 | 427 | |
|
428 | 428 | def time_tag(time) |
|
429 | 429 | text = distance_of_time_in_words(Time.now, time) |
|
430 | 430 | if @project |
|
431 | 431 | link_to(text, project_activity_path(@project, :from => User.current.time_to_date(time)), :title => format_time(time)) |
|
432 | 432 | else |
|
433 | 433 | content_tag('abbr', text, :title => format_time(time)) |
|
434 | 434 | end |
|
435 | 435 | end |
|
436 | 436 | |
|
437 | 437 | def syntax_highlight_lines(name, content) |
|
438 | 438 | lines = [] |
|
439 | 439 | syntax_highlight(name, content).each_line { |line| lines << line } |
|
440 | 440 | lines |
|
441 | 441 | end |
|
442 | 442 | |
|
443 | 443 | def syntax_highlight(name, content) |
|
444 | 444 | Redmine::SyntaxHighlighting.highlight_by_filename(content, name) |
|
445 | 445 | end |
|
446 | 446 | |
|
447 | 447 | def to_path_param(path) |
|
448 | 448 | str = path.to_s.split(%r{[/\\]}).select{|p| !p.blank?}.join("/") |
|
449 | 449 | str.blank? ? nil : str |
|
450 | 450 | end |
|
451 | 451 | |
|
452 | 452 | def reorder_links(name, url, method = :post) |
|
453 | 453 | link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), |
|
454 | 454 | url.merge({"#{name}[move_to]" => 'highest'}), |
|
455 | 455 | :method => method, :title => l(:label_sort_highest)) + |
|
456 | 456 | link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), |
|
457 | 457 | url.merge({"#{name}[move_to]" => 'higher'}), |
|
458 | 458 | :method => method, :title => l(:label_sort_higher)) + |
|
459 | 459 | link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), |
|
460 | 460 | url.merge({"#{name}[move_to]" => 'lower'}), |
|
461 | 461 | :method => method, :title => l(:label_sort_lower)) + |
|
462 | 462 | link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), |
|
463 | 463 | url.merge({"#{name}[move_to]" => 'lowest'}), |
|
464 | 464 | :method => method, :title => l(:label_sort_lowest)) |
|
465 | 465 | end |
|
466 | 466 | |
|
467 | 467 | def breadcrumb(*args) |
|
468 | 468 | elements = args.flatten |
|
469 | 469 | elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil |
|
470 | 470 | end |
|
471 | 471 | |
|
472 | 472 | def other_formats_links(&block) |
|
473 | 473 | concat('<p class="other-formats">'.html_safe + l(:label_export_to)) |
|
474 | 474 | yield Redmine::Views::OtherFormatsBuilder.new(self) |
|
475 | 475 | concat('</p>'.html_safe) |
|
476 | 476 | end |
|
477 | 477 | |
|
478 | 478 | def page_header_title |
|
479 | 479 | if @project.nil? || @project.new_record? |
|
480 | 480 | h(Setting.app_title) |
|
481 | 481 | else |
|
482 | 482 | b = [] |
|
483 | 483 | ancestors = (@project.root? ? [] : @project.ancestors.visible.to_a) |
|
484 | 484 | if ancestors.any? |
|
485 | 485 | root = ancestors.shift |
|
486 | 486 | b << link_to_project(root, {:jump => current_menu_item}, :class => 'root') |
|
487 | 487 | if ancestors.size > 2 |
|
488 | 488 | b << "\xe2\x80\xa6" |
|
489 | 489 | ancestors = ancestors[-2, 2] |
|
490 | 490 | end |
|
491 | 491 | b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') } |
|
492 | 492 | end |
|
493 | 493 | b << h(@project) |
|
494 | 494 | b.join(" \xc2\xbb ").html_safe |
|
495 | 495 | end |
|
496 | 496 | end |
|
497 | 497 | |
|
498 | 498 | # Returns a h2 tag and sets the html title with the given arguments |
|
499 | 499 | def title(*args) |
|
500 | 500 | strings = args.map do |arg| |
|
501 | 501 | if arg.is_a?(Array) && arg.size >= 2 |
|
502 | 502 | link_to(*arg) |
|
503 | 503 | else |
|
504 | 504 | h(arg.to_s) |
|
505 | 505 | end |
|
506 | 506 | end |
|
507 | 507 | html_title args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s} |
|
508 | 508 | content_tag('h2', strings.join(' » ').html_safe) |
|
509 | 509 | end |
|
510 | 510 | |
|
511 | 511 | # Sets the html title |
|
512 | 512 | # Returns the html title when called without arguments |
|
513 | 513 | # Current project name and app_title and automatically appended |
|
514 | 514 | # Exemples: |
|
515 | 515 | # html_title 'Foo', 'Bar' |
|
516 | 516 | # html_title # => 'Foo - Bar - My Project - Redmine' |
|
517 | 517 | def html_title(*args) |
|
518 | 518 | if args.empty? |
|
519 | 519 | title = @html_title || [] |
|
520 | 520 | title << @project.name if @project |
|
521 | 521 | title << Setting.app_title unless Setting.app_title == title.last |
|
522 | 522 | title.reject(&:blank?).join(' - ') |
|
523 | 523 | else |
|
524 | 524 | @html_title ||= [] |
|
525 | 525 | @html_title += args |
|
526 | 526 | end |
|
527 | 527 | end |
|
528 | 528 | |
|
529 | 529 | # Returns the theme, controller name, and action as css classes for the |
|
530 | 530 | # HTML body. |
|
531 | 531 | def body_css_classes |
|
532 | 532 | css = [] |
|
533 | 533 | if theme = Redmine::Themes.theme(Setting.ui_theme) |
|
534 | 534 | css << 'theme-' + theme.name |
|
535 | 535 | end |
|
536 | 536 | |
|
537 | 537 | css << 'project-' + @project.identifier if @project && @project.identifier.present? |
|
538 | 538 | css << 'controller-' + controller_name |
|
539 | 539 | css << 'action-' + action_name |
|
540 | 540 | css.join(' ') |
|
541 | 541 | end |
|
542 | 542 | |
|
543 | 543 | def accesskey(s) |
|
544 | 544 | @used_accesskeys ||= [] |
|
545 | 545 | key = Redmine::AccessKeys.key_for(s) |
|
546 | 546 | return nil if @used_accesskeys.include?(key) |
|
547 | 547 | @used_accesskeys << key |
|
548 | 548 | key |
|
549 | 549 | end |
|
550 | 550 | |
|
551 | 551 | # Formats text according to system settings. |
|
552 | 552 | # 2 ways to call this method: |
|
553 | 553 | # * with a String: textilizable(text, options) |
|
554 | 554 | # * with an object and one of its attribute: textilizable(issue, :description, options) |
|
555 | 555 | def textilizable(*args) |
|
556 | 556 | options = args.last.is_a?(Hash) ? args.pop : {} |
|
557 | 557 | case args.size |
|
558 | 558 | when 1 |
|
559 | 559 | obj = options[:object] |
|
560 | 560 | text = args.shift |
|
561 | 561 | when 2 |
|
562 | 562 | obj = args.shift |
|
563 | 563 | attr = args.shift |
|
564 | 564 | text = obj.send(attr).to_s |
|
565 | 565 | else |
|
566 | 566 | raise ArgumentError, 'invalid arguments to textilizable' |
|
567 | 567 | end |
|
568 | 568 | return '' if text.blank? |
|
569 | 569 | project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) |
|
570 | 570 | @only_path = only_path = options.delete(:only_path) == false ? false : true |
|
571 | 571 | |
|
572 | 572 | text = text.dup |
|
573 | 573 | macros = catch_macros(text) |
|
574 | 574 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) |
|
575 | 575 | |
|
576 | 576 | @parsed_headings = [] |
|
577 | 577 | @heading_anchors = {} |
|
578 | 578 | @current_section = 0 if options[:edit_section_links] |
|
579 | 579 | |
|
580 | 580 | parse_sections(text, project, obj, attr, only_path, options) |
|
581 | 581 | text = parse_non_pre_blocks(text, obj, macros) do |text| |
|
582 | 582 | [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name| |
|
583 | 583 | send method_name, text, project, obj, attr, only_path, options |
|
584 | 584 | end |
|
585 | 585 | end |
|
586 | 586 | parse_headings(text, project, obj, attr, only_path, options) |
|
587 | 587 | |
|
588 | 588 | if @parsed_headings.any? |
|
589 | 589 | replace_toc(text, @parsed_headings) |
|
590 | 590 | end |
|
591 | 591 | |
|
592 | 592 | text.html_safe |
|
593 | 593 | end |
|
594 | 594 | |
|
595 | 595 | def parse_non_pre_blocks(text, obj, macros) |
|
596 | 596 | s = StringScanner.new(text) |
|
597 | 597 | tags = [] |
|
598 | 598 | parsed = '' |
|
599 | 599 | while !s.eos? |
|
600 | 600 | s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im) |
|
601 | 601 | text, full_tag, closing, tag = s[1], s[2], s[3], s[4] |
|
602 | 602 | if tags.empty? |
|
603 | 603 | yield text |
|
604 | 604 | inject_macros(text, obj, macros) if macros.any? |
|
605 | 605 | else |
|
606 | 606 | inject_macros(text, obj, macros, false) if macros.any? |
|
607 | 607 | end |
|
608 | 608 | parsed << text |
|
609 | 609 | if tag |
|
610 | 610 | if closing |
|
611 | 611 | if tags.last == tag.downcase |
|
612 | 612 | tags.pop |
|
613 | 613 | end |
|
614 | 614 | else |
|
615 | 615 | tags << tag.downcase |
|
616 | 616 | end |
|
617 | 617 | parsed << full_tag |
|
618 | 618 | end |
|
619 | 619 | end |
|
620 | 620 | # Close any non closing tags |
|
621 | 621 | while tag = tags.pop |
|
622 | 622 | parsed << "</#{tag}>" |
|
623 | 623 | end |
|
624 | 624 | parsed |
|
625 | 625 | end |
|
626 | 626 | |
|
627 | 627 | def parse_inline_attachments(text, project, obj, attr, only_path, options) |
|
628 | 628 | return if options[:inline_attachments] == false |
|
629 | 629 | |
|
630 | 630 | # when using an image link, try to use an attachment, if possible |
|
631 | 631 | attachments = options[:attachments] || [] |
|
632 | 632 | attachments += obj.attachments if obj.respond_to?(:attachments) |
|
633 | 633 | if attachments.present? |
|
634 | 634 | text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| |
|
635 | 635 | filename, ext, alt, alttext = $1.downcase, $2, $3, $4 |
|
636 | 636 | # search for the picture in attachments |
|
637 | 637 | if found = Attachment.latest_attach(attachments, CGI.unescape(filename)) |
|
638 | 638 | image_url = download_named_attachment_url(found, found.filename, :only_path => only_path) |
|
639 | 639 | desc = found.description.to_s.gsub('"', '') |
|
640 | 640 | if !desc.blank? && alttext.blank? |
|
641 | 641 | alt = " title=\"#{desc}\" alt=\"#{desc}\"" |
|
642 | 642 | end |
|
643 | 643 | "src=\"#{image_url}\"#{alt}" |
|
644 | 644 | else |
|
645 | 645 | m |
|
646 | 646 | end |
|
647 | 647 | end |
|
648 | 648 | end |
|
649 | 649 | end |
|
650 | 650 | |
|
651 | 651 | # Wiki links |
|
652 | 652 | # |
|
653 | 653 | # Examples: |
|
654 | 654 | # [[mypage]] |
|
655 | 655 | # [[mypage|mytext]] |
|
656 | 656 | # wiki links can refer other project wikis, using project name or identifier: |
|
657 | 657 | # [[project:]] -> wiki starting page |
|
658 | 658 | # [[project:|mytext]] |
|
659 | 659 | # [[project:mypage]] |
|
660 | 660 | # [[project:mypage|mytext]] |
|
661 | 661 | def parse_wiki_links(text, project, obj, attr, only_path, options) |
|
662 | 662 | text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m| |
|
663 | 663 | link_project = project |
|
664 | 664 | esc, all, page, title = $1, $2, $3, $5 |
|
665 | 665 | if esc.nil? |
|
666 | 666 | if page =~ /^([^\:]+)\:(.*)$/ |
|
667 | 667 | identifier, page = $1, $2 |
|
668 | 668 | link_project = Project.find_by_identifier(identifier) || Project.find_by_name(identifier) |
|
669 | 669 | title ||= identifier if page.blank? |
|
670 | 670 | end |
|
671 | 671 | |
|
672 | 672 | if link_project && link_project.wiki |
|
673 | 673 | # extract anchor |
|
674 | 674 | anchor = nil |
|
675 | 675 | if page =~ /^(.+?)\#(.+)$/ |
|
676 | 676 | page, anchor = $1, $2 |
|
677 | 677 | end |
|
678 | 678 | anchor = sanitize_anchor_name(anchor) if anchor.present? |
|
679 | 679 | # check if page exists |
|
680 | 680 | wiki_page = link_project.wiki.find_page(page) |
|
681 | 681 | url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page |
|
682 | 682 | "##{anchor}" |
|
683 | 683 | else |
|
684 | 684 | case options[:wiki_links] |
|
685 | 685 | when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '') |
|
686 | 686 | when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export |
|
687 | 687 | else |
|
688 | 688 | wiki_page_id = page.present? ? Wiki.titleize(page) : nil |
|
689 | 689 | parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil |
|
690 | 690 | url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, |
|
691 | 691 | :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent) |
|
692 | 692 | end |
|
693 | 693 | end |
|
694 | 694 | link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
695 | 695 | else |
|
696 | 696 | # project or wiki doesn't exist |
|
697 | 697 | all |
|
698 | 698 | end |
|
699 | 699 | else |
|
700 | 700 | all |
|
701 | 701 | end |
|
702 | 702 | end |
|
703 | 703 | end |
|
704 | 704 | |
|
705 | 705 | # Redmine links |
|
706 | 706 | # |
|
707 | 707 | # Examples: |
|
708 | 708 | # Issues: |
|
709 | 709 | # #52 -> Link to issue #52 |
|
710 | 710 | # Changesets: |
|
711 | 711 | # r52 -> Link to revision 52 |
|
712 | 712 | # commit:a85130f -> Link to scmid starting with a85130f |
|
713 | 713 | # Documents: |
|
714 | 714 | # document#17 -> Link to document with id 17 |
|
715 | 715 | # document:Greetings -> Link to the document with title "Greetings" |
|
716 | 716 | # document:"Some document" -> Link to the document with title "Some document" |
|
717 | 717 | # Versions: |
|
718 | 718 | # version#3 -> Link to version with id 3 |
|
719 | 719 | # version:1.0.0 -> Link to version named "1.0.0" |
|
720 | 720 | # version:"1.0 beta 2" -> Link to version named "1.0 beta 2" |
|
721 | 721 | # Attachments: |
|
722 | 722 | # attachment:file.zip -> Link to the attachment of the current object named file.zip |
|
723 | 723 | # Source files: |
|
724 | 724 | # source:some/file -> Link to the file located at /some/file in the project's repository |
|
725 | 725 | # source:some/file@52 -> Link to the file's revision 52 |
|
726 | 726 | # source:some/file#L120 -> Link to line 120 of the file |
|
727 | 727 | # source:some/file@52#L120 -> Link to line 120 of the file's revision 52 |
|
728 | 728 | # export:some/file -> Force the download of the file |
|
729 | 729 | # Forum messages: |
|
730 | 730 | # message#1218 -> Link to message with id 1218 |
|
731 | 731 | # Projects: |
|
732 | 732 | # project:someproject -> Link to project named "someproject" |
|
733 | 733 | # project#3 -> Link to project with id 3 |
|
734 | 734 | # |
|
735 | 735 | # Links can refer other objects from other projects, using project identifier: |
|
736 | 736 | # identifier:r52 |
|
737 | 737 | # identifier:document:"Some document" |
|
738 | 738 | # identifier:version:1.0.0 |
|
739 | 739 | # identifier:source:some/file |
|
740 | 740 | def parse_redmine_links(text, default_project, obj, attr, only_path, options) |
|
741 | 741 | text.gsub!(%r{<a( [^>]+?)?>(.*?)</a>|([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-_]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m| |
|
742 | 742 | tag_content, leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $1, $3, $4, $5, $6, $7, $12, $13, $10 || $14 || $20, $16 || $21, $17, $19 |
|
743 | 743 | if tag_content |
|
744 | 744 | $& |
|
745 | 745 | else |
|
746 | 746 | link = nil |
|
747 | 747 | project = default_project |
|
748 | 748 | if project_identifier |
|
749 | 749 | project = Project.visible.find_by_identifier(project_identifier) |
|
750 | 750 | end |
|
751 | 751 | if esc.nil? |
|
752 | 752 | if prefix.nil? && sep == 'r' |
|
753 | 753 | if project |
|
754 | 754 | repository = nil |
|
755 | 755 | if repo_identifier |
|
756 | 756 | repository = project.repositories.detect {|repo| repo.identifier == repo_identifier} |
|
757 | 757 | else |
|
758 | 758 | repository = project.repository |
|
759 | 759 | end |
|
760 | 760 | # project.changesets.visible raises an SQL error because of a double join on repositories |
|
761 | 761 | if repository && |
|
762 | 762 | (changeset = Changeset.visible. |
|
763 | 763 | find_by_repository_id_and_revision(repository.id, identifier)) |
|
764 | 764 | link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"), |
|
765 | 765 | {:only_path => only_path, :controller => 'repositories', |
|
766 | 766 | :action => 'revision', :id => project, |
|
767 | 767 | :repository_id => repository.identifier_param, |
|
768 | 768 | :rev => changeset.revision}, |
|
769 | 769 | :class => 'changeset', |
|
770 | 770 | :title => truncate_single_line_raw(changeset.comments, 100)) |
|
771 | 771 | end |
|
772 | 772 | end |
|
773 | 773 | elsif sep == '#' |
|
774 | 774 | oid = identifier.to_i |
|
775 | 775 | case prefix |
|
776 | 776 | when nil |
|
777 | 777 | if oid.to_s == identifier && |
|
778 | 778 | issue = Issue.visible.find_by_id(oid) |
|
779 | 779 | anchor = comment_id ? "note-#{comment_id}" : nil |
|
780 | 780 | link = link_to("##{oid}#{comment_suffix}", |
|
781 | 781 | issue_url(issue, :only_path => only_path, :anchor => anchor), |
|
782 | 782 | :class => issue.css_classes, |
|
783 | 783 | :title => "#{issue.subject.truncate(100)} (#{issue.status.name})") |
|
784 | 784 | end |
|
785 | 785 | when 'document' |
|
786 | 786 | if document = Document.visible.find_by_id(oid) |
|
787 | 787 | link = link_to(document.title, document_url(document, :only_path => only_path), :class => 'document') |
|
788 | 788 | end |
|
789 | 789 | when 'version' |
|
790 | 790 | if version = Version.visible.find_by_id(oid) |
|
791 | 791 | link = link_to(version.name, version_url(version, :only_path => only_path), :class => 'version') |
|
792 | 792 | end |
|
793 | 793 | when 'message' |
|
794 | 794 | if message = Message.visible.find_by_id(oid) |
|
795 | 795 | link = link_to_message(message, {:only_path => only_path}, :class => 'message') |
|
796 | 796 | end |
|
797 | 797 | when 'forum' |
|
798 | 798 | if board = Board.visible.find_by_id(oid) |
|
799 | 799 | link = link_to(board.name, project_board_url(board.project, board, :only_path => only_path), :class => 'board') |
|
800 | 800 | end |
|
801 | 801 | when 'news' |
|
802 | 802 | if news = News.visible.find_by_id(oid) |
|
803 | 803 | link = link_to(news.title, news_url(news, :only_path => only_path), :class => 'news') |
|
804 | 804 | end |
|
805 | 805 | when 'project' |
|
806 | 806 | if p = Project.visible.find_by_id(oid) |
|
807 | 807 | link = link_to_project(p, {:only_path => only_path}, :class => 'project') |
|
808 | 808 | end |
|
809 | 809 | end |
|
810 | 810 | elsif sep == ':' |
|
811 | 811 | # removes the double quotes if any |
|
812 | 812 | name = identifier.gsub(%r{^"(.*)"$}, "\\1") |
|
813 | 813 | name = CGI.unescapeHTML(name) |
|
814 | 814 | case prefix |
|
815 | 815 | when 'document' |
|
816 | 816 | if project && document = project.documents.visible.find_by_title(name) |
|
817 | 817 | link = link_to(document.title, document_url(document, :only_path => only_path), :class => 'document') |
|
818 | 818 | end |
|
819 | 819 | when 'version' |
|
820 | 820 | if project && version = project.versions.visible.find_by_name(name) |
|
821 | 821 | link = link_to(version.name, version_url(version, :only_path => only_path), :class => 'version') |
|
822 | 822 | end |
|
823 | 823 | when 'forum' |
|
824 | 824 | if project && board = project.boards.visible.find_by_name(name) |
|
825 | 825 | link = link_to(board.name, project_board_url(board.project, board, :only_path => only_path), :class => 'board') |
|
826 | 826 | end |
|
827 | 827 | when 'news' |
|
828 | 828 | if project && news = project.news.visible.find_by_title(name) |
|
829 | 829 | link = link_to(news.title, news_url(news, :only_path => only_path), :class => 'news') |
|
830 | 830 | end |
|
831 | 831 | when 'commit', 'source', 'export' |
|
832 | 832 | if project |
|
833 | 833 | repository = nil |
|
834 | 834 | if name =~ %r{^(([a-z0-9\-_]+)\|)(.+)$} |
|
835 | 835 | repo_prefix, repo_identifier, name = $1, $2, $3 |
|
836 | 836 | repository = project.repositories.detect {|repo| repo.identifier == repo_identifier} |
|
837 | 837 | else |
|
838 | 838 | repository = project.repository |
|
839 | 839 | end |
|
840 | 840 | if prefix == 'commit' |
|
841 | 841 | if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first) |
|
842 | 842 | link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier}, |
|
843 | 843 | :class => 'changeset', |
|
844 | 844 | :title => truncate_single_line_raw(changeset.comments, 100) |
|
845 | 845 | end |
|
846 | 846 | else |
|
847 | 847 | if repository && User.current.allowed_to?(:browse_repository, project) |
|
848 | 848 | name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$} |
|
849 | 849 | path, rev, anchor = $1, $3, $5 |
|
850 | 850 | link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => (prefix == 'export' ? 'raw' : 'entry'), :id => project, :repository_id => repository.identifier_param, |
|
851 | 851 | :path => to_path_param(path), |
|
852 | 852 | :rev => rev, |
|
853 | 853 | :anchor => anchor}, |
|
854 | 854 | :class => (prefix == 'export' ? 'source download' : 'source') |
|
855 | 855 | end |
|
856 | 856 | end |
|
857 | 857 | repo_prefix = nil |
|
858 | 858 | end |
|
859 | 859 | when 'attachment' |
|
860 | 860 | attachments = options[:attachments] || [] |
|
861 | 861 | attachments += obj.attachments if obj.respond_to?(:attachments) |
|
862 | 862 | if attachments && attachment = Attachment.latest_attach(attachments, name) |
|
863 | 863 | link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment') |
|
864 | 864 | end |
|
865 | 865 | when 'project' |
|
866 | 866 | if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first |
|
867 | 867 | link = link_to_project(p, {:only_path => only_path}, :class => 'project') |
|
868 | 868 | end |
|
869 | 869 | end |
|
870 | 870 | end |
|
871 | 871 | end |
|
872 | 872 | (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}")) |
|
873 | 873 | end |
|
874 | 874 | end |
|
875 | 875 | end |
|
876 | 876 | |
|
877 | 877 | HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE) |
|
878 | 878 | |
|
879 | 879 | def parse_sections(text, project, obj, attr, only_path, options) |
|
880 | 880 | return unless options[:edit_section_links] |
|
881 | 881 | text.gsub!(HEADING_RE) do |
|
882 | 882 | heading = $1 |
|
883 | 883 | @current_section += 1 |
|
884 | 884 | if @current_section > 1 |
|
885 | 885 | content_tag('div', |
|
886 | 886 | link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)), |
|
887 | 887 | :class => 'contextual', |
|
888 | 888 | :title => l(:button_edit_section), |
|
889 | 889 | :id => "section-#{@current_section}") + heading.html_safe |
|
890 | 890 | else |
|
891 | 891 | heading |
|
892 | 892 | end |
|
893 | 893 | end |
|
894 | 894 | end |
|
895 | 895 | |
|
896 | 896 | # Headings and TOC |
|
897 | 897 | # Adds ids and links to headings unless options[:headings] is set to false |
|
898 | 898 | def parse_headings(text, project, obj, attr, only_path, options) |
|
899 | 899 | return if options[:headings] == false |
|
900 | 900 | |
|
901 | 901 | text.gsub!(HEADING_RE) do |
|
902 | 902 | level, attrs, content = $2.to_i, $3, $4 |
|
903 | 903 | item = strip_tags(content).strip |
|
904 | 904 | anchor = sanitize_anchor_name(item) |
|
905 | 905 | # used for single-file wiki export |
|
906 | 906 | anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) |
|
907 | 907 | @heading_anchors[anchor] ||= 0 |
|
908 | 908 | idx = (@heading_anchors[anchor] += 1) |
|
909 | 909 | if idx > 1 |
|
910 | 910 | anchor = "#{anchor}-#{idx}" |
|
911 | 911 | end |
|
912 | 912 | @parsed_headings << [level, anchor, item] |
|
913 | 913 | "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>" |
|
914 | 914 | end |
|
915 | 915 | end |
|
916 | 916 | |
|
917 | 917 | MACROS_RE = /( |
|
918 | 918 | (!)? # escaping |
|
919 | 919 | ( |
|
920 | 920 | \{\{ # opening tag |
|
921 | 921 | ([\w]+) # macro name |
|
922 | 922 | (\(([^\n\r]*?)\))? # optional arguments |
|
923 | 923 | ([\n\r].*?[\n\r])? # optional block of text |
|
924 | 924 | \}\} # closing tag |
|
925 | 925 | ) |
|
926 | 926 | )/mx unless const_defined?(:MACROS_RE) |
|
927 | 927 | |
|
928 | 928 | MACRO_SUB_RE = /( |
|
929 | 929 | \{\{ |
|
930 | 930 | macro\((\d+)\) |
|
931 | 931 | \}\} |
|
932 | 932 | )/x unless const_defined?(:MACRO_SUB_RE) |
|
933 | 933 | |
|
934 | 934 | # Extracts macros from text |
|
935 | 935 | def catch_macros(text) |
|
936 | 936 | macros = {} |
|
937 | 937 | text.gsub!(MACROS_RE) do |
|
938 | 938 | all, macro = $1, $4.downcase |
|
939 | 939 | if macro_exists?(macro) || all =~ MACRO_SUB_RE |
|
940 | 940 | index = macros.size |
|
941 | 941 | macros[index] = all |
|
942 | 942 | "{{macro(#{index})}}" |
|
943 | 943 | else |
|
944 | 944 | all |
|
945 | 945 | end |
|
946 | 946 | end |
|
947 | 947 | macros |
|
948 | 948 | end |
|
949 | 949 | |
|
950 | 950 | # Executes and replaces macros in text |
|
951 | 951 | def inject_macros(text, obj, macros, execute=true) |
|
952 | 952 | text.gsub!(MACRO_SUB_RE) do |
|
953 | 953 | all, index = $1, $2.to_i |
|
954 | 954 | orig = macros.delete(index) |
|
955 | 955 | if execute && orig && orig =~ MACROS_RE |
|
956 | 956 | esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip) |
|
957 | 957 | if esc.nil? |
|
958 | 958 | h(exec_macro(macro, obj, args, block) || all) |
|
959 | 959 | else |
|
960 | 960 | h(all) |
|
961 | 961 | end |
|
962 | 962 | elsif orig |
|
963 | 963 | h(orig) |
|
964 | 964 | else |
|
965 | 965 | h(all) |
|
966 | 966 | end |
|
967 | 967 | end |
|
968 | 968 | end |
|
969 | 969 | |
|
970 | 970 | TOC_RE = /<p>\{\{((<|<)|(>|>))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE) |
|
971 | 971 | |
|
972 | 972 | # Renders the TOC with given headings |
|
973 | 973 | def replace_toc(text, headings) |
|
974 | 974 | text.gsub!(TOC_RE) do |
|
975 | 975 | left_align, right_align = $2, $3 |
|
976 | 976 | # Keep only the 4 first levels |
|
977 | 977 | headings = headings.select{|level, anchor, item| level <= 4} |
|
978 | 978 | if headings.empty? |
|
979 | 979 | '' |
|
980 | 980 | else |
|
981 | 981 | div_class = 'toc' |
|
982 | 982 | div_class << ' right' if right_align |
|
983 | 983 | div_class << ' left' if left_align |
|
984 | 984 | out = "<ul class=\"#{div_class}\"><li>" |
|
985 | 985 | root = headings.map(&:first).min |
|
986 | 986 | current = root |
|
987 | 987 | started = false |
|
988 | 988 | headings.each do |level, anchor, item| |
|
989 | 989 | if level > current |
|
990 | 990 | out << '<ul><li>' * (level - current) |
|
991 | 991 | elsif level < current |
|
992 | 992 | out << "</li></ul>\n" * (current - level) + "</li><li>" |
|
993 | 993 | elsif started |
|
994 | 994 | out << '</li><li>' |
|
995 | 995 | end |
|
996 | 996 | out << "<a href=\"##{anchor}\">#{item}</a>" |
|
997 | 997 | current = level |
|
998 | 998 | started = true |
|
999 | 999 | end |
|
1000 | 1000 | out << '</li></ul>' * (current - root) |
|
1001 | 1001 | out << '</li></ul>' |
|
1002 | 1002 | end |
|
1003 | 1003 | end |
|
1004 | 1004 | end |
|
1005 | 1005 | |
|
1006 | 1006 | # Same as Rails' simple_format helper without using paragraphs |
|
1007 | 1007 | def simple_format_without_paragraph(text) |
|
1008 | 1008 | text.to_s. |
|
1009 | 1009 | gsub(/\r\n?/, "\n"). # \r\n and \r -> \n |
|
1010 | 1010 | gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br |
|
1011 | 1011 | gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br |
|
1012 | 1012 | html_safe |
|
1013 | 1013 | end |
|
1014 | 1014 | |
|
1015 | 1015 | def lang_options_for_select(blank=true) |
|
1016 | 1016 | (blank ? [["(auto)", ""]] : []) + languages_options |
|
1017 | 1017 | end |
|
1018 | 1018 | |
|
1019 | 1019 | def labelled_form_for(*args, &proc) |
|
1020 | 1020 | args << {} unless args.last.is_a?(Hash) |
|
1021 | 1021 | options = args.last |
|
1022 | 1022 | if args.first.is_a?(Symbol) |
|
1023 | 1023 | options.merge!(:as => args.shift) |
|
1024 | 1024 | end |
|
1025 | 1025 | options.merge!({:builder => Redmine::Views::LabelledFormBuilder}) |
|
1026 | 1026 | form_for(*args, &proc) |
|
1027 | 1027 | end |
|
1028 | 1028 | |
|
1029 | 1029 | def labelled_fields_for(*args, &proc) |
|
1030 | 1030 | args << {} unless args.last.is_a?(Hash) |
|
1031 | 1031 | options = args.last |
|
1032 | 1032 | options.merge!({:builder => Redmine::Views::LabelledFormBuilder}) |
|
1033 | 1033 | fields_for(*args, &proc) |
|
1034 | 1034 | end |
|
1035 | 1035 | |
|
1036 | 1036 | def error_messages_for(*objects) |
|
1037 | 1037 | html = "" |
|
1038 | 1038 | objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact |
|
1039 | 1039 | errors = objects.map {|o| o.errors.full_messages}.flatten |
|
1040 | 1040 | if errors.any? |
|
1041 | 1041 | html << "<div id='errorExplanation'><ul>\n" |
|
1042 | 1042 | errors.each do |error| |
|
1043 | 1043 | html << "<li>#{h error}</li>\n" |
|
1044 | 1044 | end |
|
1045 | 1045 | html << "</ul></div>\n" |
|
1046 | 1046 | end |
|
1047 | 1047 | html.html_safe |
|
1048 | 1048 | end |
|
1049 | 1049 | |
|
1050 | 1050 | def delete_link(url, options={}) |
|
1051 | 1051 | options = { |
|
1052 | 1052 | :method => :delete, |
|
1053 | 1053 | :data => {:confirm => l(:text_are_you_sure)}, |
|
1054 | 1054 | :class => 'icon icon-del' |
|
1055 | 1055 | }.merge(options) |
|
1056 | 1056 | |
|
1057 | 1057 | link_to l(:button_delete), url, options |
|
1058 | 1058 | end |
|
1059 | 1059 | |
|
1060 | 1060 | def preview_link(url, form, target='preview', options={}) |
|
1061 | 1061 | content_tag 'a', l(:label_preview), { |
|
1062 | 1062 | :href => "#", |
|
1063 | 1063 | :onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|, |
|
1064 | 1064 | :accesskey => accesskey(:preview) |
|
1065 | 1065 | }.merge(options) |
|
1066 | 1066 | end |
|
1067 | 1067 | |
|
1068 | 1068 | def link_to_function(name, function, html_options={}) |
|
1069 | 1069 | content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options)) |
|
1070 | 1070 | end |
|
1071 | 1071 | |
|
1072 | 1072 | # Helper to render JSON in views |
|
1073 | 1073 | def raw_json(arg) |
|
1074 | 1074 | arg.to_json.to_s.gsub('/', '\/').html_safe |
|
1075 | 1075 | end |
|
1076 | 1076 | |
|
1077 | 1077 | def back_url |
|
1078 | 1078 | url = params[:back_url] |
|
1079 | 1079 | if url.nil? && referer = request.env['HTTP_REFERER'] |
|
1080 | 1080 | url = CGI.unescape(referer.to_s) |
|
1081 | 1081 | end |
|
1082 | 1082 | url |
|
1083 | 1083 | end |
|
1084 | 1084 | |
|
1085 | 1085 | def back_url_hidden_field_tag |
|
1086 | 1086 | url = back_url |
|
1087 | 1087 | hidden_field_tag('back_url', url, :id => nil) unless url.blank? |
|
1088 | 1088 | end |
|
1089 | 1089 | |
|
1090 | 1090 | def check_all_links(form_name) |
|
1091 | 1091 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + |
|
1092 | 1092 | " | ".html_safe + |
|
1093 | 1093 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") |
|
1094 | 1094 | end |
|
1095 | 1095 | |
|
1096 | 1096 | def toggle_checkboxes_link(selector) |
|
1097 | 1097 | link_to_function image_tag('toggle_check.png'), |
|
1098 | 1098 | "toggleCheckboxesBySelector('#{selector}')", |
|
1099 | 1099 | :title => "#{l(:button_check_all)} / #{l(:button_uncheck_all)}" |
|
1100 | 1100 | end |
|
1101 | 1101 | |
|
1102 | 1102 | def progress_bar(pcts, options={}) |
|
1103 | 1103 | pcts = [pcts, pcts] unless pcts.is_a?(Array) |
|
1104 | 1104 | pcts = pcts.collect(&:round) |
|
1105 | 1105 | pcts[1] = pcts[1] - pcts[0] |
|
1106 | 1106 | pcts << (100 - pcts[1] - pcts[0]) |
|
1107 | 1107 | width = options[:width] || '100px;' |
|
1108 | 1108 | legend = options[:legend] || '' |
|
1109 | 1109 | content_tag('table', |
|
1110 | 1110 | content_tag('tr', |
|
1111 | 1111 | (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) + |
|
1112 | 1112 | (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) + |
|
1113 | 1113 | (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe) |
|
1114 | 1114 | ), :class => "progress progress-#{pcts[0]}", :style => "width: #{width};").html_safe + |
|
1115 | 1115 | content_tag('p', legend, :class => 'percent').html_safe |
|
1116 | 1116 | end |
|
1117 | 1117 | |
|
1118 | 1118 | def checked_image(checked=true) |
|
1119 | 1119 | if checked |
|
1120 | 1120 | image_tag 'toggle_check.png' |
|
1121 | 1121 | end |
|
1122 | 1122 | end |
|
1123 | 1123 | |
|
1124 | 1124 | def context_menu(url) |
|
1125 | 1125 | unless @context_menu_included |
|
1126 | 1126 | content_for :header_tags do |
|
1127 | 1127 | javascript_include_tag('context_menu') + |
|
1128 | 1128 | stylesheet_link_tag('context_menu') |
|
1129 | 1129 | end |
|
1130 | 1130 | if l(:direction) == 'rtl' |
|
1131 | 1131 | content_for :header_tags do |
|
1132 | 1132 | stylesheet_link_tag('context_menu_rtl') |
|
1133 | 1133 | end |
|
1134 | 1134 | end |
|
1135 | 1135 | @context_menu_included = true |
|
1136 | 1136 | end |
|
1137 | 1137 | javascript_tag "contextMenuInit('#{ url_for(url) }')" |
|
1138 | 1138 | end |
|
1139 | 1139 | |
|
1140 | 1140 | def calendar_for(field_id) |
|
1141 | 1141 | include_calendar_headers_tags |
|
1142 | 1142 | javascript_tag("$(function() { $('##{field_id}').datepicker(datepickerOptions); });") |
|
1143 | 1143 | end |
|
1144 | 1144 | |
|
1145 | 1145 | def include_calendar_headers_tags |
|
1146 | 1146 | unless @calendar_headers_tags_included |
|
1147 | 1147 | tags = ''.html_safe |
|
1148 | 1148 | @calendar_headers_tags_included = true |
|
1149 | 1149 | content_for :header_tags do |
|
1150 | 1150 | start_of_week = Setting.start_of_week |
|
1151 | 1151 | start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank? |
|
1152 | 1152 | # Redmine uses 1..7 (monday..sunday) in settings and locales |
|
1153 | 1153 | # JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0 |
|
1154 | 1154 | start_of_week = start_of_week.to_i % 7 |
|
1155 | 1155 | tags << javascript_tag( |
|
1156 | 1156 | "var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " + |
|
1157 | 1157 | "showOn: 'button', buttonImageOnly: true, buttonImage: '" + |
|
1158 | 1158 | path_to_image('/images/calendar.png') + |
|
1159 | 1159 | "', showButtonPanel: true, showWeek: true, showOtherMonths: true, " + |
|
1160 | 1160 | "selectOtherMonths: true, changeMonth: true, changeYear: true, " + |
|
1161 | 1161 | "beforeShow: beforeShowDatePicker};") |
|
1162 | 1162 | jquery_locale = l('jquery.locale', :default => current_language.to_s) |
|
1163 | 1163 | unless jquery_locale == 'en' |
|
1164 | 1164 | tags << javascript_include_tag("i18n/datepicker-#{jquery_locale}.js") |
|
1165 | 1165 | end |
|
1166 | 1166 | tags |
|
1167 | 1167 | end |
|
1168 | 1168 | end |
|
1169 | 1169 | end |
|
1170 | 1170 | |
|
1171 | 1171 | # Overrides Rails' stylesheet_link_tag with themes and plugins support. |
|
1172 | 1172 | # Examples: |
|
1173 | 1173 | # stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults |
|
1174 | 1174 | # stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets |
|
1175 | 1175 | # |
|
1176 | 1176 | def stylesheet_link_tag(*sources) |
|
1177 | 1177 | options = sources.last.is_a?(Hash) ? sources.pop : {} |
|
1178 | 1178 | plugin = options.delete(:plugin) |
|
1179 | 1179 | sources = sources.map do |source| |
|
1180 | 1180 | if plugin |
|
1181 | 1181 | "/plugin_assets/#{plugin}/stylesheets/#{source}" |
|
1182 | 1182 | elsif current_theme && current_theme.stylesheets.include?(source) |
|
1183 | 1183 | current_theme.stylesheet_path(source) |
|
1184 | 1184 | else |
|
1185 | 1185 | source |
|
1186 | 1186 | end |
|
1187 | 1187 | end |
|
1188 | 1188 | super *sources, options |
|
1189 | 1189 | end |
|
1190 | 1190 | |
|
1191 | 1191 | # Overrides Rails' image_tag with themes and plugins support. |
|
1192 | 1192 | # Examples: |
|
1193 | 1193 | # image_tag('image.png') # => picks image.png from the current theme or defaults |
|
1194 | 1194 | # image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets |
|
1195 | 1195 | # |
|
1196 | 1196 | def image_tag(source, options={}) |
|
1197 | 1197 | if plugin = options.delete(:plugin) |
|
1198 | 1198 | source = "/plugin_assets/#{plugin}/images/#{source}" |
|
1199 | 1199 | elsif current_theme && current_theme.images.include?(source) |
|
1200 | 1200 | source = current_theme.image_path(source) |
|
1201 | 1201 | end |
|
1202 | 1202 | super source, options |
|
1203 | 1203 | end |
|
1204 | 1204 | |
|
1205 | 1205 | # Overrides Rails' javascript_include_tag with plugins support |
|
1206 | 1206 | # Examples: |
|
1207 | 1207 | # javascript_include_tag('scripts') # => picks scripts.js from defaults |
|
1208 | 1208 | # javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets |
|
1209 | 1209 | # |
|
1210 | 1210 | def javascript_include_tag(*sources) |
|
1211 | 1211 | options = sources.last.is_a?(Hash) ? sources.pop : {} |
|
1212 | 1212 | if plugin = options.delete(:plugin) |
|
1213 | 1213 | sources = sources.map do |source| |
|
1214 | 1214 | if plugin |
|
1215 | 1215 | "/plugin_assets/#{plugin}/javascripts/#{source}" |
|
1216 | 1216 | else |
|
1217 | 1217 | source |
|
1218 | 1218 | end |
|
1219 | 1219 | end |
|
1220 | 1220 | end |
|
1221 | 1221 | super *sources, options |
|
1222 | 1222 | end |
|
1223 | 1223 | |
|
1224 | 1224 | def sidebar_content? |
|
1225 | 1225 | content_for?(:sidebar) || view_layouts_base_sidebar_hook_response.present? |
|
1226 | 1226 | end |
|
1227 | 1227 | |
|
1228 | 1228 | def view_layouts_base_sidebar_hook_response |
|
1229 | 1229 | @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar) |
|
1230 | 1230 | end |
|
1231 | 1231 | |
|
1232 | 1232 | def email_delivery_enabled? |
|
1233 | 1233 | !!ActionMailer::Base.perform_deliveries |
|
1234 | 1234 | end |
|
1235 | 1235 | |
|
1236 | 1236 | # Returns the avatar image tag for the given +user+ if avatars are enabled |
|
1237 | 1237 | # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>') |
|
1238 | 1238 | def avatar(user, options = { }) |
|
1239 | 1239 | if Setting.gravatar_enabled? |
|
1240 | 1240 | options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default}) |
|
1241 | 1241 | email = nil |
|
1242 | 1242 | if user.respond_to?(:mail) |
|
1243 | 1243 | email = user.mail |
|
1244 | 1244 | elsif user.to_s =~ %r{<(.+?)>} |
|
1245 | 1245 | email = $1 |
|
1246 | 1246 | end |
|
1247 | 1247 | return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil |
|
1248 | 1248 | else |
|
1249 | 1249 | '' |
|
1250 | 1250 | end |
|
1251 | 1251 | end |
|
1252 | 1252 | |
|
1253 | 1253 | def sanitize_anchor_name(anchor) |
|
1254 | 1254 | anchor.gsub(%r{[^\s\-\p{Word}]}, '').gsub(%r{\s+(\-+\s*)?}, '-') |
|
1255 | 1255 | end |
|
1256 | 1256 | |
|
1257 | 1257 | # Returns the javascript tags that are included in the html layout head |
|
1258 | 1258 | def javascript_heads |
|
1259 | 1259 | tags = javascript_include_tag('jquery-1.11.1-ui-1.11.0-ujs-3.1.1', 'application') |
|
1260 | 1260 | unless User.current.pref.warn_on_leaving_unsaved == '0' |
|
1261 | 1261 | tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") |
|
1262 | 1262 | end |
|
1263 | 1263 | tags |
|
1264 | 1264 | end |
|
1265 | 1265 | |
|
1266 | 1266 | def favicon |
|
1267 | 1267 | "<link rel='shortcut icon' href='#{favicon_path}' />".html_safe |
|
1268 | 1268 | end |
|
1269 | 1269 | |
|
1270 | 1270 | # Returns the path to the favicon |
|
1271 | 1271 | def favicon_path |
|
1272 | 1272 | icon = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico' |
|
1273 | 1273 | image_path(icon) |
|
1274 | 1274 | end |
|
1275 | 1275 | |
|
1276 | 1276 | # Returns the full URL to the favicon |
|
1277 | 1277 | def favicon_url |
|
1278 | 1278 | # TODO: use #image_url introduced in Rails4 |
|
1279 | 1279 | path = favicon_path |
|
1280 | 1280 | base = url_for(:controller => 'welcome', :action => 'index', :only_path => false) |
|
1281 | 1281 | base.sub(%r{/+$},'') + '/' + path.sub(%r{^/+},'') |
|
1282 | 1282 | end |
|
1283 | 1283 | |
|
1284 | 1284 | def robot_exclusion_tag |
|
1285 | 1285 | '<meta name="robots" content="noindex,follow,noarchive" />'.html_safe |
|
1286 | 1286 | end |
|
1287 | 1287 | |
|
1288 | 1288 | # Returns true if arg is expected in the API response |
|
1289 | 1289 | def include_in_api_response?(arg) |
|
1290 | 1290 | unless @included_in_api_response |
|
1291 | 1291 | param = params[:include] |
|
1292 | 1292 | @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',') |
|
1293 | 1293 | @included_in_api_response.collect!(&:strip) |
|
1294 | 1294 | end |
|
1295 | 1295 | @included_in_api_response.include?(arg.to_s) |
|
1296 | 1296 | end |
|
1297 | 1297 | |
|
1298 | 1298 | # Returns options or nil if nometa param or X-Redmine-Nometa header |
|
1299 | 1299 | # was set in the request |
|
1300 | 1300 | def api_meta(options) |
|
1301 | 1301 | if params[:nometa].present? || request.headers['X-Redmine-Nometa'] |
|
1302 | 1302 | # compatibility mode for activeresource clients that raise |
|
1303 | 1303 | # an error when deserializing an array with attributes |
|
1304 | 1304 | nil |
|
1305 | 1305 | else |
|
1306 | 1306 | options |
|
1307 | 1307 | end |
|
1308 | 1308 | end |
|
1309 | 1309 | |
|
1310 | 1310 | private |
|
1311 | 1311 | |
|
1312 | 1312 | def wiki_helper |
|
1313 | 1313 | helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) |
|
1314 | 1314 | extend helper |
|
1315 | 1315 | return self |
|
1316 | 1316 | end |
|
1317 | 1317 | |
|
1318 | 1318 | def link_to_content_update(text, url_params = {}, html_options = {}) |
|
1319 | 1319 | link_to(text, url_params, html_options) |
|
1320 | 1320 | end |
|
1321 | 1321 | end |
@@ -1,4214 +1,4214 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class IssuesControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, |
|
22 | 22 | :users, :email_addresses, |
|
23 | 23 | :roles, |
|
24 | 24 | :members, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :issues, |
|
27 | 27 | :issue_statuses, |
|
28 | 28 | :issue_relations, |
|
29 | 29 | :versions, |
|
30 | 30 | :trackers, |
|
31 | 31 | :projects_trackers, |
|
32 | 32 | :issue_categories, |
|
33 | 33 | :enabled_modules, |
|
34 | 34 | :enumerations, |
|
35 | 35 | :attachments, |
|
36 | 36 | :workflows, |
|
37 | 37 | :custom_fields, |
|
38 | 38 | :custom_values, |
|
39 | 39 | :custom_fields_projects, |
|
40 | 40 | :custom_fields_trackers, |
|
41 | 41 | :time_entries, |
|
42 | 42 | :journals, |
|
43 | 43 | :journal_details, |
|
44 | 44 | :queries, |
|
45 | 45 | :repositories, |
|
46 | 46 | :changesets |
|
47 | 47 | |
|
48 | 48 | include Redmine::I18n |
|
49 | 49 | |
|
50 | 50 | def setup |
|
51 | 51 | User.current = nil |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_index |
|
55 | 55 | with_settings :default_language => "en" do |
|
56 | 56 | get :index |
|
57 | 57 | assert_response :success |
|
58 | 58 | assert_template 'index' |
|
59 | 59 | assert_not_nil assigns(:issues) |
|
60 | 60 | assert_nil assigns(:project) |
|
61 | 61 | |
|
62 | 62 | # links to visible issues |
|
63 | 63 | assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/ |
|
64 | 64 | assert_select 'a[href="/issues/5"]', :text => /Subproject issue/ |
|
65 | 65 | # private projects hidden |
|
66 | 66 | assert_select 'a[href="/issues/6"]', 0 |
|
67 | 67 | assert_select 'a[href="/issues/4"]', 0 |
|
68 | 68 | # project column |
|
69 | 69 | assert_select 'th', :text => /Project/ |
|
70 | 70 | end |
|
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' |
|
78 | 78 | assert_not_nil assigns(:issues) |
|
79 | 79 | assert_nil assigns(:project) |
|
80 | 80 | |
|
81 | 81 | assert_select 'a[href="/issues/1"]', 0 |
|
82 | 82 | assert_select 'a[href="/issues/5"]', :text => /Subproject issue/ |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def test_index_should_list_visible_issues_only |
|
86 | 86 | get :index, :per_page => 100 |
|
87 | 87 | assert_response :success |
|
88 | 88 | assert_not_nil assigns(:issues) |
|
89 | 89 | assert_nil assigns(:issues).detect {|issue| !issue.visible?} |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def test_index_with_project |
|
93 | 93 | Setting.display_subprojects_issues = 0 |
|
94 | 94 | get :index, :project_id => 1 |
|
95 | 95 | assert_response :success |
|
96 | 96 | assert_template 'index' |
|
97 | 97 | assert_not_nil assigns(:issues) |
|
98 | 98 | |
|
99 | 99 | assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/ |
|
100 | 100 | assert_select 'a[href="/issues/5"]', 0 |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | def test_index_with_project_and_subprojects |
|
104 | 104 | Setting.display_subprojects_issues = 1 |
|
105 | 105 | get :index, :project_id => 1 |
|
106 | 106 | assert_response :success |
|
107 | 107 | assert_template 'index' |
|
108 | 108 | assert_not_nil assigns(:issues) |
|
109 | 109 | |
|
110 | 110 | assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/ |
|
111 | 111 | assert_select 'a[href="/issues/5"]', :text => /Subproject issue/ |
|
112 | 112 | assert_select 'a[href="/issues/6"]', 0 |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission |
|
116 | 116 | @request.session[:user_id] = 2 |
|
117 | 117 | Setting.display_subprojects_issues = 1 |
|
118 | 118 | get :index, :project_id => 1 |
|
119 | 119 | assert_response :success |
|
120 | 120 | assert_template 'index' |
|
121 | 121 | assert_not_nil assigns(:issues) |
|
122 | 122 | |
|
123 | 123 | assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/ |
|
124 | 124 | assert_select 'a[href="/issues/5"]', :text => /Subproject issue/ |
|
125 | 125 | assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/ |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def test_index_with_project_and_default_filter |
|
129 | 129 | get :index, :project_id => 1, :set_filter => 1 |
|
130 | 130 | assert_response :success |
|
131 | 131 | assert_template 'index' |
|
132 | 132 | assert_not_nil assigns(:issues) |
|
133 | 133 | |
|
134 | 134 | query = assigns(:query) |
|
135 | 135 | assert_not_nil query |
|
136 | 136 | # default filter |
|
137 | 137 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def test_index_with_project_and_filter |
|
141 | 141 | get :index, :project_id => 1, :set_filter => 1, |
|
142 | 142 | :f => ['tracker_id'], |
|
143 | 143 | :op => {'tracker_id' => '='}, |
|
144 | 144 | :v => {'tracker_id' => ['1']} |
|
145 | 145 | assert_response :success |
|
146 | 146 | assert_template 'index' |
|
147 | 147 | assert_not_nil assigns(:issues) |
|
148 | 148 | |
|
149 | 149 | query = assigns(:query) |
|
150 | 150 | assert_not_nil query |
|
151 | 151 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | def test_index_with_short_filters |
|
155 | 155 | to_test = { |
|
156 | 156 | 'status_id' => { |
|
157 | 157 | 'o' => { :op => 'o', :values => [''] }, |
|
158 | 158 | 'c' => { :op => 'c', :values => [''] }, |
|
159 | 159 | '7' => { :op => '=', :values => ['7'] }, |
|
160 | 160 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, |
|
161 | 161 | '=7' => { :op => '=', :values => ['7'] }, |
|
162 | 162 | '!3' => { :op => '!', :values => ['3'] }, |
|
163 | 163 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, |
|
164 | 164 | 'subject' => { |
|
165 | 165 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, |
|
166 | 166 | 'o' => { :op => '=', :values => ['o'] }, |
|
167 | 167 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, |
|
168 | 168 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, |
|
169 | 169 | 'tracker_id' => { |
|
170 | 170 | '3' => { :op => '=', :values => ['3'] }, |
|
171 | 171 | '=3' => { :op => '=', :values => ['3'] }}, |
|
172 | 172 | 'start_date' => { |
|
173 | 173 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
174 | 174 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
175 | 175 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
176 | 176 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, |
|
177 | 177 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, |
|
178 | 178 | '<t+2' => { :op => '<t+', :values => ['2'] }, |
|
179 | 179 | '>t+2' => { :op => '>t+', :values => ['2'] }, |
|
180 | 180 | 't+2' => { :op => 't+', :values => ['2'] }, |
|
181 | 181 | 't' => { :op => 't', :values => [''] }, |
|
182 | 182 | 'w' => { :op => 'w', :values => [''] }, |
|
183 | 183 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
184 | 184 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
185 | 185 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
186 | 186 | 'created_on' => { |
|
187 | 187 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
188 | 188 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
189 | 189 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
190 | 190 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
191 | 191 | 'cf_1' => { |
|
192 | 192 | 'c' => { :op => '=', :values => ['c'] }, |
|
193 | 193 | '!c' => { :op => '!', :values => ['c'] }, |
|
194 | 194 | '!*' => { :op => '!*', :values => [''] }, |
|
195 | 195 | '*' => { :op => '*', :values => [''] }}, |
|
196 | 196 | 'estimated_hours' => { |
|
197 | 197 | '=13.4' => { :op => '=', :values => ['13.4'] }, |
|
198 | 198 | '>=45' => { :op => '>=', :values => ['45'] }, |
|
199 | 199 | '<=125' => { :op => '<=', :values => ['125'] }, |
|
200 | 200 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, |
|
201 | 201 | '!*' => { :op => '!*', :values => [''] }, |
|
202 | 202 | '*' => { :op => '*', :values => [''] }} |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} |
|
206 | 206 | |
|
207 | 207 | to_test.each do |field, expression_and_expected| |
|
208 | 208 | expression_and_expected.each do |filter_expression, expected| |
|
209 | 209 | |
|
210 | 210 | get :index, :set_filter => 1, field => filter_expression |
|
211 | 211 | |
|
212 | 212 | assert_response :success |
|
213 | 213 | assert_template 'index' |
|
214 | 214 | assert_not_nil assigns(:issues) |
|
215 | 215 | |
|
216 | 216 | query = assigns(:query) |
|
217 | 217 | assert_not_nil query |
|
218 | 218 | assert query.has_filter?(field) |
|
219 | 219 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) |
|
220 | 220 | end |
|
221 | 221 | end |
|
222 | 222 | end |
|
223 | 223 | |
|
224 | 224 | def test_index_with_project_and_empty_filters |
|
225 | 225 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] |
|
226 | 226 | assert_response :success |
|
227 | 227 | assert_template 'index' |
|
228 | 228 | assert_not_nil assigns(:issues) |
|
229 | 229 | |
|
230 | 230 | query = assigns(:query) |
|
231 | 231 | assert_not_nil query |
|
232 | 232 | # no filter |
|
233 | 233 | assert_equal({}, query.filters) |
|
234 | 234 | end |
|
235 | 235 | |
|
236 | 236 | def test_index_with_project_custom_field_filter |
|
237 | 237 | field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string') |
|
238 | 238 | CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo') |
|
239 | 239 | CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo') |
|
240 | 240 | filter_name = "project.cf_#{field.id}" |
|
241 | 241 | @request.session[:user_id] = 1 |
|
242 | 242 | |
|
243 | 243 | get :index, :set_filter => 1, |
|
244 | 244 | :f => [filter_name], |
|
245 | 245 | :op => {filter_name => '='}, |
|
246 | 246 | :v => {filter_name => ['Foo']} |
|
247 | 247 | assert_response :success |
|
248 | 248 | assert_template 'index' |
|
249 | 249 | assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | def test_index_with_query |
|
253 | 253 | get :index, :project_id => 1, :query_id => 5 |
|
254 | 254 | assert_response :success |
|
255 | 255 | assert_template 'index' |
|
256 | 256 | assert_not_nil assigns(:issues) |
|
257 | 257 | assert_nil assigns(:issue_count_by_group) |
|
258 | 258 | end |
|
259 | 259 | |
|
260 | 260 | def test_index_with_query_grouped_by_tracker |
|
261 | 261 | get :index, :project_id => 1, :query_id => 6 |
|
262 | 262 | assert_response :success |
|
263 | 263 | assert_template 'index' |
|
264 | 264 | assert_not_nil assigns(:issues) |
|
265 | 265 | assert_not_nil assigns(:issue_count_by_group) |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | def test_index_with_query_grouped_by_list_custom_field |
|
269 | 269 | get :index, :project_id => 1, :query_id => 9 |
|
270 | 270 | assert_response :success |
|
271 | 271 | assert_template 'index' |
|
272 | 272 | assert_not_nil assigns(:issues) |
|
273 | 273 | assert_not_nil assigns(:issue_count_by_group) |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | 276 | def test_index_with_query_grouped_by_user_custom_field |
|
277 | 277 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') |
|
278 | 278 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
|
279 | 279 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
|
280 | 280 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
|
281 | 281 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
|
282 | 282 | |
|
283 | 283 | get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}" |
|
284 | 284 | assert_response :success |
|
285 | 285 | |
|
286 | 286 | assert_select 'tr.group', 3 |
|
287 | 287 | assert_select 'tr.group' do |
|
288 | 288 | assert_select 'a', :text => 'John Smith' |
|
289 | 289 | assert_select 'span.count', :text => '1' |
|
290 | 290 | end |
|
291 | 291 | assert_select 'tr.group' do |
|
292 | 292 | assert_select 'a', :text => 'Dave Lopper' |
|
293 | 293 | assert_select 'span.count', :text => '2' |
|
294 | 294 | end |
|
295 | 295 | end |
|
296 | 296 | |
|
297 | 297 | def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values |
|
298 | 298 | cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool') |
|
299 | 299 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1') |
|
300 | 300 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0') |
|
301 | 301 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '') |
|
302 | 302 | |
|
303 | 303 | with_settings :default_language => 'en' do |
|
304 | 304 | get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}" |
|
305 | 305 | assert_response :success |
|
306 | 306 | end |
|
307 | 307 | |
|
308 | 308 | assert_select 'tr.group', 3 |
|
309 | 309 | assert_select 'tr.group', :text => /Yes/ |
|
310 | 310 | assert_select 'tr.group', :text => /No/ |
|
311 | 311 | assert_select 'tr.group', :text => /blank/ |
|
312 | 312 | end |
|
313 | 313 | |
|
314 | 314 | def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group |
|
315 | 315 | cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool', :is_filter => true) |
|
316 | 316 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0') |
|
317 | 317 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0') |
|
318 | 318 | |
|
319 | 319 | with_settings :default_language => 'en' do |
|
320 | 320 | get :index, :project_id => 1, :set_filter => 1, "cf_#{cf.id}" => "*", :group_by => "cf_#{cf.id}" |
|
321 | 321 | assert_response :success |
|
322 | 322 | assert_equal [1, 2], assigns(:issues).map(&:id).sort |
|
323 | 323 | end |
|
324 | 324 | |
|
325 | 325 | assert_select 'tr.group', 1 |
|
326 | 326 | assert_select 'tr.group', :text => /No/ |
|
327 | 327 | end |
|
328 | 328 | |
|
329 | 329 | def test_index_with_query_grouped_by_tracker_in_normal_order |
|
330 | 330 | 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} |
|
331 | 331 | |
|
332 | 332 | get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc' |
|
333 | 333 | assert_response :success |
|
334 | 334 | |
|
335 | 335 | trackers = assigns(:issues).map(&:tracker).uniq |
|
336 | 336 | assert_equal [1, 2, 3], trackers.map(&:id) |
|
337 | 337 | end |
|
338 | 338 | |
|
339 | 339 | def test_index_with_query_grouped_by_tracker_in_reverse_order |
|
340 | 340 | 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} |
|
341 | 341 | |
|
342 | 342 | get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc' |
|
343 | 343 | assert_response :success |
|
344 | 344 | |
|
345 | 345 | trackers = assigns(:issues).map(&:tracker).uniq |
|
346 | 346 | assert_equal [3, 2, 1], trackers.map(&:id) |
|
347 | 347 | end |
|
348 | 348 | |
|
349 | 349 | def test_index_with_query_id_and_project_id_should_set_session_query |
|
350 | 350 | get :index, :project_id => 1, :query_id => 4 |
|
351 | 351 | assert_response :success |
|
352 | 352 | assert_kind_of Hash, session[:query] |
|
353 | 353 | assert_equal 4, session[:query][:id] |
|
354 | 354 | assert_equal 1, session[:query][:project_id] |
|
355 | 355 | end |
|
356 | 356 | |
|
357 | 357 | def test_index_with_invalid_query_id_should_respond_404 |
|
358 | 358 | get :index, :project_id => 1, :query_id => 999 |
|
359 | 359 | assert_response 404 |
|
360 | 360 | end |
|
361 | 361 | |
|
362 | 362 | def test_index_with_cross_project_query_in_session_should_show_project_issues |
|
363 | 363 | q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) |
|
364 | 364 | @request.session[:query] = {:id => q.id, :project_id => 1} |
|
365 | 365 | |
|
366 | 366 | with_settings :display_subprojects_issues => '0' do |
|
367 | 367 | get :index, :project_id => 1 |
|
368 | 368 | end |
|
369 | 369 | assert_response :success |
|
370 | 370 | assert_not_nil assigns(:query) |
|
371 | 371 | assert_equal q.id, assigns(:query).id |
|
372 | 372 | assert_equal 1, assigns(:query).project_id |
|
373 | 373 | assert_equal [1], assigns(:issues).map(&:project_id).uniq |
|
374 | 374 | end |
|
375 | 375 | |
|
376 | 376 | def test_private_query_should_not_be_available_to_other_users |
|
377 | 377 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) |
|
378 | 378 | @request.session[:user_id] = 3 |
|
379 | 379 | |
|
380 | 380 | get :index, :query_id => q.id |
|
381 | 381 | assert_response 403 |
|
382 | 382 | end |
|
383 | 383 | |
|
384 | 384 | def test_private_query_should_be_available_to_its_user |
|
385 | 385 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) |
|
386 | 386 | @request.session[:user_id] = 2 |
|
387 | 387 | |
|
388 | 388 | get :index, :query_id => q.id |
|
389 | 389 | assert_response :success |
|
390 | 390 | end |
|
391 | 391 | |
|
392 | 392 | def test_public_query_should_be_available_to_other_users |
|
393 | 393 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil) |
|
394 | 394 | @request.session[:user_id] = 3 |
|
395 | 395 | |
|
396 | 396 | get :index, :query_id => q.id |
|
397 | 397 | assert_response :success |
|
398 | 398 | end |
|
399 | 399 | |
|
400 | 400 | def test_index_should_omit_page_param_in_export_links |
|
401 | 401 | get :index, :page => 2 |
|
402 | 402 | assert_response :success |
|
403 | 403 | assert_select 'a.atom[href="/issues.atom"]' |
|
404 | 404 | assert_select 'a.csv[href="/issues.csv"]' |
|
405 | 405 | assert_select 'a.pdf[href="/issues.pdf"]' |
|
406 | 406 | assert_select 'form#csv-export-form[action="/issues.csv"]' |
|
407 | 407 | end |
|
408 | 408 | |
|
409 | 409 | def test_index_should_not_warn_when_not_exceeding_export_limit |
|
410 | 410 | with_settings :issues_export_limit => 200 do |
|
411 | 411 | get :index |
|
412 | 412 | assert_select '#csv-export-options p.icon-warning', 0 |
|
413 | 413 | end |
|
414 | 414 | end |
|
415 | 415 | |
|
416 | 416 | def test_index_should_warn_when_exceeding_export_limit |
|
417 | 417 | with_settings :issues_export_limit => 2 do |
|
418 | 418 | get :index |
|
419 | 419 | assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2} |
|
420 | 420 | end |
|
421 | 421 | end |
|
422 | 422 | |
|
423 | 423 | def test_index_csv |
|
424 | 424 | get :index, :format => 'csv' |
|
425 | 425 | assert_response :success |
|
426 | 426 | assert_not_nil assigns(:issues) |
|
427 | 427 | assert_equal 'text/csv; header=present', @response.content_type |
|
428 | 428 | assert @response.body.starts_with?("#,") |
|
429 | 429 | lines = @response.body.chomp.split("\n") |
|
430 | 430 | assert_equal assigns(:query).columns.size, lines[0].split(',').size |
|
431 | 431 | end |
|
432 | 432 | |
|
433 | 433 | def test_index_csv_with_project |
|
434 | 434 | get :index, :project_id => 1, :format => 'csv' |
|
435 | 435 | assert_response :success |
|
436 | 436 | assert_not_nil assigns(:issues) |
|
437 | 437 | assert_equal 'text/csv; header=present', @response.content_type |
|
438 | 438 | end |
|
439 | 439 | |
|
440 | 440 | def test_index_csv_with_description |
|
441 | 441 | Issue.generate!(:description => 'test_index_csv_with_description') |
|
442 | 442 | |
|
443 | 443 | with_settings :default_language => 'en' do |
|
444 | 444 | get :index, :format => 'csv', :description => '1' |
|
445 | 445 | assert_response :success |
|
446 | 446 | assert_not_nil assigns(:issues) |
|
447 | 447 | end |
|
448 | 448 | |
|
449 | 449 | assert_equal 'text/csv; header=present', response.content_type |
|
450 | 450 | headers = response.body.chomp.split("\n").first.split(',') |
|
451 | 451 | assert_include 'Description', headers |
|
452 | 452 | assert_include 'test_index_csv_with_description', response.body |
|
453 | 453 | end |
|
454 | 454 | |
|
455 | 455 | def test_index_csv_with_spent_time_column |
|
456 | 456 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) |
|
457 | 457 | TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) |
|
458 | 458 | |
|
459 | 459 | get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours) |
|
460 | 460 | assert_response :success |
|
461 | 461 | assert_equal 'text/csv; header=present', @response.content_type |
|
462 | 462 | lines = @response.body.chomp.split("\n") |
|
463 | 463 | assert_include "#{issue.id},#{issue.subject},7.33", lines |
|
464 | 464 | end |
|
465 | 465 | |
|
466 | 466 | def test_index_csv_with_all_columns |
|
467 | 467 | get :index, :format => 'csv', :columns => 'all' |
|
468 | 468 | assert_response :success |
|
469 | 469 | assert_not_nil assigns(:issues) |
|
470 | 470 | assert_equal 'text/csv; header=present', @response.content_type |
|
471 | 471 | assert_match /\A#,/, response.body |
|
472 | 472 | lines = response.body.chomp.split("\n") |
|
473 | 473 | assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size |
|
474 | 474 | end |
|
475 | 475 | |
|
476 | 476 | def test_index_csv_with_multi_column_field |
|
477 | 477 | CustomField.find(1).update_attribute :multiple, true |
|
478 | 478 | issue = Issue.find(1) |
|
479 | 479 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
480 | 480 | issue.save! |
|
481 | 481 | |
|
482 | 482 | get :index, :format => 'csv', :columns => 'all' |
|
483 | 483 | assert_response :success |
|
484 | 484 | lines = @response.body.chomp.split("\n") |
|
485 | 485 | assert lines.detect {|line| line.include?('"MySQL, Oracle"')} |
|
486 | 486 | end |
|
487 | 487 | |
|
488 | 488 | def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator |
|
489 | 489 | field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float') |
|
490 | 490 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'}) |
|
491 | 491 | |
|
492 | 492 | with_settings :default_language => 'fr' do |
|
493 | 493 | get :index, :format => 'csv', :columns => 'all' |
|
494 | 494 | assert_response :success |
|
495 | 495 | issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s} |
|
496 | 496 | assert_include '185,60', issue_line |
|
497 | 497 | end |
|
498 | 498 | |
|
499 | 499 | with_settings :default_language => 'en' do |
|
500 | 500 | get :index, :format => 'csv', :columns => 'all' |
|
501 | 501 | assert_response :success |
|
502 | 502 | issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s} |
|
503 | 503 | assert_include '185.60', issue_line |
|
504 | 504 | end |
|
505 | 505 | end |
|
506 | 506 | |
|
507 | 507 | def test_index_csv_should_fill_parent_column_with_parent_id |
|
508 | 508 | Issue.delete_all |
|
509 | 509 | parent = Issue.generate! |
|
510 | 510 | child = Issue.generate!(:parent_issue_id => parent.id) |
|
511 | 511 | |
|
512 | 512 | with_settings :default_language => 'en' do |
|
513 | 513 | get :index, :format => 'csv', :c => %w(parent) |
|
514 | 514 | end |
|
515 | 515 | lines = response.body.split("\n") |
|
516 | 516 | assert_include "#{child.id},#{parent.id}", lines |
|
517 | 517 | end |
|
518 | 518 | |
|
519 | 519 | def test_index_csv_big_5 |
|
520 | 520 | with_settings :default_language => "zh-TW" do |
|
521 | 521 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8') |
|
522 | 522 | str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5') |
|
523 | 523 | issue = Issue.generate!(:subject => str_utf8) |
|
524 | 524 | |
|
525 | 525 | get :index, :project_id => 1, |
|
526 | 526 | :f => ['subject'], |
|
527 | 527 | :op => '=', :values => [str_utf8], |
|
528 | 528 | :format => 'csv' |
|
529 | 529 | assert_equal 'text/csv; header=present', @response.content_type |
|
530 | 530 | lines = @response.body.chomp.split("\n") |
|
531 | 531 | header = lines[0] |
|
532 | 532 | issue_line = lines.find {|l| l =~ /^#{issue.id},/} |
|
533 | 533 | s1 = "\xaa\xac\xbaA".force_encoding('Big5') |
|
534 | 534 | assert_include s1, header |
|
535 | 535 | assert_include str_big5, issue_line |
|
536 | 536 | end |
|
537 | 537 | end |
|
538 | 538 | |
|
539 | 539 | def test_index_csv_cannot_convert_should_be_replaced_big_5 |
|
540 | 540 | with_settings :default_language => "zh-TW" do |
|
541 | 541 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8') |
|
542 | 542 | issue = Issue.generate!(:subject => str_utf8) |
|
543 | 543 | |
|
544 | 544 | get :index, :project_id => 1, |
|
545 | 545 | :f => ['subject'], |
|
546 | 546 | :op => '=', :values => [str_utf8], |
|
547 | 547 | :c => ['status', 'subject'], |
|
548 | 548 | :format => 'csv', |
|
549 | 549 | :set_filter => 1 |
|
550 | 550 | assert_equal 'text/csv; header=present', @response.content_type |
|
551 | 551 | lines = @response.body.chomp.split("\n") |
|
552 | 552 | header = lines[0] |
|
553 | 553 | issue_line = lines.find {|l| l =~ /^#{issue.id},/} |
|
554 | 554 | s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status |
|
555 | 555 | assert header.include?(s1) |
|
556 | 556 | s2 = issue_line.split(",")[2] |
|
557 | 557 | s3 = "\xa5H?".force_encoding('Big5') # subject |
|
558 | 558 | assert_equal s3, s2 |
|
559 | 559 | end |
|
560 | 560 | end |
|
561 | 561 | |
|
562 | 562 | def test_index_csv_tw |
|
563 | 563 | with_settings :default_language => "zh-TW" do |
|
564 | 564 | str1 = "test_index_csv_tw" |
|
565 | 565 | issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') |
|
566 | 566 | |
|
567 | 567 | get :index, :project_id => 1, |
|
568 | 568 | :f => ['subject'], |
|
569 | 569 | :op => '=', :values => [str1], |
|
570 | 570 | :c => ['estimated_hours', 'subject'], |
|
571 | 571 | :format => 'csv', |
|
572 | 572 | :set_filter => 1 |
|
573 | 573 | assert_equal 'text/csv; header=present', @response.content_type |
|
574 | 574 | lines = @response.body.chomp.split("\n") |
|
575 | 575 | assert_include "#{issue.id},1234.50,#{str1}", lines |
|
576 | 576 | end |
|
577 | 577 | end |
|
578 | 578 | |
|
579 | 579 | def test_index_csv_fr |
|
580 | 580 | with_settings :default_language => "fr" do |
|
581 | 581 | str1 = "test_index_csv_fr" |
|
582 | 582 | issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') |
|
583 | 583 | |
|
584 | 584 | get :index, :project_id => 1, |
|
585 | 585 | :f => ['subject'], |
|
586 | 586 | :op => '=', :values => [str1], |
|
587 | 587 | :c => ['estimated_hours', 'subject'], |
|
588 | 588 | :format => 'csv', |
|
589 | 589 | :set_filter => 1 |
|
590 | 590 | assert_equal 'text/csv; header=present', @response.content_type |
|
591 | 591 | lines = @response.body.chomp.split("\n") |
|
592 | 592 | assert_include "#{issue.id};1234,50;#{str1}", lines |
|
593 | 593 | end |
|
594 | 594 | end |
|
595 | 595 | |
|
596 | 596 | def test_index_pdf |
|
597 | 597 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| |
|
598 | 598 | with_settings :default_language => lang do |
|
599 | 599 | |
|
600 | 600 | get :index |
|
601 | 601 | assert_response :success |
|
602 | 602 | assert_template 'index' |
|
603 | 603 | |
|
604 | 604 | get :index, :format => 'pdf' |
|
605 | 605 | assert_response :success |
|
606 | 606 | assert_not_nil assigns(:issues) |
|
607 | 607 | assert_equal 'application/pdf', @response.content_type |
|
608 | 608 | |
|
609 | 609 | get :index, :project_id => 1, :format => 'pdf' |
|
610 | 610 | assert_response :success |
|
611 | 611 | assert_not_nil assigns(:issues) |
|
612 | 612 | assert_equal 'application/pdf', @response.content_type |
|
613 | 613 | |
|
614 | 614 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
|
615 | 615 | assert_response :success |
|
616 | 616 | assert_not_nil assigns(:issues) |
|
617 | 617 | assert_equal 'application/pdf', @response.content_type |
|
618 | 618 | end |
|
619 | 619 | end |
|
620 | 620 | end |
|
621 | 621 | |
|
622 | 622 | def test_index_pdf_with_query_grouped_by_list_custom_field |
|
623 | 623 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' |
|
624 | 624 | assert_response :success |
|
625 | 625 | assert_not_nil assigns(:issues) |
|
626 | 626 | assert_not_nil assigns(:issue_count_by_group) |
|
627 | 627 | assert_equal 'application/pdf', @response.content_type |
|
628 | 628 | end |
|
629 | 629 | |
|
630 | 630 | def test_index_atom |
|
631 | 631 | get :index, :project_id => 'ecookbook', :format => 'atom' |
|
632 | 632 | assert_response :success |
|
633 | 633 | assert_template 'common/feed' |
|
634 | 634 | assert_equal 'application/atom+xml', response.content_type |
|
635 | 635 | |
|
636 | 636 | assert_select 'feed' do |
|
637 | 637 | assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom' |
|
638 | 638 | assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues' |
|
639 | 639 | assert_select 'entry link[href=?]', 'http://test.host/issues/1' |
|
640 | 640 | end |
|
641 | 641 | end |
|
642 | 642 | |
|
643 | 643 | def test_index_sort |
|
644 | 644 | get :index, :sort => 'tracker,id:desc' |
|
645 | 645 | assert_response :success |
|
646 | 646 | |
|
647 | 647 | sort_params = @request.session['issues_index_sort'] |
|
648 | 648 | assert sort_params.is_a?(String) |
|
649 | 649 | assert_equal 'tracker,id:desc', sort_params |
|
650 | 650 | |
|
651 | 651 | issues = assigns(:issues) |
|
652 | 652 | assert_not_nil issues |
|
653 | 653 | assert !issues.empty? |
|
654 | 654 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
|
655 | 655 | assert_select 'table.issues.sort-by-tracker.sort-asc' |
|
656 | 656 | end |
|
657 | 657 | |
|
658 | 658 | def test_index_sort_by_field_not_included_in_columns |
|
659 | 659 | Setting.issue_list_default_columns = %w(subject author) |
|
660 | 660 | get :index, :sort => 'tracker' |
|
661 | 661 | end |
|
662 | 662 | |
|
663 | 663 | def test_index_sort_by_assigned_to |
|
664 | 664 | get :index, :sort => 'assigned_to' |
|
665 | 665 | assert_response :success |
|
666 | 666 | assignees = assigns(:issues).collect(&:assigned_to).compact |
|
667 | 667 | assert_equal assignees.sort, assignees |
|
668 | 668 | assert_select 'table.issues.sort-by-assigned-to.sort-asc' |
|
669 | 669 | end |
|
670 | 670 | |
|
671 | 671 | def test_index_sort_by_assigned_to_desc |
|
672 | 672 | get :index, :sort => 'assigned_to:desc' |
|
673 | 673 | assert_response :success |
|
674 | 674 | assignees = assigns(:issues).collect(&:assigned_to).compact |
|
675 | 675 | assert_equal assignees.sort.reverse, assignees |
|
676 | 676 | assert_select 'table.issues.sort-by-assigned-to.sort-desc' |
|
677 | 677 | end |
|
678 | 678 | |
|
679 | 679 | def test_index_group_by_assigned_to |
|
680 | 680 | get :index, :group_by => 'assigned_to', :sort => 'priority' |
|
681 | 681 | assert_response :success |
|
682 | 682 | end |
|
683 | 683 | |
|
684 | 684 | def test_index_sort_by_author |
|
685 | 685 | get :index, :sort => 'author' |
|
686 | 686 | assert_response :success |
|
687 | 687 | authors = assigns(:issues).collect(&:author) |
|
688 | 688 | assert_equal authors.sort, authors |
|
689 | 689 | end |
|
690 | 690 | |
|
691 | 691 | def test_index_sort_by_author_desc |
|
692 | 692 | get :index, :sort => 'author:desc' |
|
693 | 693 | assert_response :success |
|
694 | 694 | authors = assigns(:issues).collect(&:author) |
|
695 | 695 | assert_equal authors.sort.reverse, authors |
|
696 | 696 | end |
|
697 | 697 | |
|
698 | 698 | def test_index_group_by_author |
|
699 | 699 | get :index, :group_by => 'author', :sort => 'priority' |
|
700 | 700 | assert_response :success |
|
701 | 701 | end |
|
702 | 702 | |
|
703 | 703 | def test_index_sort_by_spent_hours |
|
704 | 704 | get :index, :sort => 'spent_hours:desc' |
|
705 | 705 | assert_response :success |
|
706 | 706 | hours = assigns(:issues).collect(&:spent_hours) |
|
707 | 707 | assert_equal hours.sort.reverse, hours |
|
708 | 708 | end |
|
709 | 709 | |
|
710 | 710 | def test_index_sort_by_user_custom_field |
|
711 | 711 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') |
|
712 | 712 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
|
713 | 713 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
|
714 | 714 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
|
715 | 715 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
|
716 | 716 | |
|
717 | 717 | get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id" |
|
718 | 718 | assert_response :success |
|
719 | 719 | |
|
720 | 720 | assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id) |
|
721 | 721 | end |
|
722 | 722 | |
|
723 | 723 | def test_index_with_columns |
|
724 | 724 | columns = ['tracker', 'subject', 'assigned_to'] |
|
725 | 725 | get :index, :set_filter => 1, :c => columns |
|
726 | 726 | assert_response :success |
|
727 | 727 | |
|
728 | 728 | # query should use specified columns |
|
729 | 729 | query = assigns(:query) |
|
730 | 730 | assert_kind_of IssueQuery, query |
|
731 | 731 | assert_equal columns, query.column_names.map(&:to_s) |
|
732 | 732 | |
|
733 | 733 | # columns should be stored in session |
|
734 | 734 | assert_kind_of Hash, session[:query] |
|
735 | 735 | assert_kind_of Array, session[:query][:column_names] |
|
736 | 736 | assert_equal columns, session[:query][:column_names].map(&:to_s) |
|
737 | 737 | |
|
738 | 738 | # ensure only these columns are kept in the selected columns list |
|
739 | 739 | assert_select 'select#selected_columns option' do |
|
740 | 740 | assert_select 'option', 3 |
|
741 | 741 | assert_select 'option[value=tracker]' |
|
742 | 742 | assert_select 'option[value=project]', 0 |
|
743 | 743 | end |
|
744 | 744 | end |
|
745 | 745 | |
|
746 | 746 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns |
|
747 | 747 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
748 | 748 | get :index, :set_filter => 1 |
|
749 | 749 | |
|
750 | 750 | # query should use specified columns |
|
751 | 751 | query = assigns(:query) |
|
752 | 752 | assert_kind_of IssueQuery, query |
|
753 | 753 | assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name) |
|
754 | 754 | end |
|
755 | 755 | |
|
756 | 756 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column |
|
757 | 757 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
758 | 758 | columns = ['id', 'tracker', 'subject', 'assigned_to'] |
|
759 | 759 | get :index, :set_filter => 1, :c => columns |
|
760 | 760 | |
|
761 | 761 | # query should use specified columns |
|
762 | 762 | query = assigns(:query) |
|
763 | 763 | assert_kind_of IssueQuery, query |
|
764 | 764 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) |
|
765 | 765 | end |
|
766 | 766 | |
|
767 | 767 | def test_index_with_default_columns_should_respect_default_columns_order |
|
768 | 768 | columns = ['assigned_to', 'subject', 'status', 'tracker'] |
|
769 | 769 | with_settings :issue_list_default_columns => columns do |
|
770 | 770 | get :index, :project_id => 1, :set_filter => 1 |
|
771 | 771 | |
|
772 | 772 | query = assigns(:query) |
|
773 | 773 | assert_equal (['id'] + columns).map(&:to_sym), query.columns.map(&:name) |
|
774 | 774 | end |
|
775 | 775 | end |
|
776 | 776 | |
|
777 | 777 | def test_index_with_custom_field_column |
|
778 | 778 | columns = %w(tracker subject cf_2) |
|
779 | 779 | get :index, :set_filter => 1, :c => columns |
|
780 | 780 | assert_response :success |
|
781 | 781 | |
|
782 | 782 | # query should use specified columns |
|
783 | 783 | query = assigns(:query) |
|
784 | 784 | assert_kind_of IssueQuery, query |
|
785 | 785 | assert_equal columns, query.column_names.map(&:to_s) |
|
786 | 786 | |
|
787 | 787 | assert_select 'table.issues td.cf_2.string' |
|
788 | 788 | end |
|
789 | 789 | |
|
790 | 790 | def test_index_with_multi_custom_field_column |
|
791 | 791 | field = CustomField.find(1) |
|
792 | 792 | field.update_attribute :multiple, true |
|
793 | 793 | issue = Issue.find(1) |
|
794 | 794 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
795 | 795 | issue.save! |
|
796 | 796 | |
|
797 | 797 | get :index, :set_filter => 1, :c => %w(tracker subject cf_1) |
|
798 | 798 | assert_response :success |
|
799 | 799 | |
|
800 | 800 | assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle' |
|
801 | 801 | end |
|
802 | 802 | |
|
803 | 803 | def test_index_with_multi_user_custom_field_column |
|
804 | 804 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
805 | 805 | :tracker_ids => [1], :is_for_all => true) |
|
806 | 806 | issue = Issue.find(1) |
|
807 | 807 | issue.custom_field_values = {field.id => ['2', '3']} |
|
808 | 808 | issue.save! |
|
809 | 809 | |
|
810 | 810 | get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"] |
|
811 | 811 | assert_response :success |
|
812 | 812 | |
|
813 | 813 | assert_select "table.issues td.cf_#{field.id}" do |
|
814 | 814 | assert_select 'a', 2 |
|
815 | 815 | assert_select 'a[href=?]', '/users/2', :text => 'John Smith' |
|
816 | 816 | assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper' |
|
817 | 817 | end |
|
818 | 818 | end |
|
819 | 819 | |
|
820 | 820 | def test_index_with_date_column |
|
821 | 821 | with_settings :date_format => '%d/%m/%Y' do |
|
822 | 822 | Issue.find(1).update_attribute :start_date, '1987-08-24' |
|
823 | 823 | get :index, :set_filter => 1, :c => %w(start_date) |
|
824 | 824 | assert_select "table.issues td.start_date", :text => '24/08/1987' |
|
825 | 825 | end |
|
826 | 826 | end |
|
827 | 827 | |
|
828 | 828 | def test_index_with_done_ratio_column |
|
829 | 829 | Issue.find(1).update_attribute :done_ratio, 40 |
|
830 | 830 | get :index, :set_filter => 1, :c => %w(done_ratio) |
|
831 | 831 | assert_select 'table.issues td.done_ratio' do |
|
832 | 832 | assert_select 'table.progress' do |
|
833 | 833 | assert_select 'td.closed[style=?]', 'width: 40%;' |
|
834 | 834 | end |
|
835 | 835 | end |
|
836 | 836 | end |
|
837 | 837 | |
|
838 | 838 | def test_index_with_spent_hours_column |
|
839 | 839 | get :index, :set_filter => 1, :c => %w(subject spent_hours) |
|
840 | 840 | assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00' |
|
841 | 841 | end |
|
842 | 842 | |
|
843 | 843 | def test_index_should_not_show_spent_hours_column_without_permission |
|
844 | 844 | Role.anonymous.remove_permission! :view_time_entries |
|
845 | 845 | get :index, :set_filter => 1, :c => %w(subject spent_hours) |
|
846 | 846 | assert_select 'td.spent_hours', 0 |
|
847 | 847 | end |
|
848 | 848 | |
|
849 | 849 | def test_index_with_fixed_version_column |
|
850 | 850 | get :index, :set_filter => 1, :c => %w(fixed_version) |
|
851 | 851 | assert_select 'table.issues td.fixed_version' do |
|
852 | assert_select 'a[href=?]', '/versions/2', :text => '1.0' | |
|
852 | assert_select 'a[href=?]', '/versions/2', :text => 'eCookbook - 1.0' | |
|
853 | 853 | end |
|
854 | 854 | end |
|
855 | 855 | |
|
856 | 856 | def test_index_with_relations_column |
|
857 | 857 | IssueRelation.delete_all |
|
858 | 858 | IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7)) |
|
859 | 859 | IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1)) |
|
860 | 860 | IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11)) |
|
861 | 861 | IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2)) |
|
862 | 862 | |
|
863 | 863 | get :index, :set_filter => 1, :c => %w(subject relations) |
|
864 | 864 | assert_response :success |
|
865 | 865 | assert_select "tr#issue-1 td.relations" do |
|
866 | 866 | assert_select "span", 3 |
|
867 | 867 | assert_select "span", :text => "Related to #7" |
|
868 | 868 | assert_select "span", :text => "Related to #8" |
|
869 | 869 | assert_select "span", :text => "Blocks #11" |
|
870 | 870 | end |
|
871 | 871 | assert_select "tr#issue-2 td.relations" do |
|
872 | 872 | assert_select "span", 1 |
|
873 | 873 | assert_select "span", :text => "Blocked by #12" |
|
874 | 874 | end |
|
875 | 875 | assert_select "tr#issue-3 td.relations" do |
|
876 | 876 | assert_select "span", 0 |
|
877 | 877 | end |
|
878 | 878 | |
|
879 | 879 | get :index, :set_filter => 1, :c => %w(relations), :format => 'csv' |
|
880 | 880 | assert_response :success |
|
881 | 881 | assert_equal 'text/csv; header=present', response.content_type |
|
882 | 882 | lines = response.body.chomp.split("\n") |
|
883 | 883 | assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines |
|
884 | 884 | assert_include '2,Blocked by #12', lines |
|
885 | 885 | assert_include '3,""', lines |
|
886 | 886 | |
|
887 | 887 | get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf' |
|
888 | 888 | assert_response :success |
|
889 | 889 | assert_equal 'application/pdf', response.content_type |
|
890 | 890 | end |
|
891 | 891 | |
|
892 | 892 | def test_index_with_description_column |
|
893 | 893 | get :index, :set_filter => 1, :c => %w(subject description) |
|
894 | 894 | |
|
895 | 895 | assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject |
|
896 | 896 | assert_select 'td.description[colspan="3"]', :text => 'Unable to print recipes' |
|
897 | 897 | |
|
898 | 898 | get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf' |
|
899 | 899 | assert_response :success |
|
900 | 900 | assert_equal 'application/pdf', response.content_type |
|
901 | 901 | end |
|
902 | 902 | |
|
903 | 903 | def test_index_with_parent_column |
|
904 | 904 | Issue.delete_all |
|
905 | 905 | parent = Issue.generate! |
|
906 | 906 | child = Issue.generate!(:parent_issue_id => parent.id) |
|
907 | 907 | |
|
908 | 908 | get :index, :c => %w(parent) |
|
909 | 909 | |
|
910 | 910 | assert_select 'td.parent', :text => "#{parent.tracker} ##{parent.id}" |
|
911 | 911 | assert_select 'td.parent a[title=?]', parent.subject |
|
912 | 912 | end |
|
913 | 913 | |
|
914 | 914 | def test_index_send_html_if_query_is_invalid |
|
915 | 915 | get :index, :f => ['start_date'], :op => {:start_date => '='} |
|
916 | 916 | assert_equal 'text/html', @response.content_type |
|
917 | 917 | assert_template 'index' |
|
918 | 918 | end |
|
919 | 919 | |
|
920 | 920 | def test_index_send_nothing_if_query_is_invalid |
|
921 | 921 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' |
|
922 | 922 | assert_equal 'text/csv', @response.content_type |
|
923 | 923 | assert @response.body.blank? |
|
924 | 924 | end |
|
925 | 925 | |
|
926 | 926 | def test_show_by_anonymous |
|
927 | 927 | get :show, :id => 1 |
|
928 | 928 | assert_response :success |
|
929 | 929 | assert_template 'show' |
|
930 | 930 | assert_equal Issue.find(1), assigns(:issue) |
|
931 | 931 | assert_select 'div.issue div.description', :text => /Unable to print recipes/ |
|
932 | 932 | # anonymous role is allowed to add a note |
|
933 | 933 | assert_select 'form#issue-form' do |
|
934 | 934 | assert_select 'fieldset' do |
|
935 | 935 | assert_select 'legend', :text => 'Notes' |
|
936 | 936 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
937 | 937 | end |
|
938 | 938 | end |
|
939 | 939 | assert_select 'title', :text => "Bug #1: Cannot print recipes - eCookbook - Redmine" |
|
940 | 940 | end |
|
941 | 941 | |
|
942 | 942 | def test_show_by_manager |
|
943 | 943 | @request.session[:user_id] = 2 |
|
944 | 944 | get :show, :id => 1 |
|
945 | 945 | assert_response :success |
|
946 | 946 | assert_select 'a', :text => /Quote/ |
|
947 | 947 | assert_select 'form#issue-form' do |
|
948 | 948 | assert_select 'fieldset' do |
|
949 | 949 | assert_select 'legend', :text => 'Change properties' |
|
950 | 950 | assert_select 'input[name=?]', 'issue[subject]' |
|
951 | 951 | end |
|
952 | 952 | assert_select 'fieldset' do |
|
953 | 953 | assert_select 'legend', :text => 'Log time' |
|
954 | 954 | assert_select 'input[name=?]', 'time_entry[hours]' |
|
955 | 955 | end |
|
956 | 956 | assert_select 'fieldset' do |
|
957 | 957 | assert_select 'legend', :text => 'Notes' |
|
958 | 958 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
959 | 959 | end |
|
960 | 960 | end |
|
961 | 961 | end |
|
962 | 962 | |
|
963 | 963 | def test_show_should_display_update_form |
|
964 | 964 | @request.session[:user_id] = 2 |
|
965 | 965 | get :show, :id => 1 |
|
966 | 966 | assert_response :success |
|
967 | 967 | |
|
968 | 968 | assert_select 'form#issue-form' do |
|
969 | 969 | assert_select 'input[name=?]', 'issue[is_private]' |
|
970 | 970 | assert_select 'select[name=?]', 'issue[project_id]' |
|
971 | 971 | assert_select 'select[name=?]', 'issue[tracker_id]' |
|
972 | 972 | assert_select 'input[name=?]', 'issue[subject]' |
|
973 | 973 | assert_select 'textarea[name=?]', 'issue[description]' |
|
974 | 974 | assert_select 'select[name=?]', 'issue[status_id]' |
|
975 | 975 | assert_select 'select[name=?]', 'issue[priority_id]' |
|
976 | 976 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
977 | 977 | assert_select 'select[name=?]', 'issue[category_id]' |
|
978 | 978 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
979 | 979 | assert_select 'input[name=?]', 'issue[parent_issue_id]' |
|
980 | 980 | assert_select 'input[name=?]', 'issue[start_date]' |
|
981 | 981 | assert_select 'input[name=?]', 'issue[due_date]' |
|
982 | 982 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
983 | 983 | assert_select 'input[name=?]', 'issue[custom_field_values][2]' |
|
984 | 984 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
985 | 985 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
986 | 986 | end |
|
987 | 987 | end |
|
988 | 988 | |
|
989 | 989 | def test_show_should_display_update_form_with_minimal_permissions |
|
990 | 990 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
|
991 | 991 | WorkflowTransition.delete_all :role_id => 1 |
|
992 | 992 | |
|
993 | 993 | @request.session[:user_id] = 2 |
|
994 | 994 | get :show, :id => 1 |
|
995 | 995 | assert_response :success |
|
996 | 996 | |
|
997 | 997 | assert_select 'form#issue-form' do |
|
998 | 998 | assert_select 'input[name=?]', 'issue[is_private]', 0 |
|
999 | 999 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
1000 | 1000 | assert_select 'select[name=?]', 'issue[tracker_id]', 0 |
|
1001 | 1001 | assert_select 'input[name=?]', 'issue[subject]', 0 |
|
1002 | 1002 | assert_select 'textarea[name=?]', 'issue[description]', 0 |
|
1003 | 1003 | assert_select 'select[name=?]', 'issue[status_id]', 0 |
|
1004 | 1004 | assert_select 'select[name=?]', 'issue[priority_id]', 0 |
|
1005 | 1005 | assert_select 'select[name=?]', 'issue[assigned_to_id]', 0 |
|
1006 | 1006 | assert_select 'select[name=?]', 'issue[category_id]', 0 |
|
1007 | 1007 | assert_select 'select[name=?]', 'issue[fixed_version_id]', 0 |
|
1008 | 1008 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
1009 | 1009 | assert_select 'input[name=?]', 'issue[start_date]', 0 |
|
1010 | 1010 | assert_select 'input[name=?]', 'issue[due_date]', 0 |
|
1011 | 1011 | assert_select 'select[name=?]', 'issue[done_ratio]', 0 |
|
1012 | 1012 | assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 |
|
1013 | 1013 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
1014 | 1014 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
1015 | 1015 | end |
|
1016 | 1016 | end |
|
1017 | 1017 | |
|
1018 | 1018 | def test_show_should_not_display_update_form_without_permissions |
|
1019 | 1019 | Role.find(1).update_attribute :permissions, [:view_issues] |
|
1020 | 1020 | |
|
1021 | 1021 | @request.session[:user_id] = 2 |
|
1022 | 1022 | get :show, :id => 1 |
|
1023 | 1023 | assert_response :success |
|
1024 | 1024 | |
|
1025 | 1025 | assert_select 'form#issue-form', 0 |
|
1026 | 1026 | end |
|
1027 | 1027 | |
|
1028 | 1028 | def test_update_form_should_not_display_inactive_enumerations |
|
1029 | 1029 | assert !IssuePriority.find(15).active? |
|
1030 | 1030 | |
|
1031 | 1031 | @request.session[:user_id] = 2 |
|
1032 | 1032 | get :show, :id => 1 |
|
1033 | 1033 | assert_response :success |
|
1034 | 1034 | |
|
1035 | 1035 | assert_select 'form#issue-form' do |
|
1036 | 1036 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
1037 | 1037 | assert_select 'option[value="4"]' |
|
1038 | 1038 | assert_select 'option[value="15"]', 0 |
|
1039 | 1039 | end |
|
1040 | 1040 | end |
|
1041 | 1041 | end |
|
1042 | 1042 | |
|
1043 | 1043 | def test_update_form_should_allow_attachment_upload |
|
1044 | 1044 | @request.session[:user_id] = 2 |
|
1045 | 1045 | get :show, :id => 1 |
|
1046 | 1046 | |
|
1047 | 1047 | assert_select 'form#issue-form[method=post][enctype="multipart/form-data"]' do |
|
1048 | 1048 | assert_select 'input[type=file][name=?]', 'attachments[dummy][file]' |
|
1049 | 1049 | end |
|
1050 | 1050 | end |
|
1051 | 1051 | |
|
1052 | 1052 | def test_show_should_deny_anonymous_access_without_permission |
|
1053 | 1053 | Role.anonymous.remove_permission!(:view_issues) |
|
1054 | 1054 | get :show, :id => 1 |
|
1055 | 1055 | assert_response :redirect |
|
1056 | 1056 | end |
|
1057 | 1057 | |
|
1058 | 1058 | def test_show_should_deny_anonymous_access_to_private_issue |
|
1059 | 1059 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1060 | 1060 | get :show, :id => 1 |
|
1061 | 1061 | assert_response :redirect |
|
1062 | 1062 | end |
|
1063 | 1063 | |
|
1064 | 1064 | def test_show_should_deny_non_member_access_without_permission |
|
1065 | 1065 | Role.non_member.remove_permission!(:view_issues) |
|
1066 | 1066 | @request.session[:user_id] = 9 |
|
1067 | 1067 | get :show, :id => 1 |
|
1068 | 1068 | assert_response 403 |
|
1069 | 1069 | end |
|
1070 | 1070 | |
|
1071 | 1071 | def test_show_should_deny_non_member_access_to_private_issue |
|
1072 | 1072 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1073 | 1073 | @request.session[:user_id] = 9 |
|
1074 | 1074 | get :show, :id => 1 |
|
1075 | 1075 | assert_response 403 |
|
1076 | 1076 | end |
|
1077 | 1077 | |
|
1078 | 1078 | def test_show_should_deny_member_access_without_permission |
|
1079 | 1079 | Role.find(1).remove_permission!(:view_issues) |
|
1080 | 1080 | @request.session[:user_id] = 2 |
|
1081 | 1081 | get :show, :id => 1 |
|
1082 | 1082 | assert_response 403 |
|
1083 | 1083 | end |
|
1084 | 1084 | |
|
1085 | 1085 | def test_show_should_deny_member_access_to_private_issue_without_permission |
|
1086 | 1086 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1087 | 1087 | @request.session[:user_id] = 3 |
|
1088 | 1088 | get :show, :id => 1 |
|
1089 | 1089 | assert_response 403 |
|
1090 | 1090 | end |
|
1091 | 1091 | |
|
1092 | 1092 | def test_show_should_allow_author_access_to_private_issue |
|
1093 | 1093 | Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true]) |
|
1094 | 1094 | @request.session[:user_id] = 3 |
|
1095 | 1095 | get :show, :id => 1 |
|
1096 | 1096 | assert_response :success |
|
1097 | 1097 | end |
|
1098 | 1098 | |
|
1099 | 1099 | def test_show_should_allow_assignee_access_to_private_issue |
|
1100 | 1100 | Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true]) |
|
1101 | 1101 | @request.session[:user_id] = 3 |
|
1102 | 1102 | get :show, :id => 1 |
|
1103 | 1103 | assert_response :success |
|
1104 | 1104 | end |
|
1105 | 1105 | |
|
1106 | 1106 | def test_show_should_allow_member_access_to_private_issue_with_permission |
|
1107 | 1107 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1108 | 1108 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' |
|
1109 | 1109 | @request.session[:user_id] = 3 |
|
1110 | 1110 | get :show, :id => 1 |
|
1111 | 1111 | assert_response :success |
|
1112 | 1112 | end |
|
1113 | 1113 | |
|
1114 | 1114 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
1115 | 1115 | Setting.cross_project_issue_relations = '1' |
|
1116 | 1116 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
1117 | 1117 | # Relation to a private project issue |
|
1118 | 1118 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
1119 | 1119 | |
|
1120 | 1120 | get :show, :id => 1 |
|
1121 | 1121 | assert_response :success |
|
1122 | 1122 | |
|
1123 | 1123 | assert_select 'div#relations' do |
|
1124 | 1124 | assert_select 'a', :text => /#2$/ |
|
1125 | 1125 | assert_select 'a', :text => /#4$/, :count => 0 |
|
1126 | 1126 | end |
|
1127 | 1127 | end |
|
1128 | 1128 | |
|
1129 | 1129 | def test_show_should_list_subtasks |
|
1130 | 1130 | Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
1131 | 1131 | |
|
1132 | 1132 | get :show, :id => 1 |
|
1133 | 1133 | assert_response :success |
|
1134 | 1134 | |
|
1135 | 1135 | assert_select 'div#issue_tree' do |
|
1136 | 1136 | assert_select 'td.subject', :text => /Child Issue/ |
|
1137 | 1137 | end |
|
1138 | 1138 | end |
|
1139 | 1139 | |
|
1140 | 1140 | def test_show_should_list_parents |
|
1141 | 1141 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
1142 | 1142 | |
|
1143 | 1143 | get :show, :id => issue.id |
|
1144 | 1144 | assert_response :success |
|
1145 | 1145 | |
|
1146 | 1146 | assert_select 'div.subject' do |
|
1147 | 1147 | assert_select 'h3', 'Child Issue' |
|
1148 | 1148 | assert_select 'a[href="/issues/1"]' |
|
1149 | 1149 | end |
|
1150 | 1150 | end |
|
1151 | 1151 | |
|
1152 | 1152 | def test_show_should_not_display_prev_next_links_without_query_in_session |
|
1153 | 1153 | get :show, :id => 1 |
|
1154 | 1154 | assert_response :success |
|
1155 | 1155 | assert_nil assigns(:prev_issue_id) |
|
1156 | 1156 | assert_nil assigns(:next_issue_id) |
|
1157 | 1157 | |
|
1158 | 1158 | assert_select 'div.next-prev-links', 0 |
|
1159 | 1159 | end |
|
1160 | 1160 | |
|
1161 | 1161 | def test_show_should_display_prev_next_links_with_query_in_session |
|
1162 | 1162 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} |
|
1163 | 1163 | @request.session['issues_index_sort'] = 'id' |
|
1164 | 1164 | |
|
1165 | 1165 | with_settings :display_subprojects_issues => '0' do |
|
1166 | 1166 | get :show, :id => 3 |
|
1167 | 1167 | end |
|
1168 | 1168 | |
|
1169 | 1169 | assert_response :success |
|
1170 | 1170 | # Previous and next issues for all projects |
|
1171 | 1171 | assert_equal 2, assigns(:prev_issue_id) |
|
1172 | 1172 | assert_equal 5, assigns(:next_issue_id) |
|
1173 | 1173 | |
|
1174 | 1174 | count = Issue.open.visible.count |
|
1175 | 1175 | |
|
1176 | 1176 | assert_select 'div.next-prev-links' do |
|
1177 | 1177 | assert_select 'a[href="/issues/2"]', :text => /Previous/ |
|
1178 | 1178 | assert_select 'a[href="/issues/5"]', :text => /Next/ |
|
1179 | 1179 | assert_select 'span.position', :text => "3 of #{count}" |
|
1180 | 1180 | end |
|
1181 | 1181 | end |
|
1182 | 1182 | |
|
1183 | 1183 | def test_show_should_display_prev_next_links_with_saved_query_in_session |
|
1184 | 1184 | query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, |
|
1185 | 1185 | :filters => {'status_id' => {:values => ['5'], :operator => '='}}, |
|
1186 | 1186 | :sort_criteria => [['id', 'asc']]) |
|
1187 | 1187 | @request.session[:query] = {:id => query.id, :project_id => nil} |
|
1188 | 1188 | |
|
1189 | 1189 | get :show, :id => 11 |
|
1190 | 1190 | |
|
1191 | 1191 | assert_response :success |
|
1192 | 1192 | assert_equal query, assigns(:query) |
|
1193 | 1193 | # Previous and next issues for all projects |
|
1194 | 1194 | assert_equal 8, assigns(:prev_issue_id) |
|
1195 | 1195 | assert_equal 12, assigns(:next_issue_id) |
|
1196 | 1196 | |
|
1197 | 1197 | assert_select 'div.next-prev-links' do |
|
1198 | 1198 | assert_select 'a[href="/issues/8"]', :text => /Previous/ |
|
1199 | 1199 | assert_select 'a[href="/issues/12"]', :text => /Next/ |
|
1200 | 1200 | end |
|
1201 | 1201 | end |
|
1202 | 1202 | |
|
1203 | 1203 | def test_show_should_display_prev_next_links_with_query_and_sort_on_association |
|
1204 | 1204 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} |
|
1205 | 1205 | |
|
1206 | 1206 | %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort| |
|
1207 | 1207 | @request.session['issues_index_sort'] = assoc_sort |
|
1208 | 1208 | |
|
1209 | 1209 | get :show, :id => 3 |
|
1210 | 1210 | assert_response :success, "Wrong response status for #{assoc_sort} sort" |
|
1211 | 1211 | |
|
1212 | 1212 | assert_select 'div.next-prev-links' do |
|
1213 | 1213 | assert_select 'a', :text => /(Previous|Next)/ |
|
1214 | 1214 | end |
|
1215 | 1215 | end |
|
1216 | 1216 | end |
|
1217 | 1217 | |
|
1218 | 1218 | def test_show_should_display_prev_next_links_with_project_query_in_session |
|
1219 | 1219 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} |
|
1220 | 1220 | @request.session['issues_index_sort'] = 'id' |
|
1221 | 1221 | |
|
1222 | 1222 | with_settings :display_subprojects_issues => '0' do |
|
1223 | 1223 | get :show, :id => 3 |
|
1224 | 1224 | end |
|
1225 | 1225 | |
|
1226 | 1226 | assert_response :success |
|
1227 | 1227 | # Previous and next issues inside project |
|
1228 | 1228 | assert_equal 2, assigns(:prev_issue_id) |
|
1229 | 1229 | assert_equal 7, assigns(:next_issue_id) |
|
1230 | 1230 | |
|
1231 | 1231 | assert_select 'div.next-prev-links' do |
|
1232 | 1232 | assert_select 'a[href="/issues/2"]', :text => /Previous/ |
|
1233 | 1233 | assert_select 'a[href="/issues/7"]', :text => /Next/ |
|
1234 | 1234 | end |
|
1235 | 1235 | end |
|
1236 | 1236 | |
|
1237 | 1237 | def test_show_should_not_display_prev_link_for_first_issue |
|
1238 | 1238 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} |
|
1239 | 1239 | @request.session['issues_index_sort'] = 'id' |
|
1240 | 1240 | |
|
1241 | 1241 | with_settings :display_subprojects_issues => '0' do |
|
1242 | 1242 | get :show, :id => 1 |
|
1243 | 1243 | end |
|
1244 | 1244 | |
|
1245 | 1245 | assert_response :success |
|
1246 | 1246 | assert_nil assigns(:prev_issue_id) |
|
1247 | 1247 | assert_equal 2, assigns(:next_issue_id) |
|
1248 | 1248 | |
|
1249 | 1249 | assert_select 'div.next-prev-links' do |
|
1250 | 1250 | assert_select 'a', :text => /Previous/, :count => 0 |
|
1251 | 1251 | assert_select 'a[href="/issues/2"]', :text => /Next/ |
|
1252 | 1252 | end |
|
1253 | 1253 | end |
|
1254 | 1254 | |
|
1255 | 1255 | def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results |
|
1256 | 1256 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1} |
|
1257 | 1257 | @request.session['issues_index_sort'] = 'id' |
|
1258 | 1258 | |
|
1259 | 1259 | get :show, :id => 1 |
|
1260 | 1260 | |
|
1261 | 1261 | assert_response :success |
|
1262 | 1262 | assert_nil assigns(:prev_issue_id) |
|
1263 | 1263 | assert_nil assigns(:next_issue_id) |
|
1264 | 1264 | |
|
1265 | 1265 | assert_select 'a', :text => /Previous/, :count => 0 |
|
1266 | 1266 | assert_select 'a', :text => /Next/, :count => 0 |
|
1267 | 1267 | end |
|
1268 | 1268 | |
|
1269 | 1269 | def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field |
|
1270 | 1270 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') |
|
1271 | 1271 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
|
1272 | 1272 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
|
1273 | 1273 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
|
1274 | 1274 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
|
1275 | 1275 | |
|
1276 | 1276 | query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {}, |
|
1277 | 1277 | :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) |
|
1278 | 1278 | @request.session[:query] = {:id => query.id, :project_id => nil} |
|
1279 | 1279 | |
|
1280 | 1280 | get :show, :id => 3 |
|
1281 | 1281 | assert_response :success |
|
1282 | 1282 | |
|
1283 | 1283 | assert_equal 2, assigns(:prev_issue_id) |
|
1284 | 1284 | assert_equal 1, assigns(:next_issue_id) |
|
1285 | 1285 | |
|
1286 | 1286 | assert_select 'div.next-prev-links' do |
|
1287 | 1287 | assert_select 'a[href="/issues/2"]', :text => /Previous/ |
|
1288 | 1288 | assert_select 'a[href="/issues/1"]', :text => /Next/ |
|
1289 | 1289 | end |
|
1290 | 1290 | end |
|
1291 | 1291 | |
|
1292 | 1292 | def test_show_should_display_link_to_the_assignee |
|
1293 | 1293 | get :show, :id => 2 |
|
1294 | 1294 | assert_response :success |
|
1295 | 1295 | assert_select '.assigned-to' do |
|
1296 | 1296 | assert_select 'a[href="/users/3"]' |
|
1297 | 1297 | end |
|
1298 | 1298 | end |
|
1299 | 1299 | |
|
1300 | 1300 | def test_show_should_display_visible_changesets_from_other_projects |
|
1301 | 1301 | project = Project.find(2) |
|
1302 | 1302 | issue = project.issues.first |
|
1303 | 1303 | issue.changeset_ids = [102] |
|
1304 | 1304 | issue.save! |
|
1305 | 1305 | # changesets from other projects should be displayed even if repository |
|
1306 | 1306 | # is disabled on issue's project |
|
1307 | 1307 | project.disable_module! :repository |
|
1308 | 1308 | |
|
1309 | 1309 | @request.session[:user_id] = 2 |
|
1310 | 1310 | get :show, :id => issue.id |
|
1311 | 1311 | |
|
1312 | 1312 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3' |
|
1313 | 1313 | end |
|
1314 | 1314 | |
|
1315 | 1315 | def test_show_should_display_watchers |
|
1316 | 1316 | @request.session[:user_id] = 2 |
|
1317 | 1317 | Issue.find(1).add_watcher User.find(2) |
|
1318 | 1318 | |
|
1319 | 1319 | get :show, :id => 1 |
|
1320 | 1320 | assert_select 'div#watchers ul' do |
|
1321 | 1321 | assert_select 'li' do |
|
1322 | 1322 | assert_select 'a[href="/users/2"]' |
|
1323 | 1323 | assert_select 'a img[alt=Delete]' |
|
1324 | 1324 | end |
|
1325 | 1325 | end |
|
1326 | 1326 | end |
|
1327 | 1327 | |
|
1328 | 1328 | def test_show_should_display_watchers_with_gravatars |
|
1329 | 1329 | @request.session[:user_id] = 2 |
|
1330 | 1330 | Issue.find(1).add_watcher User.find(2) |
|
1331 | 1331 | |
|
1332 | 1332 | with_settings :gravatar_enabled => '1' do |
|
1333 | 1333 | get :show, :id => 1 |
|
1334 | 1334 | end |
|
1335 | 1335 | |
|
1336 | 1336 | assert_select 'div#watchers ul' do |
|
1337 | 1337 | assert_select 'li' do |
|
1338 | 1338 | assert_select 'img.gravatar' |
|
1339 | 1339 | assert_select 'a[href="/users/2"]' |
|
1340 | 1340 | assert_select 'a img[alt=Delete]' |
|
1341 | 1341 | end |
|
1342 | 1342 | end |
|
1343 | 1343 | end |
|
1344 | 1344 | |
|
1345 | 1345 | def test_show_with_thumbnails_enabled_should_display_thumbnails |
|
1346 | 1346 | @request.session[:user_id] = 2 |
|
1347 | 1347 | |
|
1348 | 1348 | with_settings :thumbnails_enabled => '1' do |
|
1349 | 1349 | get :show, :id => 14 |
|
1350 | 1350 | assert_response :success |
|
1351 | 1351 | end |
|
1352 | 1352 | |
|
1353 | 1353 | assert_select 'div.thumbnails' do |
|
1354 | 1354 | assert_select 'a[href="/attachments/16/testfile.png"]' do |
|
1355 | 1355 | assert_select 'img[src="/attachments/thumbnail/16"]' |
|
1356 | 1356 | end |
|
1357 | 1357 | end |
|
1358 | 1358 | end |
|
1359 | 1359 | |
|
1360 | 1360 | def test_show_with_thumbnails_disabled_should_not_display_thumbnails |
|
1361 | 1361 | @request.session[:user_id] = 2 |
|
1362 | 1362 | |
|
1363 | 1363 | with_settings :thumbnails_enabled => '0' do |
|
1364 | 1364 | get :show, :id => 14 |
|
1365 | 1365 | assert_response :success |
|
1366 | 1366 | end |
|
1367 | 1367 | |
|
1368 | 1368 | assert_select 'div.thumbnails', 0 |
|
1369 | 1369 | end |
|
1370 | 1370 | |
|
1371 | 1371 | def test_show_with_multi_custom_field |
|
1372 | 1372 | field = CustomField.find(1) |
|
1373 | 1373 | field.update_attribute :multiple, true |
|
1374 | 1374 | issue = Issue.find(1) |
|
1375 | 1375 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
1376 | 1376 | issue.save! |
|
1377 | 1377 | |
|
1378 | 1378 | get :show, :id => 1 |
|
1379 | 1379 | assert_response :success |
|
1380 | 1380 | |
|
1381 | 1381 | assert_select 'td', :text => 'MySQL, Oracle' |
|
1382 | 1382 | end |
|
1383 | 1383 | |
|
1384 | 1384 | def test_show_with_multi_user_custom_field |
|
1385 | 1385 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1386 | 1386 | :tracker_ids => [1], :is_for_all => true) |
|
1387 | 1387 | issue = Issue.find(1) |
|
1388 | 1388 | issue.custom_field_values = {field.id => ['2', '3']} |
|
1389 | 1389 | issue.save! |
|
1390 | 1390 | |
|
1391 | 1391 | get :show, :id => 1 |
|
1392 | 1392 | assert_response :success |
|
1393 | 1393 | |
|
1394 | 1394 | assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do |
|
1395 | 1395 | assert_select 'a', :text => 'Dave Lopper' |
|
1396 | 1396 | assert_select 'a', :text => 'John Smith' |
|
1397 | 1397 | end |
|
1398 | 1398 | end |
|
1399 | 1399 | |
|
1400 | 1400 | def test_show_should_display_private_notes_with_permission_only |
|
1401 | 1401 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
1402 | 1402 | @request.session[:user_id] = 2 |
|
1403 | 1403 | |
|
1404 | 1404 | get :show, :id => 2 |
|
1405 | 1405 | assert_response :success |
|
1406 | 1406 | assert_include journal, assigns(:journals) |
|
1407 | 1407 | |
|
1408 | 1408 | Role.find(1).remove_permission! :view_private_notes |
|
1409 | 1409 | get :show, :id => 2 |
|
1410 | 1410 | assert_response :success |
|
1411 | 1411 | assert_not_include journal, assigns(:journals) |
|
1412 | 1412 | end |
|
1413 | 1413 | |
|
1414 | 1414 | def test_show_atom |
|
1415 | 1415 | get :show, :id => 2, :format => 'atom' |
|
1416 | 1416 | assert_response :success |
|
1417 | 1417 | assert_template 'journals/index' |
|
1418 | 1418 | # Inline image |
|
1419 | 1419 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) |
|
1420 | 1420 | end |
|
1421 | 1421 | |
|
1422 | 1422 | def test_show_export_to_pdf |
|
1423 | 1423 | issue = Issue.find(3) |
|
1424 | 1424 | assert issue.relations.select{|r| r.other_issue(issue).visible?}.present? |
|
1425 | 1425 | get :show, :id => 3, :format => 'pdf' |
|
1426 | 1426 | assert_response :success |
|
1427 | 1427 | assert_equal 'application/pdf', @response.content_type |
|
1428 | 1428 | assert @response.body.starts_with?('%PDF') |
|
1429 | 1429 | assert_not_nil assigns(:issue) |
|
1430 | 1430 | end |
|
1431 | 1431 | |
|
1432 | 1432 | def test_export_to_pdf_with_utf8_u_fffd |
|
1433 | 1433 | # U+FFFD |
|
1434 | 1434 | s = "\xef\xbf\xbd" |
|
1435 | 1435 | s.force_encoding('UTF-8') if s.respond_to?(:force_encoding) |
|
1436 | 1436 | issue = Issue.generate!(:subject => s) |
|
1437 | 1437 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| |
|
1438 | 1438 | with_settings :default_language => lang do |
|
1439 | 1439 | get :show, :id => issue.id, :format => 'pdf' |
|
1440 | 1440 | assert_response :success |
|
1441 | 1441 | assert_equal 'application/pdf', @response.content_type |
|
1442 | 1442 | assert @response.body.starts_with?('%PDF') |
|
1443 | 1443 | assert_not_nil assigns(:issue) |
|
1444 | 1444 | end |
|
1445 | 1445 | end |
|
1446 | 1446 | end |
|
1447 | 1447 | |
|
1448 | 1448 | def test_show_export_to_pdf_with_ancestors |
|
1449 | 1449 | issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) |
|
1450 | 1450 | |
|
1451 | 1451 | get :show, :id => issue.id, :format => 'pdf' |
|
1452 | 1452 | assert_response :success |
|
1453 | 1453 | assert_equal 'application/pdf', @response.content_type |
|
1454 | 1454 | assert @response.body.starts_with?('%PDF') |
|
1455 | 1455 | end |
|
1456 | 1456 | |
|
1457 | 1457 | def test_show_export_to_pdf_with_descendants |
|
1458 | 1458 | c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) |
|
1459 | 1459 | c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) |
|
1460 | 1460 | c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id) |
|
1461 | 1461 | |
|
1462 | 1462 | get :show, :id => 1, :format => 'pdf' |
|
1463 | 1463 | assert_response :success |
|
1464 | 1464 | assert_equal 'application/pdf', @response.content_type |
|
1465 | 1465 | assert @response.body.starts_with?('%PDF') |
|
1466 | 1466 | end |
|
1467 | 1467 | |
|
1468 | 1468 | def test_show_export_to_pdf_with_journals |
|
1469 | 1469 | get :show, :id => 1, :format => 'pdf' |
|
1470 | 1470 | assert_response :success |
|
1471 | 1471 | assert_equal 'application/pdf', @response.content_type |
|
1472 | 1472 | assert @response.body.starts_with?('%PDF') |
|
1473 | 1473 | end |
|
1474 | 1474 | |
|
1475 | 1475 | def test_show_export_to_pdf_with_changesets |
|
1476 | 1476 | [[100], [100, 101], [100, 101, 102]].each do |cs| |
|
1477 | 1477 | issue1 = Issue.find(3) |
|
1478 | 1478 | issue1.changesets = Changeset.find(cs) |
|
1479 | 1479 | issue1.save! |
|
1480 | 1480 | issue = Issue.find(3) |
|
1481 | 1481 | assert_equal issue.changesets.count, cs.size |
|
1482 | 1482 | get :show, :id => 3, :format => 'pdf' |
|
1483 | 1483 | assert_response :success |
|
1484 | 1484 | assert_equal 'application/pdf', @response.content_type |
|
1485 | 1485 | assert @response.body.starts_with?('%PDF') |
|
1486 | 1486 | end |
|
1487 | 1487 | end |
|
1488 | 1488 | |
|
1489 | 1489 | def test_show_invalid_should_respond_with_404 |
|
1490 | 1490 | get :show, :id => 999 |
|
1491 | 1491 | assert_response 404 |
|
1492 | 1492 | end |
|
1493 | 1493 | |
|
1494 | 1494 | def test_get_new |
|
1495 | 1495 | @request.session[:user_id] = 2 |
|
1496 | 1496 | get :new, :project_id => 1, :tracker_id => 1 |
|
1497 | 1497 | assert_response :success |
|
1498 | 1498 | assert_template 'new' |
|
1499 | 1499 | |
|
1500 | 1500 | assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues' |
|
1501 | 1501 | assert_select 'form#issue-form' do |
|
1502 | 1502 | assert_select 'input[name=?]', 'issue[is_private]' |
|
1503 | 1503 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
1504 | 1504 | assert_select 'select[name=?]', 'issue[tracker_id]' |
|
1505 | 1505 | assert_select 'input[name=?]', 'issue[subject]' |
|
1506 | 1506 | assert_select 'textarea[name=?]', 'issue[description]' |
|
1507 | 1507 | assert_select 'select[name=?]', 'issue[status_id]' |
|
1508 | 1508 | assert_select 'select[name=?]', 'issue[priority_id]' |
|
1509 | 1509 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
1510 | 1510 | assert_select 'select[name=?]', 'issue[category_id]' |
|
1511 | 1511 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
1512 | 1512 | assert_select 'input[name=?]', 'issue[parent_issue_id]' |
|
1513 | 1513 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1514 | 1514 | assert_select 'input[name=?]', 'issue[due_date]' |
|
1515 | 1515 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
1516 | 1516 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' |
|
1517 | 1517 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]' |
|
1518 | 1518 | end |
|
1519 | 1519 | |
|
1520 | 1520 | # Be sure we don't display inactive IssuePriorities |
|
1521 | 1521 | assert ! IssuePriority.find(15).active? |
|
1522 | 1522 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
1523 | 1523 | assert_select 'option[value="15"]', 0 |
|
1524 | 1524 | end |
|
1525 | 1525 | end |
|
1526 | 1526 | |
|
1527 | 1527 | def test_get_new_with_minimal_permissions |
|
1528 | 1528 | Role.find(1).update_attribute :permissions, [:add_issues] |
|
1529 | 1529 | WorkflowTransition.delete_all :role_id => 1 |
|
1530 | 1530 | |
|
1531 | 1531 | @request.session[:user_id] = 2 |
|
1532 | 1532 | get :new, :project_id => 1, :tracker_id => 1 |
|
1533 | 1533 | assert_response :success |
|
1534 | 1534 | assert_template 'new' |
|
1535 | 1535 | |
|
1536 | 1536 | assert_select 'form#issue-form' do |
|
1537 | 1537 | assert_select 'input[name=?]', 'issue[is_private]', 0 |
|
1538 | 1538 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
1539 | 1539 | assert_select 'select[name=?]', 'issue[tracker_id]' |
|
1540 | 1540 | assert_select 'input[name=?]', 'issue[subject]' |
|
1541 | 1541 | assert_select 'textarea[name=?]', 'issue[description]' |
|
1542 | 1542 | assert_select 'select[name=?]', 'issue[status_id]' |
|
1543 | 1543 | assert_select 'select[name=?]', 'issue[priority_id]' |
|
1544 | 1544 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
1545 | 1545 | assert_select 'select[name=?]', 'issue[category_id]' |
|
1546 | 1546 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
1547 | 1547 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
1548 | 1548 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1549 | 1549 | assert_select 'input[name=?]', 'issue[due_date]' |
|
1550 | 1550 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
1551 | 1551 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' |
|
1552 | 1552 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
1553 | 1553 | end |
|
1554 | 1554 | end |
|
1555 | 1555 | |
|
1556 | 1556 | def test_new_without_project_id |
|
1557 | 1557 | @request.session[:user_id] = 2 |
|
1558 | 1558 | get :new |
|
1559 | 1559 | assert_response :success |
|
1560 | 1560 | assert_template 'new' |
|
1561 | 1561 | |
|
1562 | 1562 | assert_select 'form#issue-form[action=?]', '/issues' |
|
1563 | 1563 | assert_select 'form#issue-form' do |
|
1564 | 1564 | assert_select 'select[name=?]', 'issue[project_id]' |
|
1565 | 1565 | end |
|
1566 | 1566 | |
|
1567 | 1567 | assert_nil assigns(:project) |
|
1568 | 1568 | assert_not_nil assigns(:issue) |
|
1569 | 1569 | end |
|
1570 | 1570 | |
|
1571 | 1571 | def test_new_should_select_default_status |
|
1572 | 1572 | @request.session[:user_id] = 2 |
|
1573 | 1573 | |
|
1574 | 1574 | get :new, :project_id => 1 |
|
1575 | 1575 | assert_response :success |
|
1576 | 1576 | assert_template 'new' |
|
1577 | 1577 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
1578 | 1578 | assert_select 'option[value="1"][selected=selected]' |
|
1579 | 1579 | end |
|
1580 | 1580 | assert_select 'input[name=was_default_status][value="1"]' |
|
1581 | 1581 | end |
|
1582 | 1582 | |
|
1583 | 1583 | def test_get_new_with_list_custom_field |
|
1584 | 1584 | @request.session[:user_id] = 2 |
|
1585 | 1585 | get :new, :project_id => 1, :tracker_id => 1 |
|
1586 | 1586 | assert_response :success |
|
1587 | 1587 | assert_template 'new' |
|
1588 | 1588 | |
|
1589 | 1589 | assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do |
|
1590 | 1590 | assert_select 'option', 4 |
|
1591 | 1591 | assert_select 'option[value=MySQL]', :text => 'MySQL' |
|
1592 | 1592 | end |
|
1593 | 1593 | end |
|
1594 | 1594 | |
|
1595 | 1595 | def test_get_new_with_multi_custom_field |
|
1596 | 1596 | field = IssueCustomField.find(1) |
|
1597 | 1597 | field.update_attribute :multiple, true |
|
1598 | 1598 | |
|
1599 | 1599 | @request.session[:user_id] = 2 |
|
1600 | 1600 | get :new, :project_id => 1, :tracker_id => 1 |
|
1601 | 1601 | assert_response :success |
|
1602 | 1602 | assert_template 'new' |
|
1603 | 1603 | |
|
1604 | 1604 | assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do |
|
1605 | 1605 | assert_select 'option', 3 |
|
1606 | 1606 | assert_select 'option[value=MySQL]', :text => 'MySQL' |
|
1607 | 1607 | end |
|
1608 | 1608 | assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', '' |
|
1609 | 1609 | end |
|
1610 | 1610 | |
|
1611 | 1611 | def test_get_new_with_multi_user_custom_field |
|
1612 | 1612 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1613 | 1613 | :tracker_ids => [1], :is_for_all => true) |
|
1614 | 1614 | |
|
1615 | 1615 | @request.session[:user_id] = 2 |
|
1616 | 1616 | get :new, :project_id => 1, :tracker_id => 1 |
|
1617 | 1617 | assert_response :success |
|
1618 | 1618 | assert_template 'new' |
|
1619 | 1619 | |
|
1620 | 1620 | assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do |
|
1621 | 1621 | assert_select 'option', Project.find(1).users.count |
|
1622 | 1622 | assert_select 'option[value="2"]', :text => 'John Smith' |
|
1623 | 1623 | end |
|
1624 | 1624 | assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", '' |
|
1625 | 1625 | end |
|
1626 | 1626 | |
|
1627 | 1627 | def test_get_new_with_date_custom_field |
|
1628 | 1628 | field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true) |
|
1629 | 1629 | |
|
1630 | 1630 | @request.session[:user_id] = 2 |
|
1631 | 1631 | get :new, :project_id => 1, :tracker_id => 1 |
|
1632 | 1632 | assert_response :success |
|
1633 | 1633 | |
|
1634 | 1634 | assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]" |
|
1635 | 1635 | end |
|
1636 | 1636 | |
|
1637 | 1637 | def test_get_new_with_text_custom_field |
|
1638 | 1638 | field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true) |
|
1639 | 1639 | |
|
1640 | 1640 | @request.session[:user_id] = 2 |
|
1641 | 1641 | get :new, :project_id => 1, :tracker_id => 1 |
|
1642 | 1642 | assert_response :success |
|
1643 | 1643 | |
|
1644 | 1644 | assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]" |
|
1645 | 1645 | end |
|
1646 | 1646 | |
|
1647 | 1647 | def test_get_new_without_default_start_date_is_creation_date |
|
1648 | 1648 | with_settings :default_issue_start_date_to_creation_date => 0 do |
|
1649 | 1649 | @request.session[:user_id] = 2 |
|
1650 | 1650 | get :new, :project_id => 1, :tracker_id => 1 |
|
1651 | 1651 | assert_response :success |
|
1652 | 1652 | assert_template 'new' |
|
1653 | 1653 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1654 | 1654 | assert_select 'input[name=?][value]', 'issue[start_date]', 0 |
|
1655 | 1655 | end |
|
1656 | 1656 | end |
|
1657 | 1657 | |
|
1658 | 1658 | def test_get_new_with_default_start_date_is_creation_date |
|
1659 | 1659 | with_settings :default_issue_start_date_to_creation_date => 1 do |
|
1660 | 1660 | @request.session[:user_id] = 2 |
|
1661 | 1661 | get :new, :project_id => 1, :tracker_id => 1 |
|
1662 | 1662 | assert_response :success |
|
1663 | 1663 | assert_template 'new' |
|
1664 | 1664 | assert_select 'input[name=?][value=?]', 'issue[start_date]', |
|
1665 | 1665 | Date.today.to_s |
|
1666 | 1666 | end |
|
1667 | 1667 | end |
|
1668 | 1668 | |
|
1669 | 1669 | def test_get_new_form_should_allow_attachment_upload |
|
1670 | 1670 | @request.session[:user_id] = 2 |
|
1671 | 1671 | get :new, :project_id => 1, :tracker_id => 1 |
|
1672 | 1672 | |
|
1673 | 1673 | assert_select 'form[id=issue-form][method=post][enctype="multipart/form-data"]' do |
|
1674 | 1674 | assert_select 'input[name=?][type=file]', 'attachments[dummy][file]' |
|
1675 | 1675 | end |
|
1676 | 1676 | end |
|
1677 | 1677 | |
|
1678 | 1678 | def test_get_new_should_prefill_the_form_from_params |
|
1679 | 1679 | @request.session[:user_id] = 2 |
|
1680 | 1680 | get :new, :project_id => 1, |
|
1681 | 1681 | :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}} |
|
1682 | 1682 | |
|
1683 | 1683 | issue = assigns(:issue) |
|
1684 | 1684 | assert_equal 3, issue.tracker_id |
|
1685 | 1685 | assert_equal 'Prefilled', issue.description |
|
1686 | 1686 | assert_equal 'Custom field value', issue.custom_field_value(2) |
|
1687 | 1687 | |
|
1688 | 1688 | assert_select 'select[name=?]', 'issue[tracker_id]' do |
|
1689 | 1689 | assert_select 'option[value="3"][selected=selected]' |
|
1690 | 1690 | end |
|
1691 | 1691 | assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/ |
|
1692 | 1692 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value' |
|
1693 | 1693 | end |
|
1694 | 1694 | |
|
1695 | 1695 | def test_get_new_should_mark_required_fields |
|
1696 | 1696 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1697 | 1697 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1698 | 1698 | WorkflowPermission.delete_all |
|
1699 | 1699 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') |
|
1700 | 1700 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required') |
|
1701 | 1701 | @request.session[:user_id] = 2 |
|
1702 | 1702 | |
|
1703 | 1703 | get :new, :project_id => 1 |
|
1704 | 1704 | assert_response :success |
|
1705 | 1705 | assert_template 'new' |
|
1706 | 1706 | |
|
1707 | 1707 | assert_select 'label[for=issue_start_date]' do |
|
1708 | 1708 | assert_select 'span[class=required]', 0 |
|
1709 | 1709 | end |
|
1710 | 1710 | assert_select 'label[for=issue_due_date]' do |
|
1711 | 1711 | assert_select 'span[class=required]' |
|
1712 | 1712 | end |
|
1713 | 1713 | assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do |
|
1714 | 1714 | assert_select 'span[class=required]', 0 |
|
1715 | 1715 | end |
|
1716 | 1716 | assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do |
|
1717 | 1717 | assert_select 'span[class=required]' |
|
1718 | 1718 | end |
|
1719 | 1719 | end |
|
1720 | 1720 | |
|
1721 | 1721 | def test_get_new_should_not_display_readonly_fields |
|
1722 | 1722 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1723 | 1723 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1724 | 1724 | WorkflowPermission.delete_all |
|
1725 | 1725 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
1726 | 1726 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') |
|
1727 | 1727 | @request.session[:user_id] = 2 |
|
1728 | 1728 | |
|
1729 | 1729 | get :new, :project_id => 1 |
|
1730 | 1730 | assert_response :success |
|
1731 | 1731 | assert_template 'new' |
|
1732 | 1732 | |
|
1733 | 1733 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1734 | 1734 | assert_select 'input[name=?]', 'issue[due_date]', 0 |
|
1735 | 1735 | assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]" |
|
1736 | 1736 | assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0 |
|
1737 | 1737 | end |
|
1738 | 1738 | |
|
1739 | 1739 | def test_get_new_without_tracker_id |
|
1740 | 1740 | @request.session[:user_id] = 2 |
|
1741 | 1741 | get :new, :project_id => 1 |
|
1742 | 1742 | assert_response :success |
|
1743 | 1743 | assert_template 'new' |
|
1744 | 1744 | |
|
1745 | 1745 | issue = assigns(:issue) |
|
1746 | 1746 | assert_not_nil issue |
|
1747 | 1747 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
1748 | 1748 | end |
|
1749 | 1749 | |
|
1750 | 1750 | def test_get_new_with_no_default_status_should_display_an_error |
|
1751 | 1751 | @request.session[:user_id] = 2 |
|
1752 | 1752 | IssueStatus.delete_all |
|
1753 | 1753 | |
|
1754 | 1754 | get :new, :project_id => 1 |
|
1755 | 1755 | assert_response 500 |
|
1756 | 1756 | assert_select_error /No default issue/ |
|
1757 | 1757 | end |
|
1758 | 1758 | |
|
1759 | 1759 | def test_get_new_with_no_tracker_should_display_an_error |
|
1760 | 1760 | @request.session[:user_id] = 2 |
|
1761 | 1761 | Tracker.delete_all |
|
1762 | 1762 | |
|
1763 | 1763 | get :new, :project_id => 1 |
|
1764 | 1764 | assert_response 500 |
|
1765 | 1765 | assert_select_error /No tracker/ |
|
1766 | 1766 | end |
|
1767 | 1767 | |
|
1768 | 1768 | def test_new_with_invalid_project_id |
|
1769 | 1769 | @request.session[:user_id] = 1 |
|
1770 | 1770 | get :new, :project_id => 'invalid' |
|
1771 | 1771 | assert_response 404 |
|
1772 | 1772 | end |
|
1773 | 1773 | |
|
1774 | 1774 | def test_update_form_for_new_issue |
|
1775 | 1775 | @request.session[:user_id] = 2 |
|
1776 | 1776 | xhr :post, :new, :project_id => 1, |
|
1777 | 1777 | :issue => {:tracker_id => 2, |
|
1778 | 1778 | :subject => 'This is the test_new issue', |
|
1779 | 1779 | :description => 'This is the description', |
|
1780 | 1780 | :priority_id => 5} |
|
1781 | 1781 | assert_response :success |
|
1782 | 1782 | assert_template 'new' |
|
1783 | 1783 | assert_template :partial => '_form' |
|
1784 | 1784 | assert_equal 'text/javascript', response.content_type |
|
1785 | 1785 | |
|
1786 | 1786 | issue = assigns(:issue) |
|
1787 | 1787 | assert_kind_of Issue, issue |
|
1788 | 1788 | assert_equal 1, issue.project_id |
|
1789 | 1789 | assert_equal 2, issue.tracker_id |
|
1790 | 1790 | assert_equal 'This is the test_new issue', issue.subject |
|
1791 | 1791 | end |
|
1792 | 1792 | |
|
1793 | 1793 | def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status |
|
1794 | 1794 | @request.session[:user_id] = 2 |
|
1795 | 1795 | WorkflowTransition.delete_all |
|
1796 | 1796 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) |
|
1797 | 1797 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) |
|
1798 | 1798 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) |
|
1799 | 1799 | |
|
1800 | 1800 | xhr :post, :new, :project_id => 1, |
|
1801 | 1801 | :issue => {:tracker_id => 1, |
|
1802 | 1802 | :status_id => 5, |
|
1803 | 1803 | :subject => 'This is an issue'} |
|
1804 | 1804 | |
|
1805 | 1805 | assert_equal 5, assigns(:issue).status_id |
|
1806 | 1806 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort |
|
1807 | 1807 | end |
|
1808 | 1808 | |
|
1809 | 1809 | def test_update_form_with_default_status_should_ignore_submitted_status_id_if_equals |
|
1810 | 1810 | @request.session[:user_id] = 2 |
|
1811 | 1811 | tracker = Tracker.find(2) |
|
1812 | 1812 | tracker.update! :default_status_id => 2 |
|
1813 | 1813 | tracker.generate_transitions! 2, 1, :clear => true |
|
1814 | 1814 | |
|
1815 | 1815 | xhr :post, :new, :project_id => 1, |
|
1816 | 1816 | :issue => {:tracker_id => 2, |
|
1817 | 1817 | :status_id => 1}, |
|
1818 | 1818 | :was_default_status => 1 |
|
1819 | 1819 | |
|
1820 | 1820 | assert_equal 2, assigns(:issue).status_id |
|
1821 | 1821 | end |
|
1822 | 1822 | |
|
1823 | 1823 | def test_post_create |
|
1824 | 1824 | @request.session[:user_id] = 2 |
|
1825 | 1825 | assert_difference 'Issue.count' do |
|
1826 | 1826 | assert_no_difference 'Journal.count' do |
|
1827 | 1827 | post :create, :project_id => 1, |
|
1828 | 1828 | :issue => {:tracker_id => 3, |
|
1829 | 1829 | :status_id => 2, |
|
1830 | 1830 | :subject => 'This is the test_new issue', |
|
1831 | 1831 | :description => 'This is the description', |
|
1832 | 1832 | :priority_id => 5, |
|
1833 | 1833 | :start_date => '2010-11-07', |
|
1834 | 1834 | :estimated_hours => '', |
|
1835 | 1835 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1836 | 1836 | end |
|
1837 | 1837 | end |
|
1838 | 1838 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1839 | 1839 | |
|
1840 | 1840 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1841 | 1841 | assert_not_nil issue |
|
1842 | 1842 | assert_equal 2, issue.author_id |
|
1843 | 1843 | assert_equal 3, issue.tracker_id |
|
1844 | 1844 | assert_equal 2, issue.status_id |
|
1845 | 1845 | assert_equal Date.parse('2010-11-07'), issue.start_date |
|
1846 | 1846 | assert_nil issue.estimated_hours |
|
1847 | 1847 | v = issue.custom_values.where(:custom_field_id => 2).first |
|
1848 | 1848 | assert_not_nil v |
|
1849 | 1849 | assert_equal 'Value for field 2', v.value |
|
1850 | 1850 | end |
|
1851 | 1851 | |
|
1852 | 1852 | def test_post_new_with_group_assignment |
|
1853 | 1853 | group = Group.find(11) |
|
1854 | 1854 | project = Project.find(1) |
|
1855 | 1855 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) |
|
1856 | 1856 | |
|
1857 | 1857 | with_settings :issue_group_assignment => '1' do |
|
1858 | 1858 | @request.session[:user_id] = 2 |
|
1859 | 1859 | assert_difference 'Issue.count' do |
|
1860 | 1860 | post :create, :project_id => project.id, |
|
1861 | 1861 | :issue => {:tracker_id => 3, |
|
1862 | 1862 | :status_id => 1, |
|
1863 | 1863 | :subject => 'This is the test_new_with_group_assignment issue', |
|
1864 | 1864 | :assigned_to_id => group.id} |
|
1865 | 1865 | end |
|
1866 | 1866 | end |
|
1867 | 1867 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1868 | 1868 | |
|
1869 | 1869 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') |
|
1870 | 1870 | assert_not_nil issue |
|
1871 | 1871 | assert_equal group, issue.assigned_to |
|
1872 | 1872 | end |
|
1873 | 1873 | |
|
1874 | 1874 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date |
|
1875 | 1875 | with_settings :default_issue_start_date_to_creation_date => 0 do |
|
1876 | 1876 | @request.session[:user_id] = 2 |
|
1877 | 1877 | assert_difference 'Issue.count' do |
|
1878 | 1878 | post :create, :project_id => 1, |
|
1879 | 1879 | :issue => {:tracker_id => 3, |
|
1880 | 1880 | :status_id => 2, |
|
1881 | 1881 | :subject => 'This is the test_new issue', |
|
1882 | 1882 | :description => 'This is the description', |
|
1883 | 1883 | :priority_id => 5, |
|
1884 | 1884 | :estimated_hours => '', |
|
1885 | 1885 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1886 | 1886 | end |
|
1887 | 1887 | assert_redirected_to :controller => 'issues', :action => 'show', |
|
1888 | 1888 | :id => Issue.last.id |
|
1889 | 1889 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1890 | 1890 | assert_not_nil issue |
|
1891 | 1891 | assert_nil issue.start_date |
|
1892 | 1892 | end |
|
1893 | 1893 | end |
|
1894 | 1894 | |
|
1895 | 1895 | def test_post_create_without_start_date_and_default_start_date_is_creation_date |
|
1896 | 1896 | with_settings :default_issue_start_date_to_creation_date => 1 do |
|
1897 | 1897 | @request.session[:user_id] = 2 |
|
1898 | 1898 | assert_difference 'Issue.count' do |
|
1899 | 1899 | post :create, :project_id => 1, |
|
1900 | 1900 | :issue => {:tracker_id => 3, |
|
1901 | 1901 | :status_id => 2, |
|
1902 | 1902 | :subject => 'This is the test_new issue', |
|
1903 | 1903 | :description => 'This is the description', |
|
1904 | 1904 | :priority_id => 5, |
|
1905 | 1905 | :estimated_hours => '', |
|
1906 | 1906 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1907 | 1907 | end |
|
1908 | 1908 | assert_redirected_to :controller => 'issues', :action => 'show', |
|
1909 | 1909 | :id => Issue.last.id |
|
1910 | 1910 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1911 | 1911 | assert_not_nil issue |
|
1912 | 1912 | assert_equal Date.today, issue.start_date |
|
1913 | 1913 | end |
|
1914 | 1914 | end |
|
1915 | 1915 | |
|
1916 | 1916 | def test_post_create_and_continue |
|
1917 | 1917 | @request.session[:user_id] = 2 |
|
1918 | 1918 | assert_difference 'Issue.count' do |
|
1919 | 1919 | post :create, :project_id => 1, |
|
1920 | 1920 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, |
|
1921 | 1921 | :continue => '' |
|
1922 | 1922 | end |
|
1923 | 1923 | |
|
1924 | 1924 | issue = Issue.order('id DESC').first |
|
1925 | 1925 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} |
|
1926 | 1926 | assert_not_nil flash[:notice], "flash was not set" |
|
1927 | 1927 | assert_select_in flash[:notice], |
|
1928 | 1928 | 'a[href=?][title=?]', "/issues/#{issue.id}", "This is first issue", :text => "##{issue.id}" |
|
1929 | 1929 | end |
|
1930 | 1930 | |
|
1931 | 1931 | def test_post_create_without_custom_fields_param |
|
1932 | 1932 | @request.session[:user_id] = 2 |
|
1933 | 1933 | assert_difference 'Issue.count' do |
|
1934 | 1934 | post :create, :project_id => 1, |
|
1935 | 1935 | :issue => {:tracker_id => 1, |
|
1936 | 1936 | :subject => 'This is the test_new issue', |
|
1937 | 1937 | :description => 'This is the description', |
|
1938 | 1938 | :priority_id => 5} |
|
1939 | 1939 | end |
|
1940 | 1940 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1941 | 1941 | end |
|
1942 | 1942 | |
|
1943 | 1943 | def test_post_create_with_multi_custom_field |
|
1944 | 1944 | field = IssueCustomField.find_by_name('Database') |
|
1945 | 1945 | field.update_attribute(:multiple, true) |
|
1946 | 1946 | |
|
1947 | 1947 | @request.session[:user_id] = 2 |
|
1948 | 1948 | assert_difference 'Issue.count' do |
|
1949 | 1949 | post :create, :project_id => 1, |
|
1950 | 1950 | :issue => {:tracker_id => 1, |
|
1951 | 1951 | :subject => 'This is the test_new issue', |
|
1952 | 1952 | :description => 'This is the description', |
|
1953 | 1953 | :priority_id => 5, |
|
1954 | 1954 | :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} |
|
1955 | 1955 | end |
|
1956 | 1956 | assert_response 302 |
|
1957 | 1957 | issue = Issue.order('id DESC').first |
|
1958 | 1958 | assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort |
|
1959 | 1959 | end |
|
1960 | 1960 | |
|
1961 | 1961 | def test_post_create_with_empty_multi_custom_field |
|
1962 | 1962 | field = IssueCustomField.find_by_name('Database') |
|
1963 | 1963 | field.update_attribute(:multiple, true) |
|
1964 | 1964 | |
|
1965 | 1965 | @request.session[:user_id] = 2 |
|
1966 | 1966 | assert_difference 'Issue.count' do |
|
1967 | 1967 | post :create, :project_id => 1, |
|
1968 | 1968 | :issue => {:tracker_id => 1, |
|
1969 | 1969 | :subject => 'This is the test_new issue', |
|
1970 | 1970 | :description => 'This is the description', |
|
1971 | 1971 | :priority_id => 5, |
|
1972 | 1972 | :custom_field_values => {'1' => ['']}} |
|
1973 | 1973 | end |
|
1974 | 1974 | assert_response 302 |
|
1975 | 1975 | issue = Issue.order('id DESC').first |
|
1976 | 1976 | assert_equal [''], issue.custom_field_value(1).sort |
|
1977 | 1977 | end |
|
1978 | 1978 | |
|
1979 | 1979 | def test_post_create_with_multi_user_custom_field |
|
1980 | 1980 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1981 | 1981 | :tracker_ids => [1], :is_for_all => true) |
|
1982 | 1982 | |
|
1983 | 1983 | @request.session[:user_id] = 2 |
|
1984 | 1984 | assert_difference 'Issue.count' do |
|
1985 | 1985 | post :create, :project_id => 1, |
|
1986 | 1986 | :issue => {:tracker_id => 1, |
|
1987 | 1987 | :subject => 'This is the test_new issue', |
|
1988 | 1988 | :description => 'This is the description', |
|
1989 | 1989 | :priority_id => 5, |
|
1990 | 1990 | :custom_field_values => {field.id.to_s => ['', '2', '3']}} |
|
1991 | 1991 | end |
|
1992 | 1992 | assert_response 302 |
|
1993 | 1993 | issue = Issue.order('id DESC').first |
|
1994 | 1994 | assert_equal ['2', '3'], issue.custom_field_value(field).sort |
|
1995 | 1995 | end |
|
1996 | 1996 | |
|
1997 | 1997 | def test_post_create_with_required_custom_field_and_without_custom_fields_param |
|
1998 | 1998 | field = IssueCustomField.find_by_name('Database') |
|
1999 | 1999 | field.update_attribute(:is_required, true) |
|
2000 | 2000 | |
|
2001 | 2001 | @request.session[:user_id] = 2 |
|
2002 | 2002 | assert_no_difference 'Issue.count' do |
|
2003 | 2003 | post :create, :project_id => 1, |
|
2004 | 2004 | :issue => {:tracker_id => 1, |
|
2005 | 2005 | :subject => 'This is the test_new issue', |
|
2006 | 2006 | :description => 'This is the description', |
|
2007 | 2007 | :priority_id => 5} |
|
2008 | 2008 | end |
|
2009 | 2009 | assert_response :success |
|
2010 | 2010 | assert_template 'new' |
|
2011 | 2011 | issue = assigns(:issue) |
|
2012 | 2012 | assert_not_nil issue |
|
2013 | 2013 | assert_select_error /Database cannot be blank/ |
|
2014 | 2014 | end |
|
2015 | 2015 | |
|
2016 | 2016 | def test_create_should_validate_required_fields |
|
2017 | 2017 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
2018 | 2018 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
2019 | 2019 | WorkflowPermission.delete_all |
|
2020 | 2020 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required') |
|
2021 | 2021 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required') |
|
2022 | 2022 | @request.session[:user_id] = 2 |
|
2023 | 2023 | |
|
2024 | 2024 | assert_no_difference 'Issue.count' do |
|
2025 | 2025 | post :create, :project_id => 1, :issue => { |
|
2026 | 2026 | :tracker_id => 2, |
|
2027 | 2027 | :status_id => 1, |
|
2028 | 2028 | :subject => 'Test', |
|
2029 | 2029 | :start_date => '', |
|
2030 | 2030 | :due_date => '', |
|
2031 | 2031 | :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''} |
|
2032 | 2032 | } |
|
2033 | 2033 | assert_response :success |
|
2034 | 2034 | assert_template 'new' |
|
2035 | 2035 | end |
|
2036 | 2036 | |
|
2037 | 2037 | assert_select_error /Due date cannot be blank/i |
|
2038 | 2038 | assert_select_error /Bar cannot be blank/i |
|
2039 | 2039 | end |
|
2040 | 2040 | |
|
2041 | 2041 | def test_create_should_ignore_readonly_fields |
|
2042 | 2042 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
2043 | 2043 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
2044 | 2044 | WorkflowPermission.delete_all |
|
2045 | 2045 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
2046 | 2046 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') |
|
2047 | 2047 | @request.session[:user_id] = 2 |
|
2048 | 2048 | |
|
2049 | 2049 | assert_difference 'Issue.count' do |
|
2050 | 2050 | post :create, :project_id => 1, :issue => { |
|
2051 | 2051 | :tracker_id => 2, |
|
2052 | 2052 | :status_id => 1, |
|
2053 | 2053 | :subject => 'Test', |
|
2054 | 2054 | :start_date => '2012-07-14', |
|
2055 | 2055 | :due_date => '2012-07-16', |
|
2056 | 2056 | :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'} |
|
2057 | 2057 | } |
|
2058 | 2058 | assert_response 302 |
|
2059 | 2059 | end |
|
2060 | 2060 | |
|
2061 | 2061 | issue = Issue.order('id DESC').first |
|
2062 | 2062 | assert_equal Date.parse('2012-07-14'), issue.start_date |
|
2063 | 2063 | assert_nil issue.due_date |
|
2064 | 2064 | assert_equal 'value1', issue.custom_field_value(cf1) |
|
2065 | 2065 | assert_nil issue.custom_field_value(cf2) |
|
2066 | 2066 | end |
|
2067 | 2067 | |
|
2068 | 2068 | def test_post_create_with_watchers |
|
2069 | 2069 | @request.session[:user_id] = 2 |
|
2070 | 2070 | ActionMailer::Base.deliveries.clear |
|
2071 | 2071 | |
|
2072 | 2072 | with_settings :notified_events => %w(issue_added) do |
|
2073 | 2073 | assert_difference 'Watcher.count', 2 do |
|
2074 | 2074 | post :create, :project_id => 1, |
|
2075 | 2075 | :issue => {:tracker_id => 1, |
|
2076 | 2076 | :subject => 'This is a new issue with watchers', |
|
2077 | 2077 | :description => 'This is the description', |
|
2078 | 2078 | :priority_id => 5, |
|
2079 | 2079 | :watcher_user_ids => ['2', '3']} |
|
2080 | 2080 | end |
|
2081 | 2081 | end |
|
2082 | 2082 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
2083 | 2083 | assert_not_nil issue |
|
2084 | 2084 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
2085 | 2085 | |
|
2086 | 2086 | # Watchers added |
|
2087 | 2087 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
2088 | 2088 | assert issue.watched_by?(User.find(3)) |
|
2089 | 2089 | # Watchers notified |
|
2090 | 2090 | mail = ActionMailer::Base.deliveries.last |
|
2091 | 2091 | assert_not_nil mail |
|
2092 | 2092 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
2093 | 2093 | end |
|
2094 | 2094 | |
|
2095 | 2095 | def test_post_create_subissue |
|
2096 | 2096 | @request.session[:user_id] = 2 |
|
2097 | 2097 | |
|
2098 | 2098 | assert_difference 'Issue.count' do |
|
2099 | 2099 | post :create, :project_id => 1, |
|
2100 | 2100 | :issue => {:tracker_id => 1, |
|
2101 | 2101 | :subject => 'This is a child issue', |
|
2102 | 2102 | :parent_issue_id => '2'} |
|
2103 | 2103 | assert_response 302 |
|
2104 | 2104 | end |
|
2105 | 2105 | issue = Issue.order('id DESC').first |
|
2106 | 2106 | assert_equal Issue.find(2), issue.parent |
|
2107 | 2107 | end |
|
2108 | 2108 | |
|
2109 | 2109 | def test_post_create_subissue_with_sharp_parent_id |
|
2110 | 2110 | @request.session[:user_id] = 2 |
|
2111 | 2111 | |
|
2112 | 2112 | assert_difference 'Issue.count' do |
|
2113 | 2113 | post :create, :project_id => 1, |
|
2114 | 2114 | :issue => {:tracker_id => 1, |
|
2115 | 2115 | :subject => 'This is a child issue', |
|
2116 | 2116 | :parent_issue_id => '#2'} |
|
2117 | 2117 | assert_response 302 |
|
2118 | 2118 | end |
|
2119 | 2119 | issue = Issue.order('id DESC').first |
|
2120 | 2120 | assert_equal Issue.find(2), issue.parent |
|
2121 | 2121 | end |
|
2122 | 2122 | |
|
2123 | 2123 | def test_post_create_subissue_with_non_visible_parent_id_should_not_validate |
|
2124 | 2124 | @request.session[:user_id] = 2 |
|
2125 | 2125 | |
|
2126 | 2126 | assert_no_difference 'Issue.count' do |
|
2127 | 2127 | post :create, :project_id => 1, |
|
2128 | 2128 | :issue => {:tracker_id => 1, |
|
2129 | 2129 | :subject => 'This is a child issue', |
|
2130 | 2130 | :parent_issue_id => '4'} |
|
2131 | 2131 | |
|
2132 | 2132 | assert_response :success |
|
2133 | 2133 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4' |
|
2134 | 2134 | assert_select_error /Parent task is invalid/i |
|
2135 | 2135 | end |
|
2136 | 2136 | end |
|
2137 | 2137 | |
|
2138 | 2138 | def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate |
|
2139 | 2139 | @request.session[:user_id] = 2 |
|
2140 | 2140 | |
|
2141 | 2141 | assert_no_difference 'Issue.count' do |
|
2142 | 2142 | post :create, :project_id => 1, |
|
2143 | 2143 | :issue => {:tracker_id => 1, |
|
2144 | 2144 | :subject => 'This is a child issue', |
|
2145 | 2145 | :parent_issue_id => '01ABC'} |
|
2146 | 2146 | |
|
2147 | 2147 | assert_response :success |
|
2148 | 2148 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC' |
|
2149 | 2149 | assert_select_error /Parent task is invalid/i |
|
2150 | 2150 | end |
|
2151 | 2151 | end |
|
2152 | 2152 | |
|
2153 | 2153 | def test_post_create_private |
|
2154 | 2154 | @request.session[:user_id] = 2 |
|
2155 | 2155 | |
|
2156 | 2156 | assert_difference 'Issue.count' do |
|
2157 | 2157 | post :create, :project_id => 1, |
|
2158 | 2158 | :issue => {:tracker_id => 1, |
|
2159 | 2159 | :subject => 'This is a private issue', |
|
2160 | 2160 | :is_private => '1'} |
|
2161 | 2161 | end |
|
2162 | 2162 | issue = Issue.order('id DESC').first |
|
2163 | 2163 | assert issue.is_private? |
|
2164 | 2164 | end |
|
2165 | 2165 | |
|
2166 | 2166 | def test_post_create_private_with_set_own_issues_private_permission |
|
2167 | 2167 | role = Role.find(1) |
|
2168 | 2168 | role.remove_permission! :set_issues_private |
|
2169 | 2169 | role.add_permission! :set_own_issues_private |
|
2170 | 2170 | |
|
2171 | 2171 | @request.session[:user_id] = 2 |
|
2172 | 2172 | |
|
2173 | 2173 | assert_difference 'Issue.count' do |
|
2174 | 2174 | post :create, :project_id => 1, |
|
2175 | 2175 | :issue => {:tracker_id => 1, |
|
2176 | 2176 | :subject => 'This is a private issue', |
|
2177 | 2177 | :is_private => '1'} |
|
2178 | 2178 | end |
|
2179 | 2179 | issue = Issue.order('id DESC').first |
|
2180 | 2180 | assert issue.is_private? |
|
2181 | 2181 | end |
|
2182 | 2182 | |
|
2183 | 2183 | def test_create_without_project_id |
|
2184 | 2184 | @request.session[:user_id] = 2 |
|
2185 | 2185 | |
|
2186 | 2186 | assert_difference 'Issue.count' do |
|
2187 | 2187 | post :create, |
|
2188 | 2188 | :issue => {:project_id => 3, |
|
2189 | 2189 | :tracker_id => 2, |
|
2190 | 2190 | :subject => 'Foo'} |
|
2191 | 2191 | assert_response 302 |
|
2192 | 2192 | end |
|
2193 | 2193 | issue = Issue.order('id DESC').first |
|
2194 | 2194 | assert_equal 3, issue.project_id |
|
2195 | 2195 | assert_equal 2, issue.tracker_id |
|
2196 | 2196 | end |
|
2197 | 2197 | |
|
2198 | 2198 | def test_create_without_project_id_and_continue_should_redirect_without_project_id |
|
2199 | 2199 | @request.session[:user_id] = 2 |
|
2200 | 2200 | |
|
2201 | 2201 | assert_difference 'Issue.count' do |
|
2202 | 2202 | post :create, |
|
2203 | 2203 | :issue => {:project_id => 3, |
|
2204 | 2204 | :tracker_id => 2, |
|
2205 | 2205 | :subject => 'Foo'}, |
|
2206 | 2206 | :continue => '1' |
|
2207 | 2207 | assert_redirected_to '/issues/new?issue%5Bproject_id%5D=3&issue%5Btracker_id%5D=2' |
|
2208 | 2208 | end |
|
2209 | 2209 | end |
|
2210 | 2210 | |
|
2211 | 2211 | def test_create_without_project_id_should_be_denied_without_permission |
|
2212 | 2212 | Role.non_member.remove_permission! :add_issues |
|
2213 | 2213 | Role.anonymous.remove_permission! :add_issues |
|
2214 | 2214 | @request.session[:user_id] = 2 |
|
2215 | 2215 | |
|
2216 | 2216 | assert_no_difference 'Issue.count' do |
|
2217 | 2217 | post :create, |
|
2218 | 2218 | :issue => {:project_id => 3, |
|
2219 | 2219 | :tracker_id => 2, |
|
2220 | 2220 | :subject => 'Foo'} |
|
2221 | 2221 | assert_response 403 |
|
2222 | 2222 | end |
|
2223 | 2223 | end |
|
2224 | 2224 | |
|
2225 | 2225 | def test_create_without_project_id_with_failure |
|
2226 | 2226 | @request.session[:user_id] = 2 |
|
2227 | 2227 | |
|
2228 | 2228 | post :create, |
|
2229 | 2229 | :issue => {:project_id => 3, |
|
2230 | 2230 | :tracker_id => 2, |
|
2231 | 2231 | :subject => ''} |
|
2232 | 2232 | assert_response :success |
|
2233 | 2233 | assert_nil assigns(:project) |
|
2234 | 2234 | end |
|
2235 | 2235 | |
|
2236 | 2236 | def test_post_create_should_send_a_notification |
|
2237 | 2237 | ActionMailer::Base.deliveries.clear |
|
2238 | 2238 | @request.session[:user_id] = 2 |
|
2239 | 2239 | with_settings :notified_events => %w(issue_added) do |
|
2240 | 2240 | assert_difference 'Issue.count' do |
|
2241 | 2241 | post :create, :project_id => 1, |
|
2242 | 2242 | :issue => {:tracker_id => 3, |
|
2243 | 2243 | :subject => 'This is the test_new issue', |
|
2244 | 2244 | :description => 'This is the description', |
|
2245 | 2245 | :priority_id => 5, |
|
2246 | 2246 | :estimated_hours => '', |
|
2247 | 2247 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
2248 | 2248 | end |
|
2249 | 2249 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
2250 | 2250 | |
|
2251 | 2251 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
2252 | 2252 | end |
|
2253 | 2253 | end |
|
2254 | 2254 | |
|
2255 | 2255 | def test_post_create_should_preserve_fields_values_on_validation_failure |
|
2256 | 2256 | @request.session[:user_id] = 2 |
|
2257 | 2257 | post :create, :project_id => 1, |
|
2258 | 2258 | :issue => {:tracker_id => 1, |
|
2259 | 2259 | # empty subject |
|
2260 | 2260 | :subject => '', |
|
2261 | 2261 | :description => 'This is a description', |
|
2262 | 2262 | :priority_id => 6, |
|
2263 | 2263 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
2264 | 2264 | assert_response :success |
|
2265 | 2265 | assert_template 'new' |
|
2266 | 2266 | |
|
2267 | 2267 | assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description' |
|
2268 | 2268 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
2269 | 2269 | assert_select 'option[value="6"][selected=selected]', :text => 'High' |
|
2270 | 2270 | end |
|
2271 | 2271 | # Custom fields |
|
2272 | 2272 | assert_select 'select[name=?]', 'issue[custom_field_values][1]' do |
|
2273 | 2273 | assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle' |
|
2274 | 2274 | end |
|
2275 | 2275 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2' |
|
2276 | 2276 | end |
|
2277 | 2277 | |
|
2278 | 2278 | def test_post_create_with_failure_should_preserve_watchers |
|
2279 | 2279 | assert !User.find(8).member_of?(Project.find(1)) |
|
2280 | 2280 | |
|
2281 | 2281 | @request.session[:user_id] = 2 |
|
2282 | 2282 | post :create, :project_id => 1, |
|
2283 | 2283 | :issue => {:tracker_id => 1, |
|
2284 | 2284 | :watcher_user_ids => ['3', '8']} |
|
2285 | 2285 | assert_response :success |
|
2286 | 2286 | assert_template 'new' |
|
2287 | 2287 | |
|
2288 | 2288 | assert_select 'input[name=?][value="2"]:not(checked)', 'issue[watcher_user_ids][]' |
|
2289 | 2289 | assert_select 'input[name=?][value="3"][checked=checked]', 'issue[watcher_user_ids][]' |
|
2290 | 2290 | assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]' |
|
2291 | 2291 | end |
|
2292 | 2292 | |
|
2293 | 2293 | def test_post_create_should_ignore_non_safe_attributes |
|
2294 | 2294 | @request.session[:user_id] = 2 |
|
2295 | 2295 | assert_nothing_raised do |
|
2296 | 2296 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
|
2297 | 2297 | end |
|
2298 | 2298 | end |
|
2299 | 2299 | |
|
2300 | 2300 | def test_post_create_with_attachment |
|
2301 | 2301 | set_tmp_attachments_directory |
|
2302 | 2302 | @request.session[:user_id] = 2 |
|
2303 | 2303 | |
|
2304 | 2304 | assert_difference 'Issue.count' do |
|
2305 | 2305 | assert_difference 'Attachment.count' do |
|
2306 | 2306 | assert_no_difference 'Journal.count' do |
|
2307 | 2307 | post :create, :project_id => 1, |
|
2308 | 2308 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, |
|
2309 | 2309 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2310 | 2310 | end |
|
2311 | 2311 | end |
|
2312 | 2312 | end |
|
2313 | 2313 | |
|
2314 | 2314 | issue = Issue.order('id DESC').first |
|
2315 | 2315 | attachment = Attachment.order('id DESC').first |
|
2316 | 2316 | |
|
2317 | 2317 | assert_equal issue, attachment.container |
|
2318 | 2318 | assert_equal 2, attachment.author_id |
|
2319 | 2319 | assert_equal 'testfile.txt', attachment.filename |
|
2320 | 2320 | assert_equal 'text/plain', attachment.content_type |
|
2321 | 2321 | assert_equal 'test file', attachment.description |
|
2322 | 2322 | assert_equal 59, attachment.filesize |
|
2323 | 2323 | assert File.exists?(attachment.diskfile) |
|
2324 | 2324 | assert_equal 59, File.size(attachment.diskfile) |
|
2325 | 2325 | end |
|
2326 | 2326 | |
|
2327 | 2327 | def test_post_create_with_attachment_should_notify_with_attachments |
|
2328 | 2328 | ActionMailer::Base.deliveries.clear |
|
2329 | 2329 | set_tmp_attachments_directory |
|
2330 | 2330 | @request.session[:user_id] = 2 |
|
2331 | 2331 | |
|
2332 | 2332 | with_settings :host_name => 'mydomain.foo', :protocol => 'http', :notified_events => %w(issue_added) do |
|
2333 | 2333 | assert_difference 'Issue.count' do |
|
2334 | 2334 | post :create, :project_id => 1, |
|
2335 | 2335 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, |
|
2336 | 2336 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2337 | 2337 | end |
|
2338 | 2338 | end |
|
2339 | 2339 | |
|
2340 | 2340 | assert_not_nil ActionMailer::Base.deliveries.last |
|
2341 | 2341 | assert_select_email do |
|
2342 | 2342 | assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt' |
|
2343 | 2343 | end |
|
2344 | 2344 | end |
|
2345 | 2345 | |
|
2346 | 2346 | def test_post_create_with_failure_should_save_attachments |
|
2347 | 2347 | set_tmp_attachments_directory |
|
2348 | 2348 | @request.session[:user_id] = 2 |
|
2349 | 2349 | |
|
2350 | 2350 | assert_no_difference 'Issue.count' do |
|
2351 | 2351 | assert_difference 'Attachment.count' do |
|
2352 | 2352 | post :create, :project_id => 1, |
|
2353 | 2353 | :issue => { :tracker_id => '1', :subject => '' }, |
|
2354 | 2354 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2355 | 2355 | assert_response :success |
|
2356 | 2356 | assert_template 'new' |
|
2357 | 2357 | end |
|
2358 | 2358 | end |
|
2359 | 2359 | |
|
2360 | 2360 | attachment = Attachment.order('id DESC').first |
|
2361 | 2361 | assert_equal 'testfile.txt', attachment.filename |
|
2362 | 2362 | assert File.exists?(attachment.diskfile) |
|
2363 | 2363 | assert_nil attachment.container |
|
2364 | 2364 | |
|
2365 | 2365 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
2366 | 2366 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
2367 | 2367 | end |
|
2368 | 2368 | |
|
2369 | 2369 | def test_post_create_with_failure_should_keep_saved_attachments |
|
2370 | 2370 | set_tmp_attachments_directory |
|
2371 | 2371 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
2372 | 2372 | @request.session[:user_id] = 2 |
|
2373 | 2373 | |
|
2374 | 2374 | assert_no_difference 'Issue.count' do |
|
2375 | 2375 | assert_no_difference 'Attachment.count' do |
|
2376 | 2376 | post :create, :project_id => 1, |
|
2377 | 2377 | :issue => { :tracker_id => '1', :subject => '' }, |
|
2378 | 2378 | :attachments => {'p0' => {'token' => attachment.token}} |
|
2379 | 2379 | assert_response :success |
|
2380 | 2380 | assert_template 'new' |
|
2381 | 2381 | end |
|
2382 | 2382 | end |
|
2383 | 2383 | |
|
2384 | 2384 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
2385 | 2385 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
2386 | 2386 | end |
|
2387 | 2387 | |
|
2388 | 2388 | def test_post_create_should_attach_saved_attachments |
|
2389 | 2389 | set_tmp_attachments_directory |
|
2390 | 2390 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
2391 | 2391 | @request.session[:user_id] = 2 |
|
2392 | 2392 | |
|
2393 | 2393 | assert_difference 'Issue.count' do |
|
2394 | 2394 | assert_no_difference 'Attachment.count' do |
|
2395 | 2395 | post :create, :project_id => 1, |
|
2396 | 2396 | :issue => { :tracker_id => '1', :subject => 'Saved attachments' }, |
|
2397 | 2397 | :attachments => {'p0' => {'token' => attachment.token}} |
|
2398 | 2398 | assert_response 302 |
|
2399 | 2399 | end |
|
2400 | 2400 | end |
|
2401 | 2401 | |
|
2402 | 2402 | issue = Issue.order('id DESC').first |
|
2403 | 2403 | assert_equal 1, issue.attachments.count |
|
2404 | 2404 | |
|
2405 | 2405 | attachment.reload |
|
2406 | 2406 | assert_equal issue, attachment.container |
|
2407 | 2407 | end |
|
2408 | 2408 | |
|
2409 | 2409 | def setup_without_workflow_privilege |
|
2410 | 2410 | WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) |
|
2411 | 2411 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
2412 | 2412 | end |
|
2413 | 2413 | private :setup_without_workflow_privilege |
|
2414 | 2414 | |
|
2415 | 2415 | test "without workflow privilege #new should propose default status only" do |
|
2416 | 2416 | setup_without_workflow_privilege |
|
2417 | 2417 | get :new, :project_id => 1 |
|
2418 | 2418 | assert_response :success |
|
2419 | 2419 | assert_template 'new' |
|
2420 | 2420 | |
|
2421 | 2421 | issue = assigns(:issue) |
|
2422 | 2422 | assert_not_nil issue.default_status |
|
2423 | 2423 | |
|
2424 | 2424 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
2425 | 2425 | assert_select 'option', 1 |
|
2426 | 2426 | assert_select 'option[value=?]', issue.default_status.id.to_s |
|
2427 | 2427 | end |
|
2428 | 2428 | end |
|
2429 | 2429 | |
|
2430 | 2430 | test "without workflow privilege #create should accept default status" do |
|
2431 | 2431 | setup_without_workflow_privilege |
|
2432 | 2432 | assert_difference 'Issue.count' do |
|
2433 | 2433 | post :create, :project_id => 1, |
|
2434 | 2434 | :issue => {:tracker_id => 1, |
|
2435 | 2435 | :subject => 'This is an issue', |
|
2436 | 2436 | :status_id => 1} |
|
2437 | 2437 | end |
|
2438 | 2438 | issue = Issue.order('id').last |
|
2439 | 2439 | assert_not_nil issue.default_status |
|
2440 | 2440 | assert_equal issue.default_status, issue.status |
|
2441 | 2441 | end |
|
2442 | 2442 | |
|
2443 | 2443 | test "without workflow privilege #create should ignore unauthorized status" do |
|
2444 | 2444 | setup_without_workflow_privilege |
|
2445 | 2445 | assert_difference 'Issue.count' do |
|
2446 | 2446 | post :create, :project_id => 1, |
|
2447 | 2447 | :issue => {:tracker_id => 1, |
|
2448 | 2448 | :subject => 'This is an issue', |
|
2449 | 2449 | :status_id => 3} |
|
2450 | 2450 | end |
|
2451 | 2451 | issue = Issue.order('id').last |
|
2452 | 2452 | assert_not_nil issue.default_status |
|
2453 | 2453 | assert_equal issue.default_status, issue.status |
|
2454 | 2454 | end |
|
2455 | 2455 | |
|
2456 | 2456 | test "without workflow privilege #update should ignore status change" do |
|
2457 | 2457 | setup_without_workflow_privilege |
|
2458 | 2458 | assert_difference 'Journal.count' do |
|
2459 | 2459 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} |
|
2460 | 2460 | end |
|
2461 | 2461 | assert_equal 1, Issue.find(1).status_id |
|
2462 | 2462 | end |
|
2463 | 2463 | |
|
2464 | 2464 | test "without workflow privilege #update ignore attributes changes" do |
|
2465 | 2465 | setup_without_workflow_privilege |
|
2466 | 2466 | assert_difference 'Journal.count' do |
|
2467 | 2467 | put :update, :id => 1, |
|
2468 | 2468 | :issue => {:subject => 'changed', :assigned_to_id => 2, |
|
2469 | 2469 | :notes => 'just trying'} |
|
2470 | 2470 | end |
|
2471 | 2471 | issue = Issue.find(1) |
|
2472 | 2472 | assert_equal "Cannot print recipes", issue.subject |
|
2473 | 2473 | assert_nil issue.assigned_to |
|
2474 | 2474 | end |
|
2475 | 2475 | |
|
2476 | 2476 | def setup_with_workflow_privilege |
|
2477 | 2477 | WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) |
|
2478 | 2478 | WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, |
|
2479 | 2479 | :old_status_id => 1, :new_status_id => 3) |
|
2480 | 2480 | WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, |
|
2481 | 2481 | :old_status_id => 1, :new_status_id => 4) |
|
2482 | 2482 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
2483 | 2483 | end |
|
2484 | 2484 | private :setup_with_workflow_privilege |
|
2485 | 2485 | |
|
2486 | 2486 | def setup_with_workflow_privilege_and_edit_issues_permission |
|
2487 | 2487 | setup_with_workflow_privilege |
|
2488 | 2488 | Role.anonymous.add_permission! :add_issues, :edit_issues |
|
2489 | 2489 | end |
|
2490 | 2490 | private :setup_with_workflow_privilege_and_edit_issues_permission |
|
2491 | 2491 | |
|
2492 | 2492 | test "with workflow privilege and :edit_issues permission should accept authorized status" do |
|
2493 | 2493 | setup_with_workflow_privilege_and_edit_issues_permission |
|
2494 | 2494 | assert_difference 'Journal.count' do |
|
2495 | 2495 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} |
|
2496 | 2496 | end |
|
2497 | 2497 | assert_equal 3, Issue.find(1).status_id |
|
2498 | 2498 | end |
|
2499 | 2499 | |
|
2500 | 2500 | test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do |
|
2501 | 2501 | setup_with_workflow_privilege_and_edit_issues_permission |
|
2502 | 2502 | assert_difference 'Journal.count' do |
|
2503 | 2503 | put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} |
|
2504 | 2504 | end |
|
2505 | 2505 | assert_equal 1, Issue.find(1).status_id |
|
2506 | 2506 | end |
|
2507 | 2507 | |
|
2508 | 2508 | test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do |
|
2509 | 2509 | setup_with_workflow_privilege_and_edit_issues_permission |
|
2510 | 2510 | assert_difference 'Journal.count' do |
|
2511 | 2511 | put :update, :id => 1, |
|
2512 | 2512 | :issue => {:subject => 'changed', :assigned_to_id => 2, |
|
2513 | 2513 | :notes => 'just trying'} |
|
2514 | 2514 | end |
|
2515 | 2515 | issue = Issue.find(1) |
|
2516 | 2516 | assert_equal "changed", issue.subject |
|
2517 | 2517 | assert_equal 2, issue.assigned_to_id |
|
2518 | 2518 | end |
|
2519 | 2519 | |
|
2520 | 2520 | def test_new_as_copy |
|
2521 | 2521 | @request.session[:user_id] = 2 |
|
2522 | 2522 | get :new, :project_id => 1, :copy_from => 1 |
|
2523 | 2523 | |
|
2524 | 2524 | assert_response :success |
|
2525 | 2525 | assert_template 'new' |
|
2526 | 2526 | |
|
2527 | 2527 | assert_not_nil assigns(:issue) |
|
2528 | 2528 | orig = Issue.find(1) |
|
2529 | 2529 | assert_equal 1, assigns(:issue).project_id |
|
2530 | 2530 | assert_equal orig.subject, assigns(:issue).subject |
|
2531 | 2531 | assert assigns(:issue).copy? |
|
2532 | 2532 | |
|
2533 | 2533 | assert_select 'form[id=issue-form][action="/projects/ecookbook/issues"]' do |
|
2534 | 2534 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
2535 | 2535 | assert_select 'option[value="1"][selected=selected]', :text => 'eCookbook' |
|
2536 | 2536 | assert_select 'option[value="2"]:not([selected])', :text => 'OnlineStore' |
|
2537 | 2537 | end |
|
2538 | 2538 | assert_select 'input[name=copy_from][value="1"]' |
|
2539 | 2539 | end |
|
2540 | 2540 | |
|
2541 | 2541 | # "New issue" menu item should not link to copy |
|
2542 | 2542 | assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]' |
|
2543 | 2543 | end |
|
2544 | 2544 | |
|
2545 | 2545 | def test_new_as_copy_without_add_issues_permission_should_not_propose_current_project_as_target |
|
2546 | 2546 | user = setup_user_with_copy_but_not_add_permission |
|
2547 | 2547 | |
|
2548 | 2548 | @request.session[:user_id] = user.id |
|
2549 | 2549 | get :new, :project_id => 1, :copy_from => 1 |
|
2550 | 2550 | |
|
2551 | 2551 | assert_response :success |
|
2552 | 2552 | assert_template 'new' |
|
2553 | 2553 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
2554 | 2554 | assert_select 'option[value="1"]', 0 |
|
2555 | 2555 | assert_select 'option[value="2"]', :text => 'OnlineStore' |
|
2556 | 2556 | end |
|
2557 | 2557 | end |
|
2558 | 2558 | |
|
2559 | 2559 | def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox |
|
2560 | 2560 | @request.session[:user_id] = 2 |
|
2561 | 2561 | issue = Issue.find(3) |
|
2562 | 2562 | assert issue.attachments.count > 0 |
|
2563 | 2563 | get :new, :project_id => 1, :copy_from => 3 |
|
2564 | 2564 | |
|
2565 | 2565 | assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value="1"]' |
|
2566 | 2566 | end |
|
2567 | 2567 | |
|
2568 | 2568 | def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox |
|
2569 | 2569 | @request.session[:user_id] = 2 |
|
2570 | 2570 | issue = Issue.find(3) |
|
2571 | 2571 | issue.attachments.delete_all |
|
2572 | 2572 | get :new, :project_id => 1, :copy_from => 3 |
|
2573 | 2573 | |
|
2574 | 2574 | assert_select 'input[name=copy_attachments]', 0 |
|
2575 | 2575 | end |
|
2576 | 2576 | |
|
2577 | 2577 | def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox |
|
2578 | 2578 | @request.session[:user_id] = 2 |
|
2579 | 2579 | issue = Issue.generate_with_descendants! |
|
2580 | 2580 | get :new, :project_id => 1, :copy_from => issue.id |
|
2581 | 2581 | |
|
2582 | 2582 | assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value="1"]' |
|
2583 | 2583 | end |
|
2584 | 2584 | |
|
2585 | 2585 | def test_new_as_copy_with_invalid_issue_should_respond_with_404 |
|
2586 | 2586 | @request.session[:user_id] = 2 |
|
2587 | 2587 | get :new, :project_id => 1, :copy_from => 99999 |
|
2588 | 2588 | assert_response 404 |
|
2589 | 2589 | end |
|
2590 | 2590 | |
|
2591 | 2591 | def test_create_as_copy_on_different_project |
|
2592 | 2592 | @request.session[:user_id] = 2 |
|
2593 | 2593 | assert_difference 'Issue.count' do |
|
2594 | 2594 | post :create, :project_id => 1, :copy_from => 1, |
|
2595 | 2595 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} |
|
2596 | 2596 | |
|
2597 | 2597 | assert_not_nil assigns(:issue) |
|
2598 | 2598 | assert assigns(:issue).copy? |
|
2599 | 2599 | end |
|
2600 | 2600 | issue = Issue.order('id DESC').first |
|
2601 | 2601 | assert_redirected_to "/issues/#{issue.id}" |
|
2602 | 2602 | |
|
2603 | 2603 | assert_equal 2, issue.project_id |
|
2604 | 2604 | assert_equal 3, issue.tracker_id |
|
2605 | 2605 | assert_equal 'Copy', issue.subject |
|
2606 | 2606 | end |
|
2607 | 2607 | |
|
2608 | 2608 | def test_create_as_copy_should_copy_attachments |
|
2609 | 2609 | @request.session[:user_id] = 2 |
|
2610 | 2610 | issue = Issue.find(3) |
|
2611 | 2611 | count = issue.attachments.count |
|
2612 | 2612 | assert count > 0 |
|
2613 | 2613 | assert_difference 'Issue.count' do |
|
2614 | 2614 | assert_difference 'Attachment.count', count do |
|
2615 | 2615 | post :create, :project_id => 1, :copy_from => 3, |
|
2616 | 2616 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2617 | 2617 | :status_id => '1', :subject => 'Copy with attachments'}, |
|
2618 | 2618 | :copy_attachments => '1' |
|
2619 | 2619 | end |
|
2620 | 2620 | end |
|
2621 | 2621 | copy = Issue.order('id DESC').first |
|
2622 | 2622 | assert_equal count, copy.attachments.count |
|
2623 | 2623 | assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort |
|
2624 | 2624 | end |
|
2625 | 2625 | |
|
2626 | 2626 | def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments |
|
2627 | 2627 | @request.session[:user_id] = 2 |
|
2628 | 2628 | issue = Issue.find(3) |
|
2629 | 2629 | count = issue.attachments.count |
|
2630 | 2630 | assert count > 0 |
|
2631 | 2631 | assert_difference 'Issue.count' do |
|
2632 | 2632 | assert_no_difference 'Attachment.count' do |
|
2633 | 2633 | post :create, :project_id => 1, :copy_from => 3, |
|
2634 | 2634 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2635 | 2635 | :status_id => '1', :subject => 'Copy with attachments'} |
|
2636 | 2636 | end |
|
2637 | 2637 | end |
|
2638 | 2638 | copy = Issue.order('id DESC').first |
|
2639 | 2639 | assert_equal 0, copy.attachments.count |
|
2640 | 2640 | end |
|
2641 | 2641 | |
|
2642 | 2642 | def test_create_as_copy_with_attachments_should_also_add_new_files |
|
2643 | 2643 | @request.session[:user_id] = 2 |
|
2644 | 2644 | issue = Issue.find(3) |
|
2645 | 2645 | count = issue.attachments.count |
|
2646 | 2646 | assert count > 0 |
|
2647 | 2647 | assert_difference 'Issue.count' do |
|
2648 | 2648 | assert_difference 'Attachment.count', count + 1 do |
|
2649 | 2649 | post :create, :project_id => 1, :copy_from => 3, |
|
2650 | 2650 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2651 | 2651 | :status_id => '1', :subject => 'Copy with attachments'}, |
|
2652 | 2652 | :copy_attachments => '1', |
|
2653 | 2653 | :attachments => {'1' => |
|
2654 | 2654 | {'file' => uploaded_test_file('testfile.txt', 'text/plain'), |
|
2655 | 2655 | 'description' => 'test file'}} |
|
2656 | 2656 | end |
|
2657 | 2657 | end |
|
2658 | 2658 | copy = Issue.order('id DESC').first |
|
2659 | 2659 | assert_equal count + 1, copy.attachments.count |
|
2660 | 2660 | end |
|
2661 | 2661 | |
|
2662 | 2662 | def test_create_as_copy_should_add_relation_with_copied_issue |
|
2663 | 2663 | @request.session[:user_id] = 2 |
|
2664 | 2664 | assert_difference 'Issue.count' do |
|
2665 | 2665 | assert_difference 'IssueRelation.count' do |
|
2666 | 2666 | post :create, :project_id => 1, :copy_from => 1, :link_copy => '1', |
|
2667 | 2667 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2668 | 2668 | :status_id => '1', :subject => 'Copy'} |
|
2669 | 2669 | end |
|
2670 | 2670 | end |
|
2671 | 2671 | copy = Issue.order('id DESC').first |
|
2672 | 2672 | assert_equal 1, copy.relations.size |
|
2673 | 2673 | end |
|
2674 | 2674 | |
|
2675 | 2675 | def test_create_as_copy_should_allow_not_to_add_relation_with_copied_issue |
|
2676 | 2676 | @request.session[:user_id] = 2 |
|
2677 | 2677 | assert_difference 'Issue.count' do |
|
2678 | 2678 | assert_no_difference 'IssueRelation.count' do |
|
2679 | 2679 | post :create, :project_id => 1, :copy_from => 1, |
|
2680 | 2680 | :issue => {:subject => 'Copy'} |
|
2681 | 2681 | end |
|
2682 | 2682 | end |
|
2683 | 2683 | end |
|
2684 | 2684 | |
|
2685 | 2685 | def test_create_as_copy_should_always_add_relation_with_copied_issue_by_setting |
|
2686 | 2686 | with_settings :link_copied_issue => 'yes' do |
|
2687 | 2687 | @request.session[:user_id] = 2 |
|
2688 | 2688 | assert_difference 'Issue.count' do |
|
2689 | 2689 | assert_difference 'IssueRelation.count' do |
|
2690 | 2690 | post :create, :project_id => 1, :copy_from => 1, |
|
2691 | 2691 | :issue => {:subject => 'Copy'} |
|
2692 | 2692 | end |
|
2693 | 2693 | end |
|
2694 | 2694 | end |
|
2695 | 2695 | end |
|
2696 | 2696 | |
|
2697 | 2697 | def test_create_as_copy_should_never_add_relation_with_copied_issue_by_setting |
|
2698 | 2698 | with_settings :link_copied_issue => 'no' do |
|
2699 | 2699 | @request.session[:user_id] = 2 |
|
2700 | 2700 | assert_difference 'Issue.count' do |
|
2701 | 2701 | assert_no_difference 'IssueRelation.count' do |
|
2702 | 2702 | post :create, :project_id => 1, :copy_from => 1, :link_copy => '1', |
|
2703 | 2703 | :issue => {:subject => 'Copy'} |
|
2704 | 2704 | end |
|
2705 | 2705 | end |
|
2706 | 2706 | end |
|
2707 | 2707 | end |
|
2708 | 2708 | |
|
2709 | 2709 | def test_create_as_copy_should_copy_subtasks |
|
2710 | 2710 | @request.session[:user_id] = 2 |
|
2711 | 2711 | issue = Issue.generate_with_descendants! |
|
2712 | 2712 | count = issue.descendants.count |
|
2713 | 2713 | assert_difference 'Issue.count', count + 1 do |
|
2714 | 2714 | post :create, :project_id => 1, :copy_from => issue.id, |
|
2715 | 2715 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2716 | 2716 | :status_id => '1', :subject => 'Copy with subtasks'}, |
|
2717 | 2717 | :copy_subtasks => '1' |
|
2718 | 2718 | end |
|
2719 | 2719 | copy = Issue.where(:parent_id => nil).order('id DESC').first |
|
2720 | 2720 | assert_equal count, copy.descendants.count |
|
2721 | 2721 | assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort |
|
2722 | 2722 | end |
|
2723 | 2723 | |
|
2724 | 2724 | def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks |
|
2725 | 2725 | @request.session[:user_id] = 2 |
|
2726 | 2726 | issue = Issue.generate_with_descendants! |
|
2727 | 2727 | assert_difference 'Issue.count', 1 do |
|
2728 | 2728 | post :create, :project_id => 1, :copy_from => 3, |
|
2729 | 2729 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2730 | 2730 | :status_id => '1', :subject => 'Copy with subtasks'} |
|
2731 | 2731 | end |
|
2732 | 2732 | copy = Issue.where(:parent_id => nil).order('id DESC').first |
|
2733 | 2733 | assert_equal 0, copy.descendants.count |
|
2734 | 2734 | end |
|
2735 | 2735 | |
|
2736 | 2736 | def test_create_as_copy_with_failure |
|
2737 | 2737 | @request.session[:user_id] = 2 |
|
2738 | 2738 | post :create, :project_id => 1, :copy_from => 1, |
|
2739 | 2739 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''} |
|
2740 | 2740 | |
|
2741 | 2741 | assert_response :success |
|
2742 | 2742 | assert_template 'new' |
|
2743 | 2743 | |
|
2744 | 2744 | assert_not_nil assigns(:issue) |
|
2745 | 2745 | assert assigns(:issue).copy? |
|
2746 | 2746 | |
|
2747 | 2747 | assert_select 'form#issue-form[action="/projects/ecookbook/issues"]' do |
|
2748 | 2748 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
2749 | 2749 | assert_select 'option[value="1"]:not([selected])', :text => 'eCookbook' |
|
2750 | 2750 | assert_select 'option[value="2"][selected=selected]', :text => 'OnlineStore' |
|
2751 | 2751 | end |
|
2752 | 2752 | assert_select 'input[name=copy_from][value="1"]' |
|
2753 | 2753 | end |
|
2754 | 2754 | end |
|
2755 | 2755 | |
|
2756 | 2756 | def test_create_as_copy_on_project_without_permission_should_ignore_target_project |
|
2757 | 2757 | @request.session[:user_id] = 2 |
|
2758 | 2758 | assert !User.find(2).member_of?(Project.find(4)) |
|
2759 | 2759 | |
|
2760 | 2760 | assert_difference 'Issue.count' do |
|
2761 | 2761 | post :create, :project_id => 1, :copy_from => 1, |
|
2762 | 2762 | :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} |
|
2763 | 2763 | end |
|
2764 | 2764 | issue = Issue.order('id DESC').first |
|
2765 | 2765 | assert_equal 1, issue.project_id |
|
2766 | 2766 | end |
|
2767 | 2767 | |
|
2768 | 2768 | def test_get_edit |
|
2769 | 2769 | @request.session[:user_id] = 2 |
|
2770 | 2770 | get :edit, :id => 1 |
|
2771 | 2771 | assert_response :success |
|
2772 | 2772 | assert_template 'edit' |
|
2773 | 2773 | assert_not_nil assigns(:issue) |
|
2774 | 2774 | assert_equal Issue.find(1), assigns(:issue) |
|
2775 | 2775 | |
|
2776 | 2776 | # Be sure we don't display inactive IssuePriorities |
|
2777 | 2777 | assert ! IssuePriority.find(15).active? |
|
2778 | 2778 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
2779 | 2779 | assert_select 'option[value="15"]', 0 |
|
2780 | 2780 | end |
|
2781 | 2781 | end |
|
2782 | 2782 | |
|
2783 | 2783 | def test_get_edit_should_display_the_time_entry_form_with_log_time_permission |
|
2784 | 2784 | @request.session[:user_id] = 2 |
|
2785 | 2785 | Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] |
|
2786 | 2786 | |
|
2787 | 2787 | get :edit, :id => 1 |
|
2788 | 2788 | assert_select 'input[name=?]', 'time_entry[hours]' |
|
2789 | 2789 | end |
|
2790 | 2790 | |
|
2791 | 2791 | def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission |
|
2792 | 2792 | @request.session[:user_id] = 2 |
|
2793 | 2793 | Role.find_by_name('Manager').remove_permission! :log_time |
|
2794 | 2794 | |
|
2795 | 2795 | get :edit, :id => 1 |
|
2796 | 2796 | assert_select 'input[name=?]', 'time_entry[hours]', 0 |
|
2797 | 2797 | end |
|
2798 | 2798 | |
|
2799 | 2799 | def test_get_edit_with_params |
|
2800 | 2800 | @request.session[:user_id] = 2 |
|
2801 | 2801 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
|
2802 | 2802 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 } |
|
2803 | 2803 | assert_response :success |
|
2804 | 2804 | assert_template 'edit' |
|
2805 | 2805 | |
|
2806 | 2806 | issue = assigns(:issue) |
|
2807 | 2807 | assert_not_nil issue |
|
2808 | 2808 | |
|
2809 | 2809 | assert_equal 5, issue.status_id |
|
2810 | 2810 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
2811 | 2811 | assert_select 'option[value="5"][selected=selected]', :text => 'Closed' |
|
2812 | 2812 | end |
|
2813 | 2813 | |
|
2814 | 2814 | assert_equal 7, issue.priority_id |
|
2815 | 2815 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
2816 | 2816 | assert_select 'option[value="7"][selected=selected]', :text => 'Urgent' |
|
2817 | 2817 | end |
|
2818 | 2818 | |
|
2819 | 2819 | assert_select 'input[name=?][value="2.5"]', 'time_entry[hours]' |
|
2820 | 2820 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
2821 | 2821 | assert_select 'option[value="10"][selected=selected]', :text => 'Development' |
|
2822 | 2822 | end |
|
2823 | 2823 | assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]' |
|
2824 | 2824 | end |
|
2825 | 2825 | |
|
2826 | 2826 | def test_get_edit_with_multi_custom_field |
|
2827 | 2827 | field = CustomField.find(1) |
|
2828 | 2828 | field.update_attribute :multiple, true |
|
2829 | 2829 | issue = Issue.find(1) |
|
2830 | 2830 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
2831 | 2831 | issue.save! |
|
2832 | 2832 | |
|
2833 | 2833 | @request.session[:user_id] = 2 |
|
2834 | 2834 | get :edit, :id => 1 |
|
2835 | 2835 | assert_response :success |
|
2836 | 2836 | assert_template 'edit' |
|
2837 | 2837 | |
|
2838 | 2838 | assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do |
|
2839 | 2839 | assert_select 'option', 3 |
|
2840 | 2840 | assert_select 'option[value=MySQL][selected=selected]' |
|
2841 | 2841 | assert_select 'option[value=Oracle][selected=selected]' |
|
2842 | 2842 | assert_select 'option[value=PostgreSQL]:not([selected])' |
|
2843 | 2843 | end |
|
2844 | 2844 | end |
|
2845 | 2845 | |
|
2846 | 2846 | def test_update_form_for_existing_issue |
|
2847 | 2847 | @request.session[:user_id] = 2 |
|
2848 | 2848 | xhr :patch, :edit, :id => 1, |
|
2849 | 2849 | :issue => {:tracker_id => 2, |
|
2850 | 2850 | :subject => 'This is the test_new issue', |
|
2851 | 2851 | :description => 'This is the description', |
|
2852 | 2852 | :priority_id => 5} |
|
2853 | 2853 | assert_response :success |
|
2854 | 2854 | assert_equal 'text/javascript', response.content_type |
|
2855 | 2855 | assert_template 'edit' |
|
2856 | 2856 | assert_template :partial => '_form' |
|
2857 | 2857 | |
|
2858 | 2858 | issue = assigns(:issue) |
|
2859 | 2859 | assert_kind_of Issue, issue |
|
2860 | 2860 | assert_equal 1, issue.id |
|
2861 | 2861 | assert_equal 1, issue.project_id |
|
2862 | 2862 | assert_equal 2, issue.tracker_id |
|
2863 | 2863 | assert_equal 'This is the test_new issue', issue.subject |
|
2864 | 2864 | end |
|
2865 | 2865 | |
|
2866 | 2866 | def test_update_form_for_existing_issue_should_keep_issue_author |
|
2867 | 2867 | @request.session[:user_id] = 3 |
|
2868 | 2868 | xhr :patch, :edit, :id => 1, :issue => {:subject => 'Changed'} |
|
2869 | 2869 | assert_response :success |
|
2870 | 2870 | assert_equal 'text/javascript', response.content_type |
|
2871 | 2871 | |
|
2872 | 2872 | issue = assigns(:issue) |
|
2873 | 2873 | assert_equal User.find(2), issue.author |
|
2874 | 2874 | assert_equal 2, issue.author_id |
|
2875 | 2875 | assert_not_equal User.current, issue.author |
|
2876 | 2876 | end |
|
2877 | 2877 | |
|
2878 | 2878 | def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status |
|
2879 | 2879 | @request.session[:user_id] = 2 |
|
2880 | 2880 | WorkflowTransition.delete_all |
|
2881 | 2881 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) |
|
2882 | 2882 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) |
|
2883 | 2883 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) |
|
2884 | 2884 | |
|
2885 | 2885 | xhr :patch, :edit, :id => 2, |
|
2886 | 2886 | :issue => {:tracker_id => 2, |
|
2887 | 2887 | :status_id => 5, |
|
2888 | 2888 | :subject => 'This is an issue'} |
|
2889 | 2889 | |
|
2890 | 2890 | assert_equal 5, assigns(:issue).status_id |
|
2891 | 2891 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort |
|
2892 | 2892 | end |
|
2893 | 2893 | |
|
2894 | 2894 | def test_update_form_for_existing_issue_with_project_change |
|
2895 | 2895 | @request.session[:user_id] = 2 |
|
2896 | 2896 | xhr :patch, :edit, :id => 1, |
|
2897 | 2897 | :issue => {:project_id => 2, |
|
2898 | 2898 | :tracker_id => 2, |
|
2899 | 2899 | :subject => 'This is the test_new issue', |
|
2900 | 2900 | :description => 'This is the description', |
|
2901 | 2901 | :priority_id => 5} |
|
2902 | 2902 | assert_response :success |
|
2903 | 2903 | assert_template :partial => '_form' |
|
2904 | 2904 | |
|
2905 | 2905 | issue = assigns(:issue) |
|
2906 | 2906 | assert_kind_of Issue, issue |
|
2907 | 2907 | assert_equal 1, issue.id |
|
2908 | 2908 | assert_equal 2, issue.project_id |
|
2909 | 2909 | assert_equal 2, issue.tracker_id |
|
2910 | 2910 | assert_equal 'This is the test_new issue', issue.subject |
|
2911 | 2911 | end |
|
2912 | 2912 | |
|
2913 | 2913 | def test_update_form_should_propose_default_status_for_existing_issue |
|
2914 | 2914 | @request.session[:user_id] = 2 |
|
2915 | 2915 | WorkflowTransition.delete_all |
|
2916 | 2916 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3) |
|
2917 | 2917 | |
|
2918 | 2918 | xhr :patch, :edit, :id => 2 |
|
2919 | 2919 | assert_response :success |
|
2920 | 2920 | assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort |
|
2921 | 2921 | end |
|
2922 | 2922 | |
|
2923 | 2923 | def test_put_update_without_custom_fields_param |
|
2924 | 2924 | @request.session[:user_id] = 2 |
|
2925 | 2925 | |
|
2926 | 2926 | issue = Issue.find(1) |
|
2927 | 2927 | assert_equal '125', issue.custom_value_for(2).value |
|
2928 | 2928 | |
|
2929 | 2929 | assert_difference('Journal.count') do |
|
2930 | 2930 | assert_difference('JournalDetail.count') do |
|
2931 | 2931 | put :update, :id => 1, :issue => {:subject => 'New subject'} |
|
2932 | 2932 | end |
|
2933 | 2933 | end |
|
2934 | 2934 | assert_redirected_to :action => 'show', :id => '1' |
|
2935 | 2935 | issue.reload |
|
2936 | 2936 | assert_equal 'New subject', issue.subject |
|
2937 | 2937 | # Make sure custom fields were not cleared |
|
2938 | 2938 | assert_equal '125', issue.custom_value_for(2).value |
|
2939 | 2939 | end |
|
2940 | 2940 | |
|
2941 | 2941 | def test_put_update_with_project_change |
|
2942 | 2942 | @request.session[:user_id] = 2 |
|
2943 | 2943 | ActionMailer::Base.deliveries.clear |
|
2944 | 2944 | |
|
2945 | 2945 | with_settings :notified_events => %w(issue_updated) do |
|
2946 | 2946 | assert_difference('Journal.count') do |
|
2947 | 2947 | assert_difference('JournalDetail.count', 3) do |
|
2948 | 2948 | put :update, :id => 1, :issue => {:project_id => '2', |
|
2949 | 2949 | :tracker_id => '1', # no change |
|
2950 | 2950 | :priority_id => '6', |
|
2951 | 2951 | :category_id => '3' |
|
2952 | 2952 | } |
|
2953 | 2953 | end |
|
2954 | 2954 | end |
|
2955 | 2955 | end |
|
2956 | 2956 | assert_redirected_to :action => 'show', :id => '1' |
|
2957 | 2957 | issue = Issue.find(1) |
|
2958 | 2958 | assert_equal 2, issue.project_id |
|
2959 | 2959 | assert_equal 1, issue.tracker_id |
|
2960 | 2960 | assert_equal 6, issue.priority_id |
|
2961 | 2961 | assert_equal 3, issue.category_id |
|
2962 | 2962 | |
|
2963 | 2963 | mail = ActionMailer::Base.deliveries.last |
|
2964 | 2964 | assert_not_nil mail |
|
2965 | 2965 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2966 | 2966 | assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail |
|
2967 | 2967 | end |
|
2968 | 2968 | |
|
2969 | 2969 | def test_put_update_with_tracker_change |
|
2970 | 2970 | @request.session[:user_id] = 2 |
|
2971 | 2971 | ActionMailer::Base.deliveries.clear |
|
2972 | 2972 | |
|
2973 | 2973 | with_settings :notified_events => %w(issue_updated) do |
|
2974 | 2974 | assert_difference('Journal.count') do |
|
2975 | 2975 | assert_difference('JournalDetail.count', 2) do |
|
2976 | 2976 | put :update, :id => 1, :issue => {:project_id => '1', |
|
2977 | 2977 | :tracker_id => '2', |
|
2978 | 2978 | :priority_id => '6' |
|
2979 | 2979 | } |
|
2980 | 2980 | end |
|
2981 | 2981 | end |
|
2982 | 2982 | end |
|
2983 | 2983 | assert_redirected_to :action => 'show', :id => '1' |
|
2984 | 2984 | issue = Issue.find(1) |
|
2985 | 2985 | assert_equal 1, issue.project_id |
|
2986 | 2986 | assert_equal 2, issue.tracker_id |
|
2987 | 2987 | assert_equal 6, issue.priority_id |
|
2988 | 2988 | assert_equal 1, issue.category_id |
|
2989 | 2989 | |
|
2990 | 2990 | mail = ActionMailer::Base.deliveries.last |
|
2991 | 2991 | assert_not_nil mail |
|
2992 | 2992 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2993 | 2993 | assert_mail_body_match "Tracker changed from Bug to Feature request", mail |
|
2994 | 2994 | end |
|
2995 | 2995 | |
|
2996 | 2996 | def test_put_update_with_custom_field_change |
|
2997 | 2997 | @request.session[:user_id] = 2 |
|
2998 | 2998 | issue = Issue.find(1) |
|
2999 | 2999 | assert_equal '125', issue.custom_value_for(2).value |
|
3000 | 3000 | |
|
3001 | 3001 | with_settings :notified_events => %w(issue_updated) do |
|
3002 | 3002 | assert_difference('Journal.count') do |
|
3003 | 3003 | assert_difference('JournalDetail.count', 3) do |
|
3004 | 3004 | put :update, :id => 1, :issue => {:subject => 'Custom field change', |
|
3005 | 3005 | :priority_id => '6', |
|
3006 | 3006 | :category_id => '1', # no change |
|
3007 | 3007 | :custom_field_values => { '2' => 'New custom value' } |
|
3008 | 3008 | } |
|
3009 | 3009 | end |
|
3010 | 3010 | end |
|
3011 | 3011 | end |
|
3012 | 3012 | assert_redirected_to :action => 'show', :id => '1' |
|
3013 | 3013 | issue.reload |
|
3014 | 3014 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
3015 | 3015 | |
|
3016 | 3016 | mail = ActionMailer::Base.deliveries.last |
|
3017 | 3017 | assert_not_nil mail |
|
3018 | 3018 | assert_mail_body_match "Searchable field changed from 125 to New custom value", mail |
|
3019 | 3019 | end |
|
3020 | 3020 | |
|
3021 | 3021 | def test_put_update_with_multi_custom_field_change |
|
3022 | 3022 | field = CustomField.find(1) |
|
3023 | 3023 | field.update_attribute :multiple, true |
|
3024 | 3024 | issue = Issue.find(1) |
|
3025 | 3025 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
3026 | 3026 | issue.save! |
|
3027 | 3027 | |
|
3028 | 3028 | @request.session[:user_id] = 2 |
|
3029 | 3029 | assert_difference('Journal.count') do |
|
3030 | 3030 | assert_difference('JournalDetail.count', 3) do |
|
3031 | 3031 | put :update, :id => 1, |
|
3032 | 3032 | :issue => { |
|
3033 | 3033 | :subject => 'Custom field change', |
|
3034 | 3034 | :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] } |
|
3035 | 3035 | } |
|
3036 | 3036 | end |
|
3037 | 3037 | end |
|
3038 | 3038 | assert_redirected_to :action => 'show', :id => '1' |
|
3039 | 3039 | assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort |
|
3040 | 3040 | end |
|
3041 | 3041 | |
|
3042 | 3042 | def test_put_update_with_status_and_assignee_change |
|
3043 | 3043 | issue = Issue.find(1) |
|
3044 | 3044 | assert_equal 1, issue.status_id |
|
3045 | 3045 | @request.session[:user_id] = 2 |
|
3046 | 3046 | |
|
3047 | 3047 | with_settings :notified_events => %w(issue_updated) do |
|
3048 | 3048 | assert_difference('TimeEntry.count', 0) do |
|
3049 | 3049 | put :update, |
|
3050 | 3050 | :id => 1, |
|
3051 | 3051 | :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' }, |
|
3052 | 3052 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
3053 | 3053 | end |
|
3054 | 3054 | end |
|
3055 | 3055 | assert_redirected_to :action => 'show', :id => '1' |
|
3056 | 3056 | issue.reload |
|
3057 | 3057 | assert_equal 2, issue.status_id |
|
3058 | 3058 | j = Journal.order('id DESC').first |
|
3059 | 3059 | assert_equal 'Assigned to dlopper', j.notes |
|
3060 | 3060 | assert_equal 2, j.details.size |
|
3061 | 3061 | |
|
3062 | 3062 | mail = ActionMailer::Base.deliveries.last |
|
3063 | 3063 | assert_mail_body_match "Status changed from New to Assigned", mail |
|
3064 | 3064 | # subject should contain the new status |
|
3065 | 3065 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
3066 | 3066 | end |
|
3067 | 3067 | |
|
3068 | 3068 | def test_put_update_with_note_only |
|
3069 | 3069 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
3070 | 3070 | |
|
3071 | 3071 | with_settings :notified_events => %w(issue_updated) do |
|
3072 | 3072 | # anonymous user |
|
3073 | 3073 | put :update, |
|
3074 | 3074 | :id => 1, |
|
3075 | 3075 | :issue => { :notes => notes } |
|
3076 | 3076 | end |
|
3077 | 3077 | assert_redirected_to :action => 'show', :id => '1' |
|
3078 | 3078 | j = Journal.order('id DESC').first |
|
3079 | 3079 | assert_equal notes, j.notes |
|
3080 | 3080 | assert_equal 0, j.details.size |
|
3081 | 3081 | assert_equal User.anonymous, j.user |
|
3082 | 3082 | |
|
3083 | 3083 | mail = ActionMailer::Base.deliveries.last |
|
3084 | 3084 | assert_mail_body_match notes, mail |
|
3085 | 3085 | end |
|
3086 | 3086 | |
|
3087 | 3087 | def test_put_update_with_private_note_only |
|
3088 | 3088 | notes = 'Private note' |
|
3089 | 3089 | @request.session[:user_id] = 2 |
|
3090 | 3090 | |
|
3091 | 3091 | assert_difference 'Journal.count' do |
|
3092 | 3092 | put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'} |
|
3093 | 3093 | assert_redirected_to :action => 'show', :id => '1' |
|
3094 | 3094 | end |
|
3095 | 3095 | |
|
3096 | 3096 | j = Journal.order('id DESC').first |
|
3097 | 3097 | assert_equal notes, j.notes |
|
3098 | 3098 | assert_equal true, j.private_notes |
|
3099 | 3099 | end |
|
3100 | 3100 | |
|
3101 | 3101 | def test_put_update_with_private_note_and_changes |
|
3102 | 3102 | notes = 'Private note' |
|
3103 | 3103 | @request.session[:user_id] = 2 |
|
3104 | 3104 | |
|
3105 | 3105 | assert_difference 'Journal.count', 2 do |
|
3106 | 3106 | put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'} |
|
3107 | 3107 | assert_redirected_to :action => 'show', :id => '1' |
|
3108 | 3108 | end |
|
3109 | 3109 | |
|
3110 | 3110 | j = Journal.order('id DESC').first |
|
3111 | 3111 | assert_equal notes, j.notes |
|
3112 | 3112 | assert_equal true, j.private_notes |
|
3113 | 3113 | assert_equal 0, j.details.count |
|
3114 | 3114 | |
|
3115 | 3115 | j = Journal.order('id DESC').offset(1).first |
|
3116 | 3116 | assert_nil j.notes |
|
3117 | 3117 | assert_equal false, j.private_notes |
|
3118 | 3118 | assert_equal 1, j.details.count |
|
3119 | 3119 | end |
|
3120 | 3120 | |
|
3121 | 3121 | def test_put_update_with_note_and_spent_time |
|
3122 | 3122 | @request.session[:user_id] = 2 |
|
3123 | 3123 | spent_hours_before = Issue.find(1).spent_hours |
|
3124 | 3124 | assert_difference('TimeEntry.count') do |
|
3125 | 3125 | put :update, |
|
3126 | 3126 | :id => 1, |
|
3127 | 3127 | :issue => { :notes => '2.5 hours added' }, |
|
3128 | 3128 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } |
|
3129 | 3129 | end |
|
3130 | 3130 | assert_redirected_to :action => 'show', :id => '1' |
|
3131 | 3131 | |
|
3132 | 3132 | issue = Issue.find(1) |
|
3133 | 3133 | |
|
3134 | 3134 | j = Journal.order('id DESC').first |
|
3135 | 3135 | assert_equal '2.5 hours added', j.notes |
|
3136 | 3136 | assert_equal 0, j.details.size |
|
3137 | 3137 | |
|
3138 | 3138 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
|
3139 | 3139 | assert_not_nil t |
|
3140 | 3140 | assert_equal 2.5, t.hours |
|
3141 | 3141 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
3142 | 3142 | end |
|
3143 | 3143 | |
|
3144 | 3144 | def test_put_update_should_preserve_parent_issue_even_if_not_visible |
|
3145 | 3145 | parent = Issue.generate!(:project_id => 1, :is_private => true) |
|
3146 | 3146 | issue = Issue.generate!(:parent_issue_id => parent.id) |
|
3147 | 3147 | assert !parent.visible?(User.find(3)) |
|
3148 | 3148 | @request.session[:user_id] = 3 |
|
3149 | 3149 | |
|
3150 | 3150 | get :edit, :id => issue.id |
|
3151 | 3151 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s |
|
3152 | 3152 | |
|
3153 | 3153 | put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s} |
|
3154 | 3154 | assert_response 302 |
|
3155 | 3155 | assert_equal parent, issue.parent |
|
3156 | 3156 | end |
|
3157 | 3157 | |
|
3158 | 3158 | def test_put_update_with_attachment_only |
|
3159 | 3159 | set_tmp_attachments_directory |
|
3160 | 3160 | |
|
3161 | 3161 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
3162 | 3162 | # journal to get fetched in the next find. |
|
3163 | 3163 | Journal.delete_all |
|
3164 | 3164 | |
|
3165 | 3165 | with_settings :notified_events => %w(issue_updated) do |
|
3166 | 3166 | # anonymous user |
|
3167 | 3167 | assert_difference 'Attachment.count' do |
|
3168 | 3168 | put :update, :id => 1, |
|
3169 | 3169 | :issue => {:notes => ''}, |
|
3170 | 3170 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
3171 | 3171 | end |
|
3172 | 3172 | end |
|
3173 | 3173 | |
|
3174 | 3174 | assert_redirected_to :action => 'show', :id => '1' |
|
3175 | 3175 | j = Issue.find(1).journals.reorder('id DESC').first |
|
3176 | 3176 | assert j.notes.blank? |
|
3177 | 3177 | assert_equal 1, j.details.size |
|
3178 | 3178 | assert_equal 'testfile.txt', j.details.first.value |
|
3179 | 3179 | assert_equal User.anonymous, j.user |
|
3180 | 3180 | |
|
3181 | 3181 | attachment = Attachment.order('id DESC').first |
|
3182 | 3182 | assert_equal Issue.find(1), attachment.container |
|
3183 | 3183 | assert_equal User.anonymous, attachment.author |
|
3184 | 3184 | assert_equal 'testfile.txt', attachment.filename |
|
3185 | 3185 | assert_equal 'text/plain', attachment.content_type |
|
3186 | 3186 | assert_equal 'test file', attachment.description |
|
3187 | 3187 | assert_equal 59, attachment.filesize |
|
3188 | 3188 | assert File.exists?(attachment.diskfile) |
|
3189 | 3189 | assert_equal 59, File.size(attachment.diskfile) |
|
3190 | 3190 | |
|
3191 | 3191 | mail = ActionMailer::Base.deliveries.last |
|
3192 | 3192 | assert_mail_body_match 'testfile.txt', mail |
|
3193 | 3193 | end |
|
3194 | 3194 | |
|
3195 | 3195 | def test_put_update_with_failure_should_save_attachments |
|
3196 | 3196 | set_tmp_attachments_directory |
|
3197 | 3197 | @request.session[:user_id] = 2 |
|
3198 | 3198 | |
|
3199 | 3199 | assert_no_difference 'Journal.count' do |
|
3200 | 3200 | assert_difference 'Attachment.count' do |
|
3201 | 3201 | put :update, :id => 1, |
|
3202 | 3202 | :issue => { :subject => '' }, |
|
3203 | 3203 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
3204 | 3204 | assert_response :success |
|
3205 | 3205 | assert_template 'edit' |
|
3206 | 3206 | end |
|
3207 | 3207 | end |
|
3208 | 3208 | |
|
3209 | 3209 | attachment = Attachment.order('id DESC').first |
|
3210 | 3210 | assert_equal 'testfile.txt', attachment.filename |
|
3211 | 3211 | assert File.exists?(attachment.diskfile) |
|
3212 | 3212 | assert_nil attachment.container |
|
3213 | 3213 | |
|
3214 | 3214 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
3215 | 3215 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
3216 | 3216 | end |
|
3217 | 3217 | |
|
3218 | 3218 | def test_put_update_with_failure_should_keep_saved_attachments |
|
3219 | 3219 | set_tmp_attachments_directory |
|
3220 | 3220 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
3221 | 3221 | @request.session[:user_id] = 2 |
|
3222 | 3222 | |
|
3223 | 3223 | assert_no_difference 'Journal.count' do |
|
3224 | 3224 | assert_no_difference 'Attachment.count' do |
|
3225 | 3225 | put :update, :id => 1, |
|
3226 | 3226 | :issue => { :subject => '' }, |
|
3227 | 3227 | :attachments => {'p0' => {'token' => attachment.token}} |
|
3228 | 3228 | assert_response :success |
|
3229 | 3229 | assert_template 'edit' |
|
3230 | 3230 | end |
|
3231 | 3231 | end |
|
3232 | 3232 | |
|
3233 | 3233 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
3234 | 3234 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
3235 | 3235 | end |
|
3236 | 3236 | |
|
3237 | 3237 | def test_put_update_should_attach_saved_attachments |
|
3238 | 3238 | set_tmp_attachments_directory |
|
3239 | 3239 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
3240 | 3240 | @request.session[:user_id] = 2 |
|
3241 | 3241 | |
|
3242 | 3242 | assert_difference 'Journal.count' do |
|
3243 | 3243 | assert_difference 'JournalDetail.count' do |
|
3244 | 3244 | assert_no_difference 'Attachment.count' do |
|
3245 | 3245 | put :update, :id => 1, |
|
3246 | 3246 | :issue => {:notes => 'Attachment added'}, |
|
3247 | 3247 | :attachments => {'p0' => {'token' => attachment.token}} |
|
3248 | 3248 | assert_redirected_to '/issues/1' |
|
3249 | 3249 | end |
|
3250 | 3250 | end |
|
3251 | 3251 | end |
|
3252 | 3252 | |
|
3253 | 3253 | attachment.reload |
|
3254 | 3254 | assert_equal Issue.find(1), attachment.container |
|
3255 | 3255 | |
|
3256 | 3256 | journal = Journal.order('id DESC').first |
|
3257 | 3257 | assert_equal 1, journal.details.size |
|
3258 | 3258 | assert_equal 'testfile.txt', journal.details.first.value |
|
3259 | 3259 | end |
|
3260 | 3260 | |
|
3261 | 3261 | def test_put_update_with_attachment_that_fails_to_save |
|
3262 | 3262 | set_tmp_attachments_directory |
|
3263 | 3263 | |
|
3264 | 3264 | # anonymous user |
|
3265 | 3265 | with_settings :attachment_max_size => 0 do |
|
3266 | 3266 | put :update, |
|
3267 | 3267 | :id => 1, |
|
3268 | 3268 | :issue => {:notes => ''}, |
|
3269 | 3269 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
3270 | 3270 | assert_redirected_to :action => 'show', :id => '1' |
|
3271 | 3271 | assert_equal '1 file(s) could not be saved.', flash[:warning] |
|
3272 | 3272 | end |
|
3273 | 3273 | end |
|
3274 | 3274 | |
|
3275 | 3275 | def test_put_update_with_no_change |
|
3276 | 3276 | issue = Issue.find(1) |
|
3277 | 3277 | issue.journals.clear |
|
3278 | 3278 | ActionMailer::Base.deliveries.clear |
|
3279 | 3279 | |
|
3280 | 3280 | put :update, |
|
3281 | 3281 | :id => 1, |
|
3282 | 3282 | :issue => {:notes => ''} |
|
3283 | 3283 | assert_redirected_to :action => 'show', :id => '1' |
|
3284 | 3284 | |
|
3285 | 3285 | issue.reload |
|
3286 | 3286 | assert issue.journals.empty? |
|
3287 | 3287 | # No email should be sent |
|
3288 | 3288 | assert ActionMailer::Base.deliveries.empty? |
|
3289 | 3289 | end |
|
3290 | 3290 | |
|
3291 | 3291 | def test_put_update_should_send_a_notification |
|
3292 | 3292 | @request.session[:user_id] = 2 |
|
3293 | 3293 | ActionMailer::Base.deliveries.clear |
|
3294 | 3294 | issue = Issue.find(1) |
|
3295 | 3295 | old_subject = issue.subject |
|
3296 | 3296 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
3297 | 3297 | |
|
3298 | 3298 | with_settings :notified_events => %w(issue_updated) do |
|
3299 | 3299 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
3300 | 3300 | :priority_id => '6', |
|
3301 | 3301 | :category_id => '1' # no change |
|
3302 | 3302 | } |
|
3303 | 3303 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
3304 | 3304 | end |
|
3305 | 3305 | end |
|
3306 | 3306 | |
|
3307 | 3307 | def test_put_update_with_invalid_spent_time_hours_only |
|
3308 | 3308 | @request.session[:user_id] = 2 |
|
3309 | 3309 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
3310 | 3310 | |
|
3311 | 3311 | assert_no_difference('Journal.count') do |
|
3312 | 3312 | put :update, |
|
3313 | 3313 | :id => 1, |
|
3314 | 3314 | :issue => {:notes => notes}, |
|
3315 | 3315 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
3316 | 3316 | end |
|
3317 | 3317 | assert_response :success |
|
3318 | 3318 | assert_template 'edit' |
|
3319 | 3319 | |
|
3320 | 3320 | assert_select_error /Activity cannot be blank/ |
|
3321 | 3321 | assert_select 'textarea[name=?]', 'issue[notes]', :text => notes |
|
3322 | 3322 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z' |
|
3323 | 3323 | end |
|
3324 | 3324 | |
|
3325 | 3325 | def test_put_update_with_invalid_spent_time_comments_only |
|
3326 | 3326 | @request.session[:user_id] = 2 |
|
3327 | 3327 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
3328 | 3328 | |
|
3329 | 3329 | assert_no_difference('Journal.count') do |
|
3330 | 3330 | put :update, |
|
3331 | 3331 | :id => 1, |
|
3332 | 3332 | :issue => {:notes => notes}, |
|
3333 | 3333 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} |
|
3334 | 3334 | end |
|
3335 | 3335 | assert_response :success |
|
3336 | 3336 | assert_template 'edit' |
|
3337 | 3337 | |
|
3338 | 3338 | assert_select_error /Activity cannot be blank/ |
|
3339 | 3339 | assert_select_error /Hours cannot be blank/ |
|
3340 | 3340 | assert_select 'textarea[name=?]', 'issue[notes]', :text => notes |
|
3341 | 3341 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment' |
|
3342 | 3342 | end |
|
3343 | 3343 | |
|
3344 | 3344 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
3345 | 3345 | issue = Issue.find(2) |
|
3346 | 3346 | @request.session[:user_id] = 2 |
|
3347 | 3347 | |
|
3348 | 3348 | put :update, |
|
3349 | 3349 | :id => issue.id, |
|
3350 | 3350 | :issue => { |
|
3351 | 3351 | :fixed_version_id => 4 |
|
3352 | 3352 | } |
|
3353 | 3353 | |
|
3354 | 3354 | assert_response :redirect |
|
3355 | 3355 | issue.reload |
|
3356 | 3356 | assert_equal 4, issue.fixed_version_id |
|
3357 | 3357 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
3358 | 3358 | end |
|
3359 | 3359 | |
|
3360 | 3360 | def test_put_update_should_redirect_back_using_the_back_url_parameter |
|
3361 | 3361 | issue = Issue.find(2) |
|
3362 | 3362 | @request.session[:user_id] = 2 |
|
3363 | 3363 | |
|
3364 | 3364 | put :update, |
|
3365 | 3365 | :id => issue.id, |
|
3366 | 3366 | :issue => { |
|
3367 | 3367 | :fixed_version_id => 4 |
|
3368 | 3368 | }, |
|
3369 | 3369 | :back_url => '/issues' |
|
3370 | 3370 | |
|
3371 | 3371 | assert_response :redirect |
|
3372 | 3372 | assert_redirected_to '/issues' |
|
3373 | 3373 | end |
|
3374 | 3374 | |
|
3375 | 3375 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
3376 | 3376 | issue = Issue.find(2) |
|
3377 | 3377 | @request.session[:user_id] = 2 |
|
3378 | 3378 | |
|
3379 | 3379 | put :update, |
|
3380 | 3380 | :id => issue.id, |
|
3381 | 3381 | :issue => { |
|
3382 | 3382 | :fixed_version_id => 4 |
|
3383 | 3383 | }, |
|
3384 | 3384 | :back_url => 'http://google.com' |
|
3385 | 3385 | |
|
3386 | 3386 | assert_response :redirect |
|
3387 | 3387 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
|
3388 | 3388 | end |
|
3389 | 3389 | |
|
3390 | 3390 | def test_get_bulk_edit |
|
3391 | 3391 | @request.session[:user_id] = 2 |
|
3392 | 3392 | get :bulk_edit, :ids => [1, 2] |
|
3393 | 3393 | assert_response :success |
|
3394 | 3394 | assert_template 'bulk_edit' |
|
3395 | 3395 | |
|
3396 | 3396 | assert_select 'ul#bulk-selection' do |
|
3397 | 3397 | assert_select 'li', 2 |
|
3398 | 3398 | assert_select 'li a', :text => 'Bug #1' |
|
3399 | 3399 | end |
|
3400 | 3400 | |
|
3401 | 3401 | assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do |
|
3402 | 3402 | assert_select 'input[name=?]', 'ids[]', 2 |
|
3403 | 3403 | assert_select 'input[name=?][value="1"][type=hidden]', 'ids[]' |
|
3404 | 3404 | |
|
3405 | 3405 | assert_select 'select[name=?]', 'issue[project_id]' |
|
3406 | 3406 | assert_select 'input[name=?]', 'issue[parent_issue_id]' |
|
3407 | 3407 | |
|
3408 | 3408 | # Project specific custom field, date type |
|
3409 | 3409 | field = CustomField.find(9) |
|
3410 | 3410 | assert !field.is_for_all? |
|
3411 | 3411 | assert_equal 'date', field.field_format |
|
3412 | 3412 | assert_select 'input[name=?]', 'issue[custom_field_values][9]' |
|
3413 | 3413 | |
|
3414 | 3414 | # System wide custom field |
|
3415 | 3415 | assert CustomField.find(1).is_for_all? |
|
3416 | 3416 | assert_select 'select[name=?]', 'issue[custom_field_values][1]' |
|
3417 | 3417 | |
|
3418 | 3418 | # Be sure we don't display inactive IssuePriorities |
|
3419 | 3419 | assert ! IssuePriority.find(15).active? |
|
3420 | 3420 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
3421 | 3421 | assert_select 'option[value="15"]', 0 |
|
3422 | 3422 | end |
|
3423 | 3423 | end |
|
3424 | 3424 | end |
|
3425 | 3425 | |
|
3426 | 3426 | def test_get_bulk_edit_on_different_projects |
|
3427 | 3427 | @request.session[:user_id] = 2 |
|
3428 | 3428 | get :bulk_edit, :ids => [1, 2, 6] |
|
3429 | 3429 | assert_response :success |
|
3430 | 3430 | assert_template 'bulk_edit' |
|
3431 | 3431 | |
|
3432 | 3432 | # Can not set issues from different projects as children of an issue |
|
3433 | 3433 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
3434 | 3434 | |
|
3435 | 3435 | # Project specific custom field, date type |
|
3436 | 3436 | field = CustomField.find(9) |
|
3437 | 3437 | assert !field.is_for_all? |
|
3438 | 3438 | assert !field.project_ids.include?(Issue.find(6).project_id) |
|
3439 | 3439 | assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0 |
|
3440 | 3440 | end |
|
3441 | 3441 | |
|
3442 | 3442 | def test_get_bulk_edit_with_user_custom_field |
|
3443 | 3443 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) |
|
3444 | 3444 | |
|
3445 | 3445 | @request.session[:user_id] = 2 |
|
3446 | 3446 | get :bulk_edit, :ids => [1, 2] |
|
3447 | 3447 | assert_response :success |
|
3448 | 3448 | assert_template 'bulk_edit' |
|
3449 | 3449 | |
|
3450 | 3450 | assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do |
|
3451 | 3451 | assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options |
|
3452 | 3452 | end |
|
3453 | 3453 | end |
|
3454 | 3454 | |
|
3455 | 3455 | def test_get_bulk_edit_with_version_custom_field |
|
3456 | 3456 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) |
|
3457 | 3457 | |
|
3458 | 3458 | @request.session[:user_id] = 2 |
|
3459 | 3459 | get :bulk_edit, :ids => [1, 2] |
|
3460 | 3460 | assert_response :success |
|
3461 | 3461 | assert_template 'bulk_edit' |
|
3462 | 3462 | |
|
3463 | 3463 | assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do |
|
3464 | 3464 | assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options |
|
3465 | 3465 | end |
|
3466 | 3466 | end |
|
3467 | 3467 | |
|
3468 | 3468 | def test_get_bulk_edit_with_multi_custom_field |
|
3469 | 3469 | field = CustomField.find(1) |
|
3470 | 3470 | field.update_attribute :multiple, true |
|
3471 | 3471 | |
|
3472 | 3472 | @request.session[:user_id] = 2 |
|
3473 | 3473 | get :bulk_edit, :ids => [1, 2] |
|
3474 | 3474 | assert_response :success |
|
3475 | 3475 | assert_template 'bulk_edit' |
|
3476 | 3476 | |
|
3477 | 3477 | assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do |
|
3478 | 3478 | assert_select 'option', field.possible_values.size + 1 # "none" options |
|
3479 | 3479 | end |
|
3480 | 3480 | end |
|
3481 | 3481 | |
|
3482 | 3482 | def test_bulk_edit_should_propose_to_clear_text_custom_fields |
|
3483 | 3483 | @request.session[:user_id] = 2 |
|
3484 | 3484 | get :bulk_edit, :ids => [1, 3] |
|
3485 | 3485 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__' |
|
3486 | 3486 | end |
|
3487 | 3487 | |
|
3488 | 3488 | def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues |
|
3489 | 3489 | WorkflowTransition.delete_all |
|
3490 | 3490 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
3491 | 3491 | :old_status_id => 1, :new_status_id => 1) |
|
3492 | 3492 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
3493 | 3493 | :old_status_id => 1, :new_status_id => 3) |
|
3494 | 3494 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
3495 | 3495 | :old_status_id => 1, :new_status_id => 4) |
|
3496 | 3496 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
3497 | 3497 | :old_status_id => 2, :new_status_id => 1) |
|
3498 | 3498 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
3499 | 3499 | :old_status_id => 2, :new_status_id => 3) |
|
3500 | 3500 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
3501 | 3501 | :old_status_id => 2, :new_status_id => 5) |
|
3502 | 3502 | @request.session[:user_id] = 2 |
|
3503 | 3503 | get :bulk_edit, :ids => [1, 2] |
|
3504 | 3504 | |
|
3505 | 3505 | assert_response :success |
|
3506 | 3506 | statuses = assigns(:available_statuses) |
|
3507 | 3507 | assert_not_nil statuses |
|
3508 | 3508 | assert_equal [1, 3], statuses.map(&:id).sort |
|
3509 | 3509 | |
|
3510 | 3510 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
3511 | 3511 | assert_select 'option', 3 # 2 statuses + "no change" option |
|
3512 | 3512 | end |
|
3513 | 3513 | end |
|
3514 | 3514 | |
|
3515 | 3515 | def test_bulk_edit_should_propose_target_project_open_shared_versions |
|
3516 | 3516 | @request.session[:user_id] = 2 |
|
3517 | 3517 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
|
3518 | 3518 | assert_response :success |
|
3519 | 3519 | assert_template 'bulk_edit' |
|
3520 | 3520 | assert_equal Project.find(1).shared_versions.open.to_a.sort, assigns(:versions).sort |
|
3521 | 3521 | |
|
3522 | 3522 | assert_select 'select[name=?]', 'issue[fixed_version_id]' do |
|
3523 | 3523 | assert_select 'option', :text => '2.0' |
|
3524 | 3524 | end |
|
3525 | 3525 | end |
|
3526 | 3526 | |
|
3527 | 3527 | def test_bulk_edit_should_propose_target_project_categories |
|
3528 | 3528 | @request.session[:user_id] = 2 |
|
3529 | 3529 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
|
3530 | 3530 | assert_response :success |
|
3531 | 3531 | assert_template 'bulk_edit' |
|
3532 | 3532 | assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort |
|
3533 | 3533 | |
|
3534 | 3534 | assert_select 'select[name=?]', 'issue[category_id]' do |
|
3535 | 3535 | assert_select 'option', :text => 'Recipes' |
|
3536 | 3536 | end |
|
3537 | 3537 | end |
|
3538 | 3538 | |
|
3539 | 3539 | def test_bulk_update |
|
3540 | 3540 | @request.session[:user_id] = 2 |
|
3541 | 3541 | # update issues priority |
|
3542 | 3542 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
3543 | 3543 | :issue => {:priority_id => 7, |
|
3544 | 3544 | :assigned_to_id => '', |
|
3545 | 3545 | :custom_field_values => {'2' => ''}} |
|
3546 | 3546 | |
|
3547 | 3547 | assert_response 302 |
|
3548 | 3548 | # check that the issues were updated |
|
3549 | 3549 | assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id} |
|
3550 | 3550 | |
|
3551 | 3551 | issue = Issue.find(1) |
|
3552 | 3552 | journal = issue.journals.reorder('created_on DESC').first |
|
3553 | 3553 | assert_equal '125', issue.custom_value_for(2).value |
|
3554 | 3554 | assert_equal 'Bulk editing', journal.notes |
|
3555 | 3555 | assert_equal 1, journal.details.size |
|
3556 | 3556 | end |
|
3557 | 3557 | |
|
3558 | 3558 | def test_bulk_update_with_group_assignee |
|
3559 | 3559 | group = Group.find(11) |
|
3560 | 3560 | project = Project.find(1) |
|
3561 | 3561 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) |
|
3562 | 3562 | |
|
3563 | 3563 | @request.session[:user_id] = 2 |
|
3564 | 3564 | # update issues assignee |
|
3565 | 3565 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
3566 | 3566 | :issue => {:priority_id => '', |
|
3567 | 3567 | :assigned_to_id => group.id, |
|
3568 | 3568 | :custom_field_values => {'2' => ''}} |
|
3569 | 3569 | |
|
3570 | 3570 | assert_response 302 |
|
3571 | 3571 | assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to} |
|
3572 | 3572 | end |
|
3573 | 3573 | |
|
3574 | 3574 | def test_bulk_update_on_different_projects |
|
3575 | 3575 | @request.session[:user_id] = 2 |
|
3576 | 3576 | # update issues priority |
|
3577 | 3577 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', |
|
3578 | 3578 | :issue => {:priority_id => 7, |
|
3579 | 3579 | :assigned_to_id => '', |
|
3580 | 3580 | :custom_field_values => {'2' => ''}} |
|
3581 | 3581 | |
|
3582 | 3582 | assert_response 302 |
|
3583 | 3583 | # check that the issues were updated |
|
3584 | 3584 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) |
|
3585 | 3585 | |
|
3586 | 3586 | issue = Issue.find(1) |
|
3587 | 3587 | journal = issue.journals.reorder('created_on DESC').first |
|
3588 | 3588 | assert_equal '125', issue.custom_value_for(2).value |
|
3589 | 3589 | assert_equal 'Bulk editing', journal.notes |
|
3590 | 3590 | assert_equal 1, journal.details.size |
|
3591 | 3591 | end |
|
3592 | 3592 | |
|
3593 | 3593 | def test_bulk_update_on_different_projects_without_rights |
|
3594 | 3594 | @request.session[:user_id] = 3 |
|
3595 | 3595 | user = User.find(3) |
|
3596 | 3596 | action = { :controller => "issues", :action => "bulk_update" } |
|
3597 | 3597 | assert user.allowed_to?(action, Issue.find(1).project) |
|
3598 | 3598 | assert ! user.allowed_to?(action, Issue.find(6).project) |
|
3599 | 3599 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', |
|
3600 | 3600 | :issue => {:priority_id => 7, |
|
3601 | 3601 | :assigned_to_id => '', |
|
3602 | 3602 | :custom_field_values => {'2' => ''}} |
|
3603 | 3603 | assert_response 403 |
|
3604 | 3604 | assert_not_equal "Bulk should fail", Journal.last.notes |
|
3605 | 3605 | end |
|
3606 | 3606 | |
|
3607 | 3607 | def test_bullk_update_should_send_a_notification |
|
3608 | 3608 | @request.session[:user_id] = 2 |
|
3609 | 3609 | ActionMailer::Base.deliveries.clear |
|
3610 | 3610 | with_settings :notified_events => %w(issue_updated) do |
|
3611 | 3611 | post(:bulk_update, |
|
3612 | 3612 | { |
|
3613 | 3613 | :ids => [1, 2], |
|
3614 | 3614 | :notes => 'Bulk editing', |
|
3615 | 3615 | :issue => { |
|
3616 | 3616 | :priority_id => 7, |
|
3617 | 3617 | :assigned_to_id => '', |
|
3618 | 3618 | :custom_field_values => {'2' => ''} |
|
3619 | 3619 | } |
|
3620 | 3620 | }) |
|
3621 | 3621 | assert_response 302 |
|
3622 | 3622 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
3623 | 3623 | end |
|
3624 | 3624 | end |
|
3625 | 3625 | |
|
3626 | 3626 | def test_bulk_update_project |
|
3627 | 3627 | @request.session[:user_id] = 2 |
|
3628 | 3628 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'} |
|
3629 | 3629 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3630 | 3630 | # Issues moved to project 2 |
|
3631 | 3631 | assert_equal 2, Issue.find(1).project_id |
|
3632 | 3632 | assert_equal 2, Issue.find(2).project_id |
|
3633 | 3633 | # No tracker change |
|
3634 | 3634 | assert_equal 1, Issue.find(1).tracker_id |
|
3635 | 3635 | assert_equal 2, Issue.find(2).tracker_id |
|
3636 | 3636 | end |
|
3637 | 3637 | |
|
3638 | 3638 | def test_bulk_update_project_on_single_issue_should_follow_when_needed |
|
3639 | 3639 | @request.session[:user_id] = 2 |
|
3640 | 3640 | post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1' |
|
3641 | 3641 | assert_redirected_to '/issues/1' |
|
3642 | 3642 | end |
|
3643 | 3643 | |
|
3644 | 3644 | def test_bulk_update_project_on_multiple_issues_should_follow_when_needed |
|
3645 | 3645 | @request.session[:user_id] = 2 |
|
3646 | 3646 | post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1' |
|
3647 | 3647 | assert_redirected_to '/projects/onlinestore/issues' |
|
3648 | 3648 | end |
|
3649 | 3649 | |
|
3650 | 3650 | def test_bulk_update_tracker |
|
3651 | 3651 | @request.session[:user_id] = 2 |
|
3652 | 3652 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'} |
|
3653 | 3653 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3654 | 3654 | assert_equal 2, Issue.find(1).tracker_id |
|
3655 | 3655 | assert_equal 2, Issue.find(2).tracker_id |
|
3656 | 3656 | end |
|
3657 | 3657 | |
|
3658 | 3658 | def test_bulk_update_status |
|
3659 | 3659 | @request.session[:user_id] = 2 |
|
3660 | 3660 | # update issues priority |
|
3661 | 3661 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', |
|
3662 | 3662 | :issue => {:priority_id => '', |
|
3663 | 3663 | :assigned_to_id => '', |
|
3664 | 3664 | :status_id => '5'} |
|
3665 | 3665 | |
|
3666 | 3666 | assert_response 302 |
|
3667 | 3667 | issue = Issue.find(1) |
|
3668 | 3668 | assert issue.closed? |
|
3669 | 3669 | end |
|
3670 | 3670 | |
|
3671 | 3671 | def test_bulk_update_priority |
|
3672 | 3672 | @request.session[:user_id] = 2 |
|
3673 | 3673 | post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} |
|
3674 | 3674 | |
|
3675 | 3675 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3676 | 3676 | assert_equal 6, Issue.find(1).priority_id |
|
3677 | 3677 | assert_equal 6, Issue.find(2).priority_id |
|
3678 | 3678 | end |
|
3679 | 3679 | |
|
3680 | 3680 | def test_bulk_update_with_notes |
|
3681 | 3681 | @request.session[:user_id] = 2 |
|
3682 | 3682 | post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues' |
|
3683 | 3683 | |
|
3684 | 3684 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3685 | 3685 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes |
|
3686 | 3686 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes |
|
3687 | 3687 | end |
|
3688 | 3688 | |
|
3689 | 3689 | def test_bulk_update_parent_id |
|
3690 | 3690 | IssueRelation.delete_all |
|
3691 | 3691 | @request.session[:user_id] = 2 |
|
3692 | 3692 | post :bulk_update, :ids => [1, 3], |
|
3693 | 3693 | :notes => 'Bulk editing parent', |
|
3694 | 3694 | :issue => {:priority_id => '', :assigned_to_id => '', |
|
3695 | 3695 | :status_id => '', :parent_issue_id => '2'} |
|
3696 | 3696 | assert_response 302 |
|
3697 | 3697 | parent = Issue.find(2) |
|
3698 | 3698 | assert_equal parent.id, Issue.find(1).parent_id |
|
3699 | 3699 | assert_equal parent.id, Issue.find(3).parent_id |
|
3700 | 3700 | assert_equal [1, 3], parent.children.collect(&:id).sort |
|
3701 | 3701 | end |
|
3702 | 3702 | |
|
3703 | 3703 | def test_bulk_update_custom_field |
|
3704 | 3704 | @request.session[:user_id] = 2 |
|
3705 | 3705 | # update issues priority |
|
3706 | 3706 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', |
|
3707 | 3707 | :issue => {:priority_id => '', |
|
3708 | 3708 | :assigned_to_id => '', |
|
3709 | 3709 | :custom_field_values => {'2' => '777'}} |
|
3710 | 3710 | |
|
3711 | 3711 | assert_response 302 |
|
3712 | 3712 | |
|
3713 | 3713 | issue = Issue.find(1) |
|
3714 | 3714 | journal = issue.journals.reorder('created_on DESC').first |
|
3715 | 3715 | assert_equal '777', issue.custom_value_for(2).value |
|
3716 | 3716 | assert_equal 1, journal.details.size |
|
3717 | 3717 | assert_equal '125', journal.details.first.old_value |
|
3718 | 3718 | assert_equal '777', journal.details.first.value |
|
3719 | 3719 | end |
|
3720 | 3720 | |
|
3721 | 3721 | def test_bulk_update_custom_field_to_blank |
|
3722 | 3722 | @request.session[:user_id] = 2 |
|
3723 | 3723 | post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field', |
|
3724 | 3724 | :issue => {:priority_id => '', |
|
3725 | 3725 | :assigned_to_id => '', |
|
3726 | 3726 | :custom_field_values => {'1' => '__none__'}} |
|
3727 | 3727 | assert_response 302 |
|
3728 | 3728 | assert_equal '', Issue.find(1).custom_field_value(1) |
|
3729 | 3729 | assert_equal '', Issue.find(3).custom_field_value(1) |
|
3730 | 3730 | end |
|
3731 | 3731 | |
|
3732 | 3732 | def test_bulk_update_multi_custom_field |
|
3733 | 3733 | field = CustomField.find(1) |
|
3734 | 3734 | field.update_attribute :multiple, true |
|
3735 | 3735 | |
|
3736 | 3736 | @request.session[:user_id] = 2 |
|
3737 | 3737 | post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field', |
|
3738 | 3738 | :issue => {:priority_id => '', |
|
3739 | 3739 | :assigned_to_id => '', |
|
3740 | 3740 | :custom_field_values => {'1' => ['MySQL', 'Oracle']}} |
|
3741 | 3741 | |
|
3742 | 3742 | assert_response 302 |
|
3743 | 3743 | |
|
3744 | 3744 | assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort |
|
3745 | 3745 | assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort |
|
3746 | 3746 | # the custom field is not associated with the issue tracker |
|
3747 | 3747 | assert_nil Issue.find(2).custom_field_value(1) |
|
3748 | 3748 | end |
|
3749 | 3749 | |
|
3750 | 3750 | def test_bulk_update_multi_custom_field_to_blank |
|
3751 | 3751 | field = CustomField.find(1) |
|
3752 | 3752 | field.update_attribute :multiple, true |
|
3753 | 3753 | |
|
3754 | 3754 | @request.session[:user_id] = 2 |
|
3755 | 3755 | post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field', |
|
3756 | 3756 | :issue => {:priority_id => '', |
|
3757 | 3757 | :assigned_to_id => '', |
|
3758 | 3758 | :custom_field_values => {'1' => ['__none__']}} |
|
3759 | 3759 | assert_response 302 |
|
3760 | 3760 | assert_equal [''], Issue.find(1).custom_field_value(1) |
|
3761 | 3761 | assert_equal [''], Issue.find(3).custom_field_value(1) |
|
3762 | 3762 | end |
|
3763 | 3763 | |
|
3764 | 3764 | def test_bulk_update_unassign |
|
3765 | 3765 | assert_not_nil Issue.find(2).assigned_to |
|
3766 | 3766 | @request.session[:user_id] = 2 |
|
3767 | 3767 | # unassign issues |
|
3768 | 3768 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
|
3769 | 3769 | assert_response 302 |
|
3770 | 3770 | # check that the issues were updated |
|
3771 | 3771 | assert_nil Issue.find(2).assigned_to |
|
3772 | 3772 | end |
|
3773 | 3773 | |
|
3774 | 3774 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
3775 | 3775 | @request.session[:user_id] = 2 |
|
3776 | 3776 | |
|
3777 | 3777 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} |
|
3778 | 3778 | |
|
3779 | 3779 | assert_response :redirect |
|
3780 | 3780 | issues = Issue.find([1,2]) |
|
3781 | 3781 | issues.each do |issue| |
|
3782 | 3782 | assert_equal 4, issue.fixed_version_id |
|
3783 | 3783 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
3784 | 3784 | end |
|
3785 | 3785 | end |
|
3786 | 3786 | |
|
3787 | 3787 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
3788 | 3788 | @request.session[:user_id] = 2 |
|
3789 | 3789 | post :bulk_update, :ids => [1,2], :back_url => '/issues' |
|
3790 | 3790 | |
|
3791 | 3791 | assert_response :redirect |
|
3792 | 3792 | assert_redirected_to '/issues' |
|
3793 | 3793 | end |
|
3794 | 3794 | |
|
3795 | 3795 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
3796 | 3796 | @request.session[:user_id] = 2 |
|
3797 | 3797 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
3798 | 3798 | |
|
3799 | 3799 | assert_response :redirect |
|
3800 | 3800 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
|
3801 | 3801 | end |
|
3802 | 3802 | |
|
3803 | 3803 | def test_bulk_update_with_all_failures_should_show_errors |
|
3804 | 3804 | @request.session[:user_id] = 2 |
|
3805 | 3805 | post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'} |
|
3806 | 3806 | |
|
3807 | 3807 | assert_response :success |
|
3808 | 3808 | assert_template 'bulk_edit' |
|
3809 | 3809 | assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.' |
|
3810 | 3810 | assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2' |
|
3811 | 3811 | |
|
3812 | 3812 | assert_equal [1, 2], assigns[:issues].map(&:id) |
|
3813 | 3813 | end |
|
3814 | 3814 | |
|
3815 | 3815 | def test_bulk_update_with_some_failures_should_show_errors |
|
3816 | 3816 | issue1 = Issue.generate!(:start_date => '2013-05-12') |
|
3817 | 3817 | issue2 = Issue.generate!(:start_date => '2013-05-15') |
|
3818 | 3818 | issue3 = Issue.generate! |
|
3819 | 3819 | @request.session[:user_id] = 2 |
|
3820 | 3820 | post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id], |
|
3821 | 3821 | :issue => {:due_date => '2013-05-01'} |
|
3822 | 3822 | assert_response :success |
|
3823 | 3823 | assert_template 'bulk_edit' |
|
3824 | 3824 | assert_select '#errorExplanation span', |
|
3825 | 3825 | :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}." |
|
3826 | 3826 | assert_select '#errorExplanation ul li', |
|
3827 | 3827 | :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}" |
|
3828 | 3828 | assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id) |
|
3829 | 3829 | end |
|
3830 | 3830 | |
|
3831 | 3831 | def test_bulk_update_with_failure_should_preserved_form_values |
|
3832 | 3832 | @request.session[:user_id] = 2 |
|
3833 | 3833 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'} |
|
3834 | 3834 | |
|
3835 | 3835 | assert_response :success |
|
3836 | 3836 | assert_template 'bulk_edit' |
|
3837 | 3837 | assert_select 'select[name=?]', 'issue[tracker_id]' do |
|
3838 | 3838 | assert_select 'option[value="2"][selected=selected]' |
|
3839 | 3839 | end |
|
3840 | 3840 | assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo' |
|
3841 | 3841 | end |
|
3842 | 3842 | |
|
3843 | 3843 | def test_get_bulk_copy |
|
3844 | 3844 | @request.session[:user_id] = 2 |
|
3845 | 3845 | get :bulk_edit, :ids => [1, 2, 3], :copy => '1' |
|
3846 | 3846 | assert_response :success |
|
3847 | 3847 | assert_template 'bulk_edit' |
|
3848 | 3848 | |
|
3849 | 3849 | issues = assigns(:issues) |
|
3850 | 3850 | assert_not_nil issues |
|
3851 | 3851 | assert_equal [1, 2, 3], issues.map(&:id).sort |
|
3852 | 3852 | |
|
3853 | 3853 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
3854 | 3854 | assert_select 'option[value=""]' |
|
3855 | 3855 | end |
|
3856 | 3856 | assert_select 'input[name=copy_attachments]' |
|
3857 | 3857 | end |
|
3858 | 3858 | |
|
3859 | 3859 | def test_get_bulk_copy_without_add_issues_permission_should_not_propose_current_project_as_target |
|
3860 | 3860 | user = setup_user_with_copy_but_not_add_permission |
|
3861 | 3861 | @request.session[:user_id] = user.id |
|
3862 | 3862 | |
|
3863 | 3863 | get :bulk_edit, :ids => [1, 2, 3], :copy => '1' |
|
3864 | 3864 | assert_response :success |
|
3865 | 3865 | assert_template 'bulk_edit' |
|
3866 | 3866 | |
|
3867 | 3867 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
3868 | 3868 | assert_select 'option[value=""]', 0 |
|
3869 | 3869 | assert_select 'option[value="2"]' |
|
3870 | 3870 | end |
|
3871 | 3871 | end |
|
3872 | 3872 | |
|
3873 | 3873 | def test_bulk_copy_to_another_project |
|
3874 | 3874 | @request.session[:user_id] = 2 |
|
3875 | 3875 | assert_difference 'Issue.count', 2 do |
|
3876 | 3876 | assert_no_difference 'Project.find(1).issues.count' do |
|
3877 | 3877 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' |
|
3878 | 3878 | end |
|
3879 | 3879 | end |
|
3880 | 3880 | assert_redirected_to '/projects/ecookbook/issues' |
|
3881 | 3881 | |
|
3882 | 3882 | copies = Issue.order('id DESC').limit(issues.size) |
|
3883 | 3883 | copies.each do |copy| |
|
3884 | 3884 | assert_equal 2, copy.project_id |
|
3885 | 3885 | end |
|
3886 | 3886 | end |
|
3887 | 3887 | |
|
3888 | 3888 | def test_bulk_copy_without_add_issues_permission_should_be_allowed_on_project_with_permission |
|
3889 | 3889 | user = setup_user_with_copy_but_not_add_permission |
|
3890 | 3890 | @request.session[:user_id] = user.id |
|
3891 | 3891 | |
|
3892 | 3892 | assert_difference 'Issue.count', 3 do |
|
3893 | 3893 | post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '2'}, :copy => '1' |
|
3894 | 3894 | assert_response 302 |
|
3895 | 3895 | end |
|
3896 | 3896 | end |
|
3897 | 3897 | |
|
3898 | 3898 | def test_bulk_copy_on_same_project_without_add_issues_permission_should_be_denied |
|
3899 | 3899 | user = setup_user_with_copy_but_not_add_permission |
|
3900 | 3900 | @request.session[:user_id] = user.id |
|
3901 | 3901 | |
|
3902 | 3902 | post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => ''}, :copy => '1' |
|
3903 | 3903 | assert_response 403 |
|
3904 | 3904 | end |
|
3905 | 3905 | |
|
3906 | 3906 | def test_bulk_copy_on_different_project_without_add_issues_permission_should_be_denied |
|
3907 | 3907 | user = setup_user_with_copy_but_not_add_permission |
|
3908 | 3908 | @request.session[:user_id] = user.id |
|
3909 | 3909 | |
|
3910 | 3910 | post :bulk_update, :ids => [1, 2, 3], :issue => {:project_id => '1'}, :copy => '1' |
|
3911 | 3911 | assert_response 403 |
|
3912 | 3912 | end |
|
3913 | 3913 | |
|
3914 | 3914 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes |
|
3915 | 3915 | @request.session[:user_id] = 2 |
|
3916 | 3916 | issues = [ |
|
3917 | 3917 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, |
|
3918 | 3918 | :priority_id => 2, :subject => 'issue 1', :author_id => 1, |
|
3919 | 3919 | :assigned_to_id => nil), |
|
3920 | 3920 | Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, |
|
3921 | 3921 | :priority_id => 1, :subject => 'issue 2', :author_id => 2, |
|
3922 | 3922 | :assigned_to_id => 3) |
|
3923 | 3923 | ] |
|
3924 | 3924 | assert_difference 'Issue.count', issues.size do |
|
3925 | 3925 | post :bulk_update, :ids => issues.map(&:id), :copy => '1', |
|
3926 | 3926 | :issue => { |
|
3927 | 3927 | :project_id => '', :tracker_id => '', :assigned_to_id => '', |
|
3928 | 3928 | :status_id => '', :start_date => '', :due_date => '' |
|
3929 | 3929 | } |
|
3930 | 3930 | end |
|
3931 | 3931 | |
|
3932 | 3932 | copies = Issue.order('id DESC').limit(issues.size) |
|
3933 | 3933 | issues.each do |orig| |
|
3934 | 3934 | copy = copies.detect {|c| c.subject == orig.subject} |
|
3935 | 3935 | assert_not_nil copy |
|
3936 | 3936 | assert_equal orig.project_id, copy.project_id |
|
3937 | 3937 | assert_equal orig.tracker_id, copy.tracker_id |
|
3938 | 3938 | assert_equal orig.status_id, copy.status_id |
|
3939 | 3939 | assert_equal orig.assigned_to_id, copy.assigned_to_id |
|
3940 | 3940 | assert_equal orig.priority_id, copy.priority_id |
|
3941 | 3941 | end |
|
3942 | 3942 | end |
|
3943 | 3943 | |
|
3944 | 3944 | def test_bulk_copy_should_allow_changing_the_issue_attributes |
|
3945 | 3945 | # Fixes random test failure with Mysql |
|
3946 | 3946 | # where Issue.where(:project_id => 2).limit(2).order('id desc') |
|
3947 | 3947 | # doesn't return the expected results |
|
3948 | 3948 | Issue.delete_all("project_id=2") |
|
3949 | 3949 | |
|
3950 | 3950 | @request.session[:user_id] = 2 |
|
3951 | 3951 | assert_difference 'Issue.count', 2 do |
|
3952 | 3952 | assert_no_difference 'Project.find(1).issues.count' do |
|
3953 | 3953 | post :bulk_update, :ids => [1, 2], :copy => '1', |
|
3954 | 3954 | :issue => { |
|
3955 | 3955 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', |
|
3956 | 3956 | :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
3957 | 3957 | } |
|
3958 | 3958 | end |
|
3959 | 3959 | end |
|
3960 | 3960 | |
|
3961 | 3961 | copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a |
|
3962 | 3962 | assert_equal 2, copied_issues.size |
|
3963 | 3963 | copied_issues.each do |issue| |
|
3964 | 3964 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
3965 | 3965 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
3966 | 3966 | assert_equal 1, issue.status_id, "Status is incorrect" |
|
3967 | 3967 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
3968 | 3968 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
3969 | 3969 | end |
|
3970 | 3970 | end |
|
3971 | 3971 | |
|
3972 | 3972 | def test_bulk_copy_should_allow_adding_a_note |
|
3973 | 3973 | @request.session[:user_id] = 2 |
|
3974 | 3974 | assert_difference 'Issue.count', 1 do |
|
3975 | 3975 | post :bulk_update, :ids => [1], :copy => '1', |
|
3976 | 3976 | :notes => 'Copying one issue', |
|
3977 | 3977 | :issue => { |
|
3978 | 3978 | :project_id => '', :tracker_id => '', :assigned_to_id => '4', |
|
3979 | 3979 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
3980 | 3980 | } |
|
3981 | 3981 | end |
|
3982 | 3982 | issue = Issue.order('id DESC').first |
|
3983 | 3983 | assert_equal 1, issue.journals.size |
|
3984 | 3984 | journal = issue.journals.first |
|
3985 | 3985 | assert_equal 'Copying one issue', journal.notes |
|
3986 | 3986 | end |
|
3987 | 3987 | |
|
3988 | 3988 | def test_bulk_copy_should_allow_not_copying_the_attachments |
|
3989 | 3989 | attachment_count = Issue.find(3).attachments.size |
|
3990 | 3990 | assert attachment_count > 0 |
|
3991 | 3991 | @request.session[:user_id] = 2 |
|
3992 | 3992 | |
|
3993 | 3993 | assert_difference 'Issue.count', 1 do |
|
3994 | 3994 | assert_no_difference 'Attachment.count' do |
|
3995 | 3995 | post :bulk_update, :ids => [3], :copy => '1', |
|
3996 | 3996 | :issue => { |
|
3997 | 3997 | :project_id => '' |
|
3998 | 3998 | } |
|
3999 | 3999 | end |
|
4000 | 4000 | end |
|
4001 | 4001 | end |
|
4002 | 4002 | |
|
4003 | 4003 | def test_bulk_copy_should_allow_copying_the_attachments |
|
4004 | 4004 | attachment_count = Issue.find(3).attachments.size |
|
4005 | 4005 | assert attachment_count > 0 |
|
4006 | 4006 | @request.session[:user_id] = 2 |
|
4007 | 4007 | |
|
4008 | 4008 | assert_difference 'Issue.count', 1 do |
|
4009 | 4009 | assert_difference 'Attachment.count', attachment_count do |
|
4010 | 4010 | post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1', |
|
4011 | 4011 | :issue => { |
|
4012 | 4012 | :project_id => '' |
|
4013 | 4013 | } |
|
4014 | 4014 | end |
|
4015 | 4015 | end |
|
4016 | 4016 | end |
|
4017 | 4017 | |
|
4018 | 4018 | def test_bulk_copy_should_add_relations_with_copied_issues |
|
4019 | 4019 | @request.session[:user_id] = 2 |
|
4020 | 4020 | |
|
4021 | 4021 | assert_difference 'Issue.count', 2 do |
|
4022 | 4022 | assert_difference 'IssueRelation.count', 2 do |
|
4023 | 4023 | post :bulk_update, :ids => [1, 3], :copy => '1', :link_copy => '1', |
|
4024 | 4024 | :issue => { |
|
4025 | 4025 | :project_id => '1' |
|
4026 | 4026 | } |
|
4027 | 4027 | end |
|
4028 | 4028 | end |
|
4029 | 4029 | end |
|
4030 | 4030 | |
|
4031 | 4031 | def test_bulk_copy_should_allow_not_copying_the_subtasks |
|
4032 | 4032 | issue = Issue.generate_with_descendants! |
|
4033 | 4033 | @request.session[:user_id] = 2 |
|
4034 | 4034 | |
|
4035 | 4035 | assert_difference 'Issue.count', 1 do |
|
4036 | 4036 | post :bulk_update, :ids => [issue.id], :copy => '1', |
|
4037 | 4037 | :issue => { |
|
4038 | 4038 | :project_id => '' |
|
4039 | 4039 | } |
|
4040 | 4040 | end |
|
4041 | 4041 | end |
|
4042 | 4042 | |
|
4043 | 4043 | def test_bulk_copy_should_allow_copying_the_subtasks |
|
4044 | 4044 | issue = Issue.generate_with_descendants! |
|
4045 | 4045 | count = issue.descendants.count |
|
4046 | 4046 | @request.session[:user_id] = 2 |
|
4047 | 4047 | |
|
4048 | 4048 | assert_difference 'Issue.count', count+1 do |
|
4049 | 4049 | post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1', |
|
4050 | 4050 | :issue => { |
|
4051 | 4051 | :project_id => '' |
|
4052 | 4052 | } |
|
4053 | 4053 | end |
|
4054 | 4054 | copy = Issue.where(:parent_id => nil).order("id DESC").first |
|
4055 | 4055 | assert_equal count, copy.descendants.count |
|
4056 | 4056 | end |
|
4057 | 4057 | |
|
4058 | 4058 | def test_bulk_copy_should_not_copy_selected_subtasks_twice |
|
4059 | 4059 | issue = Issue.generate_with_descendants! |
|
4060 | 4060 | count = issue.descendants.count |
|
4061 | 4061 | @request.session[:user_id] = 2 |
|
4062 | 4062 | |
|
4063 | 4063 | assert_difference 'Issue.count', count+1 do |
|
4064 | 4064 | post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1', |
|
4065 | 4065 | :issue => { |
|
4066 | 4066 | :project_id => '' |
|
4067 | 4067 | } |
|
4068 | 4068 | end |
|
4069 | 4069 | copy = Issue.where(:parent_id => nil).order("id DESC").first |
|
4070 | 4070 | assert_equal count, copy.descendants.count |
|
4071 | 4071 | end |
|
4072 | 4072 | |
|
4073 | 4073 | def test_bulk_copy_to_another_project_should_follow_when_needed |
|
4074 | 4074 | @request.session[:user_id] = 2 |
|
4075 | 4075 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' |
|
4076 | 4076 | issue = Issue.order('id DESC').first |
|
4077 | 4077 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
4078 | 4078 | end |
|
4079 | 4079 | |
|
4080 | 4080 | def test_bulk_copy_with_all_failures_should_display_errors |
|
4081 | 4081 | @request.session[:user_id] = 2 |
|
4082 | 4082 | post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'} |
|
4083 | 4083 | |
|
4084 | 4084 | assert_response :success |
|
4085 | 4085 | end |
|
4086 | 4086 | |
|
4087 | 4087 | def test_destroy_issue_with_no_time_entries |
|
4088 | 4088 | assert_nil TimeEntry.find_by_issue_id(2) |
|
4089 | 4089 | @request.session[:user_id] = 2 |
|
4090 | 4090 | |
|
4091 | 4091 | assert_difference 'Issue.count', -1 do |
|
4092 | 4092 | delete :destroy, :id => 2 |
|
4093 | 4093 | end |
|
4094 | 4094 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
4095 | 4095 | assert_nil Issue.find_by_id(2) |
|
4096 | 4096 | end |
|
4097 | 4097 | |
|
4098 | 4098 | def test_destroy_issues_with_time_entries |
|
4099 | 4099 | @request.session[:user_id] = 2 |
|
4100 | 4100 | |
|
4101 | 4101 | assert_no_difference 'Issue.count' do |
|
4102 | 4102 | delete :destroy, :ids => [1, 3] |
|
4103 | 4103 | end |
|
4104 | 4104 | assert_response :success |
|
4105 | 4105 | assert_template 'destroy' |
|
4106 | 4106 | assert_not_nil assigns(:hours) |
|
4107 | 4107 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
4108 | 4108 | |
|
4109 | 4109 | assert_select 'form' do |
|
4110 | 4110 | assert_select 'input[name=_method][value=delete]' |
|
4111 | 4111 | end |
|
4112 | 4112 | end |
|
4113 | 4113 | |
|
4114 | 4114 | def test_destroy_issues_and_destroy_time_entries |
|
4115 | 4115 | @request.session[:user_id] = 2 |
|
4116 | 4116 | |
|
4117 | 4117 | assert_difference 'Issue.count', -2 do |
|
4118 | 4118 | assert_difference 'TimeEntry.count', -3 do |
|
4119 | 4119 | delete :destroy, :ids => [1, 3], :todo => 'destroy' |
|
4120 | 4120 | end |
|
4121 | 4121 | end |
|
4122 | 4122 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
4123 | 4123 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
4124 | 4124 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
4125 | 4125 | end |
|
4126 | 4126 | |
|
4127 | 4127 | def test_destroy_issues_and_assign_time_entries_to_project |
|
4128 | 4128 | @request.session[:user_id] = 2 |
|
4129 | 4129 | |
|
4130 | 4130 | assert_difference 'Issue.count', -2 do |
|
4131 | 4131 | assert_no_difference 'TimeEntry.count' do |
|
4132 | 4132 | delete :destroy, :ids => [1, 3], :todo => 'nullify' |
|
4133 | 4133 | end |
|
4134 | 4134 | end |
|
4135 | 4135 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
4136 | 4136 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
4137 | 4137 | assert_nil TimeEntry.find(1).issue_id |
|
4138 | 4138 | assert_nil TimeEntry.find(2).issue_id |
|
4139 | 4139 | end |
|
4140 | 4140 | |
|
4141 | 4141 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
4142 | 4142 | @request.session[:user_id] = 2 |
|
4143 | 4143 | |
|
4144 | 4144 | assert_difference 'Issue.count', -2 do |
|
4145 | 4145 | assert_no_difference 'TimeEntry.count' do |
|
4146 | 4146 | delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
4147 | 4147 | end |
|
4148 | 4148 | end |
|
4149 | 4149 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
4150 | 4150 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
4151 | 4151 | assert_equal 2, TimeEntry.find(1).issue_id |
|
4152 | 4152 | assert_equal 2, TimeEntry.find(2).issue_id |
|
4153 | 4153 | end |
|
4154 | 4154 | |
|
4155 | 4155 | def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail |
|
4156 | 4156 | @request.session[:user_id] = 2 |
|
4157 | 4157 | |
|
4158 | 4158 | assert_no_difference 'Issue.count' do |
|
4159 | 4159 | assert_no_difference 'TimeEntry.count' do |
|
4160 | 4160 | # try to reassign time to an issue of another project |
|
4161 | 4161 | delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 4 |
|
4162 | 4162 | end |
|
4163 | 4163 | end |
|
4164 | 4164 | assert_response :success |
|
4165 | 4165 | assert_template 'destroy' |
|
4166 | 4166 | end |
|
4167 | 4167 | |
|
4168 | 4168 | def test_destroy_issues_from_different_projects |
|
4169 | 4169 | @request.session[:user_id] = 2 |
|
4170 | 4170 | |
|
4171 | 4171 | assert_difference 'Issue.count', -3 do |
|
4172 | 4172 | delete :destroy, :ids => [1, 2, 6], :todo => 'destroy' |
|
4173 | 4173 | end |
|
4174 | 4174 | assert_redirected_to :controller => 'issues', :action => 'index' |
|
4175 | 4175 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) |
|
4176 | 4176 | end |
|
4177 | 4177 | |
|
4178 | 4178 | def test_destroy_parent_and_child_issues |
|
4179 | 4179 | parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue') |
|
4180 | 4180 | child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id) |
|
4181 | 4181 | assert child.is_descendant_of?(parent.reload) |
|
4182 | 4182 | |
|
4183 | 4183 | @request.session[:user_id] = 2 |
|
4184 | 4184 | assert_difference 'Issue.count', -2 do |
|
4185 | 4185 | delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' |
|
4186 | 4186 | end |
|
4187 | 4187 | assert_response 302 |
|
4188 | 4188 | end |
|
4189 | 4189 | |
|
4190 | 4190 | def test_destroy_invalid_should_respond_with_404 |
|
4191 | 4191 | @request.session[:user_id] = 2 |
|
4192 | 4192 | assert_no_difference 'Issue.count' do |
|
4193 | 4193 | delete :destroy, :id => 999 |
|
4194 | 4194 | end |
|
4195 | 4195 | assert_response 404 |
|
4196 | 4196 | end |
|
4197 | 4197 | |
|
4198 | 4198 | def test_default_search_scope |
|
4199 | 4199 | get :index |
|
4200 | 4200 | |
|
4201 | 4201 | assert_select 'div#quick-search form' do |
|
4202 | 4202 | assert_select 'input[name=issues][value="1"][type=hidden]' |
|
4203 | 4203 | end |
|
4204 | 4204 | end |
|
4205 | 4205 | |
|
4206 | 4206 | def setup_user_with_copy_but_not_add_permission |
|
4207 | 4207 | Role.all.each {|r| r.remove_permission! :add_issues} |
|
4208 | 4208 | Role.find_by_name('Manager').add_permission! :add_issues |
|
4209 | 4209 | user = User.generate! |
|
4210 | 4210 | User.add_to_project(user, Project.find(1), Role.find_by_name('Developer')) |
|
4211 | 4211 | User.add_to_project(user, Project.find(2), Role.find_by_name('Manager')) |
|
4212 | 4212 | user |
|
4213 | 4213 | end |
|
4214 | 4214 | end |
@@ -1,94 +1,85 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class ProjectsHelperTest < ActionView::TestCase |
|
21 | 21 | include ApplicationHelper |
|
22 | 22 | include ProjectsHelper |
|
23 | 23 | include Redmine::I18n |
|
24 | 24 | include ERB::Util |
|
25 | 25 | include Rails.application.routes.url_helpers |
|
26 | 26 | |
|
27 | 27 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
28 | 28 | :enumerations, :users, :issue_categories, |
|
29 | 29 | :versions, |
|
30 | 30 | :projects_trackers, |
|
31 | 31 | :member_roles, |
|
32 | 32 | :members, |
|
33 | 33 | :groups_users, |
|
34 | 34 | :enabled_modules |
|
35 | 35 | |
|
36 | 36 | def setup |
|
37 | 37 | super |
|
38 | 38 | set_language_if_valid('en') |
|
39 | 39 | User.current = nil |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_link_to_version_within_project |
|
43 | 43 | @project = Project.find(2) |
|
44 | 44 | User.current = User.find(1) |
|
45 | 45 | assert_equal '<a title="07/01/2006" href="/versions/5">Alpha</a>', link_to_version(Version.find(5)) |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_link_to_version |
|
49 | 49 | User.current = User.find(1) |
|
50 | assert_equal '<a title="07/01/2006" href="/versions/5">Alpha</a>', link_to_version(Version.find(5)) | |
|
50 | assert_equal '<a title="07/01/2006" href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5)) | |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_link_to_version_without_effective_date |
|
54 | 54 | User.current = User.find(1) |
|
55 | 55 | version = Version.find(5) |
|
56 | 56 | version.effective_date = nil |
|
57 | assert_equal '<a href="/versions/5">Alpha</a>', link_to_version(version) | |
|
57 | assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(version) | |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def test_link_to_private_version |
|
61 | assert_equal 'Alpha', link_to_version(Version.find(5)) | |
|
61 | assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5)) | |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def test_link_to_version_invalid_version |
|
65 | 65 | assert_equal '', link_to_version(Object) |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_format_version_name_within_project |
|
69 | 69 | @project = Project.find(1) |
|
70 | 70 | assert_equal "0.1", format_version_name(Version.find(1)) |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def test_format_version_name |
|
74 | assert_equal "0.1", format_version_name(Version.find(1)) | |
|
75 | end | |
|
76 | ||
|
77 | def test_format_version_name_for_shared_version_within_project_should_not_display_project_name | |
|
78 | @project = Project.find(1) | |
|
79 | version = Version.find(1) | |
|
80 | version.sharing = 'system' | |
|
81 | assert_equal "0.1", format_version_name(version) | |
|
74 | assert_equal "eCookbook - 0.1", format_version_name(Version.find(1)) | |
|
82 | 75 | end |
|
83 | 76 | |
|
84 |
def test_format_version_name_for_s |
|
|
85 | version = Version.find(1) | |
|
86 | version.sharing = 'system' | |
|
87 | assert_equal "eCookbook - 0.1", format_version_name(version) | |
|
77 | def test_format_version_name_for_system_version | |
|
78 | assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7)) | |
|
88 | 79 | end |
|
89 | 80 | |
|
90 | 81 | def test_version_options_for_select_with_no_versions |
|
91 | 82 | assert_equal '', version_options_for_select([]) |
|
92 | 83 | assert_equal '', version_options_for_select([], Version.find(1)) |
|
93 | 84 | end |
|
94 | 85 | end |
General Comments 0
You need to be logged in to leave comments.
Login now