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