##// END OF EJS Templates
Prepends issue numbers with a number sign (#1005)....
Jean-Philippe Lang -
r11710:d90f46a5da07
parent child
Show More
@@ -1,405 +1,405
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 an array of error messages for bulk edited issues
98 98 def bulk_edit_error_messages(issues)
99 99 messages = {}
100 100 issues.each do |issue|
101 101 issue.errors.full_messages.each do |message|
102 102 messages[message] ||= []
103 103 messages[message] << issue
104 104 end
105 105 end
106 106 messages.map { |message, issues|
107 107 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
108 108 }
109 109 end
110 110
111 111 # Returns a link for adding a new subtask to the given issue
112 112 def link_to_new_subtask(issue)
113 113 attrs = {
114 114 :tracker_id => issue.tracker,
115 115 :parent_issue_id => issue
116 116 }
117 117 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
118 118 end
119 119
120 120 class IssueFieldsRows
121 121 include ActionView::Helpers::TagHelper
122 122
123 123 def initialize
124 124 @left = []
125 125 @right = []
126 126 end
127 127
128 128 def left(*args)
129 129 args.any? ? @left << cells(*args) : @left
130 130 end
131 131
132 132 def right(*args)
133 133 args.any? ? @right << cells(*args) : @right
134 134 end
135 135
136 136 def size
137 137 @left.size > @right.size ? @left.size : @right.size
138 138 end
139 139
140 140 def to_html
141 141 html = ''.html_safe
142 142 blank = content_tag('th', '') + content_tag('td', '')
143 143 size.times do |i|
144 144 left = @left[i] || blank
145 145 right = @right[i] || blank
146 146 html << content_tag('tr', left + right)
147 147 end
148 148 html
149 149 end
150 150
151 151 def cells(label, text, options={})
152 152 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
153 153 end
154 154 end
155 155
156 156 def issue_fields_rows
157 157 r = IssueFieldsRows.new
158 158 yield r
159 159 r.to_html
160 160 end
161 161
162 162 def render_custom_fields_rows(issue)
163 163 return if issue.custom_field_values.empty?
164 164 ordered_values = []
165 165 half = (issue.custom_field_values.size / 2.0).ceil
166 166 half.times do |i|
167 167 ordered_values << issue.custom_field_values[i]
168 168 ordered_values << issue.custom_field_values[i + half]
169 169 end
170 170 s = "<tr>\n"
171 171 n = 0
172 172 ordered_values.compact.each do |value|
173 173 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
174 174 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
175 175 n += 1
176 176 end
177 177 s << "</tr>\n"
178 178 s.html_safe
179 179 end
180 180
181 181 def issues_destroy_confirmation_message(issues)
182 182 issues = [issues] unless issues.is_a?(Array)
183 183 message = l(:text_issues_destroy_confirmation)
184 184 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
185 185 if descendant_count > 0
186 186 issues.each do |issue|
187 187 next if issue.root?
188 188 issues.each do |other_issue|
189 189 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
190 190 end
191 191 end
192 192 if descendant_count > 0
193 193 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
194 194 end
195 195 end
196 196 message
197 197 end
198 198
199 199 def sidebar_queries
200 200 unless @sidebar_queries
201 201 @sidebar_queries = IssueQuery.visible.
202 202 order("#{Query.table_name}.name ASC").
203 203 # Project specific queries and global queries
204 204 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
205 205 all
206 206 end
207 207 @sidebar_queries
208 208 end
209 209
210 210 def query_links(title, queries)
211 211 return '' if queries.empty?
212 212 # links to #index on issues/show
213 213 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
214 214
215 215 content_tag('h3', title) + "\n" +
216 216 content_tag('ul',
217 217 queries.collect {|query|
218 218 css = 'query'
219 219 css << ' selected' if query == @query
220 220 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
221 221 }.join("\n").html_safe,
222 222 :class => 'queries'
223 223 ) + "\n"
224 224 end
225 225
226 226 def render_sidebar_queries
227 227 out = ''.html_safe
228 228 out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?))
229 229 out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?))
230 230 out
231 231 end
232 232
233 233 # Returns the textual representation of a journal details
234 234 # as an array of strings
235 235 def details_to_strings(details, no_html=false, options={})
236 236 options[:only_path] = (options[:only_path] == false ? false : true)
237 237 strings = []
238 238 values_by_field = {}
239 239 details.each do |detail|
240 240 if detail.property == 'cf'
241 241 field_id = detail.prop_key
242 242 field = CustomField.find_by_id(field_id)
243 243 if field && field.multiple?
244 244 values_by_field[field_id] ||= {:added => [], :deleted => []}
245 245 if detail.old_value
246 246 values_by_field[field_id][:deleted] << detail.old_value
247 247 end
248 248 if detail.value
249 249 values_by_field[field_id][:added] << detail.value
250 250 end
251 251 next
252 252 end
253 253 end
254 254 strings << show_detail(detail, no_html, options)
255 255 end
256 256 values_by_field.each do |field_id, changes|
257 257 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
258 258 if changes[:added].any?
259 259 detail.value = changes[:added]
260 260 strings << show_detail(detail, no_html, options)
261 261 elsif changes[:deleted].any?
262 262 detail.old_value = changes[:deleted]
263 263 strings << show_detail(detail, no_html, options)
264 264 end
265 265 end
266 266 strings
267 267 end
268 268
269 269 # Returns the textual representation of a single journal detail
270 270 def show_detail(detail, no_html=false, options={})
271 271 multiple = false
272 272 case detail.property
273 273 when 'attr'
274 274 field = detail.prop_key.to_s.gsub(/\_id$/, "")
275 275 label = l(("field_" + field).to_sym)
276 276 case detail.prop_key
277 277 when 'due_date', 'start_date'
278 278 value = format_date(detail.value.to_date) if detail.value
279 279 old_value = format_date(detail.old_value.to_date) if detail.old_value
280 280
281 281 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
282 282 'priority_id', 'category_id', 'fixed_version_id'
283 283 value = find_name_by_reflection(field, detail.value)
284 284 old_value = find_name_by_reflection(field, detail.old_value)
285 285
286 286 when 'estimated_hours'
287 287 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
288 288 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
289 289
290 290 when 'parent_id'
291 291 label = l(:field_parent_issue)
292 292 value = "##{detail.value}" unless detail.value.blank?
293 293 old_value = "##{detail.old_value}" unless detail.old_value.blank?
294 294
295 295 when 'is_private'
296 296 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
297 297 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
298 298 end
299 299 when 'cf'
300 300 custom_field = CustomField.find_by_id(detail.prop_key)
301 301 if custom_field
302 302 multiple = custom_field.multiple?
303 303 label = custom_field.name
304 304 value = format_value(detail.value, custom_field.field_format) if detail.value
305 305 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
306 306 end
307 307 when 'attachment'
308 308 label = l(:label_attachment)
309 309 when 'relation'
310 310 if detail.value && !detail.old_value
311 311 rel_issue = Issue.visible.find_by_id(detail.value)
312 value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.value}" :
312 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
313 313 (no_html ? rel_issue : link_to_issue(rel_issue))
314 314 elsif detail.old_value && !detail.value
315 315 rel_issue = Issue.visible.find_by_id(detail.old_value)
316 old_value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.old_value}" :
316 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
317 317 (no_html ? rel_issue : link_to_issue(rel_issue))
318 318 end
319 319 label = l(detail.prop_key.to_sym)
320 320 end
321 321 call_hook(:helper_issues_show_detail_after_setting,
322 322 {:detail => detail, :label => label, :value => value, :old_value => old_value })
323 323
324 324 label ||= detail.prop_key
325 325 value ||= detail.value
326 326 old_value ||= detail.old_value
327 327
328 328 unless no_html
329 329 label = content_tag('strong', label)
330 330 old_value = content_tag("i", h(old_value)) if detail.old_value
331 331 if detail.old_value && detail.value.blank? && detail.property != 'relation'
332 332 old_value = content_tag("del", old_value)
333 333 end
334 334 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
335 335 # Link to the attachment if it has not been removed
336 336 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
337 337 if options[:only_path] != false && atta.is_text?
338 338 value += link_to(
339 339 image_tag('magnifier.png'),
340 340 :controller => 'attachments', :action => 'show',
341 341 :id => atta, :filename => atta.filename
342 342 )
343 343 end
344 344 else
345 345 value = content_tag("i", h(value)) if value
346 346 end
347 347 end
348 348
349 349 if detail.property == 'attr' && detail.prop_key == 'description'
350 350 s = l(:text_journal_changed_no_detail, :label => label)
351 351 unless no_html
352 352 diff_link = link_to 'diff',
353 353 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
354 354 :detail_id => detail.id, :only_path => options[:only_path]},
355 355 :title => l(:label_view_diff)
356 356 s << " (#{ diff_link })"
357 357 end
358 358 s.html_safe
359 359 elsif detail.value.present?
360 360 case detail.property
361 361 when 'attr', 'cf'
362 362 if detail.old_value.present?
363 363 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
364 364 elsif multiple
365 365 l(:text_journal_added, :label => label, :value => value).html_safe
366 366 else
367 367 l(:text_journal_set_to, :label => label, :value => value).html_safe
368 368 end
369 369 when 'attachment', 'relation'
370 370 l(:text_journal_added, :label => label, :value => value).html_safe
371 371 end
372 372 else
373 373 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
374 374 end
375 375 end
376 376
377 377 # Find the name of an associated record stored in the field attribute
378 378 def find_name_by_reflection(field, id)
379 379 unless id.present?
380 380 return nil
381 381 end
382 382 association = Issue.reflect_on_association(field.to_sym)
383 383 if association
384 384 record = association.class_name.constantize.find_by_id(id)
385 385 if record
386 386 record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding)
387 387 return record.name
388 388 end
389 389 end
390 390 end
391 391
392 392 # Renders issue children recursively
393 393 def render_api_issue_children(issue, api)
394 394 return if issue.leaf?
395 395 api.array :children do
396 396 issue.children.each do |child|
397 397 api.issue(:id => child.id) do
398 398 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
399 399 api.subject child.subject
400 400 render_api_issue_children(child, api)
401 401 end
402 402 end
403 403 end
404 404 end
405 405 end
@@ -1,265 +1,265
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 IssuesHelperTest < ActionView::TestCase
21 21 include ApplicationHelper
22 22 include Redmine::I18n
23 23 include IssuesHelper
24 24 include CustomFieldsHelper
25 25 include ERB::Util
26 26
27 27 fixtures :projects, :trackers, :issue_statuses, :issues,
28 28 :enumerations, :users, :issue_categories,
29 29 :projects_trackers,
30 30 :roles,
31 31 :member_roles,
32 32 :members,
33 33 :enabled_modules,
34 34 :custom_fields,
35 35 :attachments,
36 36 :versions
37 37
38 38 def setup
39 39 super
40 40 set_language_if_valid('en')
41 41 User.current = nil
42 42 end
43 43
44 44 def test_issue_heading
45 45 assert_equal "Bug #1", issue_heading(Issue.find(1))
46 46 end
47 47
48 48 def test_issues_destroy_confirmation_message_with_one_root_issue
49 49 assert_equal l(:text_issues_destroy_confirmation),
50 50 issues_destroy_confirmation_message(Issue.find(1))
51 51 end
52 52
53 53 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
54 54 assert_equal l(:text_issues_destroy_confirmation),
55 55 issues_destroy_confirmation_message(Issue.find([1, 2]))
56 56 end
57 57
58 58 def test_issues_destroy_confirmation_message_with_one_parent_issue
59 59 Issue.find(2).update_attribute :parent_issue_id, 1
60 60 assert_equal l(:text_issues_destroy_confirmation) + "\n" +
61 61 l(:text_issues_destroy_descendants_confirmation, :count => 1),
62 62 issues_destroy_confirmation_message(Issue.find(1))
63 63 end
64 64
65 65 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
66 66 Issue.find(2).update_attribute :parent_issue_id, 1
67 67 assert_equal l(:text_issues_destroy_confirmation),
68 68 issues_destroy_confirmation_message(Issue.find([1, 2]))
69 69 end
70 70
71 71 test 'show_detail with no_html should show a changing attribute' do
72 72 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
73 73 :value => '100', :prop_key => 'done_ratio')
74 74 assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
75 75 end
76 76
77 77 test 'show_detail with no_html should show a new attribute' do
78 78 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
79 79 :value => '100', :prop_key => 'done_ratio')
80 80 assert_equal "% Done set to 100", show_detail(detail, true)
81 81 end
82 82
83 83 test 'show_detail with no_html should show a deleted attribute' do
84 84 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
85 85 :value => nil, :prop_key => 'done_ratio')
86 86 assert_equal "% Done deleted (50)", show_detail(detail, true)
87 87 end
88 88
89 89 test 'show_detail with html should show a changing attribute with HTML highlights' do
90 90 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
91 91 :value => '100', :prop_key => 'done_ratio')
92 92 html = show_detail(detail, false)
93 93 assert_include '<strong>% Done</strong>', html
94 94 assert_include '<i>40</i>', html
95 95 assert_include '<i>100</i>', html
96 96 end
97 97
98 98 test 'show_detail with html should show a new attribute with HTML highlights' do
99 99 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
100 100 :value => '100', :prop_key => 'done_ratio')
101 101 html = show_detail(detail, false)
102 102 assert_include '<strong>% Done</strong>', html
103 103 assert_include '<i>100</i>', html
104 104 end
105 105
106 106 test 'show_detail with html should show a deleted attribute with HTML highlights' do
107 107 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
108 108 :value => nil, :prop_key => 'done_ratio')
109 109 html = show_detail(detail, false)
110 110 assert_include '<strong>% Done</strong>', html
111 111 assert_include '<del><i>50</i></del>', html
112 112 end
113 113
114 114 test 'show_detail with a start_date attribute should format the dates' do
115 115 detail = JournalDetail.new(
116 116 :property => 'attr',
117 117 :old_value => '2010-01-01',
118 118 :value => '2010-01-31',
119 119 :prop_key => 'start_date'
120 120 )
121 121 with_settings :date_format => '%m/%d/%Y' do
122 122 assert_match "01/31/2010", show_detail(detail, true)
123 123 assert_match "01/01/2010", show_detail(detail, true)
124 124 end
125 125 end
126 126
127 127 test 'show_detail with a due_date attribute should format the dates' do
128 128 detail = JournalDetail.new(
129 129 :property => 'attr',
130 130 :old_value => '2010-01-01',
131 131 :value => '2010-01-31',
132 132 :prop_key => 'due_date'
133 133 )
134 134 with_settings :date_format => '%m/%d/%Y' do
135 135 assert_match "01/31/2010", show_detail(detail, true)
136 136 assert_match "01/01/2010", show_detail(detail, true)
137 137 end
138 138 end
139 139
140 140 test 'show_detail should show old and new values with a project attribute' do
141 141 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
142 142 :old_value => 1, :value => 2)
143 143 assert_match 'eCookbook', show_detail(detail, true)
144 144 assert_match 'OnlineStore', show_detail(detail, true)
145 145 end
146 146
147 147 test 'show_detail should show old and new values with a issue status attribute' do
148 148 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
149 149 :old_value => 1, :value => 2)
150 150 assert_match 'New', show_detail(detail, true)
151 151 assert_match 'Assigned', show_detail(detail, true)
152 152 end
153 153
154 154 test 'show_detail should show old and new values with a tracker attribute' do
155 155 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
156 156 :old_value => 1, :value => 2)
157 157 assert_match 'Bug', show_detail(detail, true)
158 158 assert_match 'Feature request', show_detail(detail, true)
159 159 end
160 160
161 161 test 'show_detail should show old and new values with a assigned to attribute' do
162 162 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
163 163 :old_value => 1, :value => 2)
164 164 assert_match 'Redmine Admin', show_detail(detail, true)
165 165 assert_match 'John Smith', show_detail(detail, true)
166 166 end
167 167
168 168 test 'show_detail should show old and new values with a priority attribute' do
169 169 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
170 170 :old_value => 4, :value => 5)
171 171 assert_match 'Low', show_detail(detail, true)
172 172 assert_match 'Normal', show_detail(detail, true)
173 173 end
174 174
175 175 test 'show_detail should show old and new values with a category attribute' do
176 176 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
177 177 :old_value => 1, :value => 2)
178 178 assert_match 'Printing', show_detail(detail, true)
179 179 assert_match 'Recipes', show_detail(detail, true)
180 180 end
181 181
182 182 test 'show_detail should show old and new values with a fixed version attribute' do
183 183 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
184 184 :old_value => 1, :value => 2)
185 185 assert_match '0.1', show_detail(detail, true)
186 186 assert_match '1.0', show_detail(detail, true)
187 187 end
188 188
189 189 test 'show_detail should show old and new values with a estimated hours attribute' do
190 190 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
191 191 :old_value => '5', :value => '6.3')
192 192 assert_match '5.00', show_detail(detail, true)
193 193 assert_match '6.30', show_detail(detail, true)
194 194 end
195 195
196 196 test 'show_detail should show old and new values with a custom field' do
197 197 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
198 198 :old_value => 'MySQL', :value => 'PostgreSQL')
199 199 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
200 200 end
201 201
202 202 test 'show_detail should show added file' do
203 203 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
204 204 :old_value => nil, :value => 'error281.txt')
205 205 assert_match 'error281.txt', show_detail(detail, true)
206 206 end
207 207
208 208 test 'show_detail should show removed file' do
209 209 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
210 210 :old_value => 'error281.txt', :value => nil)
211 211 assert_match 'error281.txt', show_detail(detail, true)
212 212 end
213 213
214 214 def test_show_detail_create_relation
215 215 detail = JournalDetail.new(:property => 'relation',
216 216 :prop_key => 'label_precedes',
217 217 :value => 1)
218 218 assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true)
219 219 assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i> added},
220 220 show_detail(detail, false)
221 221 non_existed_issue_number = 9999
222 222 assert_nil Issue.find_by_id(non_existed_issue_number)
223 223 detail = JournalDetail.new(:property => 'relation',
224 224 :prop_key => 'label_precedes',
225 225 :value => non_existed_issue_number)
226 assert_equal "Precedes Issue #{non_existed_issue_number} added", show_detail(detail, true)
227 assert_equal "<strong>Precedes</strong> <i>Issue #{non_existed_issue_number}</i> added", show_detail(detail, false)
226 assert_equal "Precedes Issue ##{non_existed_issue_number} added", show_detail(detail, true)
227 assert_equal "<strong>Precedes</strong> <i>Issue ##{non_existed_issue_number}</i> added", show_detail(detail, false)
228 228 end
229 229
230 230 def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
231 231 issue = Issue.generate!(:is_private => true)
232 232 detail = JournalDetail.new(:property => 'relation',
233 233 :prop_key => 'label_precedes',
234 234 :value => issue.id)
235 235
236 assert_equal "Precedes Issue #{issue.id} added", show_detail(detail, true)
237 assert_equal "<strong>Precedes</strong> <i>Issue #{issue.id}</i> added", show_detail(detail, false)
236 assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
237 assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
238 238 end
239 239
240 240 def test_show_detail_delete_relation
241 241 detail = JournalDetail.new(:property => 'relation',
242 242 :prop_key => 'label_precedes',
243 243 :old_value => 1)
244 244 assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true)
245 245 assert_match %r{<strong>Precedes</strong> deleted \(<i><a href="/issues/1" class=".+">Bug #1</a>: Can&#x27;t print recipes</i>\)},
246 246 show_detail(detail, false)
247 247 non_existed_issue_number = 9999
248 248 assert_nil Issue.find_by_id(non_existed_issue_number)
249 249 detail = JournalDetail.new(:property => 'relation',
250 250 :prop_key => 'label_precedes',
251 251 :old_value => non_existed_issue_number)
252 assert_equal "Precedes deleted (Issue 9999)", show_detail(detail, true)
253 assert_equal "<strong>Precedes</strong> deleted (<i>Issue 9999</i>)", show_detail(detail, false)
252 assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
253 assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
254 254 end
255 255
256 256 def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
257 257 issue = Issue.generate!(:is_private => true)
258 258 detail = JournalDetail.new(:property => 'relation',
259 259 :prop_key => 'label_precedes',
260 260 :old_value => issue.id)
261 261
262 assert_equal "Precedes deleted (Issue #{issue.id})", show_detail(detail, true)
263 assert_equal "<strong>Precedes</strong> deleted (<i>Issue #{issue.id}</i>)", show_detail(detail, false)
262 assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
263 assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
264 264 end
265 265 end
General Comments 0
You need to be logged in to leave comments. Login now