##// END OF EJS Templates
Fixed that float custom fields do not use CSV decimal separator (#10364)....
Jean-Philippe Lang -
r11211:af92686c62c3
parent child
Show More
@@ -1,413 +1,393
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2013 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 module IssuesHelper
21 21 include ApplicationHelper
22 22
23 23 def issue_list(issues, &block)
24 24 ancestors = []
25 25 issues.each do |issue|
26 26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
27 27 ancestors.pop
28 28 end
29 29 yield issue, ancestors.size
30 30 ancestors << issue unless issue.leaf?
31 31 end
32 32 end
33 33
34 34 # Renders a HTML/CSS tooltip
35 35 #
36 36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
37 37 # that contains this method wrapped in a span with the class of "tip"
38 38 #
39 39 # <div class="tooltip"><%= link_to_issue(issue) %>
40 40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
41 41 # </div>
42 42 #
43 43 def render_issue_tooltip(issue)
44 44 @cached_label_status ||= l(:field_status)
45 45 @cached_label_start_date ||= l(:field_start_date)
46 46 @cached_label_due_date ||= l(:field_due_date)
47 47 @cached_label_assigned_to ||= l(:field_assigned_to)
48 48 @cached_label_priority ||= l(:field_priority)
49 49 @cached_label_project ||= l(:field_project)
50 50
51 51 link_to_issue(issue) + "<br /><br />".html_safe +
52 52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
53 53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
54 54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
55 55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
56 56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
57 57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
58 58 end
59 59
60 60 def issue_heading(issue)
61 61 h("#{issue.tracker} ##{issue.id}")
62 62 end
63 63
64 64 def render_issue_subject_with_tree(issue)
65 65 s = ''
66 66 ancestors = issue.root? ? [] : issue.ancestors.visible.all
67 67 ancestors.each do |ancestor|
68 68 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
69 69 end
70 70 s << '<div>'
71 71 subject = h(issue.subject)
72 72 if issue.is_private?
73 73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
74 74 end
75 75 s << content_tag('h3', subject)
76 76 s << '</div>' * (ancestors.size + 1)
77 77 s.html_safe
78 78 end
79 79
80 80 def render_descendants_tree(issue)
81 81 s = '<form><table class="list issues">'
82 82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
83 83 css = "issue issue-#{child.id} hascontextmenu"
84 84 css << " idnt idnt-#{level}" if level > 0
85 85 s << content_tag('tr',
86 86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
87 87 content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
88 88 content_tag('td', h(child.status)) +
89 89 content_tag('td', link_to_user(child.assigned_to)) +
90 90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
91 91 :class => css)
92 92 end
93 93 s << '</table></form>'
94 94 s.html_safe
95 95 end
96 96
97 97 # Returns a link for adding a new subtask to the given issue
98 98 def link_to_new_subtask(issue)
99 99 attrs = {
100 100 :tracker_id => issue.tracker,
101 101 :parent_issue_id => issue
102 102 }
103 103 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
104 104 end
105 105
106 106 class IssueFieldsRows
107 107 include ActionView::Helpers::TagHelper
108 108
109 109 def initialize
110 110 @left = []
111 111 @right = []
112 112 end
113 113
114 114 def left(*args)
115 115 args.any? ? @left << cells(*args) : @left
116 116 end
117 117
118 118 def right(*args)
119 119 args.any? ? @right << cells(*args) : @right
120 120 end
121 121
122 122 def size
123 123 @left.size > @right.size ? @left.size : @right.size
124 124 end
125 125
126 126 def to_html
127 127 html = ''.html_safe
128 128 blank = content_tag('th', '') + content_tag('td', '')
129 129 size.times do |i|
130 130 left = @left[i] || blank
131 131 right = @right[i] || blank
132 132 html << content_tag('tr', left + right)
133 133 end
134 134 html
135 135 end
136 136
137 137 def cells(label, text, options={})
138 138 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
139 139 end
140 140 end
141 141
142 142 def issue_fields_rows
143 143 r = IssueFieldsRows.new
144 144 yield r
145 145 r.to_html
146 146 end
147 147
148 148 def render_custom_fields_rows(issue)
149 149 return if issue.custom_field_values.empty?
150 150 ordered_values = []
151 151 half = (issue.custom_field_values.size / 2.0).ceil
152 152 half.times do |i|
153 153 ordered_values << issue.custom_field_values[i]
154 154 ordered_values << issue.custom_field_values[i + half]
155 155 end
156 156 s = "<tr>\n"
157 157 n = 0
158 158 ordered_values.compact.each do |value|
159 159 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
160 160 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
161 161 n += 1
162 162 end
163 163 s << "</tr>\n"
164 164 s.html_safe
165 165 end
166 166
167 167 def issues_destroy_confirmation_message(issues)
168 168 issues = [issues] unless issues.is_a?(Array)
169 169 message = l(:text_issues_destroy_confirmation)
170 170 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
171 171 if descendant_count > 0
172 172 issues.each do |issue|
173 173 next if issue.root?
174 174 issues.each do |other_issue|
175 175 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
176 176 end
177 177 end
178 178 if descendant_count > 0
179 179 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
180 180 end
181 181 end
182 182 message
183 183 end
184 184
185 185 def sidebar_queries
186 186 unless @sidebar_queries
187 187 @sidebar_queries = IssueQuery.visible.all(
188 188 :order => "#{Query.table_name}.name ASC",
189 189 # Project specific queries and global queries
190 190 :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
191 191 )
192 192 end
193 193 @sidebar_queries
194 194 end
195 195
196 196 def query_links(title, queries)
197 197 # links to #index on issues/show
198 198 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
199 199
200 200 content_tag('h3', h(title)) +
201 201 queries.collect {|query|
202 202 css = 'query'
203 203 css << ' selected' if query == @query
204 204 link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
205 205 }.join('<br />').html_safe
206 206 end
207 207
208 208 def render_sidebar_queries
209 209 out = ''.html_safe
210 210 queries = sidebar_queries.select {|q| !q.is_public?}
211 211 out << query_links(l(:label_my_queries), queries) if queries.any?
212 212 queries = sidebar_queries.select {|q| q.is_public?}
213 213 out << query_links(l(:label_query_plural), queries) if queries.any?
214 214 out
215 215 end
216 216
217 217 # Returns the textual representation of a journal details
218 218 # as an array of strings
219 219 def details_to_strings(details, no_html=false, options={})
220 220 options[:only_path] = (options[:only_path] == false ? false : true)
221 221 strings = []
222 222 values_by_field = {}
223 223 details.each do |detail|
224 224 if detail.property == 'cf'
225 225 field_id = detail.prop_key
226 226 field = CustomField.find_by_id(field_id)
227 227 if field && field.multiple?
228 228 values_by_field[field_id] ||= {:added => [], :deleted => []}
229 229 if detail.old_value
230 230 values_by_field[field_id][:deleted] << detail.old_value
231 231 end
232 232 if detail.value
233 233 values_by_field[field_id][:added] << detail.value
234 234 end
235 235 next
236 236 end
237 237 end
238 238 strings << show_detail(detail, no_html, options)
239 239 end
240 240 values_by_field.each do |field_id, changes|
241 241 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
242 242 if changes[:added].any?
243 243 detail.value = changes[:added]
244 244 strings << show_detail(detail, no_html, options)
245 245 elsif changes[:deleted].any?
246 246 detail.old_value = changes[:deleted]
247 247 strings << show_detail(detail, no_html, options)
248 248 end
249 249 end
250 250 strings
251 251 end
252 252
253 253 # Returns the textual representation of a single journal detail
254 254 def show_detail(detail, no_html=false, options={})
255 255 multiple = false
256 256 case detail.property
257 257 when 'attr'
258 258 field = detail.prop_key.to_s.gsub(/\_id$/, "")
259 259 label = l(("field_" + field).to_sym)
260 260 case detail.prop_key
261 261 when 'due_date', 'start_date'
262 262 value = format_date(detail.value.to_date) if detail.value
263 263 old_value = format_date(detail.old_value.to_date) if detail.old_value
264 264
265 265 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
266 266 'priority_id', 'category_id', 'fixed_version_id'
267 267 value = find_name_by_reflection(field, detail.value)
268 268 old_value = find_name_by_reflection(field, detail.old_value)
269 269
270 270 when 'estimated_hours'
271 271 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
272 272 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
273 273
274 274 when 'parent_id'
275 275 label = l(:field_parent_issue)
276 276 value = "##{detail.value}" unless detail.value.blank?
277 277 old_value = "##{detail.old_value}" unless detail.old_value.blank?
278 278
279 279 when 'is_private'
280 280 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
281 281 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
282 282 end
283 283 when 'cf'
284 284 custom_field = CustomField.find_by_id(detail.prop_key)
285 285 if custom_field
286 286 multiple = custom_field.multiple?
287 287 label = custom_field.name
288 288 value = format_value(detail.value, custom_field.field_format) if detail.value
289 289 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
290 290 end
291 291 when 'attachment'
292 292 label = l(:label_attachment)
293 293 end
294 294 call_hook(:helper_issues_show_detail_after_setting,
295 295 {:detail => detail, :label => label, :value => value, :old_value => old_value })
296 296
297 297 label ||= detail.prop_key
298 298 value ||= detail.value
299 299 old_value ||= detail.old_value
300 300
301 301 unless no_html
302 302 label = content_tag('strong', label)
303 303 old_value = content_tag("i", h(old_value)) if detail.old_value
304 304 old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
305 305 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
306 306 # Link to the attachment if it has not been removed
307 307 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
308 308 if options[:only_path] != false && atta.is_text?
309 309 value += link_to(
310 310 image_tag('magnifier.png'),
311 311 :controller => 'attachments', :action => 'show',
312 312 :id => atta, :filename => atta.filename
313 313 )
314 314 end
315 315 else
316 316 value = content_tag("i", h(value)) if value
317 317 end
318 318 end
319 319
320 320 if detail.property == 'attr' && detail.prop_key == 'description'
321 321 s = l(:text_journal_changed_no_detail, :label => label)
322 322 unless no_html
323 323 diff_link = link_to 'diff',
324 324 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
325 325 :detail_id => detail.id, :only_path => options[:only_path]},
326 326 :title => l(:label_view_diff)
327 327 s << " (#{ diff_link })"
328 328 end
329 329 s.html_safe
330 330 elsif detail.value.present?
331 331 case detail.property
332 332 when 'attr', 'cf'
333 333 if detail.old_value.present?
334 334 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
335 335 elsif multiple
336 336 l(:text_journal_added, :label => label, :value => value).html_safe
337 337 else
338 338 l(:text_journal_set_to, :label => label, :value => value).html_safe
339 339 end
340 340 when 'attachment'
341 341 l(:text_journal_added, :label => label, :value => value).html_safe
342 342 end
343 343 else
344 344 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
345 345 end
346 346 end
347 347
348 348 # Find the name of an associated record stored in the field attribute
349 349 def find_name_by_reflection(field, id)
350 350 unless id.present?
351 351 return nil
352 352 end
353 353 association = Issue.reflect_on_association(field.to_sym)
354 354 if association
355 355 record = association.class_name.constantize.find_by_id(id)
356 356 return record.name if record
357 357 end
358 358 end
359 359
360 360 # Renders issue children recursively
361 361 def render_api_issue_children(issue, api)
362 362 return if issue.leaf?
363 363 api.array :children do
364 364 issue.children.each do |child|
365 365 api.issue(:id => child.id) do
366 366 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
367 367 api.subject child.subject
368 368 render_api_issue_children(child, api)
369 369 end
370 370 end
371 371 end
372 372 end
373 373
374 374 def issues_to_csv(issues, project, query, options={})
375 decimal_separator = l(:general_csv_decimal_separator)
376 375 encoding = l(:general_csv_encoding)
377 376 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
378 377 if options[:description]
379 378 if description = query.available_columns.detect {|q| q.name == :description}
380 379 columns << description
381 380 end
382 381 end
383 382
384 383 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
385 384 # csv header fields
386 385 csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
387
388 386 # csv lines
389 387 issues.each do |issue|
390 col_values = columns.collect do |column|
391 s = if column.is_a?(QueryCustomFieldColumn)
392 cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
393 show_value(cv)
394 else
395 value = column.value(issue)
396 if value.is_a?(Date)
397 format_date(value)
398 elsif value.is_a?(Time)
399 format_time(value)
400 elsif value.is_a?(Float)
401 ("%.2f" % value).gsub('.', decimal_separator)
402 else
403 value
404 end
405 end
406 s.to_s
407 end
408 csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) }
388 csv << [ issue.id.to_s ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, issue), encoding) }
409 389 end
410 390 end
411 391 export
412 392 end
413 393 end
@@ -1,139 +1,164
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2013 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 module QueriesHelper
21 21 def filters_options_for_select(query)
22 22 options_for_select(filters_options(query))
23 23 end
24 24
25 25 def filters_options(query)
26 26 options = [[]]
27 27 options += query.available_filters.map do |field, field_options|
28 28 [field_options[:name], field]
29 29 end
30 30 end
31 31
32 32 def available_block_columns_tags(query)
33 33 tags = ''.html_safe
34 34 query.available_block_columns.each do |column|
35 35 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
36 36 end
37 37 tags
38 38 end
39 39
40 40 def column_header(column)
41 41 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
42 42 :default_order => column.default_order) :
43 43 content_tag('th', h(column.caption))
44 44 end
45 45
46 46 def column_content(column, issue)
47 47 value = column.value(issue)
48 48 if value.is_a?(Array)
49 49 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
50 50 else
51 51 column_value(column, issue, value)
52 52 end
53 53 end
54 54
55 55 def column_value(column, issue, value)
56 56 case value.class.name
57 57 when 'String'
58 58 if column.name == :subject
59 59 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
60 60 elsif column.name == :description
61 61 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
62 62 else
63 63 h(value)
64 64 end
65 65 when 'Time'
66 66 format_time(value)
67 67 when 'Date'
68 68 format_date(value)
69 69 when 'Fixnum'
70 70 if column.name == :done_ratio
71 71 progress_bar(value, :width => '80px')
72 72 else
73 73 value.to_s
74 74 end
75 75 when 'Float'
76 76 sprintf "%.2f", value
77 77 when 'User'
78 78 link_to_user value
79 79 when 'Project'
80 80 link_to_project value
81 81 when 'Version'
82 82 link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
83 83 when 'TrueClass'
84 84 l(:general_text_Yes)
85 85 when 'FalseClass'
86 86 l(:general_text_No)
87 87 when 'Issue'
88 88 value.visible? ? link_to_issue(value) : "##{value.id}"
89 89 when 'IssueRelation'
90 90 other = value.other_issue(issue)
91 91 content_tag('span',
92 92 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
93 93 :class => value.css_classes_for(issue))
94 94 else
95 95 h(value)
96 96 end
97 97 end
98 98
99 def csv_content(column, issue)
100 value = column.value(issue)
101 if value.is_a?(Array)
102 value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
103 else
104 csv_value(column, issue, value)
105 end
106 end
107
108 def csv_value(column, issue, value)
109 case value.class.name
110 when 'Time'
111 format_time(value)
112 when 'Date'
113 format_date(value)
114 when 'Float'
115 sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
116 when 'IssueRelation'
117 other = value.other_issue(issue)
118 l(value.label_for(issue)) + " ##{other.id}"
119 else
120 value.to_s
121 end
122 end
123
99 124 # Retrieve query from session or build a new query
100 125 def retrieve_query
101 126 if !params[:query_id].blank?
102 127 cond = "project_id IS NULL"
103 128 cond << " OR project_id = #{@project.id}" if @project
104 129 @query = IssueQuery.find(params[:query_id], :conditions => cond)
105 130 raise ::Unauthorized unless @query.visible?
106 131 @query.project = @project
107 132 session[:query] = {:id => @query.id, :project_id => @query.project_id}
108 133 sort_clear
109 134 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
110 135 # Give it a name, required to be valid
111 136 @query = IssueQuery.new(:name => "_")
112 137 @query.project = @project
113 138 @query.build_from_params(params)
114 139 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
115 140 else
116 141 # retrieve from session
117 142 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
118 143 @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
119 144 @query.project = @project
120 145 end
121 146 end
122 147
123 148 def retrieve_query_from_session
124 149 if session[:query]
125 150 if session[:query][:id]
126 151 @query = IssueQuery.find_by_id(session[:query][:id])
127 152 return unless @query
128 153 else
129 154 @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
130 155 end
131 156 if session[:query].has_key?(:project_id)
132 157 @query.project_id = session[:query][:project_id]
133 158 else
134 159 @query.project = @project
135 160 end
136 161 @query
137 162 end
138 163 end
139 164 end
@@ -1,3872 +1,3891
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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,
23 23 :roles,
24 24 :members,
25 25 :member_roles,
26 26 :issues,
27 27 :issue_statuses,
28 28 :versions,
29 29 :trackers,
30 30 :projects_trackers,
31 31 :issue_categories,
32 32 :enabled_modules,
33 33 :enumerations,
34 34 :attachments,
35 35 :workflows,
36 36 :custom_fields,
37 37 :custom_values,
38 38 :custom_fields_projects,
39 39 :custom_fields_trackers,
40 40 :time_entries,
41 41 :journals,
42 42 :journal_details,
43 43 :queries,
44 44 :repositories,
45 45 :changesets
46 46
47 47 include Redmine::I18n
48 48
49 49 def setup
50 50 User.current = nil
51 51 end
52 52
53 53 def test_index
54 54 with_settings :default_language => "en" do
55 55 get :index
56 56 assert_response :success
57 57 assert_template 'index'
58 58 assert_not_nil assigns(:issues)
59 59 assert_nil assigns(:project)
60 60
61 61 # links to visible issues
62 62 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
63 63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
64 64 # private projects hidden
65 65 assert_select 'a[href=/issues/6]', 0
66 66 assert_select 'a[href=/issues/4]', 0
67 67 # project column
68 68 assert_select 'th', :text => /Project/
69 69 end
70 70 end
71 71
72 72 def test_index_should_not_list_issues_when_module_disabled
73 73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 74 get :index
75 75 assert_response :success
76 76 assert_template 'index'
77 77 assert_not_nil assigns(:issues)
78 78 assert_nil assigns(:project)
79 79
80 80 assert_select 'a[href=/issues/1]', 0
81 81 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
82 82 end
83 83
84 84 def test_index_should_list_visible_issues_only
85 85 get :index, :per_page => 100
86 86 assert_response :success
87 87 assert_not_nil assigns(:issues)
88 88 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
89 89 end
90 90
91 91 def test_index_with_project
92 92 Setting.display_subprojects_issues = 0
93 93 get :index, :project_id => 1
94 94 assert_response :success
95 95 assert_template 'index'
96 96 assert_not_nil assigns(:issues)
97 97
98 98 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
99 99 assert_select 'a[href=/issues/5]', 0
100 100 end
101 101
102 102 def test_index_with_project_and_subprojects
103 103 Setting.display_subprojects_issues = 1
104 104 get :index, :project_id => 1
105 105 assert_response :success
106 106 assert_template 'index'
107 107 assert_not_nil assigns(:issues)
108 108
109 109 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
110 110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
111 111 assert_select 'a[href=/issues/6]', 0
112 112 end
113 113
114 114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
115 115 @request.session[:user_id] = 2
116 116 Setting.display_subprojects_issues = 1
117 117 get :index, :project_id => 1
118 118 assert_response :success
119 119 assert_template 'index'
120 120 assert_not_nil assigns(:issues)
121 121
122 122 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
123 123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
124 124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
125 125 end
126 126
127 127 def test_index_with_project_and_default_filter
128 128 get :index, :project_id => 1, :set_filter => 1
129 129 assert_response :success
130 130 assert_template 'index'
131 131 assert_not_nil assigns(:issues)
132 132
133 133 query = assigns(:query)
134 134 assert_not_nil query
135 135 # default filter
136 136 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
137 137 end
138 138
139 139 def test_index_with_project_and_filter
140 140 get :index, :project_id => 1, :set_filter => 1,
141 141 :f => ['tracker_id'],
142 142 :op => {'tracker_id' => '='},
143 143 :v => {'tracker_id' => ['1']}
144 144 assert_response :success
145 145 assert_template 'index'
146 146 assert_not_nil assigns(:issues)
147 147
148 148 query = assigns(:query)
149 149 assert_not_nil query
150 150 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
151 151 end
152 152
153 153 def test_index_with_short_filters
154 154 to_test = {
155 155 'status_id' => {
156 156 'o' => { :op => 'o', :values => [''] },
157 157 'c' => { :op => 'c', :values => [''] },
158 158 '7' => { :op => '=', :values => ['7'] },
159 159 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
160 160 '=7' => { :op => '=', :values => ['7'] },
161 161 '!3' => { :op => '!', :values => ['3'] },
162 162 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
163 163 'subject' => {
164 164 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
165 165 'o' => { :op => '=', :values => ['o'] },
166 166 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
167 167 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
168 168 'tracker_id' => {
169 169 '3' => { :op => '=', :values => ['3'] },
170 170 '=3' => { :op => '=', :values => ['3'] }},
171 171 'start_date' => {
172 172 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
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-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
177 177 '<t+2' => { :op => '<t+', :values => ['2'] },
178 178 '>t+2' => { :op => '>t+', :values => ['2'] },
179 179 't+2' => { :op => 't+', :values => ['2'] },
180 180 't' => { :op => 't', :values => [''] },
181 181 'w' => { :op => 'w', :values => [''] },
182 182 '>t-2' => { :op => '>t-', :values => ['2'] },
183 183 '<t-2' => { :op => '<t-', :values => ['2'] },
184 184 't-2' => { :op => 't-', :values => ['2'] }},
185 185 'created_on' => {
186 186 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
187 187 '<t-2' => { :op => '<t-', :values => ['2'] },
188 188 '>t-2' => { :op => '>t-', :values => ['2'] },
189 189 't-2' => { :op => 't-', :values => ['2'] }},
190 190 'cf_1' => {
191 191 'c' => { :op => '=', :values => ['c'] },
192 192 '!c' => { :op => '!', :values => ['c'] },
193 193 '!*' => { :op => '!*', :values => [''] },
194 194 '*' => { :op => '*', :values => [''] }},
195 195 'estimated_hours' => {
196 196 '=13.4' => { :op => '=', :values => ['13.4'] },
197 197 '>=45' => { :op => '>=', :values => ['45'] },
198 198 '<=125' => { :op => '<=', :values => ['125'] },
199 199 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
200 200 '!*' => { :op => '!*', :values => [''] },
201 201 '*' => { :op => '*', :values => [''] }}
202 202 }
203 203
204 204 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
205 205
206 206 to_test.each do |field, expression_and_expected|
207 207 expression_and_expected.each do |filter_expression, expected|
208 208
209 209 get :index, :set_filter => 1, field => filter_expression
210 210
211 211 assert_response :success
212 212 assert_template 'index'
213 213 assert_not_nil assigns(:issues)
214 214
215 215 query = assigns(:query)
216 216 assert_not_nil query
217 217 assert query.has_filter?(field)
218 218 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
219 219 end
220 220 end
221 221 end
222 222
223 223 def test_index_with_project_and_empty_filters
224 224 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
225 225 assert_response :success
226 226 assert_template 'index'
227 227 assert_not_nil assigns(:issues)
228 228
229 229 query = assigns(:query)
230 230 assert_not_nil query
231 231 # no filter
232 232 assert_equal({}, query.filters)
233 233 end
234 234
235 235 def test_index_with_project_custom_field_filter
236 236 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
237 237 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
238 238 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
239 239 filter_name = "project.cf_#{field.id}"
240 240 @request.session[:user_id] = 1
241 241
242 242 get :index, :set_filter => 1,
243 243 :f => [filter_name],
244 244 :op => {filter_name => '='},
245 245 :v => {filter_name => ['Foo']}
246 246 assert_response :success
247 247 assert_template 'index'
248 248 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
249 249 end
250 250
251 251 def test_index_with_query
252 252 get :index, :project_id => 1, :query_id => 5
253 253 assert_response :success
254 254 assert_template 'index'
255 255 assert_not_nil assigns(:issues)
256 256 assert_nil assigns(:issue_count_by_group)
257 257 end
258 258
259 259 def test_index_with_query_grouped_by_tracker
260 260 get :index, :project_id => 1, :query_id => 6
261 261 assert_response :success
262 262 assert_template 'index'
263 263 assert_not_nil assigns(:issues)
264 264 assert_not_nil assigns(:issue_count_by_group)
265 265 end
266 266
267 267 def test_index_with_query_grouped_by_list_custom_field
268 268 get :index, :project_id => 1, :query_id => 9
269 269 assert_response :success
270 270 assert_template 'index'
271 271 assert_not_nil assigns(:issues)
272 272 assert_not_nil assigns(:issue_count_by_group)
273 273 end
274 274
275 275 def test_index_with_query_grouped_by_user_custom_field
276 276 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
277 277 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
278 278 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
279 279 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
280 280 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
281 281
282 282 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
283 283 assert_response :success
284 284
285 285 assert_select 'tr.group', 3
286 286 assert_select 'tr.group' do
287 287 assert_select 'a', :text => 'John Smith'
288 288 assert_select 'span.count', :text => '1'
289 289 end
290 290 assert_select 'tr.group' do
291 291 assert_select 'a', :text => 'Dave Lopper'
292 292 assert_select 'span.count', :text => '2'
293 293 end
294 294 end
295 295
296 296 def test_index_with_query_grouped_by_tracker
297 297 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
298 298
299 299 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
300 300 assert_response :success
301 301
302 302 trackers = assigns(:issues).map(&:tracker).uniq
303 303 assert_equal [1, 2, 3], trackers.map(&:id)
304 304 end
305 305
306 306 def test_index_with_query_grouped_by_tracker_in_reverse_order
307 307 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
308 308
309 309 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
310 310 assert_response :success
311 311
312 312 trackers = assigns(:issues).map(&:tracker).uniq
313 313 assert_equal [3, 2, 1], trackers.map(&:id)
314 314 end
315 315
316 316 def test_index_with_query_id_and_project_id_should_set_session_query
317 317 get :index, :project_id => 1, :query_id => 4
318 318 assert_response :success
319 319 assert_kind_of Hash, session[:query]
320 320 assert_equal 4, session[:query][:id]
321 321 assert_equal 1, session[:query][:project_id]
322 322 end
323 323
324 324 def test_index_with_invalid_query_id_should_respond_404
325 325 get :index, :project_id => 1, :query_id => 999
326 326 assert_response 404
327 327 end
328 328
329 329 def test_index_with_cross_project_query_in_session_should_show_project_issues
330 330 q = IssueQuery.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
331 331 @request.session[:query] = {:id => q.id, :project_id => 1}
332 332
333 333 with_settings :display_subprojects_issues => '0' do
334 334 get :index, :project_id => 1
335 335 end
336 336 assert_response :success
337 337 assert_not_nil assigns(:query)
338 338 assert_equal q.id, assigns(:query).id
339 339 assert_equal 1, assigns(:query).project_id
340 340 assert_equal [1], assigns(:issues).map(&:project_id).uniq
341 341 end
342 342
343 343 def test_private_query_should_not_be_available_to_other_users
344 344 q = IssueQuery.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
345 345 @request.session[:user_id] = 3
346 346
347 347 get :index, :query_id => q.id
348 348 assert_response 403
349 349 end
350 350
351 351 def test_private_query_should_be_available_to_its_user
352 352 q = IssueQuery.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
353 353 @request.session[:user_id] = 2
354 354
355 355 get :index, :query_id => q.id
356 356 assert_response :success
357 357 end
358 358
359 359 def test_public_query_should_be_available_to_other_users
360 360 q = IssueQuery.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
361 361 @request.session[:user_id] = 3
362 362
363 363 get :index, :query_id => q.id
364 364 assert_response :success
365 365 end
366 366
367 367 def test_index_should_omit_page_param_in_export_links
368 368 get :index, :page => 2
369 369 assert_response :success
370 370 assert_select 'a.atom[href=/issues.atom]'
371 371 assert_select 'a.csv[href=/issues.csv]'
372 372 assert_select 'a.pdf[href=/issues.pdf]'
373 373 assert_select 'form#csv-export-form[action=/issues.csv]'
374 374 end
375 375
376 376 def test_index_csv
377 377 get :index, :format => 'csv'
378 378 assert_response :success
379 379 assert_not_nil assigns(:issues)
380 380 assert_equal 'text/csv; header=present', @response.content_type
381 381 assert @response.body.starts_with?("#,")
382 382 lines = @response.body.chomp.split("\n")
383 383 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
384 384 end
385 385
386 386 def test_index_csv_with_project
387 387 get :index, :project_id => 1, :format => 'csv'
388 388 assert_response :success
389 389 assert_not_nil assigns(:issues)
390 390 assert_equal 'text/csv; header=present', @response.content_type
391 391 end
392 392
393 393 def test_index_csv_with_description
394 394 get :index, :format => 'csv', :description => '1'
395 395 assert_response :success
396 396 assert_not_nil assigns(:issues)
397 397 assert_equal 'text/csv; header=present', @response.content_type
398 398 assert @response.body.starts_with?("#,")
399 399 lines = @response.body.chomp.split("\n")
400 400 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
401 401 end
402 402
403 403 def test_index_csv_with_spent_time_column
404 404 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
405 405 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
406 406
407 407 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
408 408 assert_response :success
409 409 assert_equal 'text/csv; header=present', @response.content_type
410 410 lines = @response.body.chomp.split("\n")
411 411 assert_include "#{issue.id},#{issue.subject},7.33", lines
412 412 end
413 413
414 414 def test_index_csv_with_all_columns
415 415 get :index, :format => 'csv', :columns => 'all'
416 416 assert_response :success
417 417 assert_not_nil assigns(:issues)
418 418 assert_equal 'text/csv; header=present', @response.content_type
419 419 assert @response.body.starts_with?("#,")
420 420 lines = @response.body.chomp.split("\n")
421 421 assert_equal assigns(:query).available_inline_columns.size + 1, lines[0].split(',').size
422 422 end
423 423
424 424 def test_index_csv_with_multi_column_field
425 425 CustomField.find(1).update_attribute :multiple, true
426 426 issue = Issue.find(1)
427 427 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
428 428 issue.save!
429 429
430 430 get :index, :format => 'csv', :columns => 'all'
431 431 assert_response :success
432 432 lines = @response.body.chomp.split("\n")
433 433 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
434 434 end
435 435
436 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
437 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
438 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
439
440 with_settings :default_language => 'fr' do
441 get :index, :format => 'csv', :columns => 'all'
442 assert_response :success
443 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
444 assert_include '185,60', issue_line
445 end
446
447 with_settings :default_language => 'en' do
448 get :index, :format => 'csv', :columns => 'all'
449 assert_response :success
450 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
451 assert_include '185.60', issue_line
452 end
453 end
454
436 455 def test_index_csv_big_5
437 456 with_settings :default_language => "zh-TW" do
438 457 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
439 458 str_big5 = "\xa4@\xa4\xeb"
440 459 if str_utf8.respond_to?(:force_encoding)
441 460 str_utf8.force_encoding('UTF-8')
442 461 str_big5.force_encoding('Big5')
443 462 end
444 463 issue = Issue.generate!(:subject => str_utf8)
445 464
446 465 get :index, :project_id => 1,
447 466 :f => ['subject'],
448 467 :op => '=', :values => [str_utf8],
449 468 :format => 'csv'
450 469 assert_equal 'text/csv; header=present', @response.content_type
451 470 lines = @response.body.chomp.split("\n")
452 471 s1 = "\xaa\xac\xbaA"
453 472 if str_utf8.respond_to?(:force_encoding)
454 473 s1.force_encoding('Big5')
455 474 end
456 assert lines[0].include?(s1)
457 assert lines[1].include?(str_big5)
475 assert_include s1, lines[0]
476 assert_include str_big5, lines[1]
458 477 end
459 478 end
460 479
461 480 def test_index_csv_cannot_convert_should_be_replaced_big_5
462 481 with_settings :default_language => "zh-TW" do
463 482 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
464 483 if str_utf8.respond_to?(:force_encoding)
465 484 str_utf8.force_encoding('UTF-8')
466 485 end
467 486 issue = Issue.generate!(:subject => str_utf8)
468 487
469 488 get :index, :project_id => 1,
470 489 :f => ['subject'],
471 490 :op => '=', :values => [str_utf8],
472 491 :c => ['status', 'subject'],
473 492 :format => 'csv',
474 493 :set_filter => 1
475 494 assert_equal 'text/csv; header=present', @response.content_type
476 495 lines = @response.body.chomp.split("\n")
477 496 s1 = "\xaa\xac\xbaA" # status
478 497 if str_utf8.respond_to?(:force_encoding)
479 498 s1.force_encoding('Big5')
480 499 end
481 500 assert lines[0].include?(s1)
482 501 s2 = lines[1].split(",")[2]
483 502 if s1.respond_to?(:force_encoding)
484 503 s3 = "\xa5H?" # subject
485 504 s3.force_encoding('Big5')
486 505 assert_equal s3, s2
487 506 elsif RUBY_PLATFORM == 'java'
488 507 assert_equal "??", s2
489 508 else
490 509 assert_equal "\xa5H???", s2
491 510 end
492 511 end
493 512 end
494 513
495 514 def test_index_csv_tw
496 515 with_settings :default_language => "zh-TW" do
497 516 str1 = "test_index_csv_tw"
498 517 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
499 518
500 519 get :index, :project_id => 1,
501 520 :f => ['subject'],
502 521 :op => '=', :values => [str1],
503 522 :c => ['estimated_hours', 'subject'],
504 523 :format => 'csv',
505 524 :set_filter => 1
506 525 assert_equal 'text/csv; header=present', @response.content_type
507 526 lines = @response.body.chomp.split("\n")
508 527 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
509 528 end
510 529 end
511 530
512 531 def test_index_csv_fr
513 532 with_settings :default_language => "fr" do
514 533 str1 = "test_index_csv_fr"
515 534 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
516 535
517 536 get :index, :project_id => 1,
518 537 :f => ['subject'],
519 538 :op => '=', :values => [str1],
520 539 :c => ['estimated_hours', 'subject'],
521 540 :format => 'csv',
522 541 :set_filter => 1
523 542 assert_equal 'text/csv; header=present', @response.content_type
524 543 lines = @response.body.chomp.split("\n")
525 544 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
526 545 end
527 546 end
528 547
529 548 def test_index_pdf
530 549 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
531 550 with_settings :default_language => lang do
532 551
533 552 get :index
534 553 assert_response :success
535 554 assert_template 'index'
536 555
537 556 if lang == "ja"
538 557 if RUBY_PLATFORM != 'java'
539 558 assert_equal "CP932", l(:general_pdf_encoding)
540 559 end
541 560 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
542 561 next
543 562 end
544 563 end
545 564
546 565 get :index, :format => 'pdf'
547 566 assert_response :success
548 567 assert_not_nil assigns(:issues)
549 568 assert_equal 'application/pdf', @response.content_type
550 569
551 570 get :index, :project_id => 1, :format => 'pdf'
552 571 assert_response :success
553 572 assert_not_nil assigns(:issues)
554 573 assert_equal 'application/pdf', @response.content_type
555 574
556 575 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
557 576 assert_response :success
558 577 assert_not_nil assigns(:issues)
559 578 assert_equal 'application/pdf', @response.content_type
560 579 end
561 580 end
562 581 end
563 582
564 583 def test_index_pdf_with_query_grouped_by_list_custom_field
565 584 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
566 585 assert_response :success
567 586 assert_not_nil assigns(:issues)
568 587 assert_not_nil assigns(:issue_count_by_group)
569 588 assert_equal 'application/pdf', @response.content_type
570 589 end
571 590
572 591 def test_index_atom
573 592 get :index, :project_id => 'ecookbook', :format => 'atom'
574 593 assert_response :success
575 594 assert_template 'common/feed'
576 595 assert_equal 'application/atom+xml', response.content_type
577 596
578 597 assert_select 'feed' do
579 598 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
580 599 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
581 600 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
582 601 end
583 602 end
584 603
585 604 def test_index_sort
586 605 get :index, :sort => 'tracker,id:desc'
587 606 assert_response :success
588 607
589 608 sort_params = @request.session['issues_index_sort']
590 609 assert sort_params.is_a?(String)
591 610 assert_equal 'tracker,id:desc', sort_params
592 611
593 612 issues = assigns(:issues)
594 613 assert_not_nil issues
595 614 assert !issues.empty?
596 615 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
597 616 end
598 617
599 618 def test_index_sort_by_field_not_included_in_columns
600 619 Setting.issue_list_default_columns = %w(subject author)
601 620 get :index, :sort => 'tracker'
602 621 end
603 622
604 623 def test_index_sort_by_assigned_to
605 624 get :index, :sort => 'assigned_to'
606 625 assert_response :success
607 626 assignees = assigns(:issues).collect(&:assigned_to).compact
608 627 assert_equal assignees.sort, assignees
609 628 end
610 629
611 630 def test_index_sort_by_assigned_to_desc
612 631 get :index, :sort => 'assigned_to:desc'
613 632 assert_response :success
614 633 assignees = assigns(:issues).collect(&:assigned_to).compact
615 634 assert_equal assignees.sort.reverse, assignees
616 635 end
617 636
618 637 def test_index_group_by_assigned_to
619 638 get :index, :group_by => 'assigned_to', :sort => 'priority'
620 639 assert_response :success
621 640 end
622 641
623 642 def test_index_sort_by_author
624 643 get :index, :sort => 'author'
625 644 assert_response :success
626 645 authors = assigns(:issues).collect(&:author)
627 646 assert_equal authors.sort, authors
628 647 end
629 648
630 649 def test_index_sort_by_author_desc
631 650 get :index, :sort => 'author:desc'
632 651 assert_response :success
633 652 authors = assigns(:issues).collect(&:author)
634 653 assert_equal authors.sort.reverse, authors
635 654 end
636 655
637 656 def test_index_group_by_author
638 657 get :index, :group_by => 'author', :sort => 'priority'
639 658 assert_response :success
640 659 end
641 660
642 661 def test_index_sort_by_spent_hours
643 662 get :index, :sort => 'spent_hours:desc'
644 663 assert_response :success
645 664 hours = assigns(:issues).collect(&:spent_hours)
646 665 assert_equal hours.sort.reverse, hours
647 666 end
648 667
649 668 def test_index_sort_by_user_custom_field
650 669 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
651 670 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
652 671 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
653 672 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
654 673 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
655 674
656 675 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
657 676 assert_response :success
658 677
659 678 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
660 679 end
661 680
662 681 def test_index_with_columns
663 682 columns = ['tracker', 'subject', 'assigned_to']
664 683 get :index, :set_filter => 1, :c => columns
665 684 assert_response :success
666 685
667 686 # query should use specified columns
668 687 query = assigns(:query)
669 688 assert_kind_of IssueQuery, query
670 689 assert_equal columns, query.column_names.map(&:to_s)
671 690
672 691 # columns should be stored in session
673 692 assert_kind_of Hash, session[:query]
674 693 assert_kind_of Array, session[:query][:column_names]
675 694 assert_equal columns, session[:query][:column_names].map(&:to_s)
676 695
677 696 # ensure only these columns are kept in the selected columns list
678 697 assert_select 'select#selected_columns option' do
679 698 assert_select 'option', 3
680 699 assert_select 'option[value=tracker]'
681 700 assert_select 'option[value=project]', 0
682 701 end
683 702 end
684 703
685 704 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
686 705 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
687 706 get :index, :set_filter => 1
688 707
689 708 # query should use specified columns
690 709 query = assigns(:query)
691 710 assert_kind_of IssueQuery, query
692 711 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
693 712 end
694 713
695 714 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
696 715 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
697 716 columns = ['tracker', 'subject', 'assigned_to']
698 717 get :index, :set_filter => 1, :c => columns
699 718
700 719 # query should use specified columns
701 720 query = assigns(:query)
702 721 assert_kind_of IssueQuery, query
703 722 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
704 723 end
705 724
706 725 def test_index_with_custom_field_column
707 726 columns = %w(tracker subject cf_2)
708 727 get :index, :set_filter => 1, :c => columns
709 728 assert_response :success
710 729
711 730 # query should use specified columns
712 731 query = assigns(:query)
713 732 assert_kind_of IssueQuery, query
714 733 assert_equal columns, query.column_names.map(&:to_s)
715 734
716 735 assert_select 'table.issues td.cf_2.string'
717 736 end
718 737
719 738 def test_index_with_multi_custom_field_column
720 739 field = CustomField.find(1)
721 740 field.update_attribute :multiple, true
722 741 issue = Issue.find(1)
723 742 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
724 743 issue.save!
725 744
726 745 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
727 746 assert_response :success
728 747
729 748 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
730 749 end
731 750
732 751 def test_index_with_multi_user_custom_field_column
733 752 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
734 753 :tracker_ids => [1], :is_for_all => true)
735 754 issue = Issue.find(1)
736 755 issue.custom_field_values = {field.id => ['2', '3']}
737 756 issue.save!
738 757
739 758 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
740 759 assert_response :success
741 760
742 761 assert_select "table.issues td.cf_#{field.id}" do
743 762 assert_select 'a', 2
744 763 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
745 764 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
746 765 end
747 766 end
748 767
749 768 def test_index_with_date_column
750 769 with_settings :date_format => '%d/%m/%Y' do
751 770 Issue.find(1).update_attribute :start_date, '1987-08-24'
752 771
753 772 get :index, :set_filter => 1, :c => %w(start_date)
754 773
755 774 assert_select "table.issues td.start_date", :text => '24/08/1987'
756 775 end
757 776 end
758 777
759 778 def test_index_with_done_ratio_column
760 779 Issue.find(1).update_attribute :done_ratio, 40
761 780
762 781 get :index, :set_filter => 1, :c => %w(done_ratio)
763 782
764 783 assert_select 'table.issues td.done_ratio' do
765 784 assert_select 'table.progress' do
766 785 assert_select 'td.closed[style=?]', 'width: 40%;'
767 786 end
768 787 end
769 788 end
770 789
771 790 def test_index_with_spent_hours_column
772 791 get :index, :set_filter => 1, :c => %w(subject spent_hours)
773 792
774 793 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
775 794 end
776 795
777 796 def test_index_should_not_show_spent_hours_column_without_permission
778 797 Role.anonymous.remove_permission! :view_time_entries
779 798 get :index, :set_filter => 1, :c => %w(subject spent_hours)
780 799
781 800 assert_select 'td.spent_hours', 0
782 801 end
783 802
784 803 def test_index_with_fixed_version_column
785 804 get :index, :set_filter => 1, :c => %w(fixed_version)
786 805
787 806 assert_select 'table.issues td.fixed_version' do
788 807 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
789 808 end
790 809 end
791 810
792 811 def test_index_with_relations_column
793 812 IssueRelation.delete_all
794 813 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
795 814 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
796 815 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
797 816 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
798 817
799 818 get :index, :set_filter => 1, :c => %w(subject relations)
800 819 assert_response :success
801 820 assert_select "tr#issue-1 td.relations" do
802 821 assert_select "span", 3
803 822 assert_select "span", :text => "Related to #7"
804 823 assert_select "span", :text => "Related to #8"
805 824 assert_select "span", :text => "Blocks #11"
806 825 end
807 826 assert_select "tr#issue-2 td.relations" do
808 827 assert_select "span", 1
809 828 assert_select "span", :text => "Blocked by #12"
810 829 end
811 830 assert_select "tr#issue-3 td.relations" do
812 831 assert_select "span", 0
813 832 end
814 833
815 834 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
816 835 assert_response :success
817 836 assert_equal 'text/csv; header=present', response.content_type
818 837 lines = response.body.chomp.split("\n")
819 838 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
820 839 assert_include '2,Blocked by #12', lines
821 840 assert_include '3,""', lines
822 841
823 842 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
824 843 assert_response :success
825 844 assert_equal 'application/pdf', response.content_type
826 845 end
827 846
828 847 def test_index_with_description_column
829 848 get :index, :set_filter => 1, :c => %w(subject description)
830 849
831 850 assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
832 851 assert_select 'td.description[colspan=3]', :text => 'Unable to print recipes'
833 852
834 853 get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
835 854 assert_response :success
836 855 assert_equal 'application/pdf', response.content_type
837 856 end
838 857
839 858 def test_index_send_html_if_query_is_invalid
840 859 get :index, :f => ['start_date'], :op => {:start_date => '='}
841 860 assert_equal 'text/html', @response.content_type
842 861 assert_template 'index'
843 862 end
844 863
845 864 def test_index_send_nothing_if_query_is_invalid
846 865 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
847 866 assert_equal 'text/csv', @response.content_type
848 867 assert @response.body.blank?
849 868 end
850 869
851 870 def test_show_by_anonymous
852 871 get :show, :id => 1
853 872 assert_response :success
854 873 assert_template 'show'
855 874 assert_equal Issue.find(1), assigns(:issue)
856 875
857 876 assert_select 'div.issue div.description', :text => /Unable to print recipes/
858 877
859 878 # anonymous role is allowed to add a note
860 879 assert_select 'form#issue-form' do
861 880 assert_select 'fieldset' do
862 881 assert_select 'legend', :text => 'Notes'
863 882 assert_select 'textarea[name=?]', 'issue[notes]'
864 883 end
865 884 end
866 885
867 886 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
868 887 end
869 888
870 889 def test_show_by_manager
871 890 @request.session[:user_id] = 2
872 891 get :show, :id => 1
873 892 assert_response :success
874 893
875 894 assert_select 'a', :text => /Quote/
876 895
877 896 assert_select 'form#issue-form' do
878 897 assert_select 'fieldset' do
879 898 assert_select 'legend', :text => 'Change properties'
880 899 assert_select 'input[name=?]', 'issue[subject]'
881 900 end
882 901 assert_select 'fieldset' do
883 902 assert_select 'legend', :text => 'Log time'
884 903 assert_select 'input[name=?]', 'time_entry[hours]'
885 904 end
886 905 assert_select 'fieldset' do
887 906 assert_select 'legend', :text => 'Notes'
888 907 assert_select 'textarea[name=?]', 'issue[notes]'
889 908 end
890 909 end
891 910 end
892 911
893 912 def test_show_should_display_update_form
894 913 @request.session[:user_id] = 2
895 914 get :show, :id => 1
896 915 assert_response :success
897 916
898 917 assert_select 'form#issue-form' do
899 918 assert_select 'input[name=?]', 'issue[is_private]'
900 919 assert_select 'select[name=?]', 'issue[project_id]'
901 920 assert_select 'select[name=?]', 'issue[tracker_id]'
902 921 assert_select 'input[name=?]', 'issue[subject]'
903 922 assert_select 'textarea[name=?]', 'issue[description]'
904 923 assert_select 'select[name=?]', 'issue[status_id]'
905 924 assert_select 'select[name=?]', 'issue[priority_id]'
906 925 assert_select 'select[name=?]', 'issue[assigned_to_id]'
907 926 assert_select 'select[name=?]', 'issue[category_id]'
908 927 assert_select 'select[name=?]', 'issue[fixed_version_id]'
909 928 assert_select 'input[name=?]', 'issue[parent_issue_id]'
910 929 assert_select 'input[name=?]', 'issue[start_date]'
911 930 assert_select 'input[name=?]', 'issue[due_date]'
912 931 assert_select 'select[name=?]', 'issue[done_ratio]'
913 932 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
914 933 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
915 934 assert_select 'textarea[name=?]', 'issue[notes]'
916 935 end
917 936 end
918 937
919 938 def test_show_should_display_update_form_with_minimal_permissions
920 939 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
921 940 WorkflowTransition.delete_all :role_id => 1
922 941
923 942 @request.session[:user_id] = 2
924 943 get :show, :id => 1
925 944 assert_response :success
926 945
927 946 assert_select 'form#issue-form' do
928 947 assert_select 'input[name=?]', 'issue[is_private]', 0
929 948 assert_select 'select[name=?]', 'issue[project_id]', 0
930 949 assert_select 'select[name=?]', 'issue[tracker_id]', 0
931 950 assert_select 'input[name=?]', 'issue[subject]', 0
932 951 assert_select 'textarea[name=?]', 'issue[description]', 0
933 952 assert_select 'select[name=?]', 'issue[status_id]', 0
934 953 assert_select 'select[name=?]', 'issue[priority_id]', 0
935 954 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
936 955 assert_select 'select[name=?]', 'issue[category_id]', 0
937 956 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
938 957 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
939 958 assert_select 'input[name=?]', 'issue[start_date]', 0
940 959 assert_select 'input[name=?]', 'issue[due_date]', 0
941 960 assert_select 'select[name=?]', 'issue[done_ratio]', 0
942 961 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
943 962 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
944 963 assert_select 'textarea[name=?]', 'issue[notes]'
945 964 end
946 965 end
947 966
948 967 def test_show_should_display_update_form_with_workflow_permissions
949 968 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
950 969
951 970 @request.session[:user_id] = 2
952 971 get :show, :id => 1
953 972 assert_response :success
954 973
955 974 assert_select 'form#issue-form' do
956 975 assert_select 'input[name=?]', 'issue[is_private]', 0
957 976 assert_select 'select[name=?]', 'issue[project_id]', 0
958 977 assert_select 'select[name=?]', 'issue[tracker_id]', 0
959 978 assert_select 'input[name=?]', 'issue[subject]', 0
960 979 assert_select 'textarea[name=?]', 'issue[description]', 0
961 980 assert_select 'select[name=?]', 'issue[status_id]'
962 981 assert_select 'select[name=?]', 'issue[priority_id]', 0
963 982 assert_select 'select[name=?]', 'issue[assigned_to_id]'
964 983 assert_select 'select[name=?]', 'issue[category_id]', 0
965 984 assert_select 'select[name=?]', 'issue[fixed_version_id]'
966 985 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
967 986 assert_select 'input[name=?]', 'issue[start_date]', 0
968 987 assert_select 'input[name=?]', 'issue[due_date]', 0
969 988 assert_select 'select[name=?]', 'issue[done_ratio]'
970 989 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
971 990 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
972 991 assert_select 'textarea[name=?]', 'issue[notes]'
973 992 end
974 993 end
975 994
976 995 def test_show_should_not_display_update_form_without_permissions
977 996 Role.find(1).update_attribute :permissions, [:view_issues]
978 997
979 998 @request.session[:user_id] = 2
980 999 get :show, :id => 1
981 1000 assert_response :success
982 1001
983 1002 assert_select 'form#issue-form', 0
984 1003 end
985 1004
986 1005 def test_update_form_should_not_display_inactive_enumerations
987 1006 assert !IssuePriority.find(15).active?
988 1007
989 1008 @request.session[:user_id] = 2
990 1009 get :show, :id => 1
991 1010 assert_response :success
992 1011
993 1012 assert_select 'form#issue-form' do
994 1013 assert_select 'select[name=?]', 'issue[priority_id]' do
995 1014 assert_select 'option[value=4]'
996 1015 assert_select 'option[value=15]', 0
997 1016 end
998 1017 end
999 1018 end
1000 1019
1001 1020 def test_update_form_should_allow_attachment_upload
1002 1021 @request.session[:user_id] = 2
1003 1022 get :show, :id => 1
1004 1023
1005 1024 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
1006 1025 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
1007 1026 end
1008 1027 end
1009 1028
1010 1029 def test_show_should_deny_anonymous_access_without_permission
1011 1030 Role.anonymous.remove_permission!(:view_issues)
1012 1031 get :show, :id => 1
1013 1032 assert_response :redirect
1014 1033 end
1015 1034
1016 1035 def test_show_should_deny_anonymous_access_to_private_issue
1017 1036 Issue.update_all(["is_private = ?", true], "id = 1")
1018 1037 get :show, :id => 1
1019 1038 assert_response :redirect
1020 1039 end
1021 1040
1022 1041 def test_show_should_deny_non_member_access_without_permission
1023 1042 Role.non_member.remove_permission!(:view_issues)
1024 1043 @request.session[:user_id] = 9
1025 1044 get :show, :id => 1
1026 1045 assert_response 403
1027 1046 end
1028 1047
1029 1048 def test_show_should_deny_non_member_access_to_private_issue
1030 1049 Issue.update_all(["is_private = ?", true], "id = 1")
1031 1050 @request.session[:user_id] = 9
1032 1051 get :show, :id => 1
1033 1052 assert_response 403
1034 1053 end
1035 1054
1036 1055 def test_show_should_deny_member_access_without_permission
1037 1056 Role.find(1).remove_permission!(:view_issues)
1038 1057 @request.session[:user_id] = 2
1039 1058 get :show, :id => 1
1040 1059 assert_response 403
1041 1060 end
1042 1061
1043 1062 def test_show_should_deny_member_access_to_private_issue_without_permission
1044 1063 Issue.update_all(["is_private = ?", true], "id = 1")
1045 1064 @request.session[:user_id] = 3
1046 1065 get :show, :id => 1
1047 1066 assert_response 403
1048 1067 end
1049 1068
1050 1069 def test_show_should_allow_author_access_to_private_issue
1051 1070 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
1052 1071 @request.session[:user_id] = 3
1053 1072 get :show, :id => 1
1054 1073 assert_response :success
1055 1074 end
1056 1075
1057 1076 def test_show_should_allow_assignee_access_to_private_issue
1058 1077 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
1059 1078 @request.session[:user_id] = 3
1060 1079 get :show, :id => 1
1061 1080 assert_response :success
1062 1081 end
1063 1082
1064 1083 def test_show_should_allow_member_access_to_private_issue_with_permission
1065 1084 Issue.update_all(["is_private = ?", true], "id = 1")
1066 1085 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1067 1086 @request.session[:user_id] = 3
1068 1087 get :show, :id => 1
1069 1088 assert_response :success
1070 1089 end
1071 1090
1072 1091 def test_show_should_not_disclose_relations_to_invisible_issues
1073 1092 Setting.cross_project_issue_relations = '1'
1074 1093 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1075 1094 # Relation to a private project issue
1076 1095 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1077 1096
1078 1097 get :show, :id => 1
1079 1098 assert_response :success
1080 1099
1081 1100 assert_select 'div#relations' do
1082 1101 assert_select 'a', :text => /#2$/
1083 1102 assert_select 'a', :text => /#4$/, :count => 0
1084 1103 end
1085 1104 end
1086 1105
1087 1106 def test_show_should_list_subtasks
1088 1107 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1089 1108
1090 1109 get :show, :id => 1
1091 1110 assert_response :success
1092 1111
1093 1112 assert_select 'div#issue_tree' do
1094 1113 assert_select 'td.subject', :text => /Child Issue/
1095 1114 end
1096 1115 end
1097 1116
1098 1117 def test_show_should_list_parents
1099 1118 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1100 1119
1101 1120 get :show, :id => issue.id
1102 1121 assert_response :success
1103 1122
1104 1123 assert_select 'div.subject' do
1105 1124 assert_select 'h3', 'Child Issue'
1106 1125 assert_select 'a[href=/issues/1]'
1107 1126 end
1108 1127 end
1109 1128
1110 1129 def test_show_should_not_display_prev_next_links_without_query_in_session
1111 1130 get :show, :id => 1
1112 1131 assert_response :success
1113 1132 assert_nil assigns(:prev_issue_id)
1114 1133 assert_nil assigns(:next_issue_id)
1115 1134
1116 1135 assert_select 'div.next-prev-links', 0
1117 1136 end
1118 1137
1119 1138 def test_show_should_display_prev_next_links_with_query_in_session
1120 1139 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1121 1140 @request.session['issues_index_sort'] = 'id'
1122 1141
1123 1142 with_settings :display_subprojects_issues => '0' do
1124 1143 get :show, :id => 3
1125 1144 end
1126 1145
1127 1146 assert_response :success
1128 1147 # Previous and next issues for all projects
1129 1148 assert_equal 2, assigns(:prev_issue_id)
1130 1149 assert_equal 5, assigns(:next_issue_id)
1131 1150
1132 1151 count = Issue.open.visible.count
1133 1152
1134 1153 assert_select 'div.next-prev-links' do
1135 1154 assert_select 'a[href=/issues/2]', :text => /Previous/
1136 1155 assert_select 'a[href=/issues/5]', :text => /Next/
1137 1156 assert_select 'span.position', :text => "3 of #{count}"
1138 1157 end
1139 1158 end
1140 1159
1141 1160 def test_show_should_display_prev_next_links_with_saved_query_in_session
1142 1161 query = IssueQuery.create!(:name => 'test', :is_public => true, :user_id => 1,
1143 1162 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1144 1163 :sort_criteria => [['id', 'asc']])
1145 1164 @request.session[:query] = {:id => query.id, :project_id => nil}
1146 1165
1147 1166 get :show, :id => 11
1148 1167
1149 1168 assert_response :success
1150 1169 assert_equal query, assigns(:query)
1151 1170 # Previous and next issues for all projects
1152 1171 assert_equal 8, assigns(:prev_issue_id)
1153 1172 assert_equal 12, assigns(:next_issue_id)
1154 1173
1155 1174 assert_select 'div.next-prev-links' do
1156 1175 assert_select 'a[href=/issues/8]', :text => /Previous/
1157 1176 assert_select 'a[href=/issues/12]', :text => /Next/
1158 1177 end
1159 1178 end
1160 1179
1161 1180 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1162 1181 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1163 1182
1164 1183 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1165 1184 @request.session['issues_index_sort'] = assoc_sort
1166 1185
1167 1186 get :show, :id => 3
1168 1187 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1169 1188
1170 1189 assert_select 'div.next-prev-links' do
1171 1190 assert_select 'a', :text => /(Previous|Next)/
1172 1191 end
1173 1192 end
1174 1193 end
1175 1194
1176 1195 def test_show_should_display_prev_next_links_with_project_query_in_session
1177 1196 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1178 1197 @request.session['issues_index_sort'] = 'id'
1179 1198
1180 1199 with_settings :display_subprojects_issues => '0' do
1181 1200 get :show, :id => 3
1182 1201 end
1183 1202
1184 1203 assert_response :success
1185 1204 # Previous and next issues inside project
1186 1205 assert_equal 2, assigns(:prev_issue_id)
1187 1206 assert_equal 7, assigns(:next_issue_id)
1188 1207
1189 1208 assert_select 'div.next-prev-links' do
1190 1209 assert_select 'a[href=/issues/2]', :text => /Previous/
1191 1210 assert_select 'a[href=/issues/7]', :text => /Next/
1192 1211 end
1193 1212 end
1194 1213
1195 1214 def test_show_should_not_display_prev_link_for_first_issue
1196 1215 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1197 1216 @request.session['issues_index_sort'] = 'id'
1198 1217
1199 1218 with_settings :display_subprojects_issues => '0' do
1200 1219 get :show, :id => 1
1201 1220 end
1202 1221
1203 1222 assert_response :success
1204 1223 assert_nil assigns(:prev_issue_id)
1205 1224 assert_equal 2, assigns(:next_issue_id)
1206 1225
1207 1226 assert_select 'div.next-prev-links' do
1208 1227 assert_select 'a', :text => /Previous/, :count => 0
1209 1228 assert_select 'a[href=/issues/2]', :text => /Next/
1210 1229 end
1211 1230 end
1212 1231
1213 1232 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1214 1233 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1215 1234 @request.session['issues_index_sort'] = 'id'
1216 1235
1217 1236 get :show, :id => 1
1218 1237
1219 1238 assert_response :success
1220 1239 assert_nil assigns(:prev_issue_id)
1221 1240 assert_nil assigns(:next_issue_id)
1222 1241
1223 1242 assert_select 'a', :text => /Previous/, :count => 0
1224 1243 assert_select 'a', :text => /Next/, :count => 0
1225 1244 end
1226 1245
1227 1246 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1228 1247 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1229 1248 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1230 1249 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1231 1250 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1232 1251 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1233 1252
1234 1253 query = IssueQuery.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {},
1235 1254 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1236 1255 @request.session[:query] = {:id => query.id, :project_id => nil}
1237 1256
1238 1257 get :show, :id => 3
1239 1258 assert_response :success
1240 1259
1241 1260 assert_equal 2, assigns(:prev_issue_id)
1242 1261 assert_equal 1, assigns(:next_issue_id)
1243 1262
1244 1263 assert_select 'div.next-prev-links' do
1245 1264 assert_select 'a[href=/issues/2]', :text => /Previous/
1246 1265 assert_select 'a[href=/issues/1]', :text => /Next/
1247 1266 end
1248 1267 end
1249 1268
1250 1269 def test_show_should_display_link_to_the_assignee
1251 1270 get :show, :id => 2
1252 1271 assert_response :success
1253 1272 assert_select '.assigned-to' do
1254 1273 assert_select 'a[href=/users/3]'
1255 1274 end
1256 1275 end
1257 1276
1258 1277 def test_show_should_display_visible_changesets_from_other_projects
1259 1278 project = Project.find(2)
1260 1279 issue = project.issues.first
1261 1280 issue.changeset_ids = [102]
1262 1281 issue.save!
1263 1282 # changesets from other projects should be displayed even if repository
1264 1283 # is disabled on issue's project
1265 1284 project.disable_module! :repository
1266 1285
1267 1286 @request.session[:user_id] = 2
1268 1287 get :show, :id => issue.id
1269 1288
1270 1289 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1271 1290 end
1272 1291
1273 1292 def test_show_should_display_watchers
1274 1293 @request.session[:user_id] = 2
1275 1294 Issue.find(1).add_watcher User.find(2)
1276 1295
1277 1296 get :show, :id => 1
1278 1297 assert_select 'div#watchers ul' do
1279 1298 assert_select 'li' do
1280 1299 assert_select 'a[href=/users/2]'
1281 1300 assert_select 'a img[alt=Delete]'
1282 1301 end
1283 1302 end
1284 1303 end
1285 1304
1286 1305 def test_show_should_display_watchers_with_gravatars
1287 1306 @request.session[:user_id] = 2
1288 1307 Issue.find(1).add_watcher User.find(2)
1289 1308
1290 1309 with_settings :gravatar_enabled => '1' do
1291 1310 get :show, :id => 1
1292 1311 end
1293 1312
1294 1313 assert_select 'div#watchers ul' do
1295 1314 assert_select 'li' do
1296 1315 assert_select 'img.gravatar'
1297 1316 assert_select 'a[href=/users/2]'
1298 1317 assert_select 'a img[alt=Delete]'
1299 1318 end
1300 1319 end
1301 1320 end
1302 1321
1303 1322 def test_show_with_thumbnails_enabled_should_display_thumbnails
1304 1323 @request.session[:user_id] = 2
1305 1324
1306 1325 with_settings :thumbnails_enabled => '1' do
1307 1326 get :show, :id => 14
1308 1327 assert_response :success
1309 1328 end
1310 1329
1311 1330 assert_select 'div.thumbnails' do
1312 1331 assert_select 'a[href=/attachments/16/testfile.png]' do
1313 1332 assert_select 'img[src=/attachments/thumbnail/16]'
1314 1333 end
1315 1334 end
1316 1335 end
1317 1336
1318 1337 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1319 1338 @request.session[:user_id] = 2
1320 1339
1321 1340 with_settings :thumbnails_enabled => '0' do
1322 1341 get :show, :id => 14
1323 1342 assert_response :success
1324 1343 end
1325 1344
1326 1345 assert_select 'div.thumbnails', 0
1327 1346 end
1328 1347
1329 1348 def test_show_with_multi_custom_field
1330 1349 field = CustomField.find(1)
1331 1350 field.update_attribute :multiple, true
1332 1351 issue = Issue.find(1)
1333 1352 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1334 1353 issue.save!
1335 1354
1336 1355 get :show, :id => 1
1337 1356 assert_response :success
1338 1357
1339 1358 assert_select 'td', :text => 'MySQL, Oracle'
1340 1359 end
1341 1360
1342 1361 def test_show_with_multi_user_custom_field
1343 1362 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1344 1363 :tracker_ids => [1], :is_for_all => true)
1345 1364 issue = Issue.find(1)
1346 1365 issue.custom_field_values = {field.id => ['2', '3']}
1347 1366 issue.save!
1348 1367
1349 1368 get :show, :id => 1
1350 1369 assert_response :success
1351 1370
1352 1371 # TODO: should display links
1353 1372 assert_select 'td', :text => 'Dave Lopper, John Smith'
1354 1373 end
1355 1374
1356 1375 def test_show_should_display_private_notes_with_permission_only
1357 1376 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1358 1377 @request.session[:user_id] = 2
1359 1378
1360 1379 get :show, :id => 2
1361 1380 assert_response :success
1362 1381 assert_include journal, assigns(:journals)
1363 1382
1364 1383 Role.find(1).remove_permission! :view_private_notes
1365 1384 get :show, :id => 2
1366 1385 assert_response :success
1367 1386 assert_not_include journal, assigns(:journals)
1368 1387 end
1369 1388
1370 1389 def test_show_atom
1371 1390 get :show, :id => 2, :format => 'atom'
1372 1391 assert_response :success
1373 1392 assert_template 'journals/index'
1374 1393 # Inline image
1375 1394 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1376 1395 end
1377 1396
1378 1397 def test_show_export_to_pdf
1379 1398 get :show, :id => 3, :format => 'pdf'
1380 1399 assert_response :success
1381 1400 assert_equal 'application/pdf', @response.content_type
1382 1401 assert @response.body.starts_with?('%PDF')
1383 1402 assert_not_nil assigns(:issue)
1384 1403 end
1385 1404
1386 1405 def test_show_export_to_pdf_with_ancestors
1387 1406 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1388 1407
1389 1408 get :show, :id => issue.id, :format => 'pdf'
1390 1409 assert_response :success
1391 1410 assert_equal 'application/pdf', @response.content_type
1392 1411 assert @response.body.starts_with?('%PDF')
1393 1412 end
1394 1413
1395 1414 def test_show_export_to_pdf_with_descendants
1396 1415 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1397 1416 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1398 1417 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1399 1418
1400 1419 get :show, :id => 1, :format => 'pdf'
1401 1420 assert_response :success
1402 1421 assert_equal 'application/pdf', @response.content_type
1403 1422 assert @response.body.starts_with?('%PDF')
1404 1423 end
1405 1424
1406 1425 def test_show_export_to_pdf_with_journals
1407 1426 get :show, :id => 1, :format => 'pdf'
1408 1427 assert_response :success
1409 1428 assert_equal 'application/pdf', @response.content_type
1410 1429 assert @response.body.starts_with?('%PDF')
1411 1430 end
1412 1431
1413 1432 def test_show_export_to_pdf_with_changesets
1414 1433 Issue.find(3).changesets = Changeset.find_all_by_id(100, 101, 102)
1415 1434
1416 1435 get :show, :id => 3, :format => 'pdf'
1417 1436 assert_response :success
1418 1437 assert_equal 'application/pdf', @response.content_type
1419 1438 assert @response.body.starts_with?('%PDF')
1420 1439 end
1421 1440
1422 1441 def test_show_invalid_should_respond_with_404
1423 1442 get :show, :id => 999
1424 1443 assert_response 404
1425 1444 end
1426 1445
1427 1446 def test_get_new
1428 1447 @request.session[:user_id] = 2
1429 1448 get :new, :project_id => 1, :tracker_id => 1
1430 1449 assert_response :success
1431 1450 assert_template 'new'
1432 1451
1433 1452 assert_select 'form#issue-form' do
1434 1453 assert_select 'input[name=?]', 'issue[is_private]'
1435 1454 assert_select 'select[name=?]', 'issue[project_id]', 0
1436 1455 assert_select 'select[name=?]', 'issue[tracker_id]'
1437 1456 assert_select 'input[name=?]', 'issue[subject]'
1438 1457 assert_select 'textarea[name=?]', 'issue[description]'
1439 1458 assert_select 'select[name=?]', 'issue[status_id]'
1440 1459 assert_select 'select[name=?]', 'issue[priority_id]'
1441 1460 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1442 1461 assert_select 'select[name=?]', 'issue[category_id]'
1443 1462 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1444 1463 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1445 1464 assert_select 'input[name=?]', 'issue[start_date]'
1446 1465 assert_select 'input[name=?]', 'issue[due_date]'
1447 1466 assert_select 'select[name=?]', 'issue[done_ratio]'
1448 1467 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1449 1468 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
1450 1469 end
1451 1470
1452 1471 # Be sure we don't display inactive IssuePriorities
1453 1472 assert ! IssuePriority.find(15).active?
1454 1473 assert_select 'select[name=?]', 'issue[priority_id]' do
1455 1474 assert_select 'option[value=15]', 0
1456 1475 end
1457 1476 end
1458 1477
1459 1478 def test_get_new_with_minimal_permissions
1460 1479 Role.find(1).update_attribute :permissions, [:add_issues]
1461 1480 WorkflowTransition.delete_all :role_id => 1
1462 1481
1463 1482 @request.session[:user_id] = 2
1464 1483 get :new, :project_id => 1, :tracker_id => 1
1465 1484 assert_response :success
1466 1485 assert_template 'new'
1467 1486
1468 1487 assert_select 'form#issue-form' do
1469 1488 assert_select 'input[name=?]', 'issue[is_private]', 0
1470 1489 assert_select 'select[name=?]', 'issue[project_id]', 0
1471 1490 assert_select 'select[name=?]', 'issue[tracker_id]'
1472 1491 assert_select 'input[name=?]', 'issue[subject]'
1473 1492 assert_select 'textarea[name=?]', 'issue[description]'
1474 1493 assert_select 'select[name=?]', 'issue[status_id]'
1475 1494 assert_select 'select[name=?]', 'issue[priority_id]'
1476 1495 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1477 1496 assert_select 'select[name=?]', 'issue[category_id]'
1478 1497 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1479 1498 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1480 1499 assert_select 'input[name=?]', 'issue[start_date]'
1481 1500 assert_select 'input[name=?]', 'issue[due_date]'
1482 1501 assert_select 'select[name=?]', 'issue[done_ratio]'
1483 1502 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1484 1503 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1485 1504 end
1486 1505 end
1487 1506
1488 1507 def test_get_new_with_list_custom_field
1489 1508 @request.session[:user_id] = 2
1490 1509 get :new, :project_id => 1, :tracker_id => 1
1491 1510 assert_response :success
1492 1511 assert_template 'new'
1493 1512
1494 1513 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1495 1514 assert_select 'option', 4
1496 1515 assert_select 'option[value=MySQL]', :text => 'MySQL'
1497 1516 end
1498 1517 end
1499 1518
1500 1519 def test_get_new_with_multi_custom_field
1501 1520 field = IssueCustomField.find(1)
1502 1521 field.update_attribute :multiple, true
1503 1522
1504 1523 @request.session[:user_id] = 2
1505 1524 get :new, :project_id => 1, :tracker_id => 1
1506 1525 assert_response :success
1507 1526 assert_template 'new'
1508 1527
1509 1528 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1510 1529 assert_select 'option', 3
1511 1530 assert_select 'option[value=MySQL]', :text => 'MySQL'
1512 1531 end
1513 1532 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1514 1533 end
1515 1534
1516 1535 def test_get_new_with_multi_user_custom_field
1517 1536 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1518 1537 :tracker_ids => [1], :is_for_all => true)
1519 1538
1520 1539 @request.session[:user_id] = 2
1521 1540 get :new, :project_id => 1, :tracker_id => 1
1522 1541 assert_response :success
1523 1542 assert_template 'new'
1524 1543
1525 1544 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1526 1545 assert_select 'option', Project.find(1).users.count
1527 1546 assert_select 'option[value=2]', :text => 'John Smith'
1528 1547 end
1529 1548 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1530 1549 end
1531 1550
1532 1551 def test_get_new_with_date_custom_field
1533 1552 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1534 1553
1535 1554 @request.session[:user_id] = 2
1536 1555 get :new, :project_id => 1, :tracker_id => 1
1537 1556 assert_response :success
1538 1557
1539 1558 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1540 1559 end
1541 1560
1542 1561 def test_get_new_with_text_custom_field
1543 1562 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1544 1563
1545 1564 @request.session[:user_id] = 2
1546 1565 get :new, :project_id => 1, :tracker_id => 1
1547 1566 assert_response :success
1548 1567
1549 1568 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1550 1569 end
1551 1570
1552 1571 def test_get_new_without_default_start_date_is_creation_date
1553 1572 Setting.default_issue_start_date_to_creation_date = 0
1554 1573
1555 1574 @request.session[:user_id] = 2
1556 1575 get :new, :project_id => 1, :tracker_id => 1
1557 1576 assert_response :success
1558 1577 assert_template 'new'
1559 1578
1560 1579 assert_select 'input[name=?]', 'issue[start_date]'
1561 1580 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1562 1581 end
1563 1582
1564 1583 def test_get_new_with_default_start_date_is_creation_date
1565 1584 Setting.default_issue_start_date_to_creation_date = 1
1566 1585
1567 1586 @request.session[:user_id] = 2
1568 1587 get :new, :project_id => 1, :tracker_id => 1
1569 1588 assert_response :success
1570 1589 assert_template 'new'
1571 1590
1572 1591 assert_select 'input[name=?][value=?]', 'issue[start_date]', Date.today.to_s
1573 1592 end
1574 1593
1575 1594 def test_get_new_form_should_allow_attachment_upload
1576 1595 @request.session[:user_id] = 2
1577 1596 get :new, :project_id => 1, :tracker_id => 1
1578 1597
1579 1598 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
1580 1599 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
1581 1600 end
1582 1601 end
1583 1602
1584 1603 def test_get_new_should_prefill_the_form_from_params
1585 1604 @request.session[:user_id] = 2
1586 1605 get :new, :project_id => 1,
1587 1606 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1588 1607
1589 1608 issue = assigns(:issue)
1590 1609 assert_equal 3, issue.tracker_id
1591 1610 assert_equal 'Prefilled', issue.description
1592 1611 assert_equal 'Custom field value', issue.custom_field_value(2)
1593 1612
1594 1613 assert_select 'select[name=?]', 'issue[tracker_id]' do
1595 1614 assert_select 'option[value=3][selected=selected]'
1596 1615 end
1597 1616 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1598 1617 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1599 1618 end
1600 1619
1601 1620 def test_get_new_should_mark_required_fields
1602 1621 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1603 1622 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1604 1623 WorkflowPermission.delete_all
1605 1624 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1606 1625 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1607 1626 @request.session[:user_id] = 2
1608 1627
1609 1628 get :new, :project_id => 1
1610 1629 assert_response :success
1611 1630 assert_template 'new'
1612 1631
1613 1632 assert_select 'label[for=issue_start_date]' do
1614 1633 assert_select 'span[class=required]', 0
1615 1634 end
1616 1635 assert_select 'label[for=issue_due_date]' do
1617 1636 assert_select 'span[class=required]'
1618 1637 end
1619 1638 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1620 1639 assert_select 'span[class=required]', 0
1621 1640 end
1622 1641 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1623 1642 assert_select 'span[class=required]'
1624 1643 end
1625 1644 end
1626 1645
1627 1646 def test_get_new_should_not_display_readonly_fields
1628 1647 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1629 1648 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1630 1649 WorkflowPermission.delete_all
1631 1650 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1632 1651 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1633 1652 @request.session[:user_id] = 2
1634 1653
1635 1654 get :new, :project_id => 1
1636 1655 assert_response :success
1637 1656 assert_template 'new'
1638 1657
1639 1658 assert_select 'input[name=?]', 'issue[start_date]'
1640 1659 assert_select 'input[name=?]', 'issue[due_date]', 0
1641 1660 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1642 1661 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1643 1662 end
1644 1663
1645 1664 def test_get_new_without_tracker_id
1646 1665 @request.session[:user_id] = 2
1647 1666 get :new, :project_id => 1
1648 1667 assert_response :success
1649 1668 assert_template 'new'
1650 1669
1651 1670 issue = assigns(:issue)
1652 1671 assert_not_nil issue
1653 1672 assert_equal Project.find(1).trackers.first, issue.tracker
1654 1673 end
1655 1674
1656 1675 def test_get_new_with_no_default_status_should_display_an_error
1657 1676 @request.session[:user_id] = 2
1658 1677 IssueStatus.delete_all
1659 1678
1660 1679 get :new, :project_id => 1
1661 1680 assert_response 500
1662 1681 assert_error_tag :content => /No default issue/
1663 1682 end
1664 1683
1665 1684 def test_get_new_with_no_tracker_should_display_an_error
1666 1685 @request.session[:user_id] = 2
1667 1686 Tracker.delete_all
1668 1687
1669 1688 get :new, :project_id => 1
1670 1689 assert_response 500
1671 1690 assert_error_tag :content => /No tracker/
1672 1691 end
1673 1692
1674 1693 def test_update_form_for_new_issue
1675 1694 @request.session[:user_id] = 2
1676 1695 xhr :post, :update_form, :project_id => 1,
1677 1696 :issue => {:tracker_id => 2,
1678 1697 :subject => 'This is the test_new issue',
1679 1698 :description => 'This is the description',
1680 1699 :priority_id => 5}
1681 1700 assert_response :success
1682 1701 assert_template 'update_form'
1683 1702 assert_template 'form'
1684 1703 assert_equal 'text/javascript', response.content_type
1685 1704
1686 1705 issue = assigns(:issue)
1687 1706 assert_kind_of Issue, issue
1688 1707 assert_equal 1, issue.project_id
1689 1708 assert_equal 2, issue.tracker_id
1690 1709 assert_equal 'This is the test_new issue', issue.subject
1691 1710 end
1692 1711
1693 1712 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
1694 1713 @request.session[:user_id] = 2
1695 1714 WorkflowTransition.delete_all
1696 1715 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
1697 1716 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1698 1717 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1699 1718
1700 1719 xhr :post, :update_form, :project_id => 1,
1701 1720 :issue => {:tracker_id => 1,
1702 1721 :status_id => 5,
1703 1722 :subject => 'This is an issue'}
1704 1723
1705 1724 assert_equal 5, assigns(:issue).status_id
1706 1725 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
1707 1726 end
1708 1727
1709 1728 def test_post_create
1710 1729 @request.session[:user_id] = 2
1711 1730 assert_difference 'Issue.count' do
1712 1731 post :create, :project_id => 1,
1713 1732 :issue => {:tracker_id => 3,
1714 1733 :status_id => 2,
1715 1734 :subject => 'This is the test_new issue',
1716 1735 :description => 'This is the description',
1717 1736 :priority_id => 5,
1718 1737 :start_date => '2010-11-07',
1719 1738 :estimated_hours => '',
1720 1739 :custom_field_values => {'2' => 'Value for field 2'}}
1721 1740 end
1722 1741 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1723 1742
1724 1743 issue = Issue.find_by_subject('This is the test_new issue')
1725 1744 assert_not_nil issue
1726 1745 assert_equal 2, issue.author_id
1727 1746 assert_equal 3, issue.tracker_id
1728 1747 assert_equal 2, issue.status_id
1729 1748 assert_equal Date.parse('2010-11-07'), issue.start_date
1730 1749 assert_nil issue.estimated_hours
1731 1750 v = issue.custom_values.where(:custom_field_id => 2).first
1732 1751 assert_not_nil v
1733 1752 assert_equal 'Value for field 2', v.value
1734 1753 end
1735 1754
1736 1755 def test_post_new_with_group_assignment
1737 1756 group = Group.find(11)
1738 1757 project = Project.find(1)
1739 1758 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1740 1759
1741 1760 with_settings :issue_group_assignment => '1' do
1742 1761 @request.session[:user_id] = 2
1743 1762 assert_difference 'Issue.count' do
1744 1763 post :create, :project_id => project.id,
1745 1764 :issue => {:tracker_id => 3,
1746 1765 :status_id => 1,
1747 1766 :subject => 'This is the test_new_with_group_assignment issue',
1748 1767 :assigned_to_id => group.id}
1749 1768 end
1750 1769 end
1751 1770 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1752 1771
1753 1772 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1754 1773 assert_not_nil issue
1755 1774 assert_equal group, issue.assigned_to
1756 1775 end
1757 1776
1758 1777 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1759 1778 Setting.default_issue_start_date_to_creation_date = 0
1760 1779
1761 1780 @request.session[:user_id] = 2
1762 1781 assert_difference 'Issue.count' do
1763 1782 post :create, :project_id => 1,
1764 1783 :issue => {:tracker_id => 3,
1765 1784 :status_id => 2,
1766 1785 :subject => 'This is the test_new issue',
1767 1786 :description => 'This is the description',
1768 1787 :priority_id => 5,
1769 1788 :estimated_hours => '',
1770 1789 :custom_field_values => {'2' => 'Value for field 2'}}
1771 1790 end
1772 1791 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1773 1792
1774 1793 issue = Issue.find_by_subject('This is the test_new issue')
1775 1794 assert_not_nil issue
1776 1795 assert_nil issue.start_date
1777 1796 end
1778 1797
1779 1798 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1780 1799 Setting.default_issue_start_date_to_creation_date = 1
1781 1800
1782 1801 @request.session[:user_id] = 2
1783 1802 assert_difference 'Issue.count' do
1784 1803 post :create, :project_id => 1,
1785 1804 :issue => {:tracker_id => 3,
1786 1805 :status_id => 2,
1787 1806 :subject => 'This is the test_new issue',
1788 1807 :description => 'This is the description',
1789 1808 :priority_id => 5,
1790 1809 :estimated_hours => '',
1791 1810 :custom_field_values => {'2' => 'Value for field 2'}}
1792 1811 end
1793 1812 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1794 1813
1795 1814 issue = Issue.find_by_subject('This is the test_new issue')
1796 1815 assert_not_nil issue
1797 1816 assert_equal Date.today, issue.start_date
1798 1817 end
1799 1818
1800 1819 def test_post_create_and_continue
1801 1820 @request.session[:user_id] = 2
1802 1821 assert_difference 'Issue.count' do
1803 1822 post :create, :project_id => 1,
1804 1823 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1805 1824 :continue => ''
1806 1825 end
1807 1826
1808 1827 issue = Issue.first(:order => 'id DESC')
1809 1828 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1810 1829 assert_not_nil flash[:notice], "flash was not set"
1811 1830 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message"
1812 1831 end
1813 1832
1814 1833 def test_post_create_without_custom_fields_param
1815 1834 @request.session[:user_id] = 2
1816 1835 assert_difference 'Issue.count' do
1817 1836 post :create, :project_id => 1,
1818 1837 :issue => {:tracker_id => 1,
1819 1838 :subject => 'This is the test_new issue',
1820 1839 :description => 'This is the description',
1821 1840 :priority_id => 5}
1822 1841 end
1823 1842 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1824 1843 end
1825 1844
1826 1845 def test_post_create_with_multi_custom_field
1827 1846 field = IssueCustomField.find_by_name('Database')
1828 1847 field.update_attribute(:multiple, true)
1829 1848
1830 1849 @request.session[:user_id] = 2
1831 1850 assert_difference 'Issue.count' do
1832 1851 post :create, :project_id => 1,
1833 1852 :issue => {:tracker_id => 1,
1834 1853 :subject => 'This is the test_new issue',
1835 1854 :description => 'This is the description',
1836 1855 :priority_id => 5,
1837 1856 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1838 1857 end
1839 1858 assert_response 302
1840 1859 issue = Issue.first(:order => 'id DESC')
1841 1860 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1842 1861 end
1843 1862
1844 1863 def test_post_create_with_empty_multi_custom_field
1845 1864 field = IssueCustomField.find_by_name('Database')
1846 1865 field.update_attribute(:multiple, true)
1847 1866
1848 1867 @request.session[:user_id] = 2
1849 1868 assert_difference 'Issue.count' do
1850 1869 post :create, :project_id => 1,
1851 1870 :issue => {:tracker_id => 1,
1852 1871 :subject => 'This is the test_new issue',
1853 1872 :description => 'This is the description',
1854 1873 :priority_id => 5,
1855 1874 :custom_field_values => {'1' => ['']}}
1856 1875 end
1857 1876 assert_response 302
1858 1877 issue = Issue.first(:order => 'id DESC')
1859 1878 assert_equal [''], issue.custom_field_value(1).sort
1860 1879 end
1861 1880
1862 1881 def test_post_create_with_multi_user_custom_field
1863 1882 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1864 1883 :tracker_ids => [1], :is_for_all => true)
1865 1884
1866 1885 @request.session[:user_id] = 2
1867 1886 assert_difference 'Issue.count' do
1868 1887 post :create, :project_id => 1,
1869 1888 :issue => {:tracker_id => 1,
1870 1889 :subject => 'This is the test_new issue',
1871 1890 :description => 'This is the description',
1872 1891 :priority_id => 5,
1873 1892 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1874 1893 end
1875 1894 assert_response 302
1876 1895 issue = Issue.first(:order => 'id DESC')
1877 1896 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1878 1897 end
1879 1898
1880 1899 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1881 1900 field = IssueCustomField.find_by_name('Database')
1882 1901 field.update_attribute(:is_required, true)
1883 1902
1884 1903 @request.session[:user_id] = 2
1885 1904 assert_no_difference 'Issue.count' do
1886 1905 post :create, :project_id => 1,
1887 1906 :issue => {:tracker_id => 1,
1888 1907 :subject => 'This is the test_new issue',
1889 1908 :description => 'This is the description',
1890 1909 :priority_id => 5}
1891 1910 end
1892 1911 assert_response :success
1893 1912 assert_template 'new'
1894 1913 issue = assigns(:issue)
1895 1914 assert_not_nil issue
1896 1915 assert_error_tag :content => /Database can&#x27;t be blank/
1897 1916 end
1898 1917
1899 1918 def test_create_should_validate_required_fields
1900 1919 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1901 1920 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1902 1921 WorkflowPermission.delete_all
1903 1922 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1904 1923 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1905 1924 @request.session[:user_id] = 2
1906 1925
1907 1926 assert_no_difference 'Issue.count' do
1908 1927 post :create, :project_id => 1, :issue => {
1909 1928 :tracker_id => 2,
1910 1929 :status_id => 1,
1911 1930 :subject => 'Test',
1912 1931 :start_date => '',
1913 1932 :due_date => '',
1914 1933 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
1915 1934 }
1916 1935 assert_response :success
1917 1936 assert_template 'new'
1918 1937 end
1919 1938
1920 1939 assert_error_tag :content => /Due date can&#x27;t be blank/i
1921 1940 assert_error_tag :content => /Bar can&#x27;t be blank/i
1922 1941 end
1923 1942
1924 1943 def test_create_should_ignore_readonly_fields
1925 1944 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1926 1945 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1927 1946 WorkflowPermission.delete_all
1928 1947 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1929 1948 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1930 1949 @request.session[:user_id] = 2
1931 1950
1932 1951 assert_difference 'Issue.count' do
1933 1952 post :create, :project_id => 1, :issue => {
1934 1953 :tracker_id => 2,
1935 1954 :status_id => 1,
1936 1955 :subject => 'Test',
1937 1956 :start_date => '2012-07-14',
1938 1957 :due_date => '2012-07-16',
1939 1958 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
1940 1959 }
1941 1960 assert_response 302
1942 1961 end
1943 1962
1944 1963 issue = Issue.first(:order => 'id DESC')
1945 1964 assert_equal Date.parse('2012-07-14'), issue.start_date
1946 1965 assert_nil issue.due_date
1947 1966 assert_equal 'value1', issue.custom_field_value(cf1)
1948 1967 assert_nil issue.custom_field_value(cf2)
1949 1968 end
1950 1969
1951 1970 def test_post_create_with_watchers
1952 1971 @request.session[:user_id] = 2
1953 1972 ActionMailer::Base.deliveries.clear
1954 1973
1955 1974 assert_difference 'Watcher.count', 2 do
1956 1975 post :create, :project_id => 1,
1957 1976 :issue => {:tracker_id => 1,
1958 1977 :subject => 'This is a new issue with watchers',
1959 1978 :description => 'This is the description',
1960 1979 :priority_id => 5,
1961 1980 :watcher_user_ids => ['2', '3']}
1962 1981 end
1963 1982 issue = Issue.find_by_subject('This is a new issue with watchers')
1964 1983 assert_not_nil issue
1965 1984 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1966 1985
1967 1986 # Watchers added
1968 1987 assert_equal [2, 3], issue.watcher_user_ids.sort
1969 1988 assert issue.watched_by?(User.find(3))
1970 1989 # Watchers notified
1971 1990 mail = ActionMailer::Base.deliveries.last
1972 1991 assert_not_nil mail
1973 1992 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1974 1993 end
1975 1994
1976 1995 def test_post_create_subissue
1977 1996 @request.session[:user_id] = 2
1978 1997
1979 1998 assert_difference 'Issue.count' do
1980 1999 post :create, :project_id => 1,
1981 2000 :issue => {:tracker_id => 1,
1982 2001 :subject => 'This is a child issue',
1983 2002 :parent_issue_id => '2'}
1984 2003 assert_response 302
1985 2004 end
1986 2005 issue = Issue.order('id DESC').first
1987 2006 assert_equal Issue.find(2), issue.parent
1988 2007 end
1989 2008
1990 2009 def test_post_create_subissue_with_sharp_parent_id
1991 2010 @request.session[:user_id] = 2
1992 2011
1993 2012 assert_difference 'Issue.count' do
1994 2013 post :create, :project_id => 1,
1995 2014 :issue => {:tracker_id => 1,
1996 2015 :subject => 'This is a child issue',
1997 2016 :parent_issue_id => '#2'}
1998 2017 assert_response 302
1999 2018 end
2000 2019 issue = Issue.order('id DESC').first
2001 2020 assert_equal Issue.find(2), issue.parent
2002 2021 end
2003 2022
2004 2023 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
2005 2024 @request.session[:user_id] = 2
2006 2025
2007 2026 assert_no_difference 'Issue.count' do
2008 2027 post :create, :project_id => 1,
2009 2028 :issue => {:tracker_id => 1,
2010 2029 :subject => 'This is a child issue',
2011 2030 :parent_issue_id => '4'}
2012 2031
2013 2032 assert_response :success
2014 2033 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
2015 2034 assert_error_tag :content => /Parent task is invalid/i
2016 2035 end
2017 2036 end
2018 2037
2019 2038 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
2020 2039 @request.session[:user_id] = 2
2021 2040
2022 2041 assert_no_difference 'Issue.count' do
2023 2042 post :create, :project_id => 1,
2024 2043 :issue => {:tracker_id => 1,
2025 2044 :subject => 'This is a child issue',
2026 2045 :parent_issue_id => '01ABC'}
2027 2046
2028 2047 assert_response :success
2029 2048 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2030 2049 assert_error_tag :content => /Parent task is invalid/i
2031 2050 end
2032 2051 end
2033 2052
2034 2053 def test_post_create_private
2035 2054 @request.session[:user_id] = 2
2036 2055
2037 2056 assert_difference 'Issue.count' do
2038 2057 post :create, :project_id => 1,
2039 2058 :issue => {:tracker_id => 1,
2040 2059 :subject => 'This is a private issue',
2041 2060 :is_private => '1'}
2042 2061 end
2043 2062 issue = Issue.first(:order => 'id DESC')
2044 2063 assert issue.is_private?
2045 2064 end
2046 2065
2047 2066 def test_post_create_private_with_set_own_issues_private_permission
2048 2067 role = Role.find(1)
2049 2068 role.remove_permission! :set_issues_private
2050 2069 role.add_permission! :set_own_issues_private
2051 2070
2052 2071 @request.session[:user_id] = 2
2053 2072
2054 2073 assert_difference 'Issue.count' do
2055 2074 post :create, :project_id => 1,
2056 2075 :issue => {:tracker_id => 1,
2057 2076 :subject => 'This is a private issue',
2058 2077 :is_private => '1'}
2059 2078 end
2060 2079 issue = Issue.first(:order => 'id DESC')
2061 2080 assert issue.is_private?
2062 2081 end
2063 2082
2064 2083 def test_post_create_should_send_a_notification
2065 2084 ActionMailer::Base.deliveries.clear
2066 2085 @request.session[:user_id] = 2
2067 2086 assert_difference 'Issue.count' do
2068 2087 post :create, :project_id => 1,
2069 2088 :issue => {:tracker_id => 3,
2070 2089 :subject => 'This is the test_new issue',
2071 2090 :description => 'This is the description',
2072 2091 :priority_id => 5,
2073 2092 :estimated_hours => '',
2074 2093 :custom_field_values => {'2' => 'Value for field 2'}}
2075 2094 end
2076 2095 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2077 2096
2078 2097 assert_equal 1, ActionMailer::Base.deliveries.size
2079 2098 end
2080 2099
2081 2100 def test_post_create_should_preserve_fields_values_on_validation_failure
2082 2101 @request.session[:user_id] = 2
2083 2102 post :create, :project_id => 1,
2084 2103 :issue => {:tracker_id => 1,
2085 2104 # empty subject
2086 2105 :subject => '',
2087 2106 :description => 'This is a description',
2088 2107 :priority_id => 6,
2089 2108 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2090 2109 assert_response :success
2091 2110 assert_template 'new'
2092 2111
2093 2112 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
2094 2113 assert_select 'select[name=?]', 'issue[priority_id]' do
2095 2114 assert_select 'option[value=6][selected=selected]', :text => 'High'
2096 2115 end
2097 2116 # Custom fields
2098 2117 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
2099 2118 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
2100 2119 end
2101 2120 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
2102 2121 end
2103 2122
2104 2123 def test_post_create_with_failure_should_preserve_watchers
2105 2124 assert !User.find(8).member_of?(Project.find(1))
2106 2125
2107 2126 @request.session[:user_id] = 2
2108 2127 post :create, :project_id => 1,
2109 2128 :issue => {:tracker_id => 1,
2110 2129 :watcher_user_ids => ['3', '8']}
2111 2130 assert_response :success
2112 2131 assert_template 'new'
2113 2132
2114 2133 assert_select 'input[name=?][value=2]:not(checked)', 'issue[watcher_user_ids][]'
2115 2134 assert_select 'input[name=?][value=3][checked=checked]', 'issue[watcher_user_ids][]'
2116 2135 assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]'
2117 2136 end
2118 2137
2119 2138 def test_post_create_should_ignore_non_safe_attributes
2120 2139 @request.session[:user_id] = 2
2121 2140 assert_nothing_raised do
2122 2141 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2123 2142 end
2124 2143 end
2125 2144
2126 2145 def test_post_create_with_attachment
2127 2146 set_tmp_attachments_directory
2128 2147 @request.session[:user_id] = 2
2129 2148
2130 2149 assert_difference 'Issue.count' do
2131 2150 assert_difference 'Attachment.count' do
2132 2151 post :create, :project_id => 1,
2133 2152 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2134 2153 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2135 2154 end
2136 2155 end
2137 2156
2138 2157 issue = Issue.first(:order => 'id DESC')
2139 2158 attachment = Attachment.first(:order => 'id DESC')
2140 2159
2141 2160 assert_equal issue, attachment.container
2142 2161 assert_equal 2, attachment.author_id
2143 2162 assert_equal 'testfile.txt', attachment.filename
2144 2163 assert_equal 'text/plain', attachment.content_type
2145 2164 assert_equal 'test file', attachment.description
2146 2165 assert_equal 59, attachment.filesize
2147 2166 assert File.exists?(attachment.diskfile)
2148 2167 assert_equal 59, File.size(attachment.diskfile)
2149 2168 end
2150 2169
2151 2170 def test_post_create_with_failure_should_save_attachments
2152 2171 set_tmp_attachments_directory
2153 2172 @request.session[:user_id] = 2
2154 2173
2155 2174 assert_no_difference 'Issue.count' do
2156 2175 assert_difference 'Attachment.count' do
2157 2176 post :create, :project_id => 1,
2158 2177 :issue => { :tracker_id => '1', :subject => '' },
2159 2178 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2160 2179 assert_response :success
2161 2180 assert_template 'new'
2162 2181 end
2163 2182 end
2164 2183
2165 2184 attachment = Attachment.first(:order => 'id DESC')
2166 2185 assert_equal 'testfile.txt', attachment.filename
2167 2186 assert File.exists?(attachment.diskfile)
2168 2187 assert_nil attachment.container
2169 2188
2170 2189 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2171 2190 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2172 2191 end
2173 2192
2174 2193 def test_post_create_with_failure_should_keep_saved_attachments
2175 2194 set_tmp_attachments_directory
2176 2195 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2177 2196 @request.session[:user_id] = 2
2178 2197
2179 2198 assert_no_difference 'Issue.count' do
2180 2199 assert_no_difference 'Attachment.count' do
2181 2200 post :create, :project_id => 1,
2182 2201 :issue => { :tracker_id => '1', :subject => '' },
2183 2202 :attachments => {'p0' => {'token' => attachment.token}}
2184 2203 assert_response :success
2185 2204 assert_template 'new'
2186 2205 end
2187 2206 end
2188 2207
2189 2208 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2190 2209 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2191 2210 end
2192 2211
2193 2212 def test_post_create_should_attach_saved_attachments
2194 2213 set_tmp_attachments_directory
2195 2214 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2196 2215 @request.session[:user_id] = 2
2197 2216
2198 2217 assert_difference 'Issue.count' do
2199 2218 assert_no_difference 'Attachment.count' do
2200 2219 post :create, :project_id => 1,
2201 2220 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2202 2221 :attachments => {'p0' => {'token' => attachment.token}}
2203 2222 assert_response 302
2204 2223 end
2205 2224 end
2206 2225
2207 2226 issue = Issue.first(:order => 'id DESC')
2208 2227 assert_equal 1, issue.attachments.count
2209 2228
2210 2229 attachment.reload
2211 2230 assert_equal issue, attachment.container
2212 2231 end
2213 2232
2214 2233 context "without workflow privilege" do
2215 2234 setup do
2216 2235 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2217 2236 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2218 2237 end
2219 2238
2220 2239 context "#new" do
2221 2240 should "propose default status only" do
2222 2241 get :new, :project_id => 1
2223 2242 assert_response :success
2224 2243 assert_template 'new'
2225 2244 assert_select 'select[name=?]', 'issue[status_id]' do
2226 2245 assert_select 'option', 1
2227 2246 assert_select 'option[value=?]', IssueStatus.default.id.to_s
2228 2247 end
2229 2248 end
2230 2249
2231 2250 should "accept default status" do
2232 2251 assert_difference 'Issue.count' do
2233 2252 post :create, :project_id => 1,
2234 2253 :issue => {:tracker_id => 1,
2235 2254 :subject => 'This is an issue',
2236 2255 :status_id => 1}
2237 2256 end
2238 2257 issue = Issue.last(:order => 'id')
2239 2258 assert_equal IssueStatus.default, issue.status
2240 2259 end
2241 2260
2242 2261 should "ignore unauthorized status" do
2243 2262 assert_difference 'Issue.count' do
2244 2263 post :create, :project_id => 1,
2245 2264 :issue => {:tracker_id => 1,
2246 2265 :subject => 'This is an issue',
2247 2266 :status_id => 3}
2248 2267 end
2249 2268 issue = Issue.last(:order => 'id')
2250 2269 assert_equal IssueStatus.default, issue.status
2251 2270 end
2252 2271 end
2253 2272
2254 2273 context "#update" do
2255 2274 should "ignore status change" do
2256 2275 assert_difference 'Journal.count' do
2257 2276 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2258 2277 end
2259 2278 assert_equal 1, Issue.find(1).status_id
2260 2279 end
2261 2280
2262 2281 should "ignore attributes changes" do
2263 2282 assert_difference 'Journal.count' do
2264 2283 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2265 2284 end
2266 2285 issue = Issue.find(1)
2267 2286 assert_equal "Can't print recipes", issue.subject
2268 2287 assert_nil issue.assigned_to
2269 2288 end
2270 2289 end
2271 2290 end
2272 2291
2273 2292 context "with workflow privilege" do
2274 2293 setup do
2275 2294 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2276 2295 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2277 2296 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2278 2297 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2279 2298 end
2280 2299
2281 2300 context "#update" do
2282 2301 should "accept authorized status" do
2283 2302 assert_difference 'Journal.count' do
2284 2303 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2285 2304 end
2286 2305 assert_equal 3, Issue.find(1).status_id
2287 2306 end
2288 2307
2289 2308 should "ignore unauthorized status" do
2290 2309 assert_difference 'Journal.count' do
2291 2310 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2292 2311 end
2293 2312 assert_equal 1, Issue.find(1).status_id
2294 2313 end
2295 2314
2296 2315 should "accept authorized attributes changes" do
2297 2316 assert_difference 'Journal.count' do
2298 2317 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
2299 2318 end
2300 2319 issue = Issue.find(1)
2301 2320 assert_equal 2, issue.assigned_to_id
2302 2321 end
2303 2322
2304 2323 should "ignore unauthorized attributes changes" do
2305 2324 assert_difference 'Journal.count' do
2306 2325 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
2307 2326 end
2308 2327 issue = Issue.find(1)
2309 2328 assert_equal "Can't print recipes", issue.subject
2310 2329 end
2311 2330 end
2312 2331
2313 2332 context "and :edit_issues permission" do
2314 2333 setup do
2315 2334 Role.anonymous.add_permission! :add_issues, :edit_issues
2316 2335 end
2317 2336
2318 2337 should "accept authorized status" do
2319 2338 assert_difference 'Journal.count' do
2320 2339 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2321 2340 end
2322 2341 assert_equal 3, Issue.find(1).status_id
2323 2342 end
2324 2343
2325 2344 should "ignore unauthorized status" do
2326 2345 assert_difference 'Journal.count' do
2327 2346 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2328 2347 end
2329 2348 assert_equal 1, Issue.find(1).status_id
2330 2349 end
2331 2350
2332 2351 should "accept authorized attributes changes" do
2333 2352 assert_difference 'Journal.count' do
2334 2353 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2335 2354 end
2336 2355 issue = Issue.find(1)
2337 2356 assert_equal "changed", issue.subject
2338 2357 assert_equal 2, issue.assigned_to_id
2339 2358 end
2340 2359 end
2341 2360 end
2342 2361
2343 2362 def test_new_as_copy
2344 2363 @request.session[:user_id] = 2
2345 2364 get :new, :project_id => 1, :copy_from => 1
2346 2365
2347 2366 assert_response :success
2348 2367 assert_template 'new'
2349 2368
2350 2369 assert_not_nil assigns(:issue)
2351 2370 orig = Issue.find(1)
2352 2371 assert_equal 1, assigns(:issue).project_id
2353 2372 assert_equal orig.subject, assigns(:issue).subject
2354 2373 assert assigns(:issue).copy?
2355 2374
2356 2375 assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do
2357 2376 assert_select 'select[name=?]', 'issue[project_id]' do
2358 2377 assert_select 'option[value=1][selected=selected]', :text => 'eCookbook'
2359 2378 assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore'
2360 2379 end
2361 2380 assert_select 'input[name=copy_from][value=1]'
2362 2381 end
2363 2382
2364 2383 # "New issue" menu item should not link to copy
2365 2384 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]'
2366 2385 end
2367 2386
2368 2387 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2369 2388 @request.session[:user_id] = 2
2370 2389 issue = Issue.find(3)
2371 2390 assert issue.attachments.count > 0
2372 2391 get :new, :project_id => 1, :copy_from => 3
2373 2392
2374 2393 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]'
2375 2394 end
2376 2395
2377 2396 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2378 2397 @request.session[:user_id] = 2
2379 2398 issue = Issue.find(3)
2380 2399 issue.attachments.delete_all
2381 2400 get :new, :project_id => 1, :copy_from => 3
2382 2401
2383 2402 assert_select 'input[name=copy_attachments]', 0
2384 2403 end
2385 2404
2386 2405 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2387 2406 @request.session[:user_id] = 2
2388 2407 issue = Issue.generate_with_descendants!
2389 2408 get :new, :project_id => 1, :copy_from => issue.id
2390 2409
2391 2410 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]'
2392 2411 end
2393 2412
2394 2413 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2395 2414 @request.session[:user_id] = 2
2396 2415 get :new, :project_id => 1, :copy_from => 99999
2397 2416 assert_response 404
2398 2417 end
2399 2418
2400 2419 def test_create_as_copy_on_different_project
2401 2420 @request.session[:user_id] = 2
2402 2421 assert_difference 'Issue.count' do
2403 2422 post :create, :project_id => 1, :copy_from => 1,
2404 2423 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2405 2424
2406 2425 assert_not_nil assigns(:issue)
2407 2426 assert assigns(:issue).copy?
2408 2427 end
2409 2428 issue = Issue.first(:order => 'id DESC')
2410 2429 assert_redirected_to "/issues/#{issue.id}"
2411 2430
2412 2431 assert_equal 2, issue.project_id
2413 2432 assert_equal 3, issue.tracker_id
2414 2433 assert_equal 'Copy', issue.subject
2415 2434 end
2416 2435
2417 2436 def test_create_as_copy_should_copy_attachments
2418 2437 @request.session[:user_id] = 2
2419 2438 issue = Issue.find(3)
2420 2439 count = issue.attachments.count
2421 2440 assert count > 0
2422 2441
2423 2442 assert_difference 'Issue.count' do
2424 2443 assert_difference 'Attachment.count', count do
2425 2444 assert_no_difference 'Journal.count' do
2426 2445 post :create, :project_id => 1, :copy_from => 3,
2427 2446 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2428 2447 :copy_attachments => '1'
2429 2448 end
2430 2449 end
2431 2450 end
2432 2451 copy = Issue.first(:order => 'id DESC')
2433 2452 assert_equal count, copy.attachments.count
2434 2453 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2435 2454 end
2436 2455
2437 2456 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2438 2457 @request.session[:user_id] = 2
2439 2458 issue = Issue.find(3)
2440 2459 count = issue.attachments.count
2441 2460 assert count > 0
2442 2461
2443 2462 assert_difference 'Issue.count' do
2444 2463 assert_no_difference 'Attachment.count' do
2445 2464 assert_no_difference 'Journal.count' do
2446 2465 post :create, :project_id => 1, :copy_from => 3,
2447 2466 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2448 2467 end
2449 2468 end
2450 2469 end
2451 2470 copy = Issue.first(:order => 'id DESC')
2452 2471 assert_equal 0, copy.attachments.count
2453 2472 end
2454 2473
2455 2474 def test_create_as_copy_with_attachments_should_add_new_files
2456 2475 @request.session[:user_id] = 2
2457 2476 issue = Issue.find(3)
2458 2477 count = issue.attachments.count
2459 2478 assert count > 0
2460 2479
2461 2480 assert_difference 'Issue.count' do
2462 2481 assert_difference 'Attachment.count', count + 1 do
2463 2482 assert_no_difference 'Journal.count' do
2464 2483 post :create, :project_id => 1, :copy_from => 3,
2465 2484 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2466 2485 :copy_attachments => '1',
2467 2486 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2468 2487 end
2469 2488 end
2470 2489 end
2471 2490 copy = Issue.first(:order => 'id DESC')
2472 2491 assert_equal count + 1, copy.attachments.count
2473 2492 end
2474 2493
2475 2494 def test_create_as_copy_should_add_relation_with_copied_issue
2476 2495 @request.session[:user_id] = 2
2477 2496
2478 2497 assert_difference 'Issue.count' do
2479 2498 assert_difference 'IssueRelation.count' do
2480 2499 post :create, :project_id => 1, :copy_from => 1,
2481 2500 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2482 2501 end
2483 2502 end
2484 2503 copy = Issue.first(:order => 'id DESC')
2485 2504 assert_equal 1, copy.relations.size
2486 2505 end
2487 2506
2488 2507 def test_create_as_copy_should_copy_subtasks
2489 2508 @request.session[:user_id] = 2
2490 2509 issue = Issue.generate_with_descendants!
2491 2510 count = issue.descendants.count
2492 2511
2493 2512 assert_difference 'Issue.count', count+1 do
2494 2513 assert_no_difference 'Journal.count' do
2495 2514 post :create, :project_id => 1, :copy_from => issue.id,
2496 2515 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'},
2497 2516 :copy_subtasks => '1'
2498 2517 end
2499 2518 end
2500 2519 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2501 2520 assert_equal count, copy.descendants.count
2502 2521 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2503 2522 end
2504 2523
2505 2524 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2506 2525 @request.session[:user_id] = 2
2507 2526 issue = Issue.generate_with_descendants!
2508 2527
2509 2528 assert_difference 'Issue.count', 1 do
2510 2529 assert_no_difference 'Journal.count' do
2511 2530 post :create, :project_id => 1, :copy_from => 3,
2512 2531 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'}
2513 2532 end
2514 2533 end
2515 2534 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2516 2535 assert_equal 0, copy.descendants.count
2517 2536 end
2518 2537
2519 2538 def test_create_as_copy_with_failure
2520 2539 @request.session[:user_id] = 2
2521 2540 post :create, :project_id => 1, :copy_from => 1,
2522 2541 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2523 2542
2524 2543 assert_response :success
2525 2544 assert_template 'new'
2526 2545
2527 2546 assert_not_nil assigns(:issue)
2528 2547 assert assigns(:issue).copy?
2529 2548
2530 2549 assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do
2531 2550 assert_select 'select[name=?]', 'issue[project_id]' do
2532 2551 assert_select 'option[value=1]:not([selected])', :text => 'eCookbook'
2533 2552 assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore'
2534 2553 end
2535 2554 assert_select 'input[name=copy_from][value=1]'
2536 2555 end
2537 2556 end
2538 2557
2539 2558 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2540 2559 @request.session[:user_id] = 2
2541 2560 assert !User.find(2).member_of?(Project.find(4))
2542 2561
2543 2562 assert_difference 'Issue.count' do
2544 2563 post :create, :project_id => 1, :copy_from => 1,
2545 2564 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2546 2565 end
2547 2566 issue = Issue.first(:order => 'id DESC')
2548 2567 assert_equal 1, issue.project_id
2549 2568 end
2550 2569
2551 2570 def test_get_edit
2552 2571 @request.session[:user_id] = 2
2553 2572 get :edit, :id => 1
2554 2573 assert_response :success
2555 2574 assert_template 'edit'
2556 2575 assert_not_nil assigns(:issue)
2557 2576 assert_equal Issue.find(1), assigns(:issue)
2558 2577
2559 2578 # Be sure we don't display inactive IssuePriorities
2560 2579 assert ! IssuePriority.find(15).active?
2561 2580 assert_select 'select[name=?]', 'issue[priority_id]' do
2562 2581 assert_select 'option[value=15]', 0
2563 2582 end
2564 2583 end
2565 2584
2566 2585 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2567 2586 @request.session[:user_id] = 2
2568 2587 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2569 2588
2570 2589 get :edit, :id => 1
2571 2590 assert_select 'input[name=?]', 'time_entry[hours]'
2572 2591 end
2573 2592
2574 2593 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2575 2594 @request.session[:user_id] = 2
2576 2595 Role.find_by_name('Manager').remove_permission! :log_time
2577 2596
2578 2597 get :edit, :id => 1
2579 2598 assert_select 'input[name=?]', 'time_entry[hours]', 0
2580 2599 end
2581 2600
2582 2601 def test_get_edit_with_params
2583 2602 @request.session[:user_id] = 2
2584 2603 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2585 2604 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
2586 2605 assert_response :success
2587 2606 assert_template 'edit'
2588 2607
2589 2608 issue = assigns(:issue)
2590 2609 assert_not_nil issue
2591 2610
2592 2611 assert_equal 5, issue.status_id
2593 2612 assert_select 'select[name=?]', 'issue[status_id]' do
2594 2613 assert_select 'option[value=5][selected=selected]', :text => 'Closed'
2595 2614 end
2596 2615
2597 2616 assert_equal 7, issue.priority_id
2598 2617 assert_select 'select[name=?]', 'issue[priority_id]' do
2599 2618 assert_select 'option[value=7][selected=selected]', :text => 'Urgent'
2600 2619 end
2601 2620
2602 2621 assert_select 'input[name=?][value=2.5]', 'time_entry[hours]'
2603 2622 assert_select 'select[name=?]', 'time_entry[activity_id]' do
2604 2623 assert_select 'option[value=10][selected=selected]', :text => 'Development'
2605 2624 end
2606 2625 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
2607 2626 end
2608 2627
2609 2628 def test_get_edit_with_multi_custom_field
2610 2629 field = CustomField.find(1)
2611 2630 field.update_attribute :multiple, true
2612 2631 issue = Issue.find(1)
2613 2632 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2614 2633 issue.save!
2615 2634
2616 2635 @request.session[:user_id] = 2
2617 2636 get :edit, :id => 1
2618 2637 assert_response :success
2619 2638 assert_template 'edit'
2620 2639
2621 2640 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
2622 2641 assert_select 'option', 3
2623 2642 assert_select 'option[value=MySQL][selected=selected]'
2624 2643 assert_select 'option[value=Oracle][selected=selected]'
2625 2644 assert_select 'option[value=PostgreSQL]:not([selected])'
2626 2645 end
2627 2646 end
2628 2647
2629 2648 def test_update_form_for_existing_issue
2630 2649 @request.session[:user_id] = 2
2631 2650 xhr :put, :update_form, :project_id => 1,
2632 2651 :id => 1,
2633 2652 :issue => {:tracker_id => 2,
2634 2653 :subject => 'This is the test_new issue',
2635 2654 :description => 'This is the description',
2636 2655 :priority_id => 5}
2637 2656 assert_response :success
2638 2657 assert_equal 'text/javascript', response.content_type
2639 2658 assert_template 'update_form'
2640 2659 assert_template 'form'
2641 2660
2642 2661 issue = assigns(:issue)
2643 2662 assert_kind_of Issue, issue
2644 2663 assert_equal 1, issue.id
2645 2664 assert_equal 1, issue.project_id
2646 2665 assert_equal 2, issue.tracker_id
2647 2666 assert_equal 'This is the test_new issue', issue.subject
2648 2667 end
2649 2668
2650 2669 def test_update_form_for_existing_issue_should_keep_issue_author
2651 2670 @request.session[:user_id] = 3
2652 2671 xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2653 2672 assert_response :success
2654 2673 assert_equal 'text/javascript', response.content_type
2655 2674
2656 2675 issue = assigns(:issue)
2657 2676 assert_equal User.find(2), issue.author
2658 2677 assert_equal 2, issue.author_id
2659 2678 assert_not_equal User.current, issue.author
2660 2679 end
2661 2680
2662 2681 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
2663 2682 @request.session[:user_id] = 2
2664 2683 WorkflowTransition.delete_all
2665 2684 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2666 2685 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2667 2686 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2668 2687
2669 2688 xhr :put, :update_form, :project_id => 1,
2670 2689 :id => 2,
2671 2690 :issue => {:tracker_id => 2,
2672 2691 :status_id => 5,
2673 2692 :subject => 'This is an issue'}
2674 2693
2675 2694 assert_equal 5, assigns(:issue).status_id
2676 2695 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2677 2696 end
2678 2697
2679 2698 def test_update_form_for_existing_issue_with_project_change
2680 2699 @request.session[:user_id] = 2
2681 2700 xhr :put, :update_form, :project_id => 1,
2682 2701 :id => 1,
2683 2702 :issue => {:project_id => 2,
2684 2703 :tracker_id => 2,
2685 2704 :subject => 'This is the test_new issue',
2686 2705 :description => 'This is the description',
2687 2706 :priority_id => 5}
2688 2707 assert_response :success
2689 2708 assert_template 'form'
2690 2709
2691 2710 issue = assigns(:issue)
2692 2711 assert_kind_of Issue, issue
2693 2712 assert_equal 1, issue.id
2694 2713 assert_equal 2, issue.project_id
2695 2714 assert_equal 2, issue.tracker_id
2696 2715 assert_equal 'This is the test_new issue', issue.subject
2697 2716 end
2698 2717
2699 2718 def test_put_update_without_custom_fields_param
2700 2719 @request.session[:user_id] = 2
2701 2720 ActionMailer::Base.deliveries.clear
2702 2721
2703 2722 issue = Issue.find(1)
2704 2723 assert_equal '125', issue.custom_value_for(2).value
2705 2724 old_subject = issue.subject
2706 2725 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2707 2726
2708 2727 assert_difference('Journal.count') do
2709 2728 assert_difference('JournalDetail.count', 2) do
2710 2729 put :update, :id => 1, :issue => {:subject => new_subject,
2711 2730 :priority_id => '6',
2712 2731 :category_id => '1' # no change
2713 2732 }
2714 2733 end
2715 2734 end
2716 2735 assert_redirected_to :action => 'show', :id => '1'
2717 2736 issue.reload
2718 2737 assert_equal new_subject, issue.subject
2719 2738 # Make sure custom fields were not cleared
2720 2739 assert_equal '125', issue.custom_value_for(2).value
2721 2740
2722 2741 mail = ActionMailer::Base.deliveries.last
2723 2742 assert_not_nil mail
2724 2743 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2725 2744 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2726 2745 end
2727 2746
2728 2747 def test_put_update_with_project_change
2729 2748 @request.session[:user_id] = 2
2730 2749 ActionMailer::Base.deliveries.clear
2731 2750
2732 2751 assert_difference('Journal.count') do
2733 2752 assert_difference('JournalDetail.count', 3) do
2734 2753 put :update, :id => 1, :issue => {:project_id => '2',
2735 2754 :tracker_id => '1', # no change
2736 2755 :priority_id => '6',
2737 2756 :category_id => '3'
2738 2757 }
2739 2758 end
2740 2759 end
2741 2760 assert_redirected_to :action => 'show', :id => '1'
2742 2761 issue = Issue.find(1)
2743 2762 assert_equal 2, issue.project_id
2744 2763 assert_equal 1, issue.tracker_id
2745 2764 assert_equal 6, issue.priority_id
2746 2765 assert_equal 3, issue.category_id
2747 2766
2748 2767 mail = ActionMailer::Base.deliveries.last
2749 2768 assert_not_nil mail
2750 2769 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2751 2770 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2752 2771 end
2753 2772
2754 2773 def test_put_update_with_tracker_change
2755 2774 @request.session[:user_id] = 2
2756 2775 ActionMailer::Base.deliveries.clear
2757 2776
2758 2777 assert_difference('Journal.count') do
2759 2778 assert_difference('JournalDetail.count', 2) do
2760 2779 put :update, :id => 1, :issue => {:project_id => '1',
2761 2780 :tracker_id => '2',
2762 2781 :priority_id => '6'
2763 2782 }
2764 2783 end
2765 2784 end
2766 2785 assert_redirected_to :action => 'show', :id => '1'
2767 2786 issue = Issue.find(1)
2768 2787 assert_equal 1, issue.project_id
2769 2788 assert_equal 2, issue.tracker_id
2770 2789 assert_equal 6, issue.priority_id
2771 2790 assert_equal 1, issue.category_id
2772 2791
2773 2792 mail = ActionMailer::Base.deliveries.last
2774 2793 assert_not_nil mail
2775 2794 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2776 2795 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2777 2796 end
2778 2797
2779 2798 def test_put_update_with_custom_field_change
2780 2799 @request.session[:user_id] = 2
2781 2800 issue = Issue.find(1)
2782 2801 assert_equal '125', issue.custom_value_for(2).value
2783 2802
2784 2803 assert_difference('Journal.count') do
2785 2804 assert_difference('JournalDetail.count', 3) do
2786 2805 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2787 2806 :priority_id => '6',
2788 2807 :category_id => '1', # no change
2789 2808 :custom_field_values => { '2' => 'New custom value' }
2790 2809 }
2791 2810 end
2792 2811 end
2793 2812 assert_redirected_to :action => 'show', :id => '1'
2794 2813 issue.reload
2795 2814 assert_equal 'New custom value', issue.custom_value_for(2).value
2796 2815
2797 2816 mail = ActionMailer::Base.deliveries.last
2798 2817 assert_not_nil mail
2799 2818 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2800 2819 end
2801 2820
2802 2821 def test_put_update_with_multi_custom_field_change
2803 2822 field = CustomField.find(1)
2804 2823 field.update_attribute :multiple, true
2805 2824 issue = Issue.find(1)
2806 2825 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2807 2826 issue.save!
2808 2827
2809 2828 @request.session[:user_id] = 2
2810 2829 assert_difference('Journal.count') do
2811 2830 assert_difference('JournalDetail.count', 3) do
2812 2831 put :update, :id => 1,
2813 2832 :issue => {
2814 2833 :subject => 'Custom field change',
2815 2834 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2816 2835 }
2817 2836 end
2818 2837 end
2819 2838 assert_redirected_to :action => 'show', :id => '1'
2820 2839 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2821 2840 end
2822 2841
2823 2842 def test_put_update_with_status_and_assignee_change
2824 2843 issue = Issue.find(1)
2825 2844 assert_equal 1, issue.status_id
2826 2845 @request.session[:user_id] = 2
2827 2846 assert_difference('TimeEntry.count', 0) do
2828 2847 put :update,
2829 2848 :id => 1,
2830 2849 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
2831 2850 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2832 2851 end
2833 2852 assert_redirected_to :action => 'show', :id => '1'
2834 2853 issue.reload
2835 2854 assert_equal 2, issue.status_id
2836 2855 j = Journal.order('id DESC').first
2837 2856 assert_equal 'Assigned to dlopper', j.notes
2838 2857 assert_equal 2, j.details.size
2839 2858
2840 2859 mail = ActionMailer::Base.deliveries.last
2841 2860 assert_mail_body_match "Status changed from New to Assigned", mail
2842 2861 # subject should contain the new status
2843 2862 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2844 2863 end
2845 2864
2846 2865 def test_put_update_with_note_only
2847 2866 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2848 2867 # anonymous user
2849 2868 put :update,
2850 2869 :id => 1,
2851 2870 :issue => { :notes => notes }
2852 2871 assert_redirected_to :action => 'show', :id => '1'
2853 2872 j = Journal.order('id DESC').first
2854 2873 assert_equal notes, j.notes
2855 2874 assert_equal 0, j.details.size
2856 2875 assert_equal User.anonymous, j.user
2857 2876
2858 2877 mail = ActionMailer::Base.deliveries.last
2859 2878 assert_mail_body_match notes, mail
2860 2879 end
2861 2880
2862 2881 def test_put_update_with_private_note_only
2863 2882 notes = 'Private note'
2864 2883 @request.session[:user_id] = 2
2865 2884
2866 2885 assert_difference 'Journal.count' do
2867 2886 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
2868 2887 assert_redirected_to :action => 'show', :id => '1'
2869 2888 end
2870 2889
2871 2890 j = Journal.order('id DESC').first
2872 2891 assert_equal notes, j.notes
2873 2892 assert_equal true, j.private_notes
2874 2893 end
2875 2894
2876 2895 def test_put_update_with_private_note_and_changes
2877 2896 notes = 'Private note'
2878 2897 @request.session[:user_id] = 2
2879 2898
2880 2899 assert_difference 'Journal.count', 2 do
2881 2900 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
2882 2901 assert_redirected_to :action => 'show', :id => '1'
2883 2902 end
2884 2903
2885 2904 j = Journal.order('id DESC').first
2886 2905 assert_equal notes, j.notes
2887 2906 assert_equal true, j.private_notes
2888 2907 assert_equal 0, j.details.count
2889 2908
2890 2909 j = Journal.order('id DESC').offset(1).first
2891 2910 assert_nil j.notes
2892 2911 assert_equal false, j.private_notes
2893 2912 assert_equal 1, j.details.count
2894 2913 end
2895 2914
2896 2915 def test_put_update_with_note_and_spent_time
2897 2916 @request.session[:user_id] = 2
2898 2917 spent_hours_before = Issue.find(1).spent_hours
2899 2918 assert_difference('TimeEntry.count') do
2900 2919 put :update,
2901 2920 :id => 1,
2902 2921 :issue => { :notes => '2.5 hours added' },
2903 2922 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2904 2923 end
2905 2924 assert_redirected_to :action => 'show', :id => '1'
2906 2925
2907 2926 issue = Issue.find(1)
2908 2927
2909 2928 j = Journal.order('id DESC').first
2910 2929 assert_equal '2.5 hours added', j.notes
2911 2930 assert_equal 0, j.details.size
2912 2931
2913 2932 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2914 2933 assert_not_nil t
2915 2934 assert_equal 2.5, t.hours
2916 2935 assert_equal spent_hours_before + 2.5, issue.spent_hours
2917 2936 end
2918 2937
2919 2938 def test_put_update_should_preserve_parent_issue_even_if_not_visible
2920 2939 parent = Issue.generate!(:project_id => 1, :is_private => true)
2921 2940 issue = Issue.generate!(:parent_issue_id => parent.id)
2922 2941 assert !parent.visible?(User.find(3))
2923 2942 @request.session[:user_id] = 3
2924 2943
2925 2944 get :edit, :id => issue.id
2926 2945 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s
2927 2946
2928 2947 put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s}
2929 2948 assert_response 302
2930 2949 assert_equal parent, issue.parent
2931 2950 end
2932 2951
2933 2952 def test_put_update_with_attachment_only
2934 2953 set_tmp_attachments_directory
2935 2954
2936 2955 # Delete all fixtured journals, a race condition can occur causing the wrong
2937 2956 # journal to get fetched in the next find.
2938 2957 Journal.delete_all
2939 2958
2940 2959 # anonymous user
2941 2960 assert_difference 'Attachment.count' do
2942 2961 put :update, :id => 1,
2943 2962 :issue => {:notes => ''},
2944 2963 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2945 2964 end
2946 2965
2947 2966 assert_redirected_to :action => 'show', :id => '1'
2948 2967 j = Issue.find(1).journals.reorder('id DESC').first
2949 2968 assert j.notes.blank?
2950 2969 assert_equal 1, j.details.size
2951 2970 assert_equal 'testfile.txt', j.details.first.value
2952 2971 assert_equal User.anonymous, j.user
2953 2972
2954 2973 attachment = Attachment.first(:order => 'id DESC')
2955 2974 assert_equal Issue.find(1), attachment.container
2956 2975 assert_equal User.anonymous, attachment.author
2957 2976 assert_equal 'testfile.txt', attachment.filename
2958 2977 assert_equal 'text/plain', attachment.content_type
2959 2978 assert_equal 'test file', attachment.description
2960 2979 assert_equal 59, attachment.filesize
2961 2980 assert File.exists?(attachment.diskfile)
2962 2981 assert_equal 59, File.size(attachment.diskfile)
2963 2982
2964 2983 mail = ActionMailer::Base.deliveries.last
2965 2984 assert_mail_body_match 'testfile.txt', mail
2966 2985 end
2967 2986
2968 2987 def test_put_update_with_failure_should_save_attachments
2969 2988 set_tmp_attachments_directory
2970 2989 @request.session[:user_id] = 2
2971 2990
2972 2991 assert_no_difference 'Journal.count' do
2973 2992 assert_difference 'Attachment.count' do
2974 2993 put :update, :id => 1,
2975 2994 :issue => { :subject => '' },
2976 2995 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2977 2996 assert_response :success
2978 2997 assert_template 'edit'
2979 2998 end
2980 2999 end
2981 3000
2982 3001 attachment = Attachment.first(:order => 'id DESC')
2983 3002 assert_equal 'testfile.txt', attachment.filename
2984 3003 assert File.exists?(attachment.diskfile)
2985 3004 assert_nil attachment.container
2986 3005
2987 3006 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2988 3007 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2989 3008 end
2990 3009
2991 3010 def test_put_update_with_failure_should_keep_saved_attachments
2992 3011 set_tmp_attachments_directory
2993 3012 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2994 3013 @request.session[:user_id] = 2
2995 3014
2996 3015 assert_no_difference 'Journal.count' do
2997 3016 assert_no_difference 'Attachment.count' do
2998 3017 put :update, :id => 1,
2999 3018 :issue => { :subject => '' },
3000 3019 :attachments => {'p0' => {'token' => attachment.token}}
3001 3020 assert_response :success
3002 3021 assert_template 'edit'
3003 3022 end
3004 3023 end
3005 3024
3006 3025 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3007 3026 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3008 3027 end
3009 3028
3010 3029 def test_put_update_should_attach_saved_attachments
3011 3030 set_tmp_attachments_directory
3012 3031 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3013 3032 @request.session[:user_id] = 2
3014 3033
3015 3034 assert_difference 'Journal.count' do
3016 3035 assert_difference 'JournalDetail.count' do
3017 3036 assert_no_difference 'Attachment.count' do
3018 3037 put :update, :id => 1,
3019 3038 :issue => {:notes => 'Attachment added'},
3020 3039 :attachments => {'p0' => {'token' => attachment.token}}
3021 3040 assert_redirected_to '/issues/1'
3022 3041 end
3023 3042 end
3024 3043 end
3025 3044
3026 3045 attachment.reload
3027 3046 assert_equal Issue.find(1), attachment.container
3028 3047
3029 3048 journal = Journal.first(:order => 'id DESC')
3030 3049 assert_equal 1, journal.details.size
3031 3050 assert_equal 'testfile.txt', journal.details.first.value
3032 3051 end
3033 3052
3034 3053 def test_put_update_with_attachment_that_fails_to_save
3035 3054 set_tmp_attachments_directory
3036 3055
3037 3056 # Delete all fixtured journals, a race condition can occur causing the wrong
3038 3057 # journal to get fetched in the next find.
3039 3058 Journal.delete_all
3040 3059
3041 3060 # Mock out the unsaved attachment
3042 3061 Attachment.any_instance.stubs(:create).returns(Attachment.new)
3043 3062
3044 3063 # anonymous user
3045 3064 put :update,
3046 3065 :id => 1,
3047 3066 :issue => {:notes => ''},
3048 3067 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3049 3068 assert_redirected_to :action => 'show', :id => '1'
3050 3069 assert_equal '1 file(s) could not be saved.', flash[:warning]
3051 3070 end
3052 3071
3053 3072 def test_put_update_with_no_change
3054 3073 issue = Issue.find(1)
3055 3074 issue.journals.clear
3056 3075 ActionMailer::Base.deliveries.clear
3057 3076
3058 3077 put :update,
3059 3078 :id => 1,
3060 3079 :issue => {:notes => ''}
3061 3080 assert_redirected_to :action => 'show', :id => '1'
3062 3081
3063 3082 issue.reload
3064 3083 assert issue.journals.empty?
3065 3084 # No email should be sent
3066 3085 assert ActionMailer::Base.deliveries.empty?
3067 3086 end
3068 3087
3069 3088 def test_put_update_should_send_a_notification
3070 3089 @request.session[:user_id] = 2
3071 3090 ActionMailer::Base.deliveries.clear
3072 3091 issue = Issue.find(1)
3073 3092 old_subject = issue.subject
3074 3093 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3075 3094
3076 3095 put :update, :id => 1, :issue => {:subject => new_subject,
3077 3096 :priority_id => '6',
3078 3097 :category_id => '1' # no change
3079 3098 }
3080 3099 assert_equal 1, ActionMailer::Base.deliveries.size
3081 3100 end
3082 3101
3083 3102 def test_put_update_with_invalid_spent_time_hours_only
3084 3103 @request.session[:user_id] = 2
3085 3104 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3086 3105
3087 3106 assert_no_difference('Journal.count') do
3088 3107 put :update,
3089 3108 :id => 1,
3090 3109 :issue => {:notes => notes},
3091 3110 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3092 3111 end
3093 3112 assert_response :success
3094 3113 assert_template 'edit'
3095 3114
3096 3115 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3097 3116 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3098 3117 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3099 3118 end
3100 3119
3101 3120 def test_put_update_with_invalid_spent_time_comments_only
3102 3121 @request.session[:user_id] = 2
3103 3122 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3104 3123
3105 3124 assert_no_difference('Journal.count') do
3106 3125 put :update,
3107 3126 :id => 1,
3108 3127 :issue => {:notes => notes},
3109 3128 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3110 3129 end
3111 3130 assert_response :success
3112 3131 assert_template 'edit'
3113 3132
3114 3133 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3115 3134 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/}
3116 3135 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3117 3136 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3118 3137 end
3119 3138
3120 3139 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3121 3140 issue = Issue.find(2)
3122 3141 @request.session[:user_id] = 2
3123 3142
3124 3143 put :update,
3125 3144 :id => issue.id,
3126 3145 :issue => {
3127 3146 :fixed_version_id => 4
3128 3147 }
3129 3148
3130 3149 assert_response :redirect
3131 3150 issue.reload
3132 3151 assert_equal 4, issue.fixed_version_id
3133 3152 assert_not_equal issue.project_id, issue.fixed_version.project_id
3134 3153 end
3135 3154
3136 3155 def test_put_update_should_redirect_back_using_the_back_url_parameter
3137 3156 issue = Issue.find(2)
3138 3157 @request.session[:user_id] = 2
3139 3158
3140 3159 put :update,
3141 3160 :id => issue.id,
3142 3161 :issue => {
3143 3162 :fixed_version_id => 4
3144 3163 },
3145 3164 :back_url => '/issues'
3146 3165
3147 3166 assert_response :redirect
3148 3167 assert_redirected_to '/issues'
3149 3168 end
3150 3169
3151 3170 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3152 3171 issue = Issue.find(2)
3153 3172 @request.session[:user_id] = 2
3154 3173
3155 3174 put :update,
3156 3175 :id => issue.id,
3157 3176 :issue => {
3158 3177 :fixed_version_id => 4
3159 3178 },
3160 3179 :back_url => 'http://google.com'
3161 3180
3162 3181 assert_response :redirect
3163 3182 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3164 3183 end
3165 3184
3166 3185 def test_get_bulk_edit
3167 3186 @request.session[:user_id] = 2
3168 3187 get :bulk_edit, :ids => [1, 2]
3169 3188 assert_response :success
3170 3189 assert_template 'bulk_edit'
3171 3190
3172 3191 assert_select 'ul#bulk-selection' do
3173 3192 assert_select 'li', 2
3174 3193 assert_select 'li a', :text => 'Bug #1'
3175 3194 end
3176 3195
3177 3196 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
3178 3197 assert_select 'input[name=?]', 'ids[]', 2
3179 3198 assert_select 'input[name=?][value=1][type=hidden]', 'ids[]'
3180 3199
3181 3200 assert_select 'select[name=?]', 'issue[project_id]'
3182 3201 assert_select 'input[name=?]', 'issue[parent_issue_id]'
3183 3202
3184 3203 # Project specific custom field, date type
3185 3204 field = CustomField.find(9)
3186 3205 assert !field.is_for_all?
3187 3206 assert_equal 'date', field.field_format
3188 3207 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3189 3208
3190 3209 # System wide custom field
3191 3210 assert CustomField.find(1).is_for_all?
3192 3211 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3193 3212
3194 3213 # Be sure we don't display inactive IssuePriorities
3195 3214 assert ! IssuePriority.find(15).active?
3196 3215 assert_select 'select[name=?]', 'issue[priority_id]' do
3197 3216 assert_select 'option[value=15]', 0
3198 3217 end
3199 3218 end
3200 3219 end
3201 3220
3202 3221 def test_get_bulk_edit_on_different_projects
3203 3222 @request.session[:user_id] = 2
3204 3223 get :bulk_edit, :ids => [1, 2, 6]
3205 3224 assert_response :success
3206 3225 assert_template 'bulk_edit'
3207 3226
3208 3227 # Can not set issues from different projects as children of an issue
3209 3228 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
3210 3229
3211 3230 # Project specific custom field, date type
3212 3231 field = CustomField.find(9)
3213 3232 assert !field.is_for_all?
3214 3233 assert !field.project_ids.include?(Issue.find(6).project_id)
3215 3234 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
3216 3235 end
3217 3236
3218 3237 def test_get_bulk_edit_with_user_custom_field
3219 3238 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
3220 3239
3221 3240 @request.session[:user_id] = 2
3222 3241 get :bulk_edit, :ids => [1, 2]
3223 3242 assert_response :success
3224 3243 assert_template 'bulk_edit'
3225 3244
3226 3245 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3227 3246 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
3228 3247 end
3229 3248 end
3230 3249
3231 3250 def test_get_bulk_edit_with_version_custom_field
3232 3251 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
3233 3252
3234 3253 @request.session[:user_id] = 2
3235 3254 get :bulk_edit, :ids => [1, 2]
3236 3255 assert_response :success
3237 3256 assert_template 'bulk_edit'
3238 3257
3239 3258 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3240 3259 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3241 3260 end
3242 3261 end
3243 3262
3244 3263 def test_get_bulk_edit_with_multi_custom_field
3245 3264 field = CustomField.find(1)
3246 3265 field.update_attribute :multiple, true
3247 3266
3248 3267 @request.session[:user_id] = 2
3249 3268 get :bulk_edit, :ids => [1, 2]
3250 3269 assert_response :success
3251 3270 assert_template 'bulk_edit'
3252 3271
3253 3272 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
3254 3273 assert_select 'option', field.possible_values.size + 1 # "none" options
3255 3274 end
3256 3275 end
3257 3276
3258 3277 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3259 3278 WorkflowTransition.delete_all
3260 3279 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
3261 3280 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
3262 3281 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
3263 3282 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3264 3283 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3265 3284 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3266 3285 @request.session[:user_id] = 2
3267 3286 get :bulk_edit, :ids => [1, 2]
3268 3287
3269 3288 assert_response :success
3270 3289 statuses = assigns(:available_statuses)
3271 3290 assert_not_nil statuses
3272 3291 assert_equal [1, 3], statuses.map(&:id).sort
3273 3292
3274 3293 assert_select 'select[name=?]', 'issue[status_id]' do
3275 3294 assert_select 'option', 3 # 2 statuses + "no change" option
3276 3295 end
3277 3296 end
3278 3297
3279 3298 def test_bulk_edit_should_propose_target_project_open_shared_versions
3280 3299 @request.session[:user_id] = 2
3281 3300 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3282 3301 assert_response :success
3283 3302 assert_template 'bulk_edit'
3284 3303 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
3285 3304
3286 3305 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
3287 3306 assert_select 'option', :text => '2.0'
3288 3307 end
3289 3308 end
3290 3309
3291 3310 def test_bulk_edit_should_propose_target_project_categories
3292 3311 @request.session[:user_id] = 2
3293 3312 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3294 3313 assert_response :success
3295 3314 assert_template 'bulk_edit'
3296 3315 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3297 3316
3298 3317 assert_select 'select[name=?]', 'issue[category_id]' do
3299 3318 assert_select 'option', :text => 'Recipes'
3300 3319 end
3301 3320 end
3302 3321
3303 3322 def test_bulk_update
3304 3323 @request.session[:user_id] = 2
3305 3324 # update issues priority
3306 3325 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3307 3326 :issue => {:priority_id => 7,
3308 3327 :assigned_to_id => '',
3309 3328 :custom_field_values => {'2' => ''}}
3310 3329
3311 3330 assert_response 302
3312 3331 # check that the issues were updated
3313 3332 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
3314 3333
3315 3334 issue = Issue.find(1)
3316 3335 journal = issue.journals.reorder('created_on DESC').first
3317 3336 assert_equal '125', issue.custom_value_for(2).value
3318 3337 assert_equal 'Bulk editing', journal.notes
3319 3338 assert_equal 1, journal.details.size
3320 3339 end
3321 3340
3322 3341 def test_bulk_update_with_group_assignee
3323 3342 group = Group.find(11)
3324 3343 project = Project.find(1)
3325 3344 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3326 3345
3327 3346 @request.session[:user_id] = 2
3328 3347 # update issues assignee
3329 3348 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3330 3349 :issue => {:priority_id => '',
3331 3350 :assigned_to_id => group.id,
3332 3351 :custom_field_values => {'2' => ''}}
3333 3352
3334 3353 assert_response 302
3335 3354 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
3336 3355 end
3337 3356
3338 3357 def test_bulk_update_on_different_projects
3339 3358 @request.session[:user_id] = 2
3340 3359 # update issues priority
3341 3360 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3342 3361 :issue => {:priority_id => 7,
3343 3362 :assigned_to_id => '',
3344 3363 :custom_field_values => {'2' => ''}}
3345 3364
3346 3365 assert_response 302
3347 3366 # check that the issues were updated
3348 3367 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3349 3368
3350 3369 issue = Issue.find(1)
3351 3370 journal = issue.journals.reorder('created_on DESC').first
3352 3371 assert_equal '125', issue.custom_value_for(2).value
3353 3372 assert_equal 'Bulk editing', journal.notes
3354 3373 assert_equal 1, journal.details.size
3355 3374 end
3356 3375
3357 3376 def test_bulk_update_on_different_projects_without_rights
3358 3377 @request.session[:user_id] = 3
3359 3378 user = User.find(3)
3360 3379 action = { :controller => "issues", :action => "bulk_update" }
3361 3380 assert user.allowed_to?(action, Issue.find(1).project)
3362 3381 assert ! user.allowed_to?(action, Issue.find(6).project)
3363 3382 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3364 3383 :issue => {:priority_id => 7,
3365 3384 :assigned_to_id => '',
3366 3385 :custom_field_values => {'2' => ''}}
3367 3386 assert_response 403
3368 3387 assert_not_equal "Bulk should fail", Journal.last.notes
3369 3388 end
3370 3389
3371 3390 def test_bullk_update_should_send_a_notification
3372 3391 @request.session[:user_id] = 2
3373 3392 ActionMailer::Base.deliveries.clear
3374 3393 post(:bulk_update,
3375 3394 {
3376 3395 :ids => [1, 2],
3377 3396 :notes => 'Bulk editing',
3378 3397 :issue => {
3379 3398 :priority_id => 7,
3380 3399 :assigned_to_id => '',
3381 3400 :custom_field_values => {'2' => ''}
3382 3401 }
3383 3402 })
3384 3403
3385 3404 assert_response 302
3386 3405 assert_equal 2, ActionMailer::Base.deliveries.size
3387 3406 end
3388 3407
3389 3408 def test_bulk_update_project
3390 3409 @request.session[:user_id] = 2
3391 3410 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3392 3411 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3393 3412 # Issues moved to project 2
3394 3413 assert_equal 2, Issue.find(1).project_id
3395 3414 assert_equal 2, Issue.find(2).project_id
3396 3415 # No tracker change
3397 3416 assert_equal 1, Issue.find(1).tracker_id
3398 3417 assert_equal 2, Issue.find(2).tracker_id
3399 3418 end
3400 3419
3401 3420 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3402 3421 @request.session[:user_id] = 2
3403 3422 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3404 3423 assert_redirected_to '/issues/1'
3405 3424 end
3406 3425
3407 3426 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3408 3427 @request.session[:user_id] = 2
3409 3428 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3410 3429 assert_redirected_to '/projects/onlinestore/issues'
3411 3430 end
3412 3431
3413 3432 def test_bulk_update_tracker
3414 3433 @request.session[:user_id] = 2
3415 3434 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3416 3435 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3417 3436 assert_equal 2, Issue.find(1).tracker_id
3418 3437 assert_equal 2, Issue.find(2).tracker_id
3419 3438 end
3420 3439
3421 3440 def test_bulk_update_status
3422 3441 @request.session[:user_id] = 2
3423 3442 # update issues priority
3424 3443 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3425 3444 :issue => {:priority_id => '',
3426 3445 :assigned_to_id => '',
3427 3446 :status_id => '5'}
3428 3447
3429 3448 assert_response 302
3430 3449 issue = Issue.find(1)
3431 3450 assert issue.closed?
3432 3451 end
3433 3452
3434 3453 def test_bulk_update_priority
3435 3454 @request.session[:user_id] = 2
3436 3455 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3437 3456
3438 3457 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3439 3458 assert_equal 6, Issue.find(1).priority_id
3440 3459 assert_equal 6, Issue.find(2).priority_id
3441 3460 end
3442 3461
3443 3462 def test_bulk_update_with_notes
3444 3463 @request.session[:user_id] = 2
3445 3464 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3446 3465
3447 3466 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3448 3467 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3449 3468 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3450 3469 end
3451 3470
3452 3471 def test_bulk_update_parent_id
3453 3472 @request.session[:user_id] = 2
3454 3473 post :bulk_update, :ids => [1, 3],
3455 3474 :notes => 'Bulk editing parent',
3456 3475 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
3457 3476
3458 3477 assert_response 302
3459 3478 parent = Issue.find(2)
3460 3479 assert_equal parent.id, Issue.find(1).parent_id
3461 3480 assert_equal parent.id, Issue.find(3).parent_id
3462 3481 assert_equal [1, 3], parent.children.collect(&:id).sort
3463 3482 end
3464 3483
3465 3484 def test_bulk_update_custom_field
3466 3485 @request.session[:user_id] = 2
3467 3486 # update issues priority
3468 3487 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
3469 3488 :issue => {:priority_id => '',
3470 3489 :assigned_to_id => '',
3471 3490 :custom_field_values => {'2' => '777'}}
3472 3491
3473 3492 assert_response 302
3474 3493
3475 3494 issue = Issue.find(1)
3476 3495 journal = issue.journals.reorder('created_on DESC').first
3477 3496 assert_equal '777', issue.custom_value_for(2).value
3478 3497 assert_equal 1, journal.details.size
3479 3498 assert_equal '125', journal.details.first.old_value
3480 3499 assert_equal '777', journal.details.first.value
3481 3500 end
3482 3501
3483 3502 def test_bulk_update_custom_field_to_blank
3484 3503 @request.session[:user_id] = 2
3485 3504 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
3486 3505 :issue => {:priority_id => '',
3487 3506 :assigned_to_id => '',
3488 3507 :custom_field_values => {'1' => '__none__'}}
3489 3508 assert_response 302
3490 3509 assert_equal '', Issue.find(1).custom_field_value(1)
3491 3510 assert_equal '', Issue.find(3).custom_field_value(1)
3492 3511 end
3493 3512
3494 3513 def test_bulk_update_multi_custom_field
3495 3514 field = CustomField.find(1)
3496 3515 field.update_attribute :multiple, true
3497 3516
3498 3517 @request.session[:user_id] = 2
3499 3518 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
3500 3519 :issue => {:priority_id => '',
3501 3520 :assigned_to_id => '',
3502 3521 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
3503 3522
3504 3523 assert_response 302
3505 3524
3506 3525 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
3507 3526 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
3508 3527 # the custom field is not associated with the issue tracker
3509 3528 assert_nil Issue.find(2).custom_field_value(1)
3510 3529 end
3511 3530
3512 3531 def test_bulk_update_multi_custom_field_to_blank
3513 3532 field = CustomField.find(1)
3514 3533 field.update_attribute :multiple, true
3515 3534
3516 3535 @request.session[:user_id] = 2
3517 3536 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
3518 3537 :issue => {:priority_id => '',
3519 3538 :assigned_to_id => '',
3520 3539 :custom_field_values => {'1' => ['__none__']}}
3521 3540 assert_response 302
3522 3541 assert_equal [''], Issue.find(1).custom_field_value(1)
3523 3542 assert_equal [''], Issue.find(3).custom_field_value(1)
3524 3543 end
3525 3544
3526 3545 def test_bulk_update_unassign
3527 3546 assert_not_nil Issue.find(2).assigned_to
3528 3547 @request.session[:user_id] = 2
3529 3548 # unassign issues
3530 3549 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
3531 3550 assert_response 302
3532 3551 # check that the issues were updated
3533 3552 assert_nil Issue.find(2).assigned_to
3534 3553 end
3535 3554
3536 3555 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
3537 3556 @request.session[:user_id] = 2
3538 3557
3539 3558 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
3540 3559
3541 3560 assert_response :redirect
3542 3561 issues = Issue.find([1,2])
3543 3562 issues.each do |issue|
3544 3563 assert_equal 4, issue.fixed_version_id
3545 3564 assert_not_equal issue.project_id, issue.fixed_version.project_id
3546 3565 end
3547 3566 end
3548 3567
3549 3568 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
3550 3569 @request.session[:user_id] = 2
3551 3570 post :bulk_update, :ids => [1,2], :back_url => '/issues'
3552 3571
3553 3572 assert_response :redirect
3554 3573 assert_redirected_to '/issues'
3555 3574 end
3556 3575
3557 3576 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3558 3577 @request.session[:user_id] = 2
3559 3578 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3560 3579
3561 3580 assert_response :redirect
3562 3581 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3563 3582 end
3564 3583
3565 3584 def test_bulk_update_with_failure_should_set_flash
3566 3585 @request.session[:user_id] = 2
3567 3586 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3568 3587 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3569 3588
3570 3589 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3571 3590 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3572 3591 end
3573 3592
3574 3593 def test_get_bulk_copy
3575 3594 @request.session[:user_id] = 2
3576 3595 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
3577 3596 assert_response :success
3578 3597 assert_template 'bulk_edit'
3579 3598
3580 3599 issues = assigns(:issues)
3581 3600 assert_not_nil issues
3582 3601 assert_equal [1, 2, 3], issues.map(&:id).sort
3583 3602
3584 3603 assert_select 'input[name=copy_attachments]'
3585 3604 end
3586 3605
3587 3606 def test_bulk_copy_to_another_project
3588 3607 @request.session[:user_id] = 2
3589 3608 assert_difference 'Issue.count', 2 do
3590 3609 assert_no_difference 'Project.find(1).issues.count' do
3591 3610 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3592 3611 end
3593 3612 end
3594 3613 assert_redirected_to '/projects/ecookbook/issues'
3595 3614
3596 3615 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3597 3616 copies.each do |copy|
3598 3617 assert_equal 2, copy.project_id
3599 3618 end
3600 3619 end
3601 3620
3602 3621 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3603 3622 @request.session[:user_id] = 2
3604 3623 issues = [
3605 3624 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil),
3606 3625 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3)
3607 3626 ]
3608 3627
3609 3628 assert_difference 'Issue.count', issues.size do
3610 3629 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
3611 3630 :issue => {
3612 3631 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3613 3632 :status_id => '', :start_date => '', :due_date => ''
3614 3633 }
3615 3634 end
3616 3635
3617 3636 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3618 3637 issues.each do |orig|
3619 3638 copy = copies.detect {|c| c.subject == orig.subject}
3620 3639 assert_not_nil copy
3621 3640 assert_equal orig.project_id, copy.project_id
3622 3641 assert_equal orig.tracker_id, copy.tracker_id
3623 3642 assert_equal orig.status_id, copy.status_id
3624 3643 assert_equal orig.assigned_to_id, copy.assigned_to_id
3625 3644 assert_equal orig.priority_id, copy.priority_id
3626 3645 end
3627 3646 end
3628 3647
3629 3648 def test_bulk_copy_should_allow_changing_the_issue_attributes
3630 3649 # Fixes random test failure with Mysql
3631 3650 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3632 3651 # doesn't return the expected results
3633 3652 Issue.delete_all("project_id=2")
3634 3653
3635 3654 @request.session[:user_id] = 2
3636 3655 assert_difference 'Issue.count', 2 do
3637 3656 assert_no_difference 'Project.find(1).issues.count' do
3638 3657 post :bulk_update, :ids => [1, 2], :copy => '1',
3639 3658 :issue => {
3640 3659 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3641 3660 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
3642 3661 }
3643 3662 end
3644 3663 end
3645 3664
3646 3665 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3647 3666 assert_equal 2, copied_issues.size
3648 3667 copied_issues.each do |issue|
3649 3668 assert_equal 2, issue.project_id, "Project is incorrect"
3650 3669 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3651 3670 assert_equal 1, issue.status_id, "Status is incorrect"
3652 3671 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3653 3672 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3654 3673 end
3655 3674 end
3656 3675
3657 3676 def test_bulk_copy_should_allow_adding_a_note
3658 3677 @request.session[:user_id] = 2
3659 3678 assert_difference 'Issue.count', 1 do
3660 3679 post :bulk_update, :ids => [1], :copy => '1',
3661 3680 :notes => 'Copying one issue',
3662 3681 :issue => {
3663 3682 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3664 3683 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3665 3684 }
3666 3685 end
3667 3686
3668 3687 issue = Issue.first(:order => 'id DESC')
3669 3688 assert_equal 1, issue.journals.size
3670 3689 journal = issue.journals.first
3671 3690 assert_equal 0, journal.details.size
3672 3691 assert_equal 'Copying one issue', journal.notes
3673 3692 end
3674 3693
3675 3694 def test_bulk_copy_should_allow_not_copying_the_attachments
3676 3695 attachment_count = Issue.find(3).attachments.size
3677 3696 assert attachment_count > 0
3678 3697 @request.session[:user_id] = 2
3679 3698
3680 3699 assert_difference 'Issue.count', 1 do
3681 3700 assert_no_difference 'Attachment.count' do
3682 3701 post :bulk_update, :ids => [3], :copy => '1',
3683 3702 :issue => {
3684 3703 :project_id => ''
3685 3704 }
3686 3705 end
3687 3706 end
3688 3707 end
3689 3708
3690 3709 def test_bulk_copy_should_allow_copying_the_attachments
3691 3710 attachment_count = Issue.find(3).attachments.size
3692 3711 assert attachment_count > 0
3693 3712 @request.session[:user_id] = 2
3694 3713
3695 3714 assert_difference 'Issue.count', 1 do
3696 3715 assert_difference 'Attachment.count', attachment_count do
3697 3716 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
3698 3717 :issue => {
3699 3718 :project_id => ''
3700 3719 }
3701 3720 end
3702 3721 end
3703 3722 end
3704 3723
3705 3724 def test_bulk_copy_should_add_relations_with_copied_issues
3706 3725 @request.session[:user_id] = 2
3707 3726
3708 3727 assert_difference 'Issue.count', 2 do
3709 3728 assert_difference 'IssueRelation.count', 2 do
3710 3729 post :bulk_update, :ids => [1, 3], :copy => '1',
3711 3730 :issue => {
3712 3731 :project_id => '1'
3713 3732 }
3714 3733 end
3715 3734 end
3716 3735 end
3717 3736
3718 3737 def test_bulk_copy_should_allow_not_copying_the_subtasks
3719 3738 issue = Issue.generate_with_descendants!
3720 3739 @request.session[:user_id] = 2
3721 3740
3722 3741 assert_difference 'Issue.count', 1 do
3723 3742 post :bulk_update, :ids => [issue.id], :copy => '1',
3724 3743 :issue => {
3725 3744 :project_id => ''
3726 3745 }
3727 3746 end
3728 3747 end
3729 3748
3730 3749 def test_bulk_copy_should_allow_copying_the_subtasks
3731 3750 issue = Issue.generate_with_descendants!
3732 3751 count = issue.descendants.count
3733 3752 @request.session[:user_id] = 2
3734 3753
3735 3754 assert_difference 'Issue.count', count+1 do
3736 3755 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
3737 3756 :issue => {
3738 3757 :project_id => ''
3739 3758 }
3740 3759 end
3741 3760 copy = Issue.where(:parent_id => nil).order("id DESC").first
3742 3761 assert_equal count, copy.descendants.count
3743 3762 end
3744 3763
3745 3764 def test_bulk_copy_should_not_copy_selected_subtasks_twice
3746 3765 issue = Issue.generate_with_descendants!
3747 3766 count = issue.descendants.count
3748 3767 @request.session[:user_id] = 2
3749 3768
3750 3769 assert_difference 'Issue.count', count+1 do
3751 3770 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
3752 3771 :issue => {
3753 3772 :project_id => ''
3754 3773 }
3755 3774 end
3756 3775 copy = Issue.where(:parent_id => nil).order("id DESC").first
3757 3776 assert_equal count, copy.descendants.count
3758 3777 end
3759 3778
3760 3779 def test_bulk_copy_to_another_project_should_follow_when_needed
3761 3780 @request.session[:user_id] = 2
3762 3781 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3763 3782 issue = Issue.first(:order => 'id DESC')
3764 3783 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3765 3784 end
3766 3785
3767 3786 def test_destroy_issue_with_no_time_entries
3768 3787 assert_nil TimeEntry.find_by_issue_id(2)
3769 3788 @request.session[:user_id] = 2
3770 3789
3771 3790 assert_difference 'Issue.count', -1 do
3772 3791 delete :destroy, :id => 2
3773 3792 end
3774 3793 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3775 3794 assert_nil Issue.find_by_id(2)
3776 3795 end
3777 3796
3778 3797 def test_destroy_issues_with_time_entries
3779 3798 @request.session[:user_id] = 2
3780 3799
3781 3800 assert_no_difference 'Issue.count' do
3782 3801 delete :destroy, :ids => [1, 3]
3783 3802 end
3784 3803 assert_response :success
3785 3804 assert_template 'destroy'
3786 3805 assert_not_nil assigns(:hours)
3787 3806 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3788 3807
3789 3808 assert_select 'form' do
3790 3809 assert_select 'input[name=_method][value=delete]'
3791 3810 end
3792 3811 end
3793 3812
3794 3813 def test_destroy_issues_and_destroy_time_entries
3795 3814 @request.session[:user_id] = 2
3796 3815
3797 3816 assert_difference 'Issue.count', -2 do
3798 3817 assert_difference 'TimeEntry.count', -3 do
3799 3818 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3800 3819 end
3801 3820 end
3802 3821 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3803 3822 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3804 3823 assert_nil TimeEntry.find_by_id([1, 2])
3805 3824 end
3806 3825
3807 3826 def test_destroy_issues_and_assign_time_entries_to_project
3808 3827 @request.session[:user_id] = 2
3809 3828
3810 3829 assert_difference 'Issue.count', -2 do
3811 3830 assert_no_difference 'TimeEntry.count' do
3812 3831 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3813 3832 end
3814 3833 end
3815 3834 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3816 3835 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3817 3836 assert_nil TimeEntry.find(1).issue_id
3818 3837 assert_nil TimeEntry.find(2).issue_id
3819 3838 end
3820 3839
3821 3840 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3822 3841 @request.session[:user_id] = 2
3823 3842
3824 3843 assert_difference 'Issue.count', -2 do
3825 3844 assert_no_difference 'TimeEntry.count' do
3826 3845 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3827 3846 end
3828 3847 end
3829 3848 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3830 3849 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3831 3850 assert_equal 2, TimeEntry.find(1).issue_id
3832 3851 assert_equal 2, TimeEntry.find(2).issue_id
3833 3852 end
3834 3853
3835 3854 def test_destroy_issues_from_different_projects
3836 3855 @request.session[:user_id] = 2
3837 3856
3838 3857 assert_difference 'Issue.count', -3 do
3839 3858 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3840 3859 end
3841 3860 assert_redirected_to :controller => 'issues', :action => 'index'
3842 3861 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3843 3862 end
3844 3863
3845 3864 def test_destroy_parent_and_child_issues
3846 3865 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3847 3866 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3848 3867 assert child.is_descendant_of?(parent.reload)
3849 3868
3850 3869 @request.session[:user_id] = 2
3851 3870 assert_difference 'Issue.count', -2 do
3852 3871 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3853 3872 end
3854 3873 assert_response 302
3855 3874 end
3856 3875
3857 3876 def test_destroy_invalid_should_respond_with_404
3858 3877 @request.session[:user_id] = 2
3859 3878 assert_no_difference 'Issue.count' do
3860 3879 delete :destroy, :id => 999
3861 3880 end
3862 3881 assert_response 404
3863 3882 end
3864 3883
3865 3884 def test_default_search_scope
3866 3885 get :index
3867 3886
3868 3887 assert_select 'div#quick-search form' do
3869 3888 assert_select 'input[name=issues][value=1][type=hidden]'
3870 3889 end
3871 3890 end
3872 3891 end
General Comments 0
You need to be logged in to leave comments. Login now