@@ -1,488 +1,492 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2015 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 | include Redmine::Export::PDF::IssuesPdfHelper |
|
22 | include Redmine::Export::PDF::IssuesPdfHelper | |
23 |
|
23 | |||
24 | def issue_list(issues, &block) |
|
24 | def issue_list(issues, &block) | |
25 | ancestors = [] |
|
25 | ancestors = [] | |
26 | issues.each do |issue| |
|
26 | issues.each do |issue| | |
27 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
|
27 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) | |
28 | ancestors.pop |
|
28 | ancestors.pop | |
29 | end |
|
29 | end | |
30 | yield issue, ancestors.size |
|
30 | yield issue, ancestors.size | |
31 | ancestors << issue unless issue.leaf? |
|
31 | ancestors << issue unless issue.leaf? | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def grouped_issue_list(issues, query, issue_count_by_group, &block) |
|
35 | def grouped_issue_list(issues, query, issue_count_by_group, &block) | |
36 | previous_group, first = false, true |
|
36 | previous_group, first = false, true | |
37 | issue_list(issues) do |issue, level| |
|
37 | issue_list(issues) do |issue, level| | |
38 | group_name = group_count = nil |
|
38 | group_name = group_count = nil | |
39 | if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first) |
|
39 | if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first) | |
40 | if group.blank? && group != false |
|
40 | if group.blank? && group != false | |
41 | group_name = "(#{l(:label_blank_value)})" |
|
41 | group_name = "(#{l(:label_blank_value)})" | |
42 | else |
|
42 | else | |
43 | group_name = column_content(query.group_by_column, issue) |
|
43 | group_name = column_content(query.group_by_column, issue) | |
44 | end |
|
44 | end | |
45 | group_name ||= "" |
|
45 | group_name ||= "" | |
46 | group_count = issue_count_by_group[group] |
|
46 | group_count = issue_count_by_group[group] | |
47 | end |
|
47 | end | |
48 | yield issue, level, group_name, group_count |
|
48 | yield issue, level, group_name, group_count | |
49 | previous_group, first = group, false |
|
49 | previous_group, first = group, false | |
50 | end |
|
50 | end | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | # Renders a HTML/CSS tooltip |
|
53 | # Renders a HTML/CSS tooltip | |
54 | # |
|
54 | # | |
55 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
|
55 | # To use, a trigger div is needed. This is a div with the class of "tooltip" | |
56 | # that contains this method wrapped in a span with the class of "tip" |
|
56 | # that contains this method wrapped in a span with the class of "tip" | |
57 | # |
|
57 | # | |
58 | # <div class="tooltip"><%= link_to_issue(issue) %> |
|
58 | # <div class="tooltip"><%= link_to_issue(issue) %> | |
59 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
|
59 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> | |
60 | # </div> |
|
60 | # </div> | |
61 | # |
|
61 | # | |
62 | def render_issue_tooltip(issue) |
|
62 | def render_issue_tooltip(issue) | |
63 | @cached_label_status ||= l(:field_status) |
|
63 | @cached_label_status ||= l(:field_status) | |
64 | @cached_label_start_date ||= l(:field_start_date) |
|
64 | @cached_label_start_date ||= l(:field_start_date) | |
65 | @cached_label_due_date ||= l(:field_due_date) |
|
65 | @cached_label_due_date ||= l(:field_due_date) | |
66 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
66 | @cached_label_assigned_to ||= l(:field_assigned_to) | |
67 | @cached_label_priority ||= l(:field_priority) |
|
67 | @cached_label_priority ||= l(:field_priority) | |
68 | @cached_label_project ||= l(:field_project) |
|
68 | @cached_label_project ||= l(:field_project) | |
69 |
|
69 | |||
70 | link_to_issue(issue) + "<br /><br />".html_safe + |
|
70 | link_to_issue(issue) + "<br /><br />".html_safe + | |
71 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + |
|
71 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + | |
72 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + |
|
72 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + | |
73 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + |
|
73 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + | |
74 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + |
|
74 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + | |
75 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + |
|
75 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + | |
76 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe |
|
76 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def issue_heading(issue) |
|
79 | def issue_heading(issue) | |
80 | h("#{issue.tracker} ##{issue.id}") |
|
80 | h("#{issue.tracker} ##{issue.id}") | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def render_issue_subject_with_tree(issue) |
|
83 | def render_issue_subject_with_tree(issue) | |
84 | s = '' |
|
84 | s = '' | |
85 | ancestors = issue.root? ? [] : issue.ancestors.visible.to_a |
|
85 | ancestors = issue.root? ? [] : issue.ancestors.visible.to_a | |
86 | ancestors.each do |ancestor| |
|
86 | ancestors.each do |ancestor| | |
87 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) |
|
87 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) | |
88 | end |
|
88 | end | |
89 | s << '<div>' |
|
89 | s << '<div>' | |
90 | subject = h(issue.subject) |
|
90 | subject = h(issue.subject) | |
91 | if issue.is_private? |
|
91 | if issue.is_private? | |
92 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject |
|
92 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject | |
93 | end |
|
93 | end | |
94 | s << content_tag('h3', subject) |
|
94 | s << content_tag('h3', subject) | |
95 | s << '</div>' * (ancestors.size + 1) |
|
95 | s << '</div>' * (ancestors.size + 1) | |
96 | s.html_safe |
|
96 | s.html_safe | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def render_descendants_tree(issue) |
|
99 | def render_descendants_tree(issue) | |
100 | s = '<form><table class="list issues">' |
|
100 | s = '<form><table class="list issues">' | |
101 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| |
|
101 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| | |
102 | css = "issue issue-#{child.id} hascontextmenu" |
|
102 | css = "issue issue-#{child.id} hascontextmenu" | |
103 | css << " idnt idnt-#{level}" if level > 0 |
|
103 | css << " idnt idnt-#{level}" if level > 0 | |
104 | s << content_tag('tr', |
|
104 | s << content_tag('tr', | |
105 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + |
|
105 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + | |
106 | content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') + |
|
106 | content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') + | |
107 | content_tag('td', h(child.status)) + |
|
107 | content_tag('td', h(child.status)) + | |
108 | content_tag('td', link_to_user(child.assigned_to)) + |
|
108 | content_tag('td', link_to_user(child.assigned_to)) + | |
109 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), |
|
109 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), | |
110 | :class => css) |
|
110 | :class => css) | |
111 | end |
|
111 | end | |
112 | s << '</table></form>' |
|
112 | s << '</table></form>' | |
113 | s.html_safe |
|
113 | s.html_safe | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | # Returns an array of error messages for bulk edited issues |
|
116 | # Returns an array of error messages for bulk edited issues | |
117 | def bulk_edit_error_messages(issues) |
|
117 | def bulk_edit_error_messages(issues) | |
118 | messages = {} |
|
118 | messages = {} | |
119 | issues.each do |issue| |
|
119 | issues.each do |issue| | |
120 | issue.errors.full_messages.each do |message| |
|
120 | issue.errors.full_messages.each do |message| | |
121 | messages[message] ||= [] |
|
121 | messages[message] ||= [] | |
122 | messages[message] << issue |
|
122 | messages[message] << issue | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 | messages.map { |message, issues| |
|
125 | messages.map { |message, issues| | |
126 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') |
|
126 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') | |
127 | } |
|
127 | } | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | # Returns a link for adding a new subtask to the given issue |
|
130 | # Returns a link for adding a new subtask to the given issue | |
131 | def link_to_new_subtask(issue) |
|
131 | def link_to_new_subtask(issue) | |
132 | attrs = { |
|
132 | attrs = { | |
133 | :tracker_id => issue.tracker, |
|
133 | :tracker_id => issue.tracker, | |
134 | :parent_issue_id => issue |
|
134 | :parent_issue_id => issue | |
135 | } |
|
135 | } | |
136 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
136 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | class IssueFieldsRows |
|
139 | class IssueFieldsRows | |
140 | include ActionView::Helpers::TagHelper |
|
140 | include ActionView::Helpers::TagHelper | |
141 |
|
141 | |||
142 | def initialize |
|
142 | def initialize | |
143 | @left = [] |
|
143 | @left = [] | |
144 | @right = [] |
|
144 | @right = [] | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def left(*args) |
|
147 | def left(*args) | |
148 | args.any? ? @left << cells(*args) : @left |
|
148 | args.any? ? @left << cells(*args) : @left | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def right(*args) |
|
151 | def right(*args) | |
152 | args.any? ? @right << cells(*args) : @right |
|
152 | args.any? ? @right << cells(*args) : @right | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | def size |
|
155 | def size | |
156 | @left.size > @right.size ? @left.size : @right.size |
|
156 | @left.size > @right.size ? @left.size : @right.size | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def to_html |
|
159 | def to_html | |
160 | html = ''.html_safe |
|
160 | html = ''.html_safe | |
161 | blank = content_tag('th', '') + content_tag('td', '') |
|
161 | blank = content_tag('th', '') + content_tag('td', '') | |
162 | size.times do |i| |
|
162 | size.times do |i| | |
163 | left = @left[i] || blank |
|
163 | left = @left[i] || blank | |
164 | right = @right[i] || blank |
|
164 | right = @right[i] || blank | |
165 | html << content_tag('tr', left + right) |
|
165 | html << content_tag('tr', left + right) | |
166 | end |
|
166 | end | |
167 | html |
|
167 | html | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | def cells(label, text, options={}) |
|
170 | def cells(label, text, options={}) | |
171 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
171 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) | |
172 | end |
|
172 | end | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | def issue_fields_rows |
|
175 | def issue_fields_rows | |
176 | r = IssueFieldsRows.new |
|
176 | r = IssueFieldsRows.new | |
177 | yield r |
|
177 | yield r | |
178 | r.to_html |
|
178 | r.to_html | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def render_custom_fields_rows(issue) |
|
181 | def render_custom_fields_rows(issue) | |
182 | values = issue.visible_custom_field_values |
|
182 | values = issue.visible_custom_field_values | |
183 | return if values.empty? |
|
183 | return if values.empty? | |
184 | ordered_values = [] |
|
184 | ordered_values = [] | |
185 | half = (values.size / 2.0).ceil |
|
185 | half = (values.size / 2.0).ceil | |
186 | half.times do |i| |
|
186 | half.times do |i| | |
187 | ordered_values << values[i] |
|
187 | ordered_values << values[i] | |
188 | ordered_values << values[i + half] |
|
188 | ordered_values << values[i + half] | |
189 | end |
|
189 | end | |
190 | s = "<tr>\n" |
|
190 | s = "<tr>\n" | |
191 | n = 0 |
|
191 | n = 0 | |
192 | ordered_values.compact.each do |value| |
|
192 | ordered_values.compact.each do |value| | |
193 | css = "cf_#{value.custom_field.id}" |
|
193 | css = "cf_#{value.custom_field.id}" | |
194 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
194 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 | |
195 | s << "\t<th class=\"#{css}\">#{ h(value.custom_field.name) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n" |
|
195 | s << "\t<th class=\"#{css}\">#{ h(value.custom_field.name) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n" | |
196 | n += 1 |
|
196 | n += 1 | |
197 | end |
|
197 | end | |
198 | s << "</tr>\n" |
|
198 | s << "</tr>\n" | |
199 | s.html_safe |
|
199 | s.html_safe | |
200 | end |
|
200 | end | |
201 |
|
201 | |||
202 | # Returns the path for updating the issue form |
|
202 | # Returns the path for updating the issue form | |
203 | # with project as the current project |
|
203 | # with project as the current project | |
204 | def update_issue_form_path(project, issue) |
|
204 | def update_issue_form_path(project, issue) | |
205 | options = {:format => 'js'} |
|
205 | options = {:format => 'js'} | |
206 | if issue.new_record? |
|
206 | if issue.new_record? | |
207 | if project |
|
207 | if project | |
208 | new_project_issue_path(project, options) |
|
208 | new_project_issue_path(project, options) | |
209 | else |
|
209 | else | |
210 | new_issue_path(options) |
|
210 | new_issue_path(options) | |
211 | end |
|
211 | end | |
212 | else |
|
212 | else | |
213 | edit_issue_path(issue, options) |
|
213 | edit_issue_path(issue, options) | |
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | # Returns the number of descendants for an array of issues |
|
217 | # Returns the number of descendants for an array of issues | |
218 | def issues_descendant_count(issues) |
|
218 | def issues_descendant_count(issues) | |
219 | ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq |
|
219 | ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq | |
220 | ids -= issues.map(&:id) |
|
220 | ids -= issues.map(&:id) | |
221 | ids.size |
|
221 | ids.size | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def issues_destroy_confirmation_message(issues) |
|
224 | def issues_destroy_confirmation_message(issues) | |
225 | issues = [issues] unless issues.is_a?(Array) |
|
225 | issues = [issues] unless issues.is_a?(Array) | |
226 | message = l(:text_issues_destroy_confirmation) |
|
226 | message = l(:text_issues_destroy_confirmation) | |
227 |
|
227 | |||
228 | descendant_count = issues_descendant_count(issues) |
|
228 | descendant_count = issues_descendant_count(issues) | |
229 | if descendant_count > 0 |
|
229 | if descendant_count > 0 | |
230 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
230 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
231 | end |
|
231 | end | |
232 | message |
|
232 | message | |
233 | end |
|
233 | end | |
234 |
|
234 | |||
235 | # Returns an array of users that are proposed as watchers |
|
235 | # Returns an array of users that are proposed as watchers | |
236 | # on the new issue form |
|
236 | # on the new issue form | |
237 | def users_for_new_issue_watchers(issue) |
|
237 | def users_for_new_issue_watchers(issue) | |
238 | users = issue.watcher_users |
|
238 | users = issue.watcher_users | |
239 | if issue.project.users.count <= 20 |
|
239 | if issue.project.users.count <= 20 | |
240 | users = (users + issue.project.users.sort).uniq |
|
240 | users = (users + issue.project.users.sort).uniq | |
241 | end |
|
241 | end | |
242 | users |
|
242 | users | |
243 | end |
|
243 | end | |
244 |
|
244 | |||
245 | def sidebar_queries |
|
245 | def sidebar_queries | |
246 | unless @sidebar_queries |
|
246 | unless @sidebar_queries | |
247 | @sidebar_queries = IssueQuery.visible. |
|
247 | @sidebar_queries = IssueQuery.visible. | |
248 | order("#{Query.table_name}.name ASC"). |
|
248 | order("#{Query.table_name}.name ASC"). | |
249 | # Project specific queries and global queries |
|
249 | # Project specific queries and global queries | |
250 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). |
|
250 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). | |
251 | to_a |
|
251 | to_a | |
252 | end |
|
252 | end | |
253 | @sidebar_queries |
|
253 | @sidebar_queries | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | def query_links(title, queries) |
|
256 | def query_links(title, queries) | |
257 | return '' if queries.empty? |
|
257 | return '' if queries.empty? | |
258 | # links to #index on issues/show |
|
258 | # links to #index on issues/show | |
259 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
259 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params | |
260 |
|
260 | |||
261 | content_tag('h3', title) + "\n" + |
|
261 | content_tag('h3', title) + "\n" + | |
262 | content_tag('ul', |
|
262 | content_tag('ul', | |
263 | queries.collect {|query| |
|
263 | queries.collect {|query| | |
264 | css = 'query' |
|
264 | css = 'query' | |
265 | css << ' selected' if query == @query |
|
265 | css << ' selected' if query == @query | |
266 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) |
|
266 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) | |
267 | }.join("\n").html_safe, |
|
267 | }.join("\n").html_safe, | |
268 | :class => 'queries' |
|
268 | :class => 'queries' | |
269 | ) + "\n" |
|
269 | ) + "\n" | |
270 | end |
|
270 | end | |
271 |
|
271 | |||
272 | def render_sidebar_queries |
|
272 | def render_sidebar_queries | |
273 | out = ''.html_safe |
|
273 | out = ''.html_safe | |
274 | out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?)) |
|
274 | out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?)) | |
275 | out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?)) |
|
275 | out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?)) | |
276 | out |
|
276 | out | |
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | def email_issue_attributes(issue, user) |
|
279 | def email_issue_attributes(issue, user) | |
280 | items = [] |
|
280 | items = [] | |
281 | %w(author status priority assigned_to category fixed_version).each do |attribute| |
|
281 | %w(author status priority assigned_to category fixed_version).each do |attribute| | |
282 | unless issue.disabled_core_fields.include?(attribute+"_id") |
|
282 | unless issue.disabled_core_fields.include?(attribute+"_id") | |
283 | items << "#{l("field_#{attribute}")}: #{issue.send attribute}" |
|
283 | items << "#{l("field_#{attribute}")}: #{issue.send attribute}" | |
284 | end |
|
284 | end | |
285 | end |
|
285 | end | |
286 | issue.visible_custom_field_values(user).each do |value| |
|
286 | issue.visible_custom_field_values(user).each do |value| | |
287 | items << "#{value.custom_field.name}: #{show_value(value, false)}" |
|
287 | items << "#{value.custom_field.name}: #{show_value(value, false)}" | |
288 | end |
|
288 | end | |
289 | items |
|
289 | items | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | def render_email_issue_attributes(issue, user, html=false) |
|
292 | def render_email_issue_attributes(issue, user, html=false) | |
293 | items = email_issue_attributes(issue, user) |
|
293 | items = email_issue_attributes(issue, user) | |
294 | if html |
|
294 | if html | |
295 | content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe) |
|
295 | content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe) | |
296 | else |
|
296 | else | |
297 | items.map{|s| "* #{s}"}.join("\n") |
|
297 | items.map{|s| "* #{s}"}.join("\n") | |
298 | end |
|
298 | end | |
299 | end |
|
299 | end | |
300 |
|
300 | |||
301 | # Returns the textual representation of a journal details |
|
301 | # Returns the textual representation of a journal details | |
302 | # as an array of strings |
|
302 | # as an array of strings | |
303 | def details_to_strings(details, no_html=false, options={}) |
|
303 | def details_to_strings(details, no_html=false, options={}) | |
304 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
304 | options[:only_path] = (options[:only_path] == false ? false : true) | |
305 | strings = [] |
|
305 | strings = [] | |
306 | values_by_field = {} |
|
306 | values_by_field = {} | |
307 | details.each do |detail| |
|
307 | details.each do |detail| | |
308 | if detail.property == 'cf' |
|
308 | if detail.property == 'cf' | |
309 | field = detail.custom_field |
|
309 | field = detail.custom_field | |
310 | if field && field.multiple? |
|
310 | if field && field.multiple? | |
311 | values_by_field[field] ||= {:added => [], :deleted => []} |
|
311 | values_by_field[field] ||= {:added => [], :deleted => []} | |
312 | if detail.old_value |
|
312 | if detail.old_value | |
313 | values_by_field[field][:deleted] << detail.old_value |
|
313 | values_by_field[field][:deleted] << detail.old_value | |
314 | end |
|
314 | end | |
315 | if detail.value |
|
315 | if detail.value | |
316 | values_by_field[field][:added] << detail.value |
|
316 | values_by_field[field][:added] << detail.value | |
317 | end |
|
317 | end | |
318 | next |
|
318 | next | |
319 | end |
|
319 | end | |
320 | end |
|
320 | end | |
321 | strings << show_detail(detail, no_html, options) |
|
321 | strings << show_detail(detail, no_html, options) | |
322 | end |
|
322 | end | |
323 | values_by_field.each do |field, changes| |
|
323 | if values_by_field.present? | |
324 | detail = JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s) |
|
324 | multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value) | |
325 | detail.instance_variable_set "@custom_field", field |
|
325 | values_by_field.each do |field, changes| | |
326 | if changes[:added].any? |
|
326 | if changes[:added].any? | |
327 | detail.value = changes[:added] |
|
327 | detail = multiple_values_detail.new('cf', field.id.to_s, field) | |
328 | strings << show_detail(detail, no_html, options) |
|
328 | detail.value = changes[:added] | |
329 | elsif changes[:deleted].any? |
|
329 | strings << show_detail(detail, no_html, options) | |
330 | detail.old_value = changes[:deleted] |
|
330 | end | |
331 | strings << show_detail(detail, no_html, options) |
|
331 | if changes[:deleted].any? | |
|
332 | detail = multiple_values_detail.new('cf', field.id.to_s, field) | |||
|
333 | detail.old_value = changes[:deleted] | |||
|
334 | strings << show_detail(detail, no_html, options) | |||
|
335 | end | |||
332 | end |
|
336 | end | |
333 | end |
|
337 | end | |
334 | strings |
|
338 | strings | |
335 | end |
|
339 | end | |
336 |
|
340 | |||
337 | # Returns the textual representation of a single journal detail |
|
341 | # Returns the textual representation of a single journal detail | |
338 | def show_detail(detail, no_html=false, options={}) |
|
342 | def show_detail(detail, no_html=false, options={}) | |
339 | multiple = false |
|
343 | multiple = false | |
340 | show_diff = false |
|
344 | show_diff = false | |
341 |
|
345 | |||
342 | case detail.property |
|
346 | case detail.property | |
343 | when 'attr' |
|
347 | when 'attr' | |
344 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
348 | field = detail.prop_key.to_s.gsub(/\_id$/, "") | |
345 | label = l(("field_" + field).to_sym) |
|
349 | label = l(("field_" + field).to_sym) | |
346 | case detail.prop_key |
|
350 | case detail.prop_key | |
347 | when 'due_date', 'start_date' |
|
351 | when 'due_date', 'start_date' | |
348 | value = format_date(detail.value.to_date) if detail.value |
|
352 | value = format_date(detail.value.to_date) if detail.value | |
349 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
353 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
350 |
|
354 | |||
351 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
355 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', | |
352 | 'priority_id', 'category_id', 'fixed_version_id' |
|
356 | 'priority_id', 'category_id', 'fixed_version_id' | |
353 | value = find_name_by_reflection(field, detail.value) |
|
357 | value = find_name_by_reflection(field, detail.value) | |
354 | old_value = find_name_by_reflection(field, detail.old_value) |
|
358 | old_value = find_name_by_reflection(field, detail.old_value) | |
355 |
|
359 | |||
356 | when 'estimated_hours' |
|
360 | when 'estimated_hours' | |
357 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
361 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
358 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
362 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
359 |
|
363 | |||
360 | when 'parent_id' |
|
364 | when 'parent_id' | |
361 | label = l(:field_parent_issue) |
|
365 | label = l(:field_parent_issue) | |
362 | value = "##{detail.value}" unless detail.value.blank? |
|
366 | value = "##{detail.value}" unless detail.value.blank? | |
363 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
367 | old_value = "##{detail.old_value}" unless detail.old_value.blank? | |
364 |
|
368 | |||
365 | when 'is_private' |
|
369 | when 'is_private' | |
366 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
370 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? | |
367 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
371 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? | |
368 |
|
372 | |||
369 | when 'description' |
|
373 | when 'description' | |
370 | show_diff = true |
|
374 | show_diff = true | |
371 | end |
|
375 | end | |
372 | when 'cf' |
|
376 | when 'cf' | |
373 | custom_field = detail.custom_field |
|
377 | custom_field = detail.custom_field | |
374 | if custom_field |
|
378 | if custom_field | |
375 | label = custom_field.name |
|
379 | label = custom_field.name | |
376 | if custom_field.format.class.change_as_diff |
|
380 | if custom_field.format.class.change_as_diff | |
377 | show_diff = true |
|
381 | show_diff = true | |
378 | else |
|
382 | else | |
379 | multiple = custom_field.multiple? |
|
383 | multiple = custom_field.multiple? | |
380 | value = format_value(detail.value, custom_field) if detail.value |
|
384 | value = format_value(detail.value, custom_field) if detail.value | |
381 | old_value = format_value(detail.old_value, custom_field) if detail.old_value |
|
385 | old_value = format_value(detail.old_value, custom_field) if detail.old_value | |
382 | end |
|
386 | end | |
383 | end |
|
387 | end | |
384 | when 'attachment' |
|
388 | when 'attachment' | |
385 | label = l(:label_attachment) |
|
389 | label = l(:label_attachment) | |
386 | when 'relation' |
|
390 | when 'relation' | |
387 | if detail.value && !detail.old_value |
|
391 | if detail.value && !detail.old_value | |
388 | rel_issue = Issue.visible.find_by_id(detail.value) |
|
392 | rel_issue = Issue.visible.find_by_id(detail.value) | |
389 | value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" : |
|
393 | value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" : | |
390 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) |
|
394 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) | |
391 | elsif detail.old_value && !detail.value |
|
395 | elsif detail.old_value && !detail.value | |
392 | rel_issue = Issue.visible.find_by_id(detail.old_value) |
|
396 | rel_issue = Issue.visible.find_by_id(detail.old_value) | |
393 | old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" : |
|
397 | old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" : | |
394 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) |
|
398 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) | |
395 | end |
|
399 | end | |
396 | relation_type = IssueRelation::TYPES[detail.prop_key] |
|
400 | relation_type = IssueRelation::TYPES[detail.prop_key] | |
397 | label = l(relation_type[:name]) if relation_type |
|
401 | label = l(relation_type[:name]) if relation_type | |
398 | end |
|
402 | end | |
399 | call_hook(:helper_issues_show_detail_after_setting, |
|
403 | call_hook(:helper_issues_show_detail_after_setting, | |
400 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
404 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) | |
401 |
|
405 | |||
402 | label ||= detail.prop_key |
|
406 | label ||= detail.prop_key | |
403 | value ||= detail.value |
|
407 | value ||= detail.value | |
404 | old_value ||= detail.old_value |
|
408 | old_value ||= detail.old_value | |
405 |
|
409 | |||
406 | unless no_html |
|
410 | unless no_html | |
407 | label = content_tag('strong', label) |
|
411 | label = content_tag('strong', label) | |
408 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
412 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
409 | if detail.old_value && detail.value.blank? && detail.property != 'relation' |
|
413 | if detail.old_value && detail.value.blank? && detail.property != 'relation' | |
410 | old_value = content_tag("del", old_value) |
|
414 | old_value = content_tag("del", old_value) | |
411 | end |
|
415 | end | |
412 | if detail.property == 'attachment' && value.present? && |
|
416 | if detail.property == 'attachment' && value.present? && | |
413 | atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i} |
|
417 | atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i} | |
414 | # Link to the attachment if it has not been removed |
|
418 | # Link to the attachment if it has not been removed | |
415 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
419 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) | |
416 | if options[:only_path] != false && atta.is_text? |
|
420 | if options[:only_path] != false && atta.is_text? | |
417 | value += link_to( |
|
421 | value += link_to( | |
418 | image_tag('magnifier.png'), |
|
422 | image_tag('magnifier.png'), | |
419 | :controller => 'attachments', :action => 'show', |
|
423 | :controller => 'attachments', :action => 'show', | |
420 | :id => atta, :filename => atta.filename |
|
424 | :id => atta, :filename => atta.filename | |
421 | ) |
|
425 | ) | |
422 | end |
|
426 | end | |
423 | else |
|
427 | else | |
424 | value = content_tag("i", h(value)) if value |
|
428 | value = content_tag("i", h(value)) if value | |
425 | end |
|
429 | end | |
426 | end |
|
430 | end | |
427 |
|
431 | |||
428 | if show_diff |
|
432 | if show_diff | |
429 | s = l(:text_journal_changed_no_detail, :label => label) |
|
433 | s = l(:text_journal_changed_no_detail, :label => label) | |
430 | unless no_html |
|
434 | unless no_html | |
431 | diff_link = link_to 'diff', |
|
435 | diff_link = link_to 'diff', | |
432 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
436 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, | |
433 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
437 | :detail_id => detail.id, :only_path => options[:only_path]}, | |
434 | :title => l(:label_view_diff) |
|
438 | :title => l(:label_view_diff) | |
435 | s << " (#{ diff_link })" |
|
439 | s << " (#{ diff_link })" | |
436 | end |
|
440 | end | |
437 | s.html_safe |
|
441 | s.html_safe | |
438 | elsif detail.value.present? |
|
442 | elsif detail.value.present? | |
439 | case detail.property |
|
443 | case detail.property | |
440 | when 'attr', 'cf' |
|
444 | when 'attr', 'cf' | |
441 | if detail.old_value.present? |
|
445 | if detail.old_value.present? | |
442 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
446 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe | |
443 | elsif multiple |
|
447 | elsif multiple | |
444 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
448 | l(:text_journal_added, :label => label, :value => value).html_safe | |
445 | else |
|
449 | else | |
446 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
450 | l(:text_journal_set_to, :label => label, :value => value).html_safe | |
447 | end |
|
451 | end | |
448 | when 'attachment', 'relation' |
|
452 | when 'attachment', 'relation' | |
449 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
453 | l(:text_journal_added, :label => label, :value => value).html_safe | |
450 | end |
|
454 | end | |
451 | else |
|
455 | else | |
452 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
456 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe | |
453 | end |
|
457 | end | |
454 | end |
|
458 | end | |
455 |
|
459 | |||
456 | # Find the name of an associated record stored in the field attribute |
|
460 | # Find the name of an associated record stored in the field attribute | |
457 | def find_name_by_reflection(field, id) |
|
461 | def find_name_by_reflection(field, id) | |
458 | unless id.present? |
|
462 | unless id.present? | |
459 | return nil |
|
463 | return nil | |
460 | end |
|
464 | end | |
461 | @detail_value_name_by_reflection ||= Hash.new do |hash, key| |
|
465 | @detail_value_name_by_reflection ||= Hash.new do |hash, key| | |
462 | association = Issue.reflect_on_association(key.first.to_sym) |
|
466 | association = Issue.reflect_on_association(key.first.to_sym) | |
463 | name = nil |
|
467 | name = nil | |
464 | if association |
|
468 | if association | |
465 | record = association.klass.find_by_id(key.last) |
|
469 | record = association.klass.find_by_id(key.last) | |
466 | if record |
|
470 | if record | |
467 | name = record.name.force_encoding('UTF-8') |
|
471 | name = record.name.force_encoding('UTF-8') | |
468 | end |
|
472 | end | |
469 | end |
|
473 | end | |
470 | hash[key] = name |
|
474 | hash[key] = name | |
471 | end |
|
475 | end | |
472 | @detail_value_name_by_reflection[[field, id]] |
|
476 | @detail_value_name_by_reflection[[field, id]] | |
473 | end |
|
477 | end | |
474 |
|
478 | |||
475 | # Renders issue children recursively |
|
479 | # Renders issue children recursively | |
476 | def render_api_issue_children(issue, api) |
|
480 | def render_api_issue_children(issue, api) | |
477 | return if issue.leaf? |
|
481 | return if issue.leaf? | |
478 | api.array :children do |
|
482 | api.array :children do | |
479 | issue.children.each do |child| |
|
483 | issue.children.each do |child| | |
480 | api.issue(:id => child.id) do |
|
484 | api.issue(:id => child.id) do | |
481 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
485 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? | |
482 | api.subject child.subject |
|
486 | api.subject child.subject | |
483 | render_api_issue_children(child, api) |
|
487 | render_api_issue_children(child, api) | |
484 | end |
|
488 | end | |
485 | end |
|
489 | end | |
486 | end |
|
490 | end | |
487 | end |
|
491 | end | |
488 | end |
|
492 | end |
@@ -1,302 +1,339 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 |
|
71 | def test_issues_destroy_confirmation_message_with_issues_that_share_descendants | |
72 | root = Issue.generate! |
|
72 | root = Issue.generate! | |
73 | child = Issue.generate!(:parent_issue_id => root.id) |
|
73 | child = Issue.generate!(:parent_issue_id => root.id) | |
74 | Issue.generate!(:parent_issue_id => child.id) |
|
74 | Issue.generate!(:parent_issue_id => child.id) | |
75 |
|
75 | |||
76 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + |
|
76 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + | |
77 | l(:text_issues_destroy_descendants_confirmation, :count => 1), |
|
77 | l(:text_issues_destroy_descendants_confirmation, :count => 1), | |
78 | issues_destroy_confirmation_message([root.reload, child.reload]) |
|
78 | issues_destroy_confirmation_message([root.reload, child.reload]) | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | 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 | |
82 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', |
|
82 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | |
83 | :value => '100', :prop_key => 'done_ratio') |
|
83 | :value => '100', :prop_key => 'done_ratio') | |
84 | 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) | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | 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 | |
88 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, |
|
88 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, | |
89 | :value => '100', :prop_key => 'done_ratio') |
|
89 | :value => '100', :prop_key => 'done_ratio') | |
90 | assert_equal "% Done set to 100", show_detail(detail, true) |
|
90 | assert_equal "% Done set to 100", show_detail(detail, true) | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | 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 | |
94 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', |
|
94 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', | |
95 | :value => nil, :prop_key => 'done_ratio') |
|
95 | :value => nil, :prop_key => 'done_ratio') | |
96 | assert_equal "% Done deleted (50)", show_detail(detail, true) |
|
96 | assert_equal "% Done deleted (50)", show_detail(detail, true) | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | 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 | |
100 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', |
|
100 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | |
101 | :value => '100', :prop_key => 'done_ratio') |
|
101 | :value => '100', :prop_key => 'done_ratio') | |
102 | html = show_detail(detail, false) |
|
102 | html = show_detail(detail, false) | |
103 | assert_include '<strong>% Done</strong>', html |
|
103 | assert_include '<strong>% Done</strong>', html | |
104 | assert_include '<i>40</i>', html |
|
104 | assert_include '<i>40</i>', html | |
105 | assert_include '<i>100</i>', html |
|
105 | assert_include '<i>100</i>', html | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | 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 | |
109 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, |
|
109 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, | |
110 | :value => '100', :prop_key => 'done_ratio') |
|
110 | :value => '100', :prop_key => 'done_ratio') | |
111 | html = show_detail(detail, false) |
|
111 | html = show_detail(detail, false) | |
112 | assert_include '<strong>% Done</strong>', html |
|
112 | assert_include '<strong>% Done</strong>', html | |
113 | assert_include '<i>100</i>', html |
|
113 | assert_include '<i>100</i>', html | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | 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 | |
117 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', |
|
117 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', | |
118 | :value => nil, :prop_key => 'done_ratio') |
|
118 | :value => nil, :prop_key => 'done_ratio') | |
119 | html = show_detail(detail, false) |
|
119 | html = show_detail(detail, false) | |
120 | assert_include '<strong>% Done</strong>', html |
|
120 | assert_include '<strong>% Done</strong>', html | |
121 | assert_include '<del><i>50</i></del>', html |
|
121 | assert_include '<del><i>50</i></del>', html | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | 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 | |
125 | detail = JournalDetail.new( |
|
125 | detail = JournalDetail.new( | |
126 | :property => 'attr', |
|
126 | :property => 'attr', | |
127 | :old_value => '2010-01-01', |
|
127 | :old_value => '2010-01-01', | |
128 | :value => '2010-01-31', |
|
128 | :value => '2010-01-31', | |
129 | :prop_key => 'start_date' |
|
129 | :prop_key => 'start_date' | |
130 | ) |
|
130 | ) | |
131 | with_settings :date_format => '%m/%d/%Y' do |
|
131 | with_settings :date_format => '%m/%d/%Y' do | |
132 | assert_match "01/31/2010", show_detail(detail, true) |
|
132 | assert_match "01/31/2010", show_detail(detail, true) | |
133 | assert_match "01/01/2010", show_detail(detail, true) |
|
133 | assert_match "01/01/2010", show_detail(detail, true) | |
134 | end |
|
134 | end | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | 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 | |
138 | detail = JournalDetail.new( |
|
138 | detail = JournalDetail.new( | |
139 | :property => 'attr', |
|
139 | :property => 'attr', | |
140 | :old_value => '2010-01-01', |
|
140 | :old_value => '2010-01-01', | |
141 | :value => '2010-01-31', |
|
141 | :value => '2010-01-31', | |
142 | :prop_key => 'due_date' |
|
142 | :prop_key => 'due_date' | |
143 | ) |
|
143 | ) | |
144 | with_settings :date_format => '%m/%d/%Y' do |
|
144 | with_settings :date_format => '%m/%d/%Y' do | |
145 | assert_match "01/31/2010", show_detail(detail, true) |
|
145 | assert_match "01/31/2010", show_detail(detail, true) | |
146 | assert_match "01/01/2010", show_detail(detail, true) |
|
146 | assert_match "01/01/2010", show_detail(detail, true) | |
147 | end |
|
147 | end | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | 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 | |
151 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', |
|
151 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', | |
152 | :old_value => 1, :value => 2) |
|
152 | :old_value => 1, :value => 2) | |
153 | assert_match 'eCookbook', show_detail(detail, true) |
|
153 | assert_match 'eCookbook', show_detail(detail, true) | |
154 | assert_match 'OnlineStore', show_detail(detail, true) |
|
154 | assert_match 'OnlineStore', show_detail(detail, true) | |
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | 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 | |
158 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', |
|
158 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', | |
159 | :old_value => 1, :value => 2) |
|
159 | :old_value => 1, :value => 2) | |
160 | assert_match 'New', show_detail(detail, true) |
|
160 | assert_match 'New', show_detail(detail, true) | |
161 | assert_match 'Assigned', show_detail(detail, true) |
|
161 | assert_match 'Assigned', show_detail(detail, true) | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | 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 | |
165 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', |
|
165 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', | |
166 | :old_value => 1, :value => 2) |
|
166 | :old_value => 1, :value => 2) | |
167 | assert_match 'Bug', show_detail(detail, true) |
|
167 | assert_match 'Bug', show_detail(detail, true) | |
168 | assert_match 'Feature request', show_detail(detail, true) |
|
168 | assert_match 'Feature request', show_detail(detail, true) | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | 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 | |
172 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', |
|
172 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', | |
173 | :old_value => 1, :value => 2) |
|
173 | :old_value => 1, :value => 2) | |
174 | assert_match 'Redmine Admin', show_detail(detail, true) |
|
174 | assert_match 'Redmine Admin', show_detail(detail, true) | |
175 | assert_match 'John Smith', show_detail(detail, true) |
|
175 | assert_match 'John Smith', show_detail(detail, true) | |
176 | end |
|
176 | end | |
177 |
|
177 | |||
178 | 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 | |
179 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', |
|
179 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', | |
180 | :old_value => 4, :value => 5) |
|
180 | :old_value => 4, :value => 5) | |
181 | assert_match 'Low', show_detail(detail, true) |
|
181 | assert_match 'Low', show_detail(detail, true) | |
182 | assert_match 'Normal', show_detail(detail, true) |
|
182 | assert_match 'Normal', show_detail(detail, true) | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | 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 | |
186 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', |
|
186 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', | |
187 | :old_value => 1, :value => 2) |
|
187 | :old_value => 1, :value => 2) | |
188 | assert_match 'Printing', show_detail(detail, true) |
|
188 | assert_match 'Printing', show_detail(detail, true) | |
189 | assert_match 'Recipes', show_detail(detail, true) |
|
189 | assert_match 'Recipes', show_detail(detail, true) | |
190 | end |
|
190 | end | |
191 |
|
191 | |||
192 | 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 | |
193 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', |
|
193 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', | |
194 | :old_value => 1, :value => 2) |
|
194 | :old_value => 1, :value => 2) | |
195 | assert_match '0.1', show_detail(detail, true) |
|
195 | assert_match '0.1', show_detail(detail, true) | |
196 | assert_match '1.0', show_detail(detail, true) |
|
196 | assert_match '1.0', show_detail(detail, true) | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | 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 | |
200 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', |
|
200 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', | |
201 | :old_value => '5', :value => '6.3') |
|
201 | :old_value => '5', :value => '6.3') | |
202 | assert_match '5.00', show_detail(detail, true) |
|
202 | assert_match '5.00', show_detail(detail, true) | |
203 | assert_match '6.30', show_detail(detail, true) |
|
203 | assert_match '6.30', show_detail(detail, true) | |
204 | end |
|
204 | end | |
205 |
|
205 | |||
206 | test 'show_detail should not show values with a description attribute' do |
|
206 | test 'show_detail should not show values with a description attribute' do | |
207 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'description', |
|
207 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'description', | |
208 | :old_value => 'Foo', :value => 'Bar') |
|
208 | :old_value => 'Foo', :value => 'Bar') | |
209 | assert_equal 'Description updated', show_detail(detail, true) |
|
209 | assert_equal 'Description updated', show_detail(detail, true) | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | test 'show_detail should show old and new values with a custom field' do |
|
212 | test 'show_detail should show old and new values with a custom field' do | |
213 | detail = JournalDetail.new(:property => 'cf', :prop_key => '1', |
|
213 | detail = JournalDetail.new(:property => 'cf', :prop_key => '1', | |
214 | :old_value => 'MySQL', :value => 'PostgreSQL') |
|
214 | :old_value => 'MySQL', :value => 'PostgreSQL') | |
215 | assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) |
|
215 | assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | test 'show_detail should not show values with a long text custom field' do |
|
218 | test 'show_detail should not show values with a long text custom field' do | |
219 | field = IssueCustomField.create!(:name => "Long field", :field_format => 'text') |
|
219 | field = IssueCustomField.create!(:name => "Long field", :field_format => 'text') | |
220 | detail = JournalDetail.new(:property => 'cf', :prop_key => field.id, |
|
220 | detail = JournalDetail.new(:property => 'cf', :prop_key => field.id, | |
221 | :old_value => 'Foo', :value => 'Bar') |
|
221 | :old_value => 'Foo', :value => 'Bar') | |
222 | assert_equal 'Long field updated', show_detail(detail, true) |
|
222 | assert_equal 'Long field updated', show_detail(detail, true) | |
223 | end |
|
223 | end | |
224 |
|
224 | |||
225 | test 'show_detail should show added file' do |
|
225 | test 'show_detail should show added file' do | |
226 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', |
|
226 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', | |
227 | :old_value => nil, :value => 'error281.txt') |
|
227 | :old_value => nil, :value => 'error281.txt') | |
228 | assert_match 'error281.txt', show_detail(detail, true) |
|
228 | assert_match 'error281.txt', show_detail(detail, true) | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | test 'show_detail should show removed file' do |
|
231 | test 'show_detail should show removed file' do | |
232 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', |
|
232 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', | |
233 | :old_value => 'error281.txt', :value => nil) |
|
233 | :old_value => 'error281.txt', :value => nil) | |
234 | assert_match 'error281.txt', show_detail(detail, true) |
|
234 | assert_match 'error281.txt', show_detail(detail, true) | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | def test_show_detail_relation_added |
|
237 | def test_show_detail_relation_added | |
238 | detail = JournalDetail.new(:property => 'relation', |
|
238 | detail = JournalDetail.new(:property => 'relation', | |
239 | :prop_key => 'precedes', |
|
239 | :prop_key => 'precedes', | |
240 | :value => 1) |
|
240 | :value => 1) | |
241 | assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true) |
|
241 | assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true) | |
242 | str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes) |
|
242 | str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes) | |
243 | assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added", |
|
243 | assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added", | |
244 | show_detail(detail, false) |
|
244 | show_detail(detail, false) | |
245 | end |
|
245 | end | |
246 |
|
246 | |||
247 | def test_show_detail_relation_added_with_inexistant_issue |
|
247 | def test_show_detail_relation_added_with_inexistant_issue | |
248 | inexistant_issue_number = 9999 |
|
248 | inexistant_issue_number = 9999 | |
249 | assert_nil Issue.find_by_id(inexistant_issue_number) |
|
249 | assert_nil Issue.find_by_id(inexistant_issue_number) | |
250 | detail = JournalDetail.new(:property => 'relation', |
|
250 | detail = JournalDetail.new(:property => 'relation', | |
251 | :prop_key => 'precedes', |
|
251 | :prop_key => 'precedes', | |
252 | :value => inexistant_issue_number) |
|
252 | :value => inexistant_issue_number) | |
253 | assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true) |
|
253 | assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true) | |
254 | assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false) |
|
254 | assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false) | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible |
|
257 | def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible | |
258 | issue = Issue.generate!(:is_private => true) |
|
258 | issue = Issue.generate!(:is_private => true) | |
259 | detail = JournalDetail.new(:property => 'relation', |
|
259 | detail = JournalDetail.new(:property => 'relation', | |
260 | :prop_key => 'precedes', |
|
260 | :prop_key => 'precedes', | |
261 | :value => issue.id) |
|
261 | :value => issue.id) | |
262 |
|
262 | |||
263 | assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true) |
|
263 | assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true) | |
264 | assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false) |
|
264 | assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false) | |
265 | end |
|
265 | end | |
266 |
|
266 | |||
267 | def test_show_detail_relation_deleted |
|
267 | def test_show_detail_relation_deleted | |
268 | detail = JournalDetail.new(:property => 'relation', |
|
268 | detail = JournalDetail.new(:property => 'relation', | |
269 | :prop_key => 'precedes', |
|
269 | :prop_key => 'precedes', | |
270 | :old_value => 1) |
|
270 | :old_value => 1) | |
271 | assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true) |
|
271 | assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true) | |
272 | str = link_to("Bug #1", |
|
272 | str = link_to("Bug #1", | |
273 | "/issues/1", |
|
273 | "/issues/1", | |
274 | :class => Issue.find(1).css_classes) |
|
274 | :class => Issue.find(1).css_classes) | |
275 | assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)", |
|
275 | assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)", | |
276 | show_detail(detail, false) |
|
276 | show_detail(detail, false) | |
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | def test_show_detail_relation_deleted_with_inexistant_issue |
|
279 | def test_show_detail_relation_deleted_with_inexistant_issue | |
280 | inexistant_issue_number = 9999 |
|
280 | inexistant_issue_number = 9999 | |
281 | assert_nil Issue.find_by_id(inexistant_issue_number) |
|
281 | assert_nil Issue.find_by_id(inexistant_issue_number) | |
282 | detail = JournalDetail.new(:property => 'relation', |
|
282 | detail = JournalDetail.new(:property => 'relation', | |
283 | :prop_key => 'precedes', |
|
283 | :prop_key => 'precedes', | |
284 | :old_value => inexistant_issue_number) |
|
284 | :old_value => inexistant_issue_number) | |
285 | assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true) |
|
285 | assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true) | |
286 | assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false) |
|
286 | assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false) | |
287 | end |
|
287 | end | |
288 |
|
288 | |||
289 | def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible |
|
289 | def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible | |
290 | issue = Issue.generate!(:is_private => true) |
|
290 | issue = Issue.generate!(:is_private => true) | |
291 | detail = JournalDetail.new(:property => 'relation', |
|
291 | detail = JournalDetail.new(:property => 'relation', | |
292 | :prop_key => 'precedes', |
|
292 | :prop_key => 'precedes', | |
293 | :old_value => issue.id) |
|
293 | :old_value => issue.id) | |
294 |
|
294 | |||
295 | assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true) |
|
295 | assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true) | |
296 | assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false) |
|
296 | assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false) | |
297 | end |
|
297 | end | |
298 |
|
298 | |||
|
299 | def test_details_to_strings_with_multiple_values_removed_from_custom_field | |||
|
300 | field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true) | |||
|
301 | details = [] | |||
|
302 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '1', :value => nil) | |||
|
303 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil) | |||
|
304 | ||||
|
305 | assert_equal ["User deleted (Dave Lopper, Redmine Admin)"], details_to_strings(details, true) | |||
|
306 | assert_equal ["<strong>User</strong> deleted (<del><i>Dave Lopper, Redmine Admin</i></del>)"], details_to_strings(details, false) | |||
|
307 | end | |||
|
308 | ||||
|
309 | def test_details_to_strings_with_multiple_values_added_to_custom_field | |||
|
310 | field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true) | |||
|
311 | details = [] | |||
|
312 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1') | |||
|
313 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '3') | |||
|
314 | ||||
|
315 | assert_equal ["User Dave Lopper, Redmine Admin added"], details_to_strings(details, true) | |||
|
316 | assert_equal ["<strong>User</strong> <i>Dave Lopper, Redmine Admin</i> added"], details_to_strings(details, false) | |||
|
317 | end | |||
|
318 | ||||
|
319 | def test_details_to_strings_with_multiple_values_added_and_removed_from_custom_field | |||
|
320 | field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true) | |||
|
321 | details = [] | |||
|
322 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1') | |||
|
323 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '2', :value => nil) | |||
|
324 | details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil) | |||
|
325 | ||||
|
326 | assert_equal [ | |||
|
327 | "User Redmine Admin added", | |||
|
328 | "User deleted (Dave Lopper, John Smith)" | |||
|
329 | ], details_to_strings(details, true) | |||
|
330 | assert_equal [ | |||
|
331 | "<strong>User</strong> <i>Redmine Admin</i> added", | |||
|
332 | "<strong>User</strong> deleted (<del><i>Dave Lopper, John Smith</i></del>)" | |||
|
333 | ], details_to_strings(details, false) | |||
|
334 | end | |||
|
335 | ||||
299 | def test_find_name_by_reflection_should_return_nil_for_missing_record |
|
336 | def test_find_name_by_reflection_should_return_nil_for_missing_record | |
300 | assert_nil find_name_by_reflection('status', 99) |
|
337 | assert_nil find_name_by_reflection('status', 99) | |
301 | end |
|
338 | end | |
302 | end |
|
339 | end |
General Comments 0
You need to be logged in to leave comments.
Login now