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