##// END OF EJS Templates
The descendant count in the issues delete confirmation message is wrong if issues share some descendants....
Jean-Philippe Lang -
r13436:bfdd9f7c295d
parent child
Show More
@@ -1,430 +1,430
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module IssuesHelper
20 module IssuesHelper
21 include ApplicationHelper
21 include ApplicationHelper
22
22
23 def issue_list(issues, &block)
23 def issue_list(issues, &block)
24 ancestors = []
24 ancestors = []
25 issues.each do |issue|
25 issues.each do |issue|
26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
27 ancestors.pop
27 ancestors.pop
28 end
28 end
29 yield issue, ancestors.size
29 yield issue, ancestors.size
30 ancestors << issue unless issue.leaf?
30 ancestors << issue unless issue.leaf?
31 end
31 end
32 end
32 end
33
33
34 # Renders a HTML/CSS tooltip
34 # Renders a HTML/CSS tooltip
35 #
35 #
36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
37 # that contains this method wrapped in a span with the class of "tip"
37 # that contains this method wrapped in a span with the class of "tip"
38 #
38 #
39 # <div class="tooltip"><%= link_to_issue(issue) %>
39 # <div class="tooltip"><%= link_to_issue(issue) %>
40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
41 # </div>
41 # </div>
42 #
42 #
43 def render_issue_tooltip(issue)
43 def render_issue_tooltip(issue)
44 @cached_label_status ||= l(:field_status)
44 @cached_label_status ||= l(:field_status)
45 @cached_label_start_date ||= l(:field_start_date)
45 @cached_label_start_date ||= l(:field_start_date)
46 @cached_label_due_date ||= l(:field_due_date)
46 @cached_label_due_date ||= l(:field_due_date)
47 @cached_label_assigned_to ||= l(:field_assigned_to)
47 @cached_label_assigned_to ||= l(:field_assigned_to)
48 @cached_label_priority ||= l(:field_priority)
48 @cached_label_priority ||= l(:field_priority)
49 @cached_label_project ||= l(:field_project)
49 @cached_label_project ||= l(:field_project)
50
50
51 link_to_issue(issue) + "<br /><br />".html_safe +
51 link_to_issue(issue) + "<br /><br />".html_safe +
52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
58 end
58 end
59
59
60 def issue_heading(issue)
60 def issue_heading(issue)
61 h("#{issue.tracker} ##{issue.id}")
61 h("#{issue.tracker} ##{issue.id}")
62 end
62 end
63
63
64 def render_issue_subject_with_tree(issue)
64 def render_issue_subject_with_tree(issue)
65 s = ''
65 s = ''
66 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
66 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
67 ancestors.each do |ancestor|
67 ancestors.each do |ancestor|
68 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
68 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
69 end
69 end
70 s << '<div>'
70 s << '<div>'
71 subject = h(issue.subject)
71 subject = h(issue.subject)
72 if issue.is_private?
72 if issue.is_private?
73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
74 end
74 end
75 s << content_tag('h3', subject)
75 s << content_tag('h3', subject)
76 s << '</div>' * (ancestors.size + 1)
76 s << '</div>' * (ancestors.size + 1)
77 s.html_safe
77 s.html_safe
78 end
78 end
79
79
80 def render_descendants_tree(issue)
80 def render_descendants_tree(issue)
81 s = '<form><table class="list issues">'
81 s = '<form><table class="list issues">'
82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
83 css = "issue issue-#{child.id} hascontextmenu"
83 css = "issue issue-#{child.id} hascontextmenu"
84 css << " idnt idnt-#{level}" if level > 0
84 css << " idnt idnt-#{level}" if level > 0
85 s << content_tag('tr',
85 s << content_tag('tr',
86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
87 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
87 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
88 content_tag('td', h(child.status)) +
88 content_tag('td', h(child.status)) +
89 content_tag('td', link_to_user(child.assigned_to)) +
89 content_tag('td', link_to_user(child.assigned_to)) +
90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
91 :class => css)
91 :class => css)
92 end
92 end
93 s << '</table></form>'
93 s << '</table></form>'
94 s.html_safe
94 s.html_safe
95 end
95 end
96
96
97 # Returns an array of error messages for bulk edited issues
97 # Returns an array of error messages for bulk edited issues
98 def bulk_edit_error_messages(issues)
98 def bulk_edit_error_messages(issues)
99 messages = {}
99 messages = {}
100 issues.each do |issue|
100 issues.each do |issue|
101 issue.errors.full_messages.each do |message|
101 issue.errors.full_messages.each do |message|
102 messages[message] ||= []
102 messages[message] ||= []
103 messages[message] << issue
103 messages[message] << issue
104 end
104 end
105 end
105 end
106 messages.map { |message, issues|
106 messages.map { |message, issues|
107 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
107 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
108 }
108 }
109 end
109 end
110
110
111 # Returns a link for adding a new subtask to the given issue
111 # Returns a link for adding a new subtask to the given issue
112 def link_to_new_subtask(issue)
112 def link_to_new_subtask(issue)
113 attrs = {
113 attrs = {
114 :tracker_id => issue.tracker,
114 :tracker_id => issue.tracker,
115 :parent_issue_id => issue
115 :parent_issue_id => issue
116 }
116 }
117 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
117 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
118 end
118 end
119
119
120 class IssueFieldsRows
120 class IssueFieldsRows
121 include ActionView::Helpers::TagHelper
121 include ActionView::Helpers::TagHelper
122
122
123 def initialize
123 def initialize
124 @left = []
124 @left = []
125 @right = []
125 @right = []
126 end
126 end
127
127
128 def left(*args)
128 def left(*args)
129 args.any? ? @left << cells(*args) : @left
129 args.any? ? @left << cells(*args) : @left
130 end
130 end
131
131
132 def right(*args)
132 def right(*args)
133 args.any? ? @right << cells(*args) : @right
133 args.any? ? @right << cells(*args) : @right
134 end
134 end
135
135
136 def size
136 def size
137 @left.size > @right.size ? @left.size : @right.size
137 @left.size > @right.size ? @left.size : @right.size
138 end
138 end
139
139
140 def to_html
140 def to_html
141 html = ''.html_safe
141 html = ''.html_safe
142 blank = content_tag('th', '') + content_tag('td', '')
142 blank = content_tag('th', '') + content_tag('td', '')
143 size.times do |i|
143 size.times do |i|
144 left = @left[i] || blank
144 left = @left[i] || blank
145 right = @right[i] || blank
145 right = @right[i] || blank
146 html << content_tag('tr', left + right)
146 html << content_tag('tr', left + right)
147 end
147 end
148 html
148 html
149 end
149 end
150
150
151 def cells(label, text, options={})
151 def cells(label, text, options={})
152 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
152 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
153 end
153 end
154 end
154 end
155
155
156 def issue_fields_rows
156 def issue_fields_rows
157 r = IssueFieldsRows.new
157 r = IssueFieldsRows.new
158 yield r
158 yield r
159 r.to_html
159 r.to_html
160 end
160 end
161
161
162 def render_custom_fields_rows(issue)
162 def render_custom_fields_rows(issue)
163 values = issue.visible_custom_field_values
163 values = issue.visible_custom_field_values
164 return if values.empty?
164 return if values.empty?
165 ordered_values = []
165 ordered_values = []
166 half = (values.size / 2.0).ceil
166 half = (values.size / 2.0).ceil
167 half.times do |i|
167 half.times do |i|
168 ordered_values << values[i]
168 ordered_values << values[i]
169 ordered_values << values[i + half]
169 ordered_values << values[i + half]
170 end
170 end
171 s = "<tr>\n"
171 s = "<tr>\n"
172 n = 0
172 n = 0
173 ordered_values.compact.each do |value|
173 ordered_values.compact.each do |value|
174 css = "cf_#{value.custom_field.id}"
174 css = "cf_#{value.custom_field.id}"
175 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
175 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
176 s << "\t<th class=\"#{css}\">#{ h(value.custom_field.name) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n"
176 s << "\t<th class=\"#{css}\">#{ h(value.custom_field.name) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n"
177 n += 1
177 n += 1
178 end
178 end
179 s << "</tr>\n"
179 s << "</tr>\n"
180 s.html_safe
180 s.html_safe
181 end
181 end
182
182
183 # Returns the number of descendants for an array of issues
184 def issues_descendant_count(issues)
185 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
186 ids -= issues.map(&:id)
187 ids.size
188 end
189
183 def issues_destroy_confirmation_message(issues)
190 def issues_destroy_confirmation_message(issues)
184 issues = [issues] unless issues.is_a?(Array)
191 issues = [issues] unless issues.is_a?(Array)
185 message = l(:text_issues_destroy_confirmation)
192 message = l(:text_issues_destroy_confirmation)
186 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
193
194 descendant_count = issues_descendant_count(issues)
187 if descendant_count > 0
195 if descendant_count > 0
188 issues.each do |issue|
196 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
189 next if issue.root?
190 issues.each do |other_issue|
191 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
192 end
193 end
194 if descendant_count > 0
195 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
196 end
197 end
197 end
198 message
198 message
199 end
199 end
200
200
201 def sidebar_queries
201 def sidebar_queries
202 unless @sidebar_queries
202 unless @sidebar_queries
203 @sidebar_queries = IssueQuery.visible.
203 @sidebar_queries = IssueQuery.visible.
204 order("#{Query.table_name}.name ASC").
204 order("#{Query.table_name}.name ASC").
205 # Project specific queries and global queries
205 # Project specific queries and global queries
206 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
206 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
207 to_a
207 to_a
208 end
208 end
209 @sidebar_queries
209 @sidebar_queries
210 end
210 end
211
211
212 def query_links(title, queries)
212 def query_links(title, queries)
213 return '' if queries.empty?
213 return '' if queries.empty?
214 # links to #index on issues/show
214 # links to #index on issues/show
215 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
215 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
216
216
217 content_tag('h3', title) + "\n" +
217 content_tag('h3', title) + "\n" +
218 content_tag('ul',
218 content_tag('ul',
219 queries.collect {|query|
219 queries.collect {|query|
220 css = 'query'
220 css = 'query'
221 css << ' selected' if query == @query
221 css << ' selected' if query == @query
222 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
222 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
223 }.join("\n").html_safe,
223 }.join("\n").html_safe,
224 :class => 'queries'
224 :class => 'queries'
225 ) + "\n"
225 ) + "\n"
226 end
226 end
227
227
228 def render_sidebar_queries
228 def render_sidebar_queries
229 out = ''.html_safe
229 out = ''.html_safe
230 out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?))
230 out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?))
231 out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?))
231 out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?))
232 out
232 out
233 end
233 end
234
234
235 def email_issue_attributes(issue, user)
235 def email_issue_attributes(issue, user)
236 items = []
236 items = []
237 %w(author status priority assigned_to category fixed_version).each do |attribute|
237 %w(author status priority assigned_to category fixed_version).each do |attribute|
238 unless issue.disabled_core_fields.include?(attribute+"_id")
238 unless issue.disabled_core_fields.include?(attribute+"_id")
239 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
239 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
240 end
240 end
241 end
241 end
242 issue.visible_custom_field_values(user).each do |value|
242 issue.visible_custom_field_values(user).each do |value|
243 items << "#{value.custom_field.name}: #{show_value(value, false)}"
243 items << "#{value.custom_field.name}: #{show_value(value, false)}"
244 end
244 end
245 items
245 items
246 end
246 end
247
247
248 def render_email_issue_attributes(issue, user, html=false)
248 def render_email_issue_attributes(issue, user, html=false)
249 items = email_issue_attributes(issue, user)
249 items = email_issue_attributes(issue, user)
250 if html
250 if html
251 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
251 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
252 else
252 else
253 items.map{|s| "* #{s}"}.join("\n")
253 items.map{|s| "* #{s}"}.join("\n")
254 end
254 end
255 end
255 end
256
256
257 # Returns the textual representation of a journal details
257 # Returns the textual representation of a journal details
258 # as an array of strings
258 # as an array of strings
259 def details_to_strings(details, no_html=false, options={})
259 def details_to_strings(details, no_html=false, options={})
260 options[:only_path] = (options[:only_path] == false ? false : true)
260 options[:only_path] = (options[:only_path] == false ? false : true)
261 strings = []
261 strings = []
262 values_by_field = {}
262 values_by_field = {}
263 details.each do |detail|
263 details.each do |detail|
264 if detail.property == 'cf'
264 if detail.property == 'cf'
265 field = detail.custom_field
265 field = detail.custom_field
266 if field && field.multiple?
266 if field && field.multiple?
267 values_by_field[field] ||= {:added => [], :deleted => []}
267 values_by_field[field] ||= {:added => [], :deleted => []}
268 if detail.old_value
268 if detail.old_value
269 values_by_field[field][:deleted] << detail.old_value
269 values_by_field[field][:deleted] << detail.old_value
270 end
270 end
271 if detail.value
271 if detail.value
272 values_by_field[field][:added] << detail.value
272 values_by_field[field][:added] << detail.value
273 end
273 end
274 next
274 next
275 end
275 end
276 end
276 end
277 strings << show_detail(detail, no_html, options)
277 strings << show_detail(detail, no_html, options)
278 end
278 end
279 values_by_field.each do |field, changes|
279 values_by_field.each do |field, changes|
280 detail = JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s)
280 detail = JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s)
281 detail.instance_variable_set "@custom_field", field
281 detail.instance_variable_set "@custom_field", field
282 if changes[:added].any?
282 if changes[:added].any?
283 detail.value = changes[:added]
283 detail.value = changes[:added]
284 strings << show_detail(detail, no_html, options)
284 strings << show_detail(detail, no_html, options)
285 elsif changes[:deleted].any?
285 elsif changes[:deleted].any?
286 detail.old_value = changes[:deleted]
286 detail.old_value = changes[:deleted]
287 strings << show_detail(detail, no_html, options)
287 strings << show_detail(detail, no_html, options)
288 end
288 end
289 end
289 end
290 strings
290 strings
291 end
291 end
292
292
293 # Returns the textual representation of a single journal detail
293 # Returns the textual representation of a single journal detail
294 def show_detail(detail, no_html=false, options={})
294 def show_detail(detail, no_html=false, options={})
295 multiple = false
295 multiple = false
296 case detail.property
296 case detail.property
297 when 'attr'
297 when 'attr'
298 field = detail.prop_key.to_s.gsub(/\_id$/, "")
298 field = detail.prop_key.to_s.gsub(/\_id$/, "")
299 label = l(("field_" + field).to_sym)
299 label = l(("field_" + field).to_sym)
300 case detail.prop_key
300 case detail.prop_key
301 when 'due_date', 'start_date'
301 when 'due_date', 'start_date'
302 value = format_date(detail.value.to_date) if detail.value
302 value = format_date(detail.value.to_date) if detail.value
303 old_value = format_date(detail.old_value.to_date) if detail.old_value
303 old_value = format_date(detail.old_value.to_date) if detail.old_value
304
304
305 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
305 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
306 'priority_id', 'category_id', 'fixed_version_id'
306 'priority_id', 'category_id', 'fixed_version_id'
307 value = find_name_by_reflection(field, detail.value)
307 value = find_name_by_reflection(field, detail.value)
308 old_value = find_name_by_reflection(field, detail.old_value)
308 old_value = find_name_by_reflection(field, detail.old_value)
309
309
310 when 'estimated_hours'
310 when 'estimated_hours'
311 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
311 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
312 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
312 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
313
313
314 when 'parent_id'
314 when 'parent_id'
315 label = l(:field_parent_issue)
315 label = l(:field_parent_issue)
316 value = "##{detail.value}" unless detail.value.blank?
316 value = "##{detail.value}" unless detail.value.blank?
317 old_value = "##{detail.old_value}" unless detail.old_value.blank?
317 old_value = "##{detail.old_value}" unless detail.old_value.blank?
318
318
319 when 'is_private'
319 when 'is_private'
320 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
320 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
321 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
321 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
322 end
322 end
323 when 'cf'
323 when 'cf'
324 custom_field = detail.custom_field
324 custom_field = detail.custom_field
325 if custom_field
325 if custom_field
326 multiple = custom_field.multiple?
326 multiple = custom_field.multiple?
327 label = custom_field.name
327 label = custom_field.name
328 value = format_value(detail.value, custom_field) if detail.value
328 value = format_value(detail.value, custom_field) if detail.value
329 old_value = format_value(detail.old_value, custom_field) if detail.old_value
329 old_value = format_value(detail.old_value, custom_field) if detail.old_value
330 end
330 end
331 when 'attachment'
331 when 'attachment'
332 label = l(:label_attachment)
332 label = l(:label_attachment)
333 when 'relation'
333 when 'relation'
334 if detail.value && !detail.old_value
334 if detail.value && !detail.old_value
335 rel_issue = Issue.visible.find_by_id(detail.value)
335 rel_issue = Issue.visible.find_by_id(detail.value)
336 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
336 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
337 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
337 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
338 elsif detail.old_value && !detail.value
338 elsif detail.old_value && !detail.value
339 rel_issue = Issue.visible.find_by_id(detail.old_value)
339 rel_issue = Issue.visible.find_by_id(detail.old_value)
340 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
340 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
341 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
341 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
342 end
342 end
343 relation_type = IssueRelation::TYPES[detail.prop_key]
343 relation_type = IssueRelation::TYPES[detail.prop_key]
344 label = l(relation_type[:name]) if relation_type
344 label = l(relation_type[:name]) if relation_type
345 end
345 end
346 call_hook(:helper_issues_show_detail_after_setting,
346 call_hook(:helper_issues_show_detail_after_setting,
347 {:detail => detail, :label => label, :value => value, :old_value => old_value })
347 {:detail => detail, :label => label, :value => value, :old_value => old_value })
348
348
349 label ||= detail.prop_key
349 label ||= detail.prop_key
350 value ||= detail.value
350 value ||= detail.value
351 old_value ||= detail.old_value
351 old_value ||= detail.old_value
352
352
353 unless no_html
353 unless no_html
354 label = content_tag('strong', label)
354 label = content_tag('strong', label)
355 old_value = content_tag("i", h(old_value)) if detail.old_value
355 old_value = content_tag("i", h(old_value)) if detail.old_value
356 if detail.old_value && detail.value.blank? && detail.property != 'relation'
356 if detail.old_value && detail.value.blank? && detail.property != 'relation'
357 old_value = content_tag("del", old_value)
357 old_value = content_tag("del", old_value)
358 end
358 end
359 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
359 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
360 # Link to the attachment if it has not been removed
360 # Link to the attachment if it has not been removed
361 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
361 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
362 if options[:only_path] != false && atta.is_text?
362 if options[:only_path] != false && atta.is_text?
363 value += link_to(
363 value += link_to(
364 image_tag('magnifier.png'),
364 image_tag('magnifier.png'),
365 :controller => 'attachments', :action => 'show',
365 :controller => 'attachments', :action => 'show',
366 :id => atta, :filename => atta.filename
366 :id => atta, :filename => atta.filename
367 )
367 )
368 end
368 end
369 else
369 else
370 value = content_tag("i", h(value)) if value
370 value = content_tag("i", h(value)) if value
371 end
371 end
372 end
372 end
373
373
374 if detail.property == 'attr' && detail.prop_key == 'description'
374 if detail.property == 'attr' && detail.prop_key == 'description'
375 s = l(:text_journal_changed_no_detail, :label => label)
375 s = l(:text_journal_changed_no_detail, :label => label)
376 unless no_html
376 unless no_html
377 diff_link = link_to 'diff',
377 diff_link = link_to 'diff',
378 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
378 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
379 :detail_id => detail.id, :only_path => options[:only_path]},
379 :detail_id => detail.id, :only_path => options[:only_path]},
380 :title => l(:label_view_diff)
380 :title => l(:label_view_diff)
381 s << " (#{ diff_link })"
381 s << " (#{ diff_link })"
382 end
382 end
383 s.html_safe
383 s.html_safe
384 elsif detail.value.present?
384 elsif detail.value.present?
385 case detail.property
385 case detail.property
386 when 'attr', 'cf'
386 when 'attr', 'cf'
387 if detail.old_value.present?
387 if detail.old_value.present?
388 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
388 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
389 elsif multiple
389 elsif multiple
390 l(:text_journal_added, :label => label, :value => value).html_safe
390 l(:text_journal_added, :label => label, :value => value).html_safe
391 else
391 else
392 l(:text_journal_set_to, :label => label, :value => value).html_safe
392 l(:text_journal_set_to, :label => label, :value => value).html_safe
393 end
393 end
394 when 'attachment', 'relation'
394 when 'attachment', 'relation'
395 l(:text_journal_added, :label => label, :value => value).html_safe
395 l(:text_journal_added, :label => label, :value => value).html_safe
396 end
396 end
397 else
397 else
398 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
398 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
399 end
399 end
400 end
400 end
401
401
402 # Find the name of an associated record stored in the field attribute
402 # Find the name of an associated record stored in the field attribute
403 def find_name_by_reflection(field, id)
403 def find_name_by_reflection(field, id)
404 unless id.present?
404 unless id.present?
405 return nil
405 return nil
406 end
406 end
407 association = Issue.reflect_on_association(field.to_sym)
407 association = Issue.reflect_on_association(field.to_sym)
408 if association
408 if association
409 record = association.class_name.constantize.find_by_id(id)
409 record = association.class_name.constantize.find_by_id(id)
410 if record
410 if record
411 record.name.force_encoding('UTF-8')
411 record.name.force_encoding('UTF-8')
412 return record.name
412 return record.name
413 end
413 end
414 end
414 end
415 end
415 end
416
416
417 # Renders issue children recursively
417 # Renders issue children recursively
418 def render_api_issue_children(issue, api)
418 def render_api_issue_children(issue, api)
419 return if issue.leaf?
419 return if issue.leaf?
420 api.array :children do
420 api.array :children do
421 issue.children.each do |child|
421 issue.children.each do |child|
422 api.issue(:id => child.id) do
422 api.issue(:id => child.id) do
423 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
423 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
424 api.subject child.subject
424 api.subject child.subject
425 render_api_issue_children(child, api)
425 render_api_issue_children(child, api)
426 end
426 end
427 end
427 end
428 end
428 end
429 end
429 end
430 end
430 end
@@ -1,275 +1,285
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../../test_helper', __FILE__)
18 require File.expand_path('../../../test_helper', __FILE__)
19
19
20 class IssuesHelperTest < ActionView::TestCase
20 class IssuesHelperTest < ActionView::TestCase
21 include Redmine::I18n
21 include Redmine::I18n
22 include IssuesHelper
22 include IssuesHelper
23 include CustomFieldsHelper
23 include CustomFieldsHelper
24 include ERB::Util
24 include ERB::Util
25 include Rails.application.routes.url_helpers
25 include Rails.application.routes.url_helpers
26
26
27 fixtures :projects, :trackers, :issue_statuses, :issues,
27 fixtures :projects, :trackers, :issue_statuses, :issues,
28 :enumerations, :users, :issue_categories,
28 :enumerations, :users, :issue_categories,
29 :projects_trackers,
29 :projects_trackers,
30 :roles,
30 :roles,
31 :member_roles,
31 :member_roles,
32 :members,
32 :members,
33 :enabled_modules,
33 :enabled_modules,
34 :custom_fields,
34 :custom_fields,
35 :attachments,
35 :attachments,
36 :versions
36 :versions
37
37
38 def setup
38 def setup
39 super
39 super
40 set_language_if_valid('en')
40 set_language_if_valid('en')
41 User.current = nil
41 User.current = nil
42 end
42 end
43
43
44 def test_issue_heading
44 def test_issue_heading
45 assert_equal "Bug #1", issue_heading(Issue.find(1))
45 assert_equal "Bug #1", issue_heading(Issue.find(1))
46 end
46 end
47
47
48 def test_issues_destroy_confirmation_message_with_one_root_issue
48 def test_issues_destroy_confirmation_message_with_one_root_issue
49 assert_equal l(:text_issues_destroy_confirmation),
49 assert_equal l(:text_issues_destroy_confirmation),
50 issues_destroy_confirmation_message(Issue.find(1))
50 issues_destroy_confirmation_message(Issue.find(1))
51 end
51 end
52
52
53 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
53 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
54 assert_equal l(:text_issues_destroy_confirmation),
54 assert_equal l(:text_issues_destroy_confirmation),
55 issues_destroy_confirmation_message(Issue.find([1, 2]))
55 issues_destroy_confirmation_message(Issue.find([1, 2]))
56 end
56 end
57
57
58 def test_issues_destroy_confirmation_message_with_one_parent_issue
58 def test_issues_destroy_confirmation_message_with_one_parent_issue
59 Issue.find(2).update_attribute :parent_issue_id, 1
59 Issue.find(2).update_attribute :parent_issue_id, 1
60 assert_equal l(:text_issues_destroy_confirmation) + "\n" +
60 assert_equal l(:text_issues_destroy_confirmation) + "\n" +
61 l(:text_issues_destroy_descendants_confirmation, :count => 1),
61 l(:text_issues_destroy_descendants_confirmation, :count => 1),
62 issues_destroy_confirmation_message(Issue.find(1))
62 issues_destroy_confirmation_message(Issue.find(1))
63 end
63 end
64
64
65 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
65 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
66 Issue.find(2).update_attribute :parent_issue_id, 1
66 Issue.find(2).update_attribute :parent_issue_id, 1
67 assert_equal l(:text_issues_destroy_confirmation),
67 assert_equal l(:text_issues_destroy_confirmation),
68 issues_destroy_confirmation_message(Issue.find([1, 2]))
68 issues_destroy_confirmation_message(Issue.find([1, 2]))
69 end
69 end
70
70
71 def test_issues_destroy_confirmation_message_with_issues_that_share_descendants
72 root = Issue.generate!
73 child = Issue.generate!(:parent_issue_id => root.id)
74 Issue.generate!(:parent_issue_id => child.id)
75
76 assert_equal l(:text_issues_destroy_confirmation) + "\n" +
77 l(:text_issues_destroy_descendants_confirmation, :count => 1),
78 issues_destroy_confirmation_message([root.reload, child.reload])
79 end
80
71 test 'show_detail with no_html should show a changing attribute' do
81 test 'show_detail with no_html should show a changing attribute' do
72 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
82 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
73 :value => '100', :prop_key => 'done_ratio')
83 :value => '100', :prop_key => 'done_ratio')
74 assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
84 assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
75 end
85 end
76
86
77 test 'show_detail with no_html should show a new attribute' do
87 test 'show_detail with no_html should show a new attribute' do
78 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
88 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
79 :value => '100', :prop_key => 'done_ratio')
89 :value => '100', :prop_key => 'done_ratio')
80 assert_equal "% Done set to 100", show_detail(detail, true)
90 assert_equal "% Done set to 100", show_detail(detail, true)
81 end
91 end
82
92
83 test 'show_detail with no_html should show a deleted attribute' do
93 test 'show_detail with no_html should show a deleted attribute' do
84 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
94 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
85 :value => nil, :prop_key => 'done_ratio')
95 :value => nil, :prop_key => 'done_ratio')
86 assert_equal "% Done deleted (50)", show_detail(detail, true)
96 assert_equal "% Done deleted (50)", show_detail(detail, true)
87 end
97 end
88
98
89 test 'show_detail with html should show a changing attribute with HTML highlights' do
99 test 'show_detail with html should show a changing attribute with HTML highlights' do
90 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
100 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
91 :value => '100', :prop_key => 'done_ratio')
101 :value => '100', :prop_key => 'done_ratio')
92 html = show_detail(detail, false)
102 html = show_detail(detail, false)
93 assert_include '<strong>% Done</strong>', html
103 assert_include '<strong>% Done</strong>', html
94 assert_include '<i>40</i>', html
104 assert_include '<i>40</i>', html
95 assert_include '<i>100</i>', html
105 assert_include '<i>100</i>', html
96 end
106 end
97
107
98 test 'show_detail with html should show a new attribute with HTML highlights' do
108 test 'show_detail with html should show a new attribute with HTML highlights' do
99 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
109 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
100 :value => '100', :prop_key => 'done_ratio')
110 :value => '100', :prop_key => 'done_ratio')
101 html = show_detail(detail, false)
111 html = show_detail(detail, false)
102 assert_include '<strong>% Done</strong>', html
112 assert_include '<strong>% Done</strong>', html
103 assert_include '<i>100</i>', html
113 assert_include '<i>100</i>', html
104 end
114 end
105
115
106 test 'show_detail with html should show a deleted attribute with HTML highlights' do
116 test 'show_detail with html should show a deleted attribute with HTML highlights' do
107 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
117 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
108 :value => nil, :prop_key => 'done_ratio')
118 :value => nil, :prop_key => 'done_ratio')
109 html = show_detail(detail, false)
119 html = show_detail(detail, false)
110 assert_include '<strong>% Done</strong>', html
120 assert_include '<strong>% Done</strong>', html
111 assert_include '<del><i>50</i></del>', html
121 assert_include '<del><i>50</i></del>', html
112 end
122 end
113
123
114 test 'show_detail with a start_date attribute should format the dates' do
124 test 'show_detail with a start_date attribute should format the dates' do
115 detail = JournalDetail.new(
125 detail = JournalDetail.new(
116 :property => 'attr',
126 :property => 'attr',
117 :old_value => '2010-01-01',
127 :old_value => '2010-01-01',
118 :value => '2010-01-31',
128 :value => '2010-01-31',
119 :prop_key => 'start_date'
129 :prop_key => 'start_date'
120 )
130 )
121 with_settings :date_format => '%m/%d/%Y' do
131 with_settings :date_format => '%m/%d/%Y' do
122 assert_match "01/31/2010", show_detail(detail, true)
132 assert_match "01/31/2010", show_detail(detail, true)
123 assert_match "01/01/2010", show_detail(detail, true)
133 assert_match "01/01/2010", show_detail(detail, true)
124 end
134 end
125 end
135 end
126
136
127 test 'show_detail with a due_date attribute should format the dates' do
137 test 'show_detail with a due_date attribute should format the dates' do
128 detail = JournalDetail.new(
138 detail = JournalDetail.new(
129 :property => 'attr',
139 :property => 'attr',
130 :old_value => '2010-01-01',
140 :old_value => '2010-01-01',
131 :value => '2010-01-31',
141 :value => '2010-01-31',
132 :prop_key => 'due_date'
142 :prop_key => 'due_date'
133 )
143 )
134 with_settings :date_format => '%m/%d/%Y' do
144 with_settings :date_format => '%m/%d/%Y' do
135 assert_match "01/31/2010", show_detail(detail, true)
145 assert_match "01/31/2010", show_detail(detail, true)
136 assert_match "01/01/2010", show_detail(detail, true)
146 assert_match "01/01/2010", show_detail(detail, true)
137 end
147 end
138 end
148 end
139
149
140 test 'show_detail should show old and new values with a project attribute' do
150 test 'show_detail should show old and new values with a project attribute' do
141 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
151 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
142 :old_value => 1, :value => 2)
152 :old_value => 1, :value => 2)
143 assert_match 'eCookbook', show_detail(detail, true)
153 assert_match 'eCookbook', show_detail(detail, true)
144 assert_match 'OnlineStore', show_detail(detail, true)
154 assert_match 'OnlineStore', show_detail(detail, true)
145 end
155 end
146
156
147 test 'show_detail should show old and new values with a issue status attribute' do
157 test 'show_detail should show old and new values with a issue status attribute' do
148 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
158 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
149 :old_value => 1, :value => 2)
159 :old_value => 1, :value => 2)
150 assert_match 'New', show_detail(detail, true)
160 assert_match 'New', show_detail(detail, true)
151 assert_match 'Assigned', show_detail(detail, true)
161 assert_match 'Assigned', show_detail(detail, true)
152 end
162 end
153
163
154 test 'show_detail should show old and new values with a tracker attribute' do
164 test 'show_detail should show old and new values with a tracker attribute' do
155 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
165 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
156 :old_value => 1, :value => 2)
166 :old_value => 1, :value => 2)
157 assert_match 'Bug', show_detail(detail, true)
167 assert_match 'Bug', show_detail(detail, true)
158 assert_match 'Feature request', show_detail(detail, true)
168 assert_match 'Feature request', show_detail(detail, true)
159 end
169 end
160
170
161 test 'show_detail should show old and new values with a assigned to attribute' do
171 test 'show_detail should show old and new values with a assigned to attribute' do
162 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
172 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
163 :old_value => 1, :value => 2)
173 :old_value => 1, :value => 2)
164 assert_match 'Redmine Admin', show_detail(detail, true)
174 assert_match 'Redmine Admin', show_detail(detail, true)
165 assert_match 'John Smith', show_detail(detail, true)
175 assert_match 'John Smith', show_detail(detail, true)
166 end
176 end
167
177
168 test 'show_detail should show old and new values with a priority attribute' do
178 test 'show_detail should show old and new values with a priority attribute' do
169 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
179 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
170 :old_value => 4, :value => 5)
180 :old_value => 4, :value => 5)
171 assert_match 'Low', show_detail(detail, true)
181 assert_match 'Low', show_detail(detail, true)
172 assert_match 'Normal', show_detail(detail, true)
182 assert_match 'Normal', show_detail(detail, true)
173 end
183 end
174
184
175 test 'show_detail should show old and new values with a category attribute' do
185 test 'show_detail should show old and new values with a category attribute' do
176 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
186 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
177 :old_value => 1, :value => 2)
187 :old_value => 1, :value => 2)
178 assert_match 'Printing', show_detail(detail, true)
188 assert_match 'Printing', show_detail(detail, true)
179 assert_match 'Recipes', show_detail(detail, true)
189 assert_match 'Recipes', show_detail(detail, true)
180 end
190 end
181
191
182 test 'show_detail should show old and new values with a fixed version attribute' do
192 test 'show_detail should show old and new values with a fixed version attribute' do
183 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
193 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
184 :old_value => 1, :value => 2)
194 :old_value => 1, :value => 2)
185 assert_match '0.1', show_detail(detail, true)
195 assert_match '0.1', show_detail(detail, true)
186 assert_match '1.0', show_detail(detail, true)
196 assert_match '1.0', show_detail(detail, true)
187 end
197 end
188
198
189 test 'show_detail should show old and new values with a estimated hours attribute' do
199 test 'show_detail should show old and new values with a estimated hours attribute' do
190 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
200 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
191 :old_value => '5', :value => '6.3')
201 :old_value => '5', :value => '6.3')
192 assert_match '5.00', show_detail(detail, true)
202 assert_match '5.00', show_detail(detail, true)
193 assert_match '6.30', show_detail(detail, true)
203 assert_match '6.30', show_detail(detail, true)
194 end
204 end
195
205
196 test 'show_detail should show old and new values with a custom field' do
206 test 'show_detail should show old and new values with a custom field' do
197 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
207 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
198 :old_value => 'MySQL', :value => 'PostgreSQL')
208 :old_value => 'MySQL', :value => 'PostgreSQL')
199 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
209 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
200 end
210 end
201
211
202 test 'show_detail should show added file' do
212 test 'show_detail should show added file' do
203 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
213 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
204 :old_value => nil, :value => 'error281.txt')
214 :old_value => nil, :value => 'error281.txt')
205 assert_match 'error281.txt', show_detail(detail, true)
215 assert_match 'error281.txt', show_detail(detail, true)
206 end
216 end
207
217
208 test 'show_detail should show removed file' do
218 test 'show_detail should show removed file' do
209 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
219 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
210 :old_value => 'error281.txt', :value => nil)
220 :old_value => 'error281.txt', :value => nil)
211 assert_match 'error281.txt', show_detail(detail, true)
221 assert_match 'error281.txt', show_detail(detail, true)
212 end
222 end
213
223
214 def test_show_detail_relation_added
224 def test_show_detail_relation_added
215 detail = JournalDetail.new(:property => 'relation',
225 detail = JournalDetail.new(:property => 'relation',
216 :prop_key => 'precedes',
226 :prop_key => 'precedes',
217 :value => 1)
227 :value => 1)
218 assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true)
228 assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true)
219 str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes)
229 str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes)
220 assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added",
230 assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added",
221 show_detail(detail, false)
231 show_detail(detail, false)
222 end
232 end
223
233
224 def test_show_detail_relation_added_with_inexistant_issue
234 def test_show_detail_relation_added_with_inexistant_issue
225 inexistant_issue_number = 9999
235 inexistant_issue_number = 9999
226 assert_nil Issue.find_by_id(inexistant_issue_number)
236 assert_nil Issue.find_by_id(inexistant_issue_number)
227 detail = JournalDetail.new(:property => 'relation',
237 detail = JournalDetail.new(:property => 'relation',
228 :prop_key => 'precedes',
238 :prop_key => 'precedes',
229 :value => inexistant_issue_number)
239 :value => inexistant_issue_number)
230 assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
240 assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
231 assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
241 assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
232 end
242 end
233
243
234 def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
244 def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
235 issue = Issue.generate!(:is_private => true)
245 issue = Issue.generate!(:is_private => true)
236 detail = JournalDetail.new(:property => 'relation',
246 detail = JournalDetail.new(:property => 'relation',
237 :prop_key => 'precedes',
247 :prop_key => 'precedes',
238 :value => issue.id)
248 :value => issue.id)
239
249
240 assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
250 assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
241 assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
251 assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
242 end
252 end
243
253
244 def test_show_detail_relation_deleted
254 def test_show_detail_relation_deleted
245 detail = JournalDetail.new(:property => 'relation',
255 detail = JournalDetail.new(:property => 'relation',
246 :prop_key => 'precedes',
256 :prop_key => 'precedes',
247 :old_value => 1)
257 :old_value => 1)
248 assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true)
258 assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true)
249 str = link_to("Bug #1",
259 str = link_to("Bug #1",
250 "/issues/1",
260 "/issues/1",
251 :class => Issue.find(1).css_classes)
261 :class => Issue.find(1).css_classes)
252 assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)",
262 assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)",
253 show_detail(detail, false)
263 show_detail(detail, false)
254 end
264 end
255
265
256 def test_show_detail_relation_deleted_with_inexistant_issue
266 def test_show_detail_relation_deleted_with_inexistant_issue
257 inexistant_issue_number = 9999
267 inexistant_issue_number = 9999
258 assert_nil Issue.find_by_id(inexistant_issue_number)
268 assert_nil Issue.find_by_id(inexistant_issue_number)
259 detail = JournalDetail.new(:property => 'relation',
269 detail = JournalDetail.new(:property => 'relation',
260 :prop_key => 'precedes',
270 :prop_key => 'precedes',
261 :old_value => inexistant_issue_number)
271 :old_value => inexistant_issue_number)
262 assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
272 assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
263 assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
273 assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
264 end
274 end
265
275
266 def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
276 def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
267 issue = Issue.generate!(:is_private => true)
277 issue = Issue.generate!(:is_private => true)
268 detail = JournalDetail.new(:property => 'relation',
278 detail = JournalDetail.new(:property => 'relation',
269 :prop_key => 'precedes',
279 :prop_key => 'precedes',
270 :old_value => issue.id)
280 :old_value => issue.id)
271
281
272 assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
282 assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
273 assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
283 assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
274 end
284 end
275 end
285 end
General Comments 0
You need to be logged in to leave comments. Login now