@@ -1,406 +1,428 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | module IssuesHelper |
|
21 | 21 | include ApplicationHelper |
|
22 | 22 | |
|
23 | 23 | def issue_list(issues, &block) |
|
24 | 24 | ancestors = [] |
|
25 | 25 | issues.each do |issue| |
|
26 | 26 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
|
27 | 27 | ancestors.pop |
|
28 | 28 | end |
|
29 | 29 | yield issue, ancestors.size |
|
30 | 30 | ancestors << issue unless issue.leaf? |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | # Renders a HTML/CSS tooltip |
|
35 | 35 | # |
|
36 | 36 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
|
37 | 37 | # that contains this method wrapped in a span with the class of "tip" |
|
38 | 38 | # |
|
39 | 39 | # <div class="tooltip"><%= link_to_issue(issue) %> |
|
40 | 40 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
|
41 | 41 | # </div> |
|
42 | 42 | # |
|
43 | 43 | def render_issue_tooltip(issue) |
|
44 | 44 | @cached_label_status ||= l(:field_status) |
|
45 | 45 | @cached_label_start_date ||= l(:field_start_date) |
|
46 | 46 | @cached_label_due_date ||= l(:field_due_date) |
|
47 | 47 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
48 | 48 | @cached_label_priority ||= l(:field_priority) |
|
49 | 49 | @cached_label_project ||= l(:field_project) |
|
50 | 50 | |
|
51 | 51 | link_to_issue(issue) + "<br /><br />".html_safe + |
|
52 | 52 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + |
|
53 | 53 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + |
|
54 | 54 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + |
|
55 | 55 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + |
|
56 | 56 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + |
|
57 | 57 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def issue_heading(issue) |
|
61 | 61 | h("#{issue.tracker} ##{issue.id}") |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def render_issue_subject_with_tree(issue) |
|
65 | 65 | s = '' |
|
66 | 66 | ancestors = issue.root? ? [] : issue.ancestors.visible.all |
|
67 | 67 | ancestors.each do |ancestor| |
|
68 | 68 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) |
|
69 | 69 | end |
|
70 | 70 | s << '<div>' |
|
71 | 71 | subject = h(issue.subject) |
|
72 | 72 | if issue.is_private? |
|
73 | 73 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject |
|
74 | 74 | end |
|
75 | 75 | s << content_tag('h3', subject) |
|
76 | 76 | s << '</div>' * (ancestors.size + 1) |
|
77 | 77 | s.html_safe |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def render_descendants_tree(issue) |
|
81 | 81 | s = '<form><table class="list issues">' |
|
82 | 82 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| |
|
83 | 83 | css = "issue issue-#{child.id} hascontextmenu" |
|
84 | 84 | css << " idnt idnt-#{level}" if level > 0 |
|
85 | 85 | s << content_tag('tr', |
|
86 | 86 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + |
|
87 | 87 | content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + |
|
88 | 88 | content_tag('td', h(child.status)) + |
|
89 | 89 | content_tag('td', link_to_user(child.assigned_to)) + |
|
90 | 90 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), |
|
91 | 91 | :class => css) |
|
92 | 92 | end |
|
93 | 93 | s << '</table></form>' |
|
94 | 94 | s.html_safe |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | # Returns an array of error messages for bulk edited issues |
|
98 | 98 | def bulk_edit_error_messages(issues) |
|
99 | 99 | messages = {} |
|
100 | 100 | issues.each do |issue| |
|
101 | 101 | issue.errors.full_messages.each do |message| |
|
102 | 102 | messages[message] ||= [] |
|
103 | 103 | messages[message] << issue |
|
104 | 104 | end |
|
105 | 105 | end |
|
106 | 106 | messages.map { |message, issues| |
|
107 | 107 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') |
|
108 | 108 | } |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | # Returns a link for adding a new subtask to the given issue |
|
112 | 112 | def link_to_new_subtask(issue) |
|
113 | 113 | attrs = { |
|
114 | 114 | :tracker_id => issue.tracker, |
|
115 | 115 | :parent_issue_id => issue |
|
116 | 116 | } |
|
117 | 117 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | class IssueFieldsRows |
|
121 | 121 | include ActionView::Helpers::TagHelper |
|
122 | 122 | |
|
123 | 123 | def initialize |
|
124 | 124 | @left = [] |
|
125 | 125 | @right = [] |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def left(*args) |
|
129 | 129 | args.any? ? @left << cells(*args) : @left |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def right(*args) |
|
133 | 133 | args.any? ? @right << cells(*args) : @right |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | def size |
|
137 | 137 | @left.size > @right.size ? @left.size : @right.size |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def to_html |
|
141 | 141 | html = ''.html_safe |
|
142 | 142 | blank = content_tag('th', '') + content_tag('td', '') |
|
143 | 143 | size.times do |i| |
|
144 | 144 | left = @left[i] || blank |
|
145 | 145 | right = @right[i] || blank |
|
146 | 146 | html << content_tag('tr', left + right) |
|
147 | 147 | end |
|
148 | 148 | html |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def cells(label, text, options={}) |
|
152 | 152 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
153 | 153 | end |
|
154 | 154 | end |
|
155 | 155 | |
|
156 | 156 | def issue_fields_rows |
|
157 | 157 | r = IssueFieldsRows.new |
|
158 | 158 | yield r |
|
159 | 159 | r.to_html |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def render_custom_fields_rows(issue) |
|
163 | 163 | values = issue.visible_custom_field_values |
|
164 | 164 | return if values.empty? |
|
165 | 165 | ordered_values = [] |
|
166 | 166 | half = (values.size / 2.0).ceil |
|
167 | 167 | half.times do |i| |
|
168 | 168 | ordered_values << values[i] |
|
169 | 169 | ordered_values << values[i + half] |
|
170 | 170 | end |
|
171 | 171 | s = "<tr>\n" |
|
172 | 172 | n = 0 |
|
173 | 173 | ordered_values.compact.each do |value| |
|
174 | 174 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
175 | 175 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" |
|
176 | 176 | n += 1 |
|
177 | 177 | end |
|
178 | 178 | s << "</tr>\n" |
|
179 | 179 | s.html_safe |
|
180 | 180 | end |
|
181 | 181 | |
|
182 | 182 | def issues_destroy_confirmation_message(issues) |
|
183 | 183 | issues = [issues] unless issues.is_a?(Array) |
|
184 | 184 | message = l(:text_issues_destroy_confirmation) |
|
185 | 185 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} |
|
186 | 186 | if descendant_count > 0 |
|
187 | 187 | issues.each do |issue| |
|
188 | 188 | next if issue.root? |
|
189 | 189 | issues.each do |other_issue| |
|
190 | 190 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) |
|
191 | 191 | end |
|
192 | 192 | end |
|
193 | 193 | if descendant_count > 0 |
|
194 | 194 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
195 | 195 | end |
|
196 | 196 | end |
|
197 | 197 | message |
|
198 | 198 | end |
|
199 | 199 | |
|
200 | 200 | def sidebar_queries |
|
201 | 201 | unless @sidebar_queries |
|
202 | 202 | @sidebar_queries = IssueQuery.visible. |
|
203 | 203 | order("#{Query.table_name}.name ASC"). |
|
204 | 204 | # Project specific queries and global queries |
|
205 | 205 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). |
|
206 | 206 | all |
|
207 | 207 | end |
|
208 | 208 | @sidebar_queries |
|
209 | 209 | end |
|
210 | 210 | |
|
211 | 211 | def query_links(title, queries) |
|
212 | 212 | return '' if queries.empty? |
|
213 | 213 | # links to #index on issues/show |
|
214 | 214 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
215 | 215 | |
|
216 | 216 | content_tag('h3', title) + "\n" + |
|
217 | 217 | content_tag('ul', |
|
218 | 218 | queries.collect {|query| |
|
219 | 219 | css = 'query' |
|
220 | 220 | css << ' selected' if query == @query |
|
221 | 221 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) |
|
222 | 222 | }.join("\n").html_safe, |
|
223 | 223 | :class => 'queries' |
|
224 | 224 | ) + "\n" |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | def render_sidebar_queries |
|
228 | 228 | out = ''.html_safe |
|
229 | 229 | out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?)) |
|
230 | 230 | out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?)) |
|
231 | 231 | out |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | def email_issue_attributes(issue, user) | |
|
235 | items = [] | |
|
236 | %w(author status priority assigned_to category fixed_version).each do |attribute| | |
|
237 | unless issue.disabled_core_fields.include?(attribute+"_id") | |
|
238 | items << "#{l("field_#{attribute}")}: #{issue.send attribute}" | |
|
239 | end | |
|
240 | end | |
|
241 | issue.visible_custom_field_values(user).each do |value| | |
|
242 | items << "#{value.custom_field.name}: #{show_value(value)}" | |
|
243 | end | |
|
244 | items | |
|
245 | end | |
|
246 | ||
|
247 | def render_email_issue_attributes(issue, user, html=false) | |
|
248 | items = email_issue_attributes(issue, user) | |
|
249 | if html | |
|
250 | content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe) | |
|
251 | else | |
|
252 | items.map{|s| "* #{s}"}.join("\n") | |
|
253 | end | |
|
254 | end | |
|
255 | ||
|
234 | 256 | # Returns the textual representation of a journal details |
|
235 | 257 | # as an array of strings |
|
236 | 258 | def details_to_strings(details, no_html=false, options={}) |
|
237 | 259 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
238 | 260 | strings = [] |
|
239 | 261 | values_by_field = {} |
|
240 | 262 | details.each do |detail| |
|
241 | 263 | if detail.property == 'cf' |
|
242 | 264 | field_id = detail.prop_key |
|
243 | 265 | field = CustomField.find_by_id(field_id) |
|
244 | 266 | if field && field.multiple? |
|
245 | 267 | values_by_field[field_id] ||= {:added => [], :deleted => []} |
|
246 | 268 | if detail.old_value |
|
247 | 269 | values_by_field[field_id][:deleted] << detail.old_value |
|
248 | 270 | end |
|
249 | 271 | if detail.value |
|
250 | 272 | values_by_field[field_id][:added] << detail.value |
|
251 | 273 | end |
|
252 | 274 | next |
|
253 | 275 | end |
|
254 | 276 | end |
|
255 | 277 | strings << show_detail(detail, no_html, options) |
|
256 | 278 | end |
|
257 | 279 | values_by_field.each do |field_id, changes| |
|
258 | 280 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) |
|
259 | 281 | if changes[:added].any? |
|
260 | 282 | detail.value = changes[:added] |
|
261 | 283 | strings << show_detail(detail, no_html, options) |
|
262 | 284 | elsif changes[:deleted].any? |
|
263 | 285 | detail.old_value = changes[:deleted] |
|
264 | 286 | strings << show_detail(detail, no_html, options) |
|
265 | 287 | end |
|
266 | 288 | end |
|
267 | 289 | strings |
|
268 | 290 | end |
|
269 | 291 | |
|
270 | 292 | # Returns the textual representation of a single journal detail |
|
271 | 293 | def show_detail(detail, no_html=false, options={}) |
|
272 | 294 | multiple = false |
|
273 | 295 | case detail.property |
|
274 | 296 | when 'attr' |
|
275 | 297 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
276 | 298 | label = l(("field_" + field).to_sym) |
|
277 | 299 | case detail.prop_key |
|
278 | 300 | when 'due_date', 'start_date' |
|
279 | 301 | value = format_date(detail.value.to_date) if detail.value |
|
280 | 302 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
281 | 303 | |
|
282 | 304 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
283 | 305 | 'priority_id', 'category_id', 'fixed_version_id' |
|
284 | 306 | value = find_name_by_reflection(field, detail.value) |
|
285 | 307 | old_value = find_name_by_reflection(field, detail.old_value) |
|
286 | 308 | |
|
287 | 309 | when 'estimated_hours' |
|
288 | 310 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
289 | 311 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
290 | 312 | |
|
291 | 313 | when 'parent_id' |
|
292 | 314 | label = l(:field_parent_issue) |
|
293 | 315 | value = "##{detail.value}" unless detail.value.blank? |
|
294 | 316 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
295 | 317 | |
|
296 | 318 | when 'is_private' |
|
297 | 319 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
298 | 320 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
299 | 321 | end |
|
300 | 322 | when 'cf' |
|
301 | 323 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
302 | 324 | if custom_field |
|
303 | 325 | multiple = custom_field.multiple? |
|
304 | 326 | label = custom_field.name |
|
305 | 327 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
306 | 328 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
307 | 329 | end |
|
308 | 330 | when 'attachment' |
|
309 | 331 | label = l(:label_attachment) |
|
310 | 332 | when 'relation' |
|
311 | 333 | if detail.value && !detail.old_value |
|
312 | 334 | rel_issue = Issue.visible.find_by_id(detail.value) |
|
313 | 335 | value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" : |
|
314 | 336 | (no_html ? rel_issue : link_to_issue(rel_issue)) |
|
315 | 337 | elsif detail.old_value && !detail.value |
|
316 | 338 | rel_issue = Issue.visible.find_by_id(detail.old_value) |
|
317 | 339 | old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" : |
|
318 | 340 | (no_html ? rel_issue : link_to_issue(rel_issue)) |
|
319 | 341 | end |
|
320 | 342 | label = l(detail.prop_key.to_sym) |
|
321 | 343 | end |
|
322 | 344 | call_hook(:helper_issues_show_detail_after_setting, |
|
323 | 345 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
324 | 346 | |
|
325 | 347 | label ||= detail.prop_key |
|
326 | 348 | value ||= detail.value |
|
327 | 349 | old_value ||= detail.old_value |
|
328 | 350 | |
|
329 | 351 | unless no_html |
|
330 | 352 | label = content_tag('strong', label) |
|
331 | 353 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
332 | 354 | if detail.old_value && detail.value.blank? && detail.property != 'relation' |
|
333 | 355 | old_value = content_tag("del", old_value) |
|
334 | 356 | end |
|
335 | 357 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) |
|
336 | 358 | # Link to the attachment if it has not been removed |
|
337 | 359 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
338 | 360 | if options[:only_path] != false && atta.is_text? |
|
339 | 361 | value += link_to( |
|
340 | 362 | image_tag('magnifier.png'), |
|
341 | 363 | :controller => 'attachments', :action => 'show', |
|
342 | 364 | :id => atta, :filename => atta.filename |
|
343 | 365 | ) |
|
344 | 366 | end |
|
345 | 367 | else |
|
346 | 368 | value = content_tag("i", h(value)) if value |
|
347 | 369 | end |
|
348 | 370 | end |
|
349 | 371 | |
|
350 | 372 | if detail.property == 'attr' && detail.prop_key == 'description' |
|
351 | 373 | s = l(:text_journal_changed_no_detail, :label => label) |
|
352 | 374 | unless no_html |
|
353 | 375 | diff_link = link_to 'diff', |
|
354 | 376 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
355 | 377 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
356 | 378 | :title => l(:label_view_diff) |
|
357 | 379 | s << " (#{ diff_link })" |
|
358 | 380 | end |
|
359 | 381 | s.html_safe |
|
360 | 382 | elsif detail.value.present? |
|
361 | 383 | case detail.property |
|
362 | 384 | when 'attr', 'cf' |
|
363 | 385 | if detail.old_value.present? |
|
364 | 386 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
365 | 387 | elsif multiple |
|
366 | 388 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
367 | 389 | else |
|
368 | 390 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
369 | 391 | end |
|
370 | 392 | when 'attachment', 'relation' |
|
371 | 393 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
372 | 394 | end |
|
373 | 395 | else |
|
374 | 396 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
375 | 397 | end |
|
376 | 398 | end |
|
377 | 399 | |
|
378 | 400 | # Find the name of an associated record stored in the field attribute |
|
379 | 401 | def find_name_by_reflection(field, id) |
|
380 | 402 | unless id.present? |
|
381 | 403 | return nil |
|
382 | 404 | end |
|
383 | 405 | association = Issue.reflect_on_association(field.to_sym) |
|
384 | 406 | if association |
|
385 | 407 | record = association.class_name.constantize.find_by_id(id) |
|
386 | 408 | if record |
|
387 | 409 | record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding) |
|
388 | 410 | return record.name |
|
389 | 411 | end |
|
390 | 412 | end |
|
391 | 413 | end |
|
392 | 414 | |
|
393 | 415 | # Renders issue children recursively |
|
394 | 416 | def render_api_issue_children(issue, api) |
|
395 | 417 | return if issue.leaf? |
|
396 | 418 | api.array :children do |
|
397 | 419 | issue.children.each do |child| |
|
398 | 420 | api.issue(:id => child.id) do |
|
399 | 421 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
400 | 422 | api.subject child.subject |
|
401 | 423 | render_api_issue_children(child, api) |
|
402 | 424 | end |
|
403 | 425 | end |
|
404 | 426 | end |
|
405 | 427 | end |
|
406 | 428 | end |
@@ -1,24 +1,14 | |||
|
1 | 1 | <h1><%= link_to(h("#{issue.tracker.name} ##{issue.id}: #{issue.subject}"), issue_url) %></h1> |
|
2 | 2 | |
|
3 | <ul> | |
|
4 | <li><%=l(:field_author)%>: <%=h issue.author %></li> | |
|
5 | <li><%=l(:field_status)%>: <%=h issue.status %></li> | |
|
6 | <li><%=l(:field_priority)%>: <%=h issue.priority %></li> | |
|
7 | <li><%=l(:field_assigned_to)%>: <%=h issue.assigned_to %></li> | |
|
8 | <li><%=l(:field_category)%>: <%=h issue.category %></li> | |
|
9 | <li><%=l(:field_fixed_version)%>: <%=h issue.fixed_version %></li> | |
|
10 | <% issue.visible_custom_field_values(users.first).each do |c| %> | |
|
11 | <li><%=h c.custom_field.name %>: <%=h show_value(c) %></li> | |
|
12 | <% end %> | |
|
13 | </ul> | |
|
3 | <%= render_email_issue_attributes(issue, users.first, true) %> | |
|
14 | 4 | |
|
15 | 5 | <%= textilizable(issue, :description, :only_path => false) %> |
|
16 | 6 | |
|
17 | 7 | <% if issue.attachments.any? %> |
|
18 | 8 | <fieldset class="attachments"><legend><%= l(:label_attachment_plural) %></legend> |
|
19 | 9 | <% issue.attachments.each do |attachment| %> |
|
20 | 10 | <%= link_to_attachment attachment, :download => true, :only_path => false %> |
|
21 | 11 | (<%= number_to_human_size(attachment.filesize) %>)<br /> |
|
22 | 12 | <% end %> |
|
23 | 13 | </fieldset> |
|
24 | 14 | <% end %> |
@@ -1,20 +1,13 | |||
|
1 | 1 | <%= "#{issue.tracker.name} ##{issue.id}: #{issue.subject}" %> |
|
2 | 2 | <%= issue_url %> |
|
3 | 3 | |
|
4 | * <%=l(:field_author)%>: <%= issue.author %> | |
|
5 | * <%=l(:field_status)%>: <%= issue.status %> | |
|
6 | * <%=l(:field_priority)%>: <%= issue.priority %> | |
|
7 | * <%=l(:field_assigned_to)%>: <%= issue.assigned_to %> | |
|
8 | * <%=l(:field_category)%>: <%= issue.category %> | |
|
9 | * <%=l(:field_fixed_version)%>: <%= issue.fixed_version %> | |
|
10 | <% issue.visible_custom_field_values(users.first).each do |c| %>* <%= c.custom_field.name %>: <%= show_value(c) %> | |
|
11 | <% end -%> | |
|
4 | <%= render_email_issue_attributes(issue, users.first) %> | |
|
12 | 5 | ---------------------------------------- |
|
13 | 6 | <%= issue.description %> |
|
14 | 7 | |
|
15 | 8 | <% if issue.attachments.any? -%> |
|
16 | 9 | ---<%= l(:label_attachment_plural).ljust(37, '-') %> |
|
17 | 10 | <% issue.attachments.each do |attachment| -%> |
|
18 | 11 | <%= attachment.filename %> (<%= number_to_human_size(attachment.filesize) %>) |
|
19 | 12 | <% end -%> |
|
20 | 13 | <% end -%> |
@@ -1,720 +1,743 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class MailerTest < ActiveSupport::TestCase |
|
21 | 21 | include Redmine::I18n |
|
22 | 22 | include ActionDispatch::Assertions::SelectorAssertions |
|
23 | 23 | fixtures :projects, :enabled_modules, :issues, :users, :members, |
|
24 | 24 | :member_roles, :roles, :documents, :attachments, :news, |
|
25 | 25 | :tokens, :journals, :journal_details, :changesets, |
|
26 | 26 | :trackers, :projects_trackers, |
|
27 | 27 | :issue_statuses, :enumerations, :messages, :boards, :repositories, |
|
28 | 28 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, |
|
29 | 29 | :versions, |
|
30 | 30 | :comments |
|
31 | 31 | |
|
32 | 32 | def setup |
|
33 | 33 | ActionMailer::Base.deliveries.clear |
|
34 | 34 | Setting.host_name = 'mydomain.foo' |
|
35 | 35 | Setting.protocol = 'http' |
|
36 | 36 | Setting.plain_text_mail = '0' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def test_generated_links_in_emails |
|
40 | 40 | Setting.default_language = 'en' |
|
41 | 41 | Setting.host_name = 'mydomain.foo' |
|
42 | 42 | Setting.protocol = 'https' |
|
43 | 43 | |
|
44 | 44 | journal = Journal.find(3) |
|
45 | 45 | assert Mailer.deliver_issue_edit(journal) |
|
46 | 46 | |
|
47 | 47 | mail = last_email |
|
48 | 48 | assert_not_nil mail |
|
49 | 49 | |
|
50 | 50 | assert_select_email do |
|
51 | 51 | # link to the main ticket |
|
52 | 52 | assert_select 'a[href=?]', |
|
53 | 53 | 'https://mydomain.foo/issues/2#change-3', |
|
54 | 54 | :text => 'Feature request #2: Add ingredients categories' |
|
55 | 55 | # link to a referenced ticket |
|
56 | 56 | assert_select 'a[href=?][title=?]', |
|
57 | 57 | 'https://mydomain.foo/issues/1', |
|
58 | 58 | 'Can't print recipes (New)', |
|
59 | 59 | :text => '#1' |
|
60 | 60 | # link to a changeset |
|
61 | 61 | assert_select 'a[href=?][title=?]', |
|
62 | 62 | 'https://mydomain.foo/projects/ecookbook/repository/revisions/2', |
|
63 | 63 | 'This commit fixes #1, #2 and references #1 & #3', |
|
64 | 64 | :text => 'r2' |
|
65 | 65 | # link to a description diff |
|
66 | 66 | assert_select 'a[href=?][title=?]', |
|
67 | 67 | 'https://mydomain.foo/journals/diff/3?detail_id=4', |
|
68 | 68 | 'View differences', |
|
69 | 69 | :text => 'diff' |
|
70 | 70 | # link to an attachment |
|
71 | 71 | assert_select 'a[href=?]', |
|
72 | 72 | 'https://mydomain.foo/attachments/download/4/source.rb', |
|
73 | 73 | :text => 'source.rb' |
|
74 | 74 | end |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def test_generated_links_with_prefix |
|
78 | 78 | Setting.default_language = 'en' |
|
79 | 79 | relative_url_root = Redmine::Utils.relative_url_root |
|
80 | 80 | Setting.host_name = 'mydomain.foo/rdm' |
|
81 | 81 | Setting.protocol = 'http' |
|
82 | 82 | |
|
83 | 83 | journal = Journal.find(3) |
|
84 | 84 | assert Mailer.deliver_issue_edit(journal) |
|
85 | 85 | |
|
86 | 86 | mail = last_email |
|
87 | 87 | assert_not_nil mail |
|
88 | 88 | |
|
89 | 89 | assert_select_email do |
|
90 | 90 | # link to the main ticket |
|
91 | 91 | assert_select 'a[href=?]', |
|
92 | 92 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
93 | 93 | :text => 'Feature request #2: Add ingredients categories' |
|
94 | 94 | # link to a referenced ticket |
|
95 | 95 | assert_select 'a[href=?][title=?]', |
|
96 | 96 | 'http://mydomain.foo/rdm/issues/1', |
|
97 | 97 | 'Can't print recipes (New)', |
|
98 | 98 | :text => '#1' |
|
99 | 99 | # link to a changeset |
|
100 | 100 | assert_select 'a[href=?][title=?]', |
|
101 | 101 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
102 | 102 | 'This commit fixes #1, #2 and references #1 & #3', |
|
103 | 103 | :text => 'r2' |
|
104 | 104 | # link to a description diff |
|
105 | 105 | assert_select 'a[href=?][title=?]', |
|
106 | 106 | 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4', |
|
107 | 107 | 'View differences', |
|
108 | 108 | :text => 'diff' |
|
109 | 109 | # link to an attachment |
|
110 | 110 | assert_select 'a[href=?]', |
|
111 | 111 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
112 | 112 | :text => 'source.rb' |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
117 | 117 | Setting.default_language = 'en' |
|
118 | 118 | relative_url_root = Redmine::Utils.relative_url_root |
|
119 | 119 | Setting.host_name = 'mydomain.foo/rdm' |
|
120 | 120 | Setting.protocol = 'http' |
|
121 | 121 | Redmine::Utils.relative_url_root = nil |
|
122 | 122 | |
|
123 | 123 | journal = Journal.find(3) |
|
124 | 124 | assert Mailer.deliver_issue_edit(journal) |
|
125 | 125 | |
|
126 | 126 | mail = last_email |
|
127 | 127 | assert_not_nil mail |
|
128 | 128 | |
|
129 | 129 | assert_select_email do |
|
130 | 130 | # link to the main ticket |
|
131 | 131 | assert_select 'a[href=?]', |
|
132 | 132 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
133 | 133 | :text => 'Feature request #2: Add ingredients categories' |
|
134 | 134 | # link to a referenced ticket |
|
135 | 135 | assert_select 'a[href=?][title=?]', |
|
136 | 136 | 'http://mydomain.foo/rdm/issues/1', |
|
137 | 137 | 'Can't print recipes (New)', |
|
138 | 138 | :text => '#1' |
|
139 | 139 | # link to a changeset |
|
140 | 140 | assert_select 'a[href=?][title=?]', |
|
141 | 141 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
142 | 142 | 'This commit fixes #1, #2 and references #1 & #3', |
|
143 | 143 | :text => 'r2' |
|
144 | 144 | # link to a description diff |
|
145 | 145 | assert_select 'a[href=?][title=?]', |
|
146 | 146 | 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4', |
|
147 | 147 | 'View differences', |
|
148 | 148 | :text => 'diff' |
|
149 | 149 | # link to an attachment |
|
150 | 150 | assert_select 'a[href=?]', |
|
151 | 151 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
152 | 152 | :text => 'source.rb' |
|
153 | 153 | end |
|
154 | 154 | ensure |
|
155 | 155 | # restore it |
|
156 | 156 | Redmine::Utils.relative_url_root = relative_url_root |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def test_email_headers |
|
160 | 160 | issue = Issue.find(1) |
|
161 | 161 | Mailer.deliver_issue_add(issue) |
|
162 | 162 | mail = last_email |
|
163 | 163 | assert_not_nil mail |
|
164 | 164 | assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s |
|
165 | 165 | assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s |
|
166 | 166 | assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | def test_email_headers_should_include_sender |
|
170 | 170 | issue = Issue.find(1) |
|
171 | 171 | Mailer.deliver_issue_add(issue) |
|
172 | 172 | mail = last_email |
|
173 | 173 | assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def test_plain_text_mail |
|
177 | 177 | Setting.plain_text_mail = 1 |
|
178 | 178 | journal = Journal.find(2) |
|
179 | 179 | Mailer.deliver_issue_edit(journal) |
|
180 | 180 | mail = last_email |
|
181 | 181 | assert_equal "text/plain; charset=UTF-8", mail.content_type |
|
182 | 182 | assert_equal 0, mail.parts.size |
|
183 | 183 | assert !mail.encoded.include?('href') |
|
184 | 184 | end |
|
185 | 185 | |
|
186 | 186 | def test_html_mail |
|
187 | 187 | Setting.plain_text_mail = 0 |
|
188 | 188 | journal = Journal.find(2) |
|
189 | 189 | Mailer.deliver_issue_edit(journal) |
|
190 | 190 | mail = last_email |
|
191 | 191 | assert_equal 2, mail.parts.size |
|
192 | 192 | assert mail.encoded.include?('href') |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | def test_from_header |
|
196 | 196 | with_settings :mail_from => 'redmine@example.net' do |
|
197 | 197 | Mailer.test_email(User.find(1)).deliver |
|
198 | 198 | end |
|
199 | 199 | mail = last_email |
|
200 | 200 | assert_equal 'redmine@example.net', mail.from_addrs.first |
|
201 | 201 | end |
|
202 | 202 | |
|
203 | 203 | def test_from_header_with_phrase |
|
204 | 204 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do |
|
205 | 205 | Mailer.test_email(User.find(1)).deliver |
|
206 | 206 | end |
|
207 | 207 | mail = last_email |
|
208 | 208 | assert_equal 'redmine@example.net', mail.from_addrs.first |
|
209 | 209 | assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s |
|
210 | 210 | end |
|
211 | 211 | |
|
212 | 212 | def test_should_not_send_email_without_recipient |
|
213 | 213 | news = News.first |
|
214 | 214 | user = news.author |
|
215 | 215 | # Remove members except news author |
|
216 | 216 | news.project.memberships.each {|m| m.destroy unless m.user == user} |
|
217 | 217 | |
|
218 | 218 | user.pref.no_self_notified = false |
|
219 | 219 | user.pref.save |
|
220 | 220 | User.current = user |
|
221 | 221 | Mailer.news_added(news.reload).deliver |
|
222 | 222 | assert_equal 1, last_email.bcc.size |
|
223 | 223 | |
|
224 | 224 | # nobody to notify |
|
225 | 225 | user.pref.no_self_notified = true |
|
226 | 226 | user.pref.save |
|
227 | 227 | User.current = user |
|
228 | 228 | ActionMailer::Base.deliveries.clear |
|
229 | 229 | Mailer.news_added(news.reload).deliver |
|
230 | 230 | assert ActionMailer::Base.deliveries.empty? |
|
231 | 231 | end |
|
232 | 232 | |
|
233 | 233 | def test_issue_add_message_id |
|
234 | 234 | issue = Issue.find(2) |
|
235 | 235 | Mailer.deliver_issue_add(issue) |
|
236 | 236 | mail = last_email |
|
237 | 237 | assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id |
|
238 | 238 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
239 | 239 | end |
|
240 | 240 | |
|
241 | 241 | def test_issue_edit_message_id |
|
242 | 242 | journal = Journal.find(3) |
|
243 | 243 | journal.issue = Issue.find(2) |
|
244 | 244 | |
|
245 | 245 | Mailer.deliver_issue_edit(journal) |
|
246 | 246 | mail = last_email |
|
247 | 247 | assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
248 | 248 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
249 | 249 | assert_select_email do |
|
250 | 250 | # link to the update |
|
251 | 251 | assert_select "a[href=?]", |
|
252 | 252 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" |
|
253 | 253 | end |
|
254 | 254 | end |
|
255 | 255 | |
|
256 | 256 | def test_message_posted_message_id |
|
257 | 257 | message = Message.find(1) |
|
258 | 258 | Mailer.message_posted(message).deliver |
|
259 | 259 | mail = last_email |
|
260 | 260 | assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
261 | 261 | assert_include "redmine.message-1.20070512151532@example.net", mail.references |
|
262 | 262 | assert_select_email do |
|
263 | 263 | # link to the message |
|
264 | 264 | assert_select "a[href=?]", |
|
265 | 265 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", |
|
266 | 266 | :text => message.subject |
|
267 | 267 | end |
|
268 | 268 | end |
|
269 | 269 | |
|
270 | 270 | def test_reply_posted_message_id |
|
271 | 271 | message = Message.find(3) |
|
272 | 272 | Mailer.message_posted(message).deliver |
|
273 | 273 | mail = last_email |
|
274 | 274 | assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
275 | 275 | assert_include "redmine.message-1.20070512151532@example.net", mail.references |
|
276 | 276 | assert_select_email do |
|
277 | 277 | # link to the reply |
|
278 | 278 | assert_select "a[href=?]", |
|
279 | 279 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
|
280 | 280 | :text => message.subject |
|
281 | 281 | end |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | test "#issue_add should notify project members" do |
|
285 | 285 | issue = Issue.find(1) |
|
286 | 286 | assert Mailer.deliver_issue_add(issue) |
|
287 | 287 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
288 | 288 | end |
|
289 | 289 | |
|
290 | 290 | test "#issue_add should not notify project members that are not allow to view the issue" do |
|
291 | 291 | issue = Issue.find(1) |
|
292 | 292 | Role.find(2).remove_permission!(:view_issues) |
|
293 | 293 | assert Mailer.deliver_issue_add(issue) |
|
294 | 294 | assert !last_email.bcc.include?('dlopper@somenet.foo') |
|
295 | 295 | end |
|
296 | 296 | |
|
297 | 297 | test "#issue_add should notify issue watchers" do |
|
298 | 298 | issue = Issue.find(1) |
|
299 | 299 | user = User.find(9) |
|
300 | 300 | # minimal email notification options |
|
301 | 301 | user.pref.no_self_notified = '1' |
|
302 | 302 | user.pref.save |
|
303 | 303 | user.mail_notification = false |
|
304 | 304 | user.save |
|
305 | 305 | |
|
306 | 306 | Watcher.create!(:watchable => issue, :user => user) |
|
307 | 307 | assert Mailer.deliver_issue_add(issue) |
|
308 | 308 | assert last_email.bcc.include?(user.mail) |
|
309 | 309 | end |
|
310 | 310 | |
|
311 | 311 | test "#issue_add should not notify watchers not allowed to view the issue" do |
|
312 | 312 | issue = Issue.find(1) |
|
313 | 313 | user = User.find(9) |
|
314 | 314 | Watcher.create!(:watchable => issue, :user => user) |
|
315 | 315 | Role.non_member.remove_permission!(:view_issues) |
|
316 | 316 | assert Mailer.deliver_issue_add(issue) |
|
317 | 317 | assert !last_email.bcc.include?(user.mail) |
|
318 | 318 | end |
|
319 | 319 | |
|
320 | def test_issue_add_should_include_enabled_fields | |
|
321 | Setting.default_language = 'en' | |
|
322 | issue = Issue.find(2) | |
|
323 | assert Mailer.deliver_issue_add(issue) | |
|
324 | assert_mail_body_match '* Target version: 1.0', last_email | |
|
325 | assert_select_email do | |
|
326 | assert_select 'li', :text => 'Target version: 1.0' | |
|
327 | end | |
|
328 | end | |
|
329 | ||
|
330 | def test_issue_add_should_not_include_disabled_fields | |
|
331 | Setting.default_language = 'en' | |
|
332 | issue = Issue.find(2) | |
|
333 | tracker = issue.tracker | |
|
334 | tracker.core_fields -= ['fixed_version_id'] | |
|
335 | tracker.save! | |
|
336 | assert Mailer.deliver_issue_add(issue) | |
|
337 | assert_mail_body_no_match 'Target version', last_email | |
|
338 | assert_select_email do | |
|
339 | assert_select 'li', :text => /Target version/, :count => 0 | |
|
340 | end | |
|
341 | end | |
|
342 | ||
|
320 | 343 | # test mailer methods for each language |
|
321 | 344 | def test_issue_add |
|
322 | 345 | issue = Issue.find(1) |
|
323 | 346 | valid_languages.each do |lang| |
|
324 | 347 | Setting.default_language = lang.to_s |
|
325 | 348 | assert Mailer.deliver_issue_add(issue) |
|
326 | 349 | end |
|
327 | 350 | end |
|
328 | 351 | |
|
329 | 352 | def test_issue_edit |
|
330 | 353 | journal = Journal.find(1) |
|
331 | 354 | valid_languages.each do |lang| |
|
332 | 355 | Setting.default_language = lang.to_s |
|
333 | 356 | assert Mailer.deliver_issue_edit(journal) |
|
334 | 357 | end |
|
335 | 358 | end |
|
336 | 359 | |
|
337 | 360 | def test_issue_edit_should_send_private_notes_to_users_with_permission_only |
|
338 | 361 | journal = Journal.find(1) |
|
339 | 362 | journal.private_notes = true |
|
340 | 363 | journal.save! |
|
341 | 364 | |
|
342 | 365 | Role.find(2).add_permission! :view_private_notes |
|
343 | 366 | Mailer.deliver_issue_edit(journal) |
|
344 | 367 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort |
|
345 | 368 | |
|
346 | 369 | Role.find(2).remove_permission! :view_private_notes |
|
347 | 370 | Mailer.deliver_issue_edit(journal) |
|
348 | 371 | assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort |
|
349 | 372 | end |
|
350 | 373 | |
|
351 | 374 | def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only |
|
352 | 375 | Issue.find(1).set_watcher(User.find_by_login('someone')) |
|
353 | 376 | journal = Journal.find(1) |
|
354 | 377 | journal.private_notes = true |
|
355 | 378 | journal.save! |
|
356 | 379 | |
|
357 | 380 | Role.non_member.add_permission! :view_private_notes |
|
358 | 381 | Mailer.deliver_issue_edit(journal) |
|
359 | 382 | assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort |
|
360 | 383 | |
|
361 | 384 | Role.non_member.remove_permission! :view_private_notes |
|
362 | 385 | Mailer.deliver_issue_edit(journal) |
|
363 | 386 | assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort |
|
364 | 387 | end |
|
365 | 388 | |
|
366 | 389 | def test_issue_edit_should_mark_private_notes |
|
367 | 390 | journal = Journal.find(2) |
|
368 | 391 | journal.private_notes = true |
|
369 | 392 | journal.save! |
|
370 | 393 | |
|
371 | 394 | with_settings :default_language => 'en' do |
|
372 | 395 | Mailer.deliver_issue_edit(journal) |
|
373 | 396 | end |
|
374 | 397 | assert_mail_body_match '(Private notes)', last_email |
|
375 | 398 | end |
|
376 | 399 | |
|
377 | 400 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue |
|
378 | 401 | issue = Issue.generate! |
|
379 | 402 | private_issue = Issue.generate!(:is_private => true) |
|
380 | 403 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') |
|
381 | 404 | issue.reload |
|
382 | 405 | assert_equal 1, issue.journals.size |
|
383 | 406 | journal = issue.journals.first |
|
384 | 407 | ActionMailer::Base.deliveries.clear |
|
385 | 408 | |
|
386 | 409 | Mailer.deliver_issue_edit(journal) |
|
387 | 410 | last_email.bcc.each do |email| |
|
388 | 411 | user = User.find_by_mail(email) |
|
389 | 412 | assert private_issue.visible?(user), "Issue was not visible to #{user}" |
|
390 | 413 | end |
|
391 | 414 | end |
|
392 | 415 | |
|
393 | 416 | def test_document_added |
|
394 | 417 | document = Document.find(1) |
|
395 | 418 | valid_languages.each do |lang| |
|
396 | 419 | Setting.default_language = lang.to_s |
|
397 | 420 | assert Mailer.document_added(document).deliver |
|
398 | 421 | end |
|
399 | 422 | end |
|
400 | 423 | |
|
401 | 424 | def test_attachments_added |
|
402 | 425 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
403 | 426 | valid_languages.each do |lang| |
|
404 | 427 | Setting.default_language = lang.to_s |
|
405 | 428 | assert Mailer.attachments_added(attachements).deliver |
|
406 | 429 | end |
|
407 | 430 | end |
|
408 | 431 | |
|
409 | 432 | def test_version_file_added |
|
410 | 433 | attachements = [ Attachment.find_by_container_type('Version') ] |
|
411 | 434 | assert Mailer.attachments_added(attachements).deliver |
|
412 | 435 | assert_not_nil last_email.bcc |
|
413 | 436 | assert last_email.bcc.any? |
|
414 | 437 | assert_select_email do |
|
415 | 438 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
416 | 439 | end |
|
417 | 440 | end |
|
418 | 441 | |
|
419 | 442 | def test_project_file_added |
|
420 | 443 | attachements = [ Attachment.find_by_container_type('Project') ] |
|
421 | 444 | assert Mailer.attachments_added(attachements).deliver |
|
422 | 445 | assert_not_nil last_email.bcc |
|
423 | 446 | assert last_email.bcc.any? |
|
424 | 447 | assert_select_email do |
|
425 | 448 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
426 | 449 | end |
|
427 | 450 | end |
|
428 | 451 | |
|
429 | 452 | def test_news_added |
|
430 | 453 | news = News.first |
|
431 | 454 | valid_languages.each do |lang| |
|
432 | 455 | Setting.default_language = lang.to_s |
|
433 | 456 | assert Mailer.news_added(news).deliver |
|
434 | 457 | end |
|
435 | 458 | end |
|
436 | 459 | |
|
437 | 460 | def test_news_comment_added |
|
438 | 461 | comment = Comment.find(2) |
|
439 | 462 | valid_languages.each do |lang| |
|
440 | 463 | Setting.default_language = lang.to_s |
|
441 | 464 | assert Mailer.news_comment_added(comment).deliver |
|
442 | 465 | end |
|
443 | 466 | end |
|
444 | 467 | |
|
445 | 468 | def test_message_posted |
|
446 | 469 | message = Message.first |
|
447 | 470 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
448 | 471 | recipients = recipients.compact.uniq |
|
449 | 472 | valid_languages.each do |lang| |
|
450 | 473 | Setting.default_language = lang.to_s |
|
451 | 474 | assert Mailer.message_posted(message).deliver |
|
452 | 475 | end |
|
453 | 476 | end |
|
454 | 477 | |
|
455 | 478 | def test_wiki_content_added |
|
456 | 479 | content = WikiContent.find(1) |
|
457 | 480 | valid_languages.each do |lang| |
|
458 | 481 | Setting.default_language = lang.to_s |
|
459 | 482 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
460 | 483 | assert Mailer.wiki_content_added(content).deliver |
|
461 | 484 | assert_select_email do |
|
462 | 485 | assert_select 'a[href=?]', |
|
463 | 486 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', |
|
464 | 487 | :text => 'CookBook documentation' |
|
465 | 488 | end |
|
466 | 489 | end |
|
467 | 490 | end |
|
468 | 491 | end |
|
469 | 492 | |
|
470 | 493 | def test_wiki_content_updated |
|
471 | 494 | content = WikiContent.find(1) |
|
472 | 495 | valid_languages.each do |lang| |
|
473 | 496 | Setting.default_language = lang.to_s |
|
474 | 497 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
475 | 498 | assert Mailer.wiki_content_updated(content).deliver |
|
476 | 499 | assert_select_email do |
|
477 | 500 | assert_select 'a[href=?]', |
|
478 | 501 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', |
|
479 | 502 | :text => 'CookBook documentation' |
|
480 | 503 | end |
|
481 | 504 | end |
|
482 | 505 | end |
|
483 | 506 | end |
|
484 | 507 | |
|
485 | 508 | def test_account_information |
|
486 | 509 | user = User.find(2) |
|
487 | 510 | valid_languages.each do |lang| |
|
488 | 511 | user.update_attribute :language, lang.to_s |
|
489 | 512 | user.reload |
|
490 | 513 | assert Mailer.account_information(user, 'pAsswORd').deliver |
|
491 | 514 | end |
|
492 | 515 | end |
|
493 | 516 | |
|
494 | 517 | def test_lost_password |
|
495 | 518 | token = Token.find(2) |
|
496 | 519 | valid_languages.each do |lang| |
|
497 | 520 | token.user.update_attribute :language, lang.to_s |
|
498 | 521 | token.reload |
|
499 | 522 | assert Mailer.lost_password(token).deliver |
|
500 | 523 | end |
|
501 | 524 | end |
|
502 | 525 | |
|
503 | 526 | def test_register |
|
504 | 527 | token = Token.find(1) |
|
505 | 528 | Setting.host_name = 'redmine.foo' |
|
506 | 529 | Setting.protocol = 'https' |
|
507 | 530 | |
|
508 | 531 | valid_languages.each do |lang| |
|
509 | 532 | token.user.update_attribute :language, lang.to_s |
|
510 | 533 | token.reload |
|
511 | 534 | ActionMailer::Base.deliveries.clear |
|
512 | 535 | assert Mailer.register(token).deliver |
|
513 | 536 | mail = last_email |
|
514 | 537 | assert_select_email do |
|
515 | 538 | assert_select "a[href=?]", |
|
516 | 539 | "https://redmine.foo/account/activate?token=#{token.value}", |
|
517 | 540 | :text => "https://redmine.foo/account/activate?token=#{token.value}" |
|
518 | 541 | end |
|
519 | 542 | end |
|
520 | 543 | end |
|
521 | 544 | |
|
522 | 545 | def test_test |
|
523 | 546 | user = User.find(1) |
|
524 | 547 | valid_languages.each do |lang| |
|
525 | 548 | user.update_attribute :language, lang.to_s |
|
526 | 549 | assert Mailer.test_email(user).deliver |
|
527 | 550 | end |
|
528 | 551 | end |
|
529 | 552 | |
|
530 | 553 | def test_reminders |
|
531 | 554 | Mailer.reminders(:days => 42) |
|
532 | 555 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
533 | 556 | mail = last_email |
|
534 | 557 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
535 | 558 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail |
|
536 | 559 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
537 | 560 | end |
|
538 | 561 | |
|
539 | 562 | def test_reminders_should_not_include_closed_issues |
|
540 | 563 | with_settings :default_language => 'en' do |
|
541 | 564 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, |
|
542 | 565 | :subject => 'Closed issue', :assigned_to_id => 3, |
|
543 | 566 | :due_date => 5.days.from_now, |
|
544 | 567 | :author_id => 2) |
|
545 | 568 | ActionMailer::Base.deliveries.clear |
|
546 | 569 | |
|
547 | 570 | Mailer.reminders(:days => 42) |
|
548 | 571 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
549 | 572 | mail = last_email |
|
550 | 573 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
551 | 574 | assert_mail_body_no_match 'Closed issue', mail |
|
552 | 575 | end |
|
553 | 576 | end |
|
554 | 577 | |
|
555 | 578 | def test_reminders_for_users |
|
556 | 579 | Mailer.reminders(:days => 42, :users => ['5']) |
|
557 | 580 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
558 | 581 | Mailer.reminders(:days => 42, :users => ['3']) |
|
559 | 582 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
560 | 583 | mail = last_email |
|
561 | 584 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
562 | 585 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail |
|
563 | 586 | end |
|
564 | 587 | |
|
565 | 588 | def test_reminder_should_include_issues_assigned_to_groups |
|
566 | 589 | with_settings :default_language => 'en' do |
|
567 | 590 | group = Group.generate! |
|
568 | 591 | group.users << User.find(2) |
|
569 | 592 | group.users << User.find(3) |
|
570 | 593 | |
|
571 | 594 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, |
|
572 | 595 | :subject => 'Assigned to group', :assigned_to => group, |
|
573 | 596 | :due_date => 5.days.from_now, |
|
574 | 597 | :author_id => 2) |
|
575 | 598 | ActionMailer::Base.deliveries.clear |
|
576 | 599 | |
|
577 | 600 | Mailer.reminders(:days => 7) |
|
578 | 601 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
579 | 602 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort |
|
580 | 603 | ActionMailer::Base.deliveries.each do |mail| |
|
581 | 604 | assert_mail_body_match 'Assigned to group', mail |
|
582 | 605 | end |
|
583 | 606 | end |
|
584 | 607 | end |
|
585 | 608 | |
|
586 | 609 | def test_mailer_should_not_change_locale |
|
587 | 610 | Setting.default_language = 'en' |
|
588 | 611 | # Set current language to italian |
|
589 | 612 | set_language_if_valid 'it' |
|
590 | 613 | # Send an email to a french user |
|
591 | 614 | user = User.find(1) |
|
592 | 615 | user.language = 'fr' |
|
593 | 616 | Mailer.account_activated(user).deliver |
|
594 | 617 | mail = last_email |
|
595 | 618 | assert_mail_body_match 'Votre compte', mail |
|
596 | 619 | |
|
597 | 620 | assert_equal :it, current_language |
|
598 | 621 | end |
|
599 | 622 | |
|
600 | 623 | def test_with_deliveries_off |
|
601 | 624 | Mailer.with_deliveries false do |
|
602 | 625 | Mailer.test_email(User.find(1)).deliver |
|
603 | 626 | end |
|
604 | 627 | assert ActionMailer::Base.deliveries.empty? |
|
605 | 628 | # should restore perform_deliveries |
|
606 | 629 | assert ActionMailer::Base.perform_deliveries |
|
607 | 630 | end |
|
608 | 631 | |
|
609 | 632 | def test_layout_should_include_the_emails_header |
|
610 | 633 | with_settings :emails_header => "*Header content*" do |
|
611 | 634 | with_settings :plain_text_mail => 0 do |
|
612 | 635 | assert Mailer.test_email(User.find(1)).deliver |
|
613 | 636 | assert_select_email do |
|
614 | 637 | assert_select ".header" do |
|
615 | 638 | assert_select "strong", :text => "Header content" |
|
616 | 639 | end |
|
617 | 640 | end |
|
618 | 641 | end |
|
619 | 642 | with_settings :plain_text_mail => 1 do |
|
620 | 643 | assert Mailer.test_email(User.find(1)).deliver |
|
621 | 644 | mail = last_email |
|
622 | 645 | assert_not_nil mail |
|
623 | 646 | assert_include "*Header content*", mail.body.decoded |
|
624 | 647 | end |
|
625 | 648 | end |
|
626 | 649 | end |
|
627 | 650 | |
|
628 | 651 | def test_layout_should_not_include_empty_emails_header |
|
629 | 652 | with_settings :emails_header => "", :plain_text_mail => 0 do |
|
630 | 653 | assert Mailer.test_email(User.find(1)).deliver |
|
631 | 654 | assert_select_email do |
|
632 | 655 | assert_select ".header", false |
|
633 | 656 | end |
|
634 | 657 | end |
|
635 | 658 | end |
|
636 | 659 | |
|
637 | 660 | def test_layout_should_include_the_emails_footer |
|
638 | 661 | with_settings :emails_footer => "*Footer content*" do |
|
639 | 662 | with_settings :plain_text_mail => 0 do |
|
640 | 663 | assert Mailer.test_email(User.find(1)).deliver |
|
641 | 664 | assert_select_email do |
|
642 | 665 | assert_select ".footer" do |
|
643 | 666 | assert_select "strong", :text => "Footer content" |
|
644 | 667 | end |
|
645 | 668 | end |
|
646 | 669 | end |
|
647 | 670 | with_settings :plain_text_mail => 1 do |
|
648 | 671 | assert Mailer.test_email(User.find(1)).deliver |
|
649 | 672 | mail = last_email |
|
650 | 673 | assert_not_nil mail |
|
651 | 674 | assert_include "\n-- \n", mail.body.decoded |
|
652 | 675 | assert_include "*Footer content*", mail.body.decoded |
|
653 | 676 | end |
|
654 | 677 | end |
|
655 | 678 | end |
|
656 | 679 | |
|
657 | 680 | def test_layout_should_not_include_empty_emails_footer |
|
658 | 681 | with_settings :emails_footer => "" do |
|
659 | 682 | with_settings :plain_text_mail => 0 do |
|
660 | 683 | assert Mailer.test_email(User.find(1)).deliver |
|
661 | 684 | assert_select_email do |
|
662 | 685 | assert_select ".footer", false |
|
663 | 686 | end |
|
664 | 687 | end |
|
665 | 688 | with_settings :plain_text_mail => 1 do |
|
666 | 689 | assert Mailer.test_email(User.find(1)).deliver |
|
667 | 690 | mail = last_email |
|
668 | 691 | assert_not_nil mail |
|
669 | 692 | assert_not_include "\n-- \n", mail.body.decoded |
|
670 | 693 | end |
|
671 | 694 | end |
|
672 | 695 | end |
|
673 | 696 | |
|
674 | 697 | def test_should_escape_html_templates_only |
|
675 | 698 | Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>') |
|
676 | 699 | mail = last_email |
|
677 | 700 | assert_equal 2, mail.parts.size |
|
678 | 701 | assert_include '<tag>', text_part.body.encoded |
|
679 | 702 | assert_include '<tag>', html_part.body.encoded |
|
680 | 703 | end |
|
681 | 704 | |
|
682 | 705 | def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true |
|
683 | 706 | mail = Mailer.test_email(User.find(1)) |
|
684 | 707 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) |
|
685 | 708 | |
|
686 | 709 | ActionMailer::Base.raise_delivery_errors = true |
|
687 | 710 | assert_raise Exception, "delivery error" do |
|
688 | 711 | mail.deliver |
|
689 | 712 | end |
|
690 | 713 | ensure |
|
691 | 714 | ActionMailer::Base.raise_delivery_errors = false |
|
692 | 715 | end |
|
693 | 716 | |
|
694 | 717 | def test_should_log_delivery_errors_when_raise_delivery_errors_is_false |
|
695 | 718 | mail = Mailer.test_email(User.find(1)) |
|
696 | 719 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) |
|
697 | 720 | |
|
698 | 721 | Rails.logger.expects(:error).with("Email delivery error: delivery error") |
|
699 | 722 | ActionMailer::Base.raise_delivery_errors = false |
|
700 | 723 | assert_nothing_raised do |
|
701 | 724 | mail.deliver |
|
702 | 725 | end |
|
703 | 726 | end |
|
704 | 727 | |
|
705 | 728 | private |
|
706 | 729 | |
|
707 | 730 | def last_email |
|
708 | 731 | mail = ActionMailer::Base.deliveries.last |
|
709 | 732 | assert_not_nil mail |
|
710 | 733 | |
|
711 | 734 | end |
|
712 | 735 | |
|
713 | 736 | def text_part |
|
714 | 737 | last_email.parts.detect {|part| part.content_type.include?('text/plain')} |
|
715 | 738 | end |
|
716 | 739 | |
|
717 | 740 | def html_part |
|
718 | 741 | last_email.parts.detect {|part| part.content_type.include?('text/html')} |
|
719 | 742 | end |
|
720 | 743 | end |
General Comments 0
You need to be logged in to leave comments.
Login now