##// END OF EJS Templates
Override @#url_for@ in AM to force generation of absolute links (#10251)....
Etienne Massip -
r8902:7056649a4be9
parent child
Show More
@@ -1,477 +1,482
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Mailer < ActionMailer::Base
19 19 layout 'mailer'
20 20 helper :application
21 21 helper :issues
22 22 helper :custom_fields
23 23
24 24 include ActionController::UrlWriter
25 25 include Redmine::I18n
26 26
27 27 def self.default_url_options
28 28 h = Setting.host_name
29 29 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
30 30 { :host => h, :protocol => Setting.protocol }
31 31 end
32 32
33 def url_for(options)
34 options[:only_path] = false if options.is_a?(Hash)
35 super options
36 end
37
33 38 # Builds a tmail object used to email recipients of the added issue.
34 39 #
35 40 # Example:
36 41 # issue_add(issue) => tmail object
37 42 # Mailer.deliver_issue_add(issue) => sends an email to issue recipients
38 43 def issue_add(issue)
39 44 redmine_headers 'Project' => issue.project.identifier,
40 45 'Issue-Id' => issue.id,
41 46 'Issue-Author' => issue.author.login
42 47 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
43 48 message_id issue
44 49 @author = issue.author
45 50 recipients issue.recipients
46 51 cc(issue.watcher_recipients - @recipients)
47 52 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
48 53 body :issue => issue,
49 54 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
50 55 render_multipart('issue_add', body)
51 56 end
52 57
53 58 # Builds a tmail object used to email recipients of the edited issue.
54 59 #
55 60 # Example:
56 61 # issue_edit(journal) => tmail object
57 62 # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
58 63 def issue_edit(journal)
59 64 issue = journal.journalized.reload
60 65 redmine_headers 'Project' => issue.project.identifier,
61 66 'Issue-Id' => issue.id,
62 67 'Issue-Author' => issue.author.login
63 68 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
64 69 message_id journal
65 70 references issue
66 71 @author = journal.user
67 72 recipients issue.recipients
68 73 # Watchers in cc
69 74 cc(issue.watcher_recipients - @recipients)
70 75 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
71 76 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
72 77 s << issue.subject
73 78 subject s
74 79 body :issue => issue,
75 80 :journal => journal,
76 81 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
77 82
78 83 render_multipart('issue_edit', body)
79 84 end
80 85
81 86 def reminder(user, issues, days)
82 87 set_language_if_valid user.language
83 88 recipients user.mail
84 89 subject l(:mail_subject_reminder, :count => issues.size, :days => days)
85 90 body :issues => issues,
86 91 :days => days,
87 92 :issues_url => url_for(:controller => 'issues', :action => 'index',
88 93 :set_filter => 1, :assigned_to_id => user.id,
89 94 :sort => 'due_date:asc')
90 95 render_multipart('reminder', body)
91 96 end
92 97
93 98 # Builds a tmail object used to email users belonging to the added document's project.
94 99 #
95 100 # Example:
96 101 # document_added(document) => tmail object
97 102 # Mailer.deliver_document_added(document) => sends an email to the document's project recipients
98 103 def document_added(document)
99 104 redmine_headers 'Project' => document.project.identifier
100 105 recipients document.recipients
101 106 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
102 107 body :document => document,
103 108 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
104 109 render_multipart('document_added', body)
105 110 end
106 111
107 112 # Builds a tmail object used to email recipients of a project when an attachements are added.
108 113 #
109 114 # Example:
110 115 # attachments_added(attachments) => tmail object
111 116 # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
112 117 def attachments_added(attachments)
113 118 container = attachments.first.container
114 119 added_to = ''
115 120 added_to_url = ''
116 121 case container.class.name
117 122 when 'Project'
118 123 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
119 124 added_to = "#{l(:label_project)}: #{container}"
120 125 recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
121 126 when 'Version'
122 127 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
123 128 added_to = "#{l(:label_version)}: #{container.name}"
124 129 recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
125 130 when 'Document'
126 131 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
127 132 added_to = "#{l(:label_document)}: #{container.title}"
128 133 recipients container.recipients
129 134 end
130 135 redmine_headers 'Project' => container.project.identifier
131 136 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
132 137 body :attachments => attachments,
133 138 :added_to => added_to,
134 139 :added_to_url => added_to_url
135 140 render_multipart('attachments_added', body)
136 141 end
137 142
138 143 # Builds a tmail object used to email recipients of a news' project when a news item is added.
139 144 #
140 145 # Example:
141 146 # news_added(news) => tmail object
142 147 # Mailer.deliver_news_added(news) => sends an email to the news' project recipients
143 148 def news_added(news)
144 149 redmine_headers 'Project' => news.project.identifier
145 150 message_id news
146 151 recipients news.recipients
147 152 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
148 153 body :news => news,
149 154 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
150 155 render_multipart('news_added', body)
151 156 end
152 157
153 158 # Builds a tmail object used to email recipients of a news' project when a news comment is added.
154 159 #
155 160 # Example:
156 161 # news_comment_added(comment) => tmail object
157 162 # Mailer.news_comment_added(comment) => sends an email to the news' project recipients
158 163 def news_comment_added(comment)
159 164 news = comment.commented
160 165 redmine_headers 'Project' => news.project.identifier
161 166 message_id comment
162 167 recipients news.recipients
163 168 cc news.watcher_recipients
164 169 subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
165 170 body :news => news,
166 171 :comment => comment,
167 172 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
168 173 render_multipart('news_comment_added', body)
169 174 end
170 175
171 176 # Builds a tmail object used to email the recipients of the specified message that was posted.
172 177 #
173 178 # Example:
174 179 # message_posted(message) => tmail object
175 180 # Mailer.deliver_message_posted(message) => sends an email to the recipients
176 181 def message_posted(message)
177 182 redmine_headers 'Project' => message.project.identifier,
178 183 'Topic-Id' => (message.parent_id || message.id)
179 184 message_id message
180 185 references message.parent unless message.parent.nil?
181 186 recipients(message.recipients)
182 187 cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients)
183 188 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
184 189 body :message => message,
185 190 :message_url => url_for(message.event_url)
186 191 render_multipart('message_posted', body)
187 192 end
188 193
189 194 # Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
190 195 #
191 196 # Example:
192 197 # wiki_content_added(wiki_content) => tmail object
193 198 # Mailer.deliver_wiki_content_added(wiki_content) => sends an email to the project's recipients
194 199 def wiki_content_added(wiki_content)
195 200 redmine_headers 'Project' => wiki_content.project.identifier,
196 201 'Wiki-Page-Id' => wiki_content.page.id
197 202 message_id wiki_content
198 203 recipients wiki_content.recipients
199 204 cc(wiki_content.page.wiki.watcher_recipients - recipients)
200 205 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}"
201 206 body :wiki_content => wiki_content,
202 207 :wiki_content_url => url_for(:controller => 'wiki', :action => 'show',
203 208 :project_id => wiki_content.project,
204 209 :id => wiki_content.page.title)
205 210 render_multipart('wiki_content_added', body)
206 211 end
207 212
208 213 # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
209 214 #
210 215 # Example:
211 216 # wiki_content_updated(wiki_content) => tmail object
212 217 # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
213 218 def wiki_content_updated(wiki_content)
214 219 redmine_headers 'Project' => wiki_content.project.identifier,
215 220 'Wiki-Page-Id' => wiki_content.page.id
216 221 message_id wiki_content
217 222 recipients wiki_content.recipients
218 223 cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients)
219 224 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}"
220 225 body :wiki_content => wiki_content,
221 226 :wiki_content_url => url_for(:controller => 'wiki', :action => 'show',
222 227 :project_id => wiki_content.project,
223 228 :id => wiki_content.page.title),
224 229 :wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff',
225 230 :project_id => wiki_content.project, :id => wiki_content.page.title,
226 231 :version => wiki_content.version)
227 232 render_multipart('wiki_content_updated', body)
228 233 end
229 234
230 235 # Builds a tmail object used to email the specified user their account information.
231 236 #
232 237 # Example:
233 238 # account_information(user, password) => tmail object
234 239 # Mailer.deliver_account_information(user, password) => sends account information to the user
235 240 def account_information(user, password)
236 241 set_language_if_valid user.language
237 242 recipients user.mail
238 243 subject l(:mail_subject_register, Setting.app_title)
239 244 body :user => user,
240 245 :password => password,
241 246 :login_url => url_for(:controller => 'account', :action => 'login')
242 247 render_multipart('account_information', body)
243 248 end
244 249
245 250 # Builds a tmail object used to email all active administrators of an account activation request.
246 251 #
247 252 # Example:
248 253 # account_activation_request(user) => tmail object
249 254 # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
250 255 def account_activation_request(user)
251 256 # Send the email to all active administrators
252 257 recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
253 258 subject l(:mail_subject_account_activation_request, Setting.app_title)
254 259 body :user => user,
255 260 :url => url_for(:controller => 'users', :action => 'index',
256 261 :status => User::STATUS_REGISTERED,
257 262 :sort_key => 'created_on', :sort_order => 'desc')
258 263 render_multipart('account_activation_request', body)
259 264 end
260 265
261 266 # Builds a tmail object used to email the specified user that their account was activated by an administrator.
262 267 #
263 268 # Example:
264 269 # account_activated(user) => tmail object
265 270 # Mailer.deliver_account_activated(user) => sends an email to the registered user
266 271 def account_activated(user)
267 272 set_language_if_valid user.language
268 273 recipients user.mail
269 274 subject l(:mail_subject_register, Setting.app_title)
270 275 body :user => user,
271 276 :login_url => url_for(:controller => 'account', :action => 'login')
272 277 render_multipart('account_activated', body)
273 278 end
274 279
275 280 def lost_password(token)
276 281 set_language_if_valid(token.user.language)
277 282 recipients token.user.mail
278 283 subject l(:mail_subject_lost_password, Setting.app_title)
279 284 body :token => token,
280 285 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
281 286 render_multipart('lost_password', body)
282 287 end
283 288
284 289 def register(token)
285 290 set_language_if_valid(token.user.language)
286 291 recipients token.user.mail
287 292 subject l(:mail_subject_register, Setting.app_title)
288 293 body :token => token,
289 294 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
290 295 render_multipart('register', body)
291 296 end
292 297
293 298 def test(user)
294 299 set_language_if_valid(user.language)
295 300 recipients user.mail
296 301 subject 'Redmine test'
297 302 body :url => url_for(:controller => 'welcome')
298 303 render_multipart('test', body)
299 304 end
300 305
301 306 # Overrides default deliver! method to prevent from sending an email
302 307 # with no recipient, cc or bcc
303 308 def deliver!(mail = @mail)
304 309 set_language_if_valid @initial_language
305 310 return false if (recipients.nil? || recipients.empty?) &&
306 311 (cc.nil? || cc.empty?) &&
307 312 (bcc.nil? || bcc.empty?)
308 313
309 314 # Set Message-Id and References
310 315 if @message_id_object
311 316 mail.message_id = self.class.message_id_for(@message_id_object)
312 317 end
313 318 if @references_objects
314 319 mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
315 320 end
316 321
317 322 # Log errors when raise_delivery_errors is set to false, Rails does not
318 323 raise_errors = self.class.raise_delivery_errors
319 324 self.class.raise_delivery_errors = true
320 325 begin
321 326 return super(mail)
322 327 rescue Exception => e
323 328 if raise_errors
324 329 raise e
325 330 elsif mylogger
326 331 mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/configuration.yml."
327 332 end
328 333 ensure
329 334 self.class.raise_delivery_errors = raise_errors
330 335 end
331 336 end
332 337
333 338 # Sends reminders to issue assignees
334 339 # Available options:
335 340 # * :days => how many days in the future to remind about (defaults to 7)
336 341 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
337 342 # * :project => id or identifier of project to process (defaults to all projects)
338 343 # * :users => array of user ids who should be reminded
339 344 def self.reminders(options={})
340 345 days = options[:days] || 7
341 346 project = options[:project] ? Project.find(options[:project]) : nil
342 347 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
343 348 user_ids = options[:users]
344 349
345 350 scope = Issue.open.scoped(:conditions => ["#{Issue.table_name}.assigned_to_id IS NOT NULL" +
346 351 " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
347 352 " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date]
348 353 )
349 354 scope = scope.scoped(:conditions => {:assigned_to_id => user_ids}) if user_ids.present?
350 355 scope = scope.scoped(:conditions => {:project_id => project.id}) if project
351 356 scope = scope.scoped(:conditions => {:tracker_id => tracker.id}) if tracker
352 357
353 358 issues_by_assignee = scope.all(:include => [:status, :assigned_to, :project, :tracker]).group_by(&:assigned_to)
354 359 issues_by_assignee.each do |assignee, issues|
355 360 deliver_reminder(assignee, issues, days) if assignee && assignee.active?
356 361 end
357 362 end
358 363
359 364 # Activates/desactivates email deliveries during +block+
360 365 def self.with_deliveries(enabled = true, &block)
361 366 was_enabled = ActionMailer::Base.perform_deliveries
362 367 ActionMailer::Base.perform_deliveries = !!enabled
363 368 yield
364 369 ensure
365 370 ActionMailer::Base.perform_deliveries = was_enabled
366 371 end
367 372
368 373 private
369 374 def initialize_defaults(method_name)
370 375 super
371 376 @initial_language = current_language
372 377 set_language_if_valid Setting.default_language
373 378 from Setting.mail_from
374 379
375 380 # Common headers
376 381 headers 'X-Mailer' => 'Redmine',
377 382 'X-Redmine-Host' => Setting.host_name,
378 383 'X-Redmine-Site' => Setting.app_title,
379 384 'X-Auto-Response-Suppress' => 'OOF',
380 385 'Auto-Submitted' => 'auto-generated'
381 386 end
382 387
383 388 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
384 389 def redmine_headers(h)
385 390 h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s }
386 391 end
387 392
388 393 # Overrides the create_mail method
389 394 def create_mail
390 395 # Removes the current user from the recipients and cc
391 396 # if he doesn't want to receive notifications about what he does
392 397 @author ||= User.current
393 398 if @author.pref[:no_self_notified]
394 399 recipients.delete(@author.mail) if recipients
395 400 cc.delete(@author.mail) if cc
396 401 end
397 402
398 403 if @author.logged?
399 404 redmine_headers 'Sender' => @author.login
400 405 end
401 406
402 407 notified_users = [recipients, cc].flatten.compact.uniq
403 408 # Rails would log recipients only, not cc and bcc
404 409 mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger
405 410
406 411 # Blind carbon copy recipients
407 412 if Setting.bcc_recipients?
408 413 bcc(notified_users)
409 414 recipients []
410 415 cc []
411 416 end
412 417 super
413 418 end
414 419
415 420 # Rails 2.3 has problems rendering implicit multipart messages with
416 421 # layouts so this method will wrap an multipart messages with
417 422 # explicit parts.
418 423 #
419 424 # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type
420 425 # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts
421 426
422 427 def render_multipart(method_name, body)
423 428 if Setting.plain_text_mail?
424 429 content_type "text/plain"
425 430 body render(:file => "#{method_name}.text.erb",
426 431 :body => body,
427 432 :layout => 'mailer.text.erb')
428 433 else
429 434 content_type "multipart/alternative"
430 435 part :content_type => "text/plain",
431 436 :body => render(:file => "#{method_name}.text.erb",
432 437 :body => body, :layout => 'mailer.text.erb')
433 438 part :content_type => "text/html",
434 439 :body => render_message("#{method_name}.html.erb", body)
435 440 end
436 441 end
437 442
438 443 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
439 444 def self.controller_path
440 445 ''
441 446 end unless respond_to?('controller_path')
442 447
443 448 # Returns a predictable Message-Id for the given object
444 449 def self.message_id_for(object)
445 450 # id + timestamp should reduce the odds of a collision
446 451 # as far as we don't send multiple emails for the same object
447 452 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
448 453 hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
449 454 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
450 455 host = "#{::Socket.gethostname}.redmine" if host.empty?
451 456 "<#{hash}@#{host}>"
452 457 end
453 458
454 459 private
455 460
456 461 def message_id(object)
457 462 @message_id_object = object
458 463 end
459 464
460 465 def references(object)
461 466 @references_objects ||= []
462 467 @references_objects << object
463 468 end
464 469
465 470 def mylogger
466 471 Rails.logger
467 472 end
468 473 end
469 474
470 475 # Patch TMail so that message_id is not overwritten
471 476 module TMail
472 477 class Mail
473 478 def add_message_id( fqdn = nil )
474 479 self.message_id ||= ::TMail::new_message_id(fqdn)
475 480 end
476 481 end
477 482 end
@@ -1,15 +1,15
1 1 <h1><%= link_to(h("#{issue.tracker.name} ##{issue.id}: #{issue.subject}"), issue_url) %></h1>
2 2
3 3 <ul>
4 4 <li><%=l(:field_author)%>: <%=h issue.author %></li>
5 5 <li><%=l(:field_status)%>: <%=h issue.status %></li>
6 6 <li><%=l(:field_priority)%>: <%=h issue.priority %></li>
7 7 <li><%=l(:field_assigned_to)%>: <%=h issue.assigned_to %></li>
8 8 <li><%=l(:field_category)%>: <%=h issue.category %></li>
9 9 <li><%=l(:field_fixed_version)%>: <%=h issue.fixed_version %></li>
10 10 <% issue.custom_field_values.each do |c| %>
11 11 <li><%=h c.custom_field.name %>: <%=h show_value(c) %></li>
12 12 <% end %>
13 13 </ul>
14 14
15 <%= textilizable(issue, :description, :only_path => false) %>
15 <%= textilizable(issue, :description) %>
@@ -1,3 +1,3
1 1 <%= link_to(h(@document.title), @document_url) %> (<%=h @document.category.name %>)<br />
2 2 <br />
3 <%= textilizable(@document, :description, :only_path => false) %>
3 <%= textilizable(@document, :description) %>
@@ -1,11 +1,11
1 1 <%= l(:text_issue_updated, :id => "##{@issue.id}", :author => h(@journal.user)) %>
2 2
3 3 <ul>
4 4 <% details_to_strings(@journal.details).each do |string| %>
5 5 <li><%= string %></li>
6 6 <% end %>
7 7 </ul>
8 8
9 <%= textilizable(@journal, :notes, :only_path => false) %>
9 <%= textilizable(@journal, :notes) %>
10 10 <hr />
11 11 <%= render :partial => "issue.html.erb", :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,4 +1,4
1 1 <h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to(h(@message.subject), @message_url) %></h1>
2 2 <em><%=h @message.author %></em>
3 3
4 <%= textilizable(@message, :content, :only_path => false) %>
4 <%= textilizable(@message, :content) %>
@@ -1,4 +1,4
1 1 <h1><%= link_to(h(@news.title), @news_url) %></h1>
2 2 <em><%=h @news.author.name %></em>
3 3
4 <%= textilizable(@news, :description, :only_path => false) %>
4 <%= textilizable(@news, :description) %>
@@ -1,5 +1,5
1 1 <h1><%= link_to(h(@news.title), @news_url) %></h1>
2 2
3 3 <p><%= l(:text_user_wrote, :value => h(@comment.author)) %></p>
4 4
5 <%= textilizable @comment, :comments, :only_path => false %>
5 <%= textilizable @comment, :comments %>
@@ -1,9 +1,9
1 1 <p><%= l(:mail_body_reminder, :count => @issues.size, :days => @days) %></p>
2 2
3 3 <ul>
4 4 <% @issues.each do |issue| -%>
5 <li><%=h issue.project %> - <%=link_to(h("#{issue.tracker} ##{issue.id}"), :controller => 'issues', :action => 'show', :id => issue, :only_path => false)%>: <%=h issue.subject %></li>
5 <li><%=h issue.project %> - <%=link_to(h("#{issue.tracker} ##{issue.id}"), :controller => 'issues', :action => 'show', :id => issue)%>: <%=h issue.subject %></li>
6 6 <% end -%>
7 7 </ul>
8 8
9 9 <p><%= link_to l(:label_issue_view_all), @issues_url %></p>
@@ -1,36 +1,43
1 1 ---
2 2 journal_details_001:
3 3 old_value: "1"
4 4 property: attr
5 5 id: 1
6 6 value: "2"
7 7 prop_key: status_id
8 8 journal_id: 1
9 9 journal_details_002:
10 10 old_value: "40"
11 11 property: attr
12 12 id: 2
13 13 value: "30"
14 14 prop_key: done_ratio
15 15 journal_id: 1
16 16 journal_details_003:
17 17 old_value: nil
18 18 property: attr
19 19 id: 3
20 20 value: "6"
21 21 prop_key: fixed_version_id
22 22 journal_id: 4
23 23 journal_details_004:
24 24 old_value: "This word was removed and an other was"
25 25 property: attr
26 26 id: 4
27 27 value: "This word was and an other was added"
28 28 prop_key: description
29 29 journal_id: 3
30 30 journal_details_005:
31 31 old_value: Old value
32 32 property: cf
33 33 id: 5
34 34 value: New value
35 35 prop_key: 2
36 36 journal_id: 3
37 journal_details_006:
38 old_value: nil
39 property: attachment
40 id: 6
41 value: 060719210727_picture.jpg
42 prop_key: 4
43 journal_id: 3
@@ -1,36 +1,36
1 1 ---
2 2 journals_001:
3 3 created_on: <%= 2.days.ago.to_date.to_s(:db) %>
4 4 notes: "Journal notes"
5 5 id: 1
6 6 journalized_type: Issue
7 7 user_id: 1
8 8 journalized_id: 1
9 9 journals_002:
10 10 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
11 11 notes: "Some notes with Redmine links: #2, r2."
12 12 id: 2
13 13 journalized_type: Issue
14 14 user_id: 2
15 15 journalized_id: 1
16 16 journals_003:
17 17 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
18 notes: "A comment with inline image: !picture.jpg!"
18 notes: "A comment with inline image: !picture.jpg! and a reference to #1 and r2."
19 19 id: 3
20 20 journalized_type: Issue
21 21 user_id: 2
22 22 journalized_id: 2
23 23 journals_004:
24 24 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
25 25 notes: "A comment with a private version."
26 26 id: 4
27 27 journalized_type: Issue
28 28 user_id: 1
29 29 journalized_id: 6
30 30 journals_005:
31 31 id: 5
32 32 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
33 33 notes: "A comment on a private issue."
34 34 user_id: 2
35 35 journalized_type: Issue
36 36 journalized_id: 14
@@ -1,526 +1,549
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class MailerTest < ActiveSupport::TestCase
21 21 include Redmine::I18n
22 22 include ActionController::Assertions::SelectorAssertions
23 23 fixtures :projects, :enabled_modules, :issues, :users, :members,
24 24 :member_roles, :roles, :documents, :attachments, :news,
25 25 :tokens, :journals, :journal_details, :changesets, :trackers,
26 26 :issue_statuses, :enumerations, :messages, :boards, :repositories,
27 27 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
28 28 :versions,
29 29 :comments
30 30
31 31 def setup
32 32 ActionMailer::Base.deliveries.clear
33 33 Setting.host_name = 'mydomain.foo'
34 34 Setting.protocol = 'http'
35 35 Setting.plain_text_mail = '0'
36 36 end
37 37
38 38 def test_generated_links_in_emails
39 Setting.default_language = 'en'
39 40 Setting.host_name = 'mydomain.foo'
40 41 Setting.protocol = 'https'
41 42
42 journal = Journal.find(2)
43 journal = Journal.find(3)
43 44 assert Mailer.deliver_issue_edit(journal)
44 45
45 mail = ActionMailer::Base.deliveries.last
46 mail = last_email
46 47 assert_not_nil mail
47 48
48 49 assert_select_email do
49 50 # link to the main ticket
50 assert_select "a[href=?]",
51 "https://mydomain.foo/issues/1#change-2",
52 :text => "Bug #1: Can't print recipes"
51 assert_select 'a[href=?]',
52 'https://mydomain.foo/issues/2#change-3',
53 :text => 'Feature request #2: Add ingredients categories'
53 54 # link to a referenced ticket
54 assert_select "a[href=?][title=?]",
55 "https://mydomain.foo/issues/2",
56 "Add ingredients categories (Assigned)",
57 :text => "#2"
55 assert_select 'a[href=?][title=?]',
56 'https://mydomain.foo/issues/1',
57 'Can\'t print recipes (New)',
58 :text => '#1'
58 59 # link to a changeset
59 assert_select "a[href=?][title=?]",
60 "https://mydomain.foo/projects/ecookbook/repository/revisions/2",
61 "This commit fixes #1, #2 and references #1 &amp; #3",
62 :text => "r2"
60 assert_select 'a[href=?][title=?]',
61 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
62 'This commit fixes #1, #2 and references #1 &amp; #3',
63 :text => 'r2'
64 # link to a description diff
65 assert_select 'a[href=?][title=?]',
66 'https://mydomain.foo/journals/diff/3?detail_id=4',
67 'View differences',
68 :text => 'diff'
69 # link to an attachment
70 assert_select 'a[href=?]',
71 'https://mydomain.foo/attachments/download/4/source.rb',
72 :text => 'source.rb'
63 73 end
64 74 end
65 75
66 76 def test_generated_links_with_prefix
77 Setting.default_language = 'en'
67 78 relative_url_root = Redmine::Utils.relative_url_root
68 79 Setting.host_name = 'mydomain.foo/rdm'
69 80 Setting.protocol = 'http'
70 81 Redmine::Utils.relative_url_root = '/rdm'
71 82
72 journal = Journal.find(2)
83 journal = Journal.find(3)
73 84 assert Mailer.deliver_issue_edit(journal)
74 85
75 mail = ActionMailer::Base.deliveries.last
86 mail = last_email
76 87 assert_not_nil mail
77 88
78 89 assert_select_email do
79 90 # link to the main ticket
80 assert_select "a[href=?]",
81 "http://mydomain.foo/rdm/issues/1#change-2",
82 :text => "Bug #1: Can't print recipes"
91 assert_select 'a[href=?]',
92 'http://mydomain.foo/rdm/issues/2#change-3',
93 :text => 'Feature request #2: Add ingredients categories'
83 94 # link to a referenced ticket
84 assert_select "a[href=?][title=?]",
85 "http://mydomain.foo/rdm/issues/2",
86 "Add ingredients categories (Assigned)",
87 :text => "#2"
95 assert_select 'a[href=?][title=?]',
96 'http://mydomain.foo/rdm/issues/1',
97 'Can\'t print recipes (New)',
98 :text => '#1'
88 99 # link to a changeset
89 assert_select "a[href=?][title=?]",
90 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
91 "This commit fixes #1, #2 and references #1 &amp; #3",
92 :text => "r2"
100 assert_select 'a[href=?][title=?]',
101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
102 'This commit fixes #1, #2 and references #1 &amp; #3',
103 :text => 'r2'
104 # link to a description diff
105 assert_select 'a[href=?][title=?]',
106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
107 'View differences',
108 :text => 'diff'
109 # link to an attachment
110 assert_select 'a[href=?]',
111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
112 :text => 'source.rb'
93 113 end
94 114 ensure
95 115 # restore it
96 116 Redmine::Utils.relative_url_root = relative_url_root
97 117 end
98 118
99 119 def test_generated_links_with_prefix_and_no_relative_url_root
120 Setting.default_language = 'en'
100 121 relative_url_root = Redmine::Utils.relative_url_root
101 122 Setting.host_name = 'mydomain.foo/rdm'
102 123 Setting.protocol = 'http'
103 124 Redmine::Utils.relative_url_root = nil
104 125
105 journal = Journal.find(2)
126 journal = Journal.find(3)
106 127 assert Mailer.deliver_issue_edit(journal)
107 128
108 mail = ActionMailer::Base.deliveries.last
129 mail = last_email
109 130 assert_not_nil mail
110 131
111 132 assert_select_email do
112 133 # link to the main ticket
113 assert_select "a[href=?]",
114 "http://mydomain.foo/rdm/issues/1#change-2",
115 :text => "Bug #1: Can't print recipes"
134 assert_select 'a[href=?]',
135 'http://mydomain.foo/rdm/issues/2#change-3',
136 :text => 'Feature request #2: Add ingredients categories'
116 137 # link to a referenced ticket
117 assert_select "a[href=?][title=?]",
118 "http://mydomain.foo/rdm/issues/2",
119 "Add ingredients categories (Assigned)",
120 :text => "#2"
138 assert_select 'a[href=?][title=?]',
139 'http://mydomain.foo/rdm/issues/1',
140 'Can\'t print recipes (New)',
141 :text => '#1'
121 142 # link to a changeset
122 assert_select "a[href=?][title=?]",
123 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
124 "This commit fixes #1, #2 and references #1 &amp; #3",
125 :text => "r2"
143 assert_select 'a[href=?][title=?]',
144 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
145 'This commit fixes #1, #2 and references #1 &amp; #3',
146 :text => 'r2'
147 # link to a description diff
148 assert_select 'a[href=?][title=?]',
149 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
150 'View differences',
151 :text => 'diff'
152 # link to an attachment
153 assert_select 'a[href=?]',
154 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
155 :text => 'source.rb'
126 156 end
127 157 ensure
128 158 # restore it
129 159 Redmine::Utils.relative_url_root = relative_url_root
130 160 end
131 161
132 162 def test_email_headers
133 163 issue = Issue.find(1)
134 164 Mailer.deliver_issue_add(issue)
135 mail = ActionMailer::Base.deliveries.last
165 mail = last_email
136 166 assert_not_nil mail
137 167 assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress')
138 168 assert_equal 'auto-generated', mail.header_string('Auto-Submitted')
139 169 end
140 170
141 171 def test_email_headers_should_include_sender
142 172 issue = Issue.find(1)
143 173 Mailer.deliver_issue_add(issue)
144 mail = ActionMailer::Base.deliveries.last
145 assert_not_nil mail
174 mail = last_email
146 175 assert_equal issue.author.login, mail.header_string('X-Redmine-Sender')
147 176 end
148 177
149 178 def test_plain_text_mail
150 179 Setting.plain_text_mail = 1
151 180 journal = Journal.find(2)
152 181 Mailer.deliver_issue_edit(journal)
153 mail = ActionMailer::Base.deliveries.last
182 mail = last_email
154 183 assert_equal "text/plain", mail.content_type
155 184 assert_equal 0, mail.parts.size
156 185 assert !mail.encoded.include?('href')
157 186 end
158 187
159 188 def test_html_mail
160 189 Setting.plain_text_mail = 0
161 190 journal = Journal.find(2)
162 191 Mailer.deliver_issue_edit(journal)
163 mail = ActionMailer::Base.deliveries.last
192 mail = last_email
164 193 assert_equal 2, mail.parts.size
165 194 assert mail.encoded.include?('href')
166 195 end
167 196
168 197 def test_from_header
169 198 with_settings :mail_from => 'redmine@example.net' do
170 199 Mailer.deliver_test(User.find(1))
171 200 end
172 mail = ActionMailer::Base.deliveries.last
173 assert_not_nil mail
201 mail = last_email
174 202 assert_equal 'redmine@example.net', mail.from_addrs.first.address
175 203 end
176 204
177 205 def test_from_header_with_phrase
178 206 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
179 207 Mailer.deliver_test(User.find(1))
180 208 end
181 mail = ActionMailer::Base.deliveries.last
182 assert_not_nil mail
209 mail = last_email
183 210 assert_equal 'redmine@example.net', mail.from_addrs.first.address
184 211 assert_equal 'Redmine app', mail.from_addrs.first.name
185 212 end
186 213
187 214 def test_should_not_send_email_without_recipient
188 215 news = News.find(:first)
189 216 user = news.author
190 217 # Remove members except news author
191 218 news.project.memberships.each {|m| m.destroy unless m.user == user}
192 219
193 220 user.pref[:no_self_notified] = false
194 221 user.pref.save
195 222 User.current = user
196 223 Mailer.deliver_news_added(news.reload)
197 224 assert_equal 1, last_email.bcc.size
198 225
199 226 # nobody to notify
200 227 user.pref[:no_self_notified] = true
201 228 user.pref.save
202 229 User.current = user
203 230 ActionMailer::Base.deliveries.clear
204 231 Mailer.deliver_news_added(news.reload)
205 232 assert ActionMailer::Base.deliveries.empty?
206 233 end
207 234
208 235 def test_issue_add_message_id
209 236 issue = Issue.find(1)
210 237 Mailer.deliver_issue_add(issue)
211 mail = ActionMailer::Base.deliveries.last
212 assert_not_nil mail
238 mail = last_email
213 239 assert_equal Mailer.message_id_for(issue), mail.message_id
214 240 assert_nil mail.references
215 241 end
216 242
217 243 def test_issue_edit_message_id
218 244 journal = Journal.find(1)
219 245 Mailer.deliver_issue_edit(journal)
220 mail = ActionMailer::Base.deliveries.last
221 assert_not_nil mail
246 mail = last_email
222 247 assert_equal Mailer.message_id_for(journal), mail.message_id
223 248 assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s
224 249 assert_select_email do
225 250 # link to the update
226 251 assert_select "a[href=?]",
227 252 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}"
228 253 end
229 254 end
230 255
231 256 def test_message_posted_message_id
232 257 message = Message.find(1)
233 258 Mailer.deliver_message_posted(message)
234 mail = ActionMailer::Base.deliveries.last
235 assert_not_nil mail
259 mail = last_email
236 260 assert_equal Mailer.message_id_for(message), mail.message_id
237 261 assert_nil mail.references
238 262 assert_select_email do
239 263 # link to the message
240 264 assert_select "a[href=?]",
241 265 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
242 266 :text => message.subject
243 267 end
244 268 end
245 269
246 270 def test_reply_posted_message_id
247 271 message = Message.find(3)
248 272 Mailer.deliver_message_posted(message)
249 mail = ActionMailer::Base.deliveries.last
250 assert_not_nil mail
273 mail = last_email
251 274 assert_equal Mailer.message_id_for(message), mail.message_id
252 275 assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s
253 276 assert_select_email do
254 277 # link to the reply
255 278 assert_select "a[href=?]",
256 279 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
257 280 :text => message.subject
258 281 end
259 282 end
260 283
261 284 context("#issue_add") do
262 285 setup do
263 286 ActionMailer::Base.deliveries.clear
264 287 Setting.bcc_recipients = '1'
265 288 @issue = Issue.find(1)
266 289 end
267 290
268 291 should "notify project members" do
269 292 assert Mailer.deliver_issue_add(@issue)
270 293 assert last_email.bcc.include?('dlopper@somenet.foo')
271 294 end
272 295
273 296 should "not notify project members that are not allow to view the issue" do
274 297 Role.find(2).remove_permission!(:view_issues)
275 298 assert Mailer.deliver_issue_add(@issue)
276 299 assert !last_email.bcc.include?('dlopper@somenet.foo')
277 300 end
278 301
279 302 should "notify issue watchers" do
280 303 user = User.find(9)
281 304 # minimal email notification options
282 305 user.pref[:no_self_notified] = '1'
283 306 user.pref.save
284 307 user.mail_notification = false
285 308 user.save
286 309
287 310 Watcher.create!(:watchable => @issue, :user => user)
288 311 assert Mailer.deliver_issue_add(@issue)
289 312 assert last_email.bcc.include?(user.mail)
290 313 end
291 314
292 315 should "not notify watchers not allowed to view the issue" do
293 316 user = User.find(9)
294 317 Watcher.create!(:watchable => @issue, :user => user)
295 318 Role.non_member.remove_permission!(:view_issues)
296 319 assert Mailer.deliver_issue_add(@issue)
297 320 assert !last_email.bcc.include?(user.mail)
298 321 end
299 322 end
300 323
301 324 # test mailer methods for each language
302 325 def test_issue_add
303 326 issue = Issue.find(1)
304 327 valid_languages.each do |lang|
305 328 Setting.default_language = lang.to_s
306 329 assert Mailer.deliver_issue_add(issue)
307 330 end
308 331 end
309 332
310 333 def test_issue_edit
311 334 journal = Journal.find(1)
312 335 valid_languages.each do |lang|
313 336 Setting.default_language = lang.to_s
314 337 assert Mailer.deliver_issue_edit(journal)
315 338 end
316 339 end
317 340
318 341 def test_document_added
319 342 document = Document.find(1)
320 343 valid_languages.each do |lang|
321 344 Setting.default_language = lang.to_s
322 345 assert Mailer.deliver_document_added(document)
323 346 end
324 347 end
325 348
326 349 def test_attachments_added
327 350 attachements = [ Attachment.find_by_container_type('Document') ]
328 351 valid_languages.each do |lang|
329 352 Setting.default_language = lang.to_s
330 353 assert Mailer.deliver_attachments_added(attachements)
331 354 end
332 355 end
333 356
334 357 def test_version_file_added
335 358 attachements = [ Attachment.find_by_container_type('Version') ]
336 359 assert Mailer.deliver_attachments_added(attachements)
337 360 assert_not_nil last_email.bcc
338 361 assert last_email.bcc.any?
339 362 assert_select_email do
340 363 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
341 364 end
342 365 end
343 366
344 367 def test_project_file_added
345 368 attachements = [ Attachment.find_by_container_type('Project') ]
346 369 assert Mailer.deliver_attachments_added(attachements)
347 370 assert_not_nil last_email.bcc
348 371 assert last_email.bcc.any?
349 372 assert_select_email do
350 373 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
351 374 end
352 375 end
353 376
354 377 def test_news_added
355 378 news = News.find(:first)
356 379 valid_languages.each do |lang|
357 380 Setting.default_language = lang.to_s
358 381 assert Mailer.deliver_news_added(news)
359 382 end
360 383 end
361 384
362 385 def test_news_comment_added
363 386 comment = Comment.find(2)
364 387 valid_languages.each do |lang|
365 388 Setting.default_language = lang.to_s
366 389 assert Mailer.deliver_news_comment_added(comment)
367 390 end
368 391 end
369 392
370 393 def test_message_posted
371 394 message = Message.find(:first)
372 395 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
373 396 recipients = recipients.compact.uniq
374 397 valid_languages.each do |lang|
375 398 Setting.default_language = lang.to_s
376 399 assert Mailer.deliver_message_posted(message)
377 400 end
378 401 end
379 402
380 403 def test_wiki_content_added
381 404 content = WikiContent.find(:first)
382 405 valid_languages.each do |lang|
383 406 Setting.default_language = lang.to_s
384 407 assert_difference 'ActionMailer::Base.deliveries.size' do
385 408 assert Mailer.deliver_wiki_content_added(content)
386 409 end
387 410 end
388 411 end
389 412
390 413 def test_wiki_content_updated
391 414 content = WikiContent.find(:first)
392 415 valid_languages.each do |lang|
393 416 Setting.default_language = lang.to_s
394 417 assert_difference 'ActionMailer::Base.deliveries.size' do
395 418 assert Mailer.deliver_wiki_content_updated(content)
396 419 end
397 420 end
398 421 end
399 422
400 423 def test_account_information
401 424 user = User.find(2)
402 425 valid_languages.each do |lang|
403 426 user.update_attribute :language, lang.to_s
404 427 user.reload
405 428 assert Mailer.deliver_account_information(user, 'pAsswORd')
406 429 end
407 430 end
408 431
409 432 def test_lost_password
410 433 token = Token.find(2)
411 434 valid_languages.each do |lang|
412 435 token.user.update_attribute :language, lang.to_s
413 436 token.reload
414 437 assert Mailer.deliver_lost_password(token)
415 438 end
416 439 end
417 440
418 441 def test_register
419 442 token = Token.find(1)
420 443 Setting.host_name = 'redmine.foo'
421 444 Setting.protocol = 'https'
422 445
423 446 valid_languages.each do |lang|
424 447 token.user.update_attribute :language, lang.to_s
425 448 token.reload
426 449 ActionMailer::Base.deliveries.clear
427 450 assert Mailer.deliver_register(token)
428 mail = ActionMailer::Base.deliveries.last
451 mail = last_email
429 452 assert_select_email do
430 453 assert_select "a[href=?]",
431 454 "https://redmine.foo/account/activate?token=#{token.value}",
432 455 :text => "https://redmine.foo/account/activate?token=#{token.value}"
433 456 end
434 457 end
435 458 end
436 459
437 460 def test_test
438 461 user = User.find(1)
439 462 valid_languages.each do |lang|
440 463 user.update_attribute :language, lang.to_s
441 464 assert Mailer.deliver_test(user)
442 465 end
443 466 end
444 467
445 468 def test_reminders
446 469 Mailer.reminders(:days => 42)
447 470 assert_equal 1, ActionMailer::Base.deliveries.size
448 mail = ActionMailer::Base.deliveries.last
471 mail = last_email
449 472 assert mail.bcc.include?('dlopper@somenet.foo')
450 473 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
451 474 assert_equal '1 issue(s) due in the next 42 days', mail.subject
452 475 end
453 476
454 477 def test_reminders_should_not_include_closed_issues
455 478 with_settings :default_language => 'en' do
456 479 Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 5,
457 480 :subject => 'Closed issue', :assigned_to_id => 3,
458 481 :due_date => 5.days.from_now)
459 482 ActionMailer::Base.deliveries.clear
460 483
461 484 Mailer.reminders(:days => 42)
462 485 assert_equal 1, ActionMailer::Base.deliveries.size
463 mail = ActionMailer::Base.deliveries.last
486 mail = last_email
464 487 assert mail.bcc.include?('dlopper@somenet.foo')
465 488 assert !mail.body.include?('Closed issue')
466 489 end
467 490 end
468 491
469 492 def test_reminders_for_users
470 493 Mailer.reminders(:days => 42, :users => ['5'])
471 494 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
472 495 Mailer.reminders(:days => 42, :users => ['3'])
473 496 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
474 mail = ActionMailer::Base.deliveries.last
497 mail = last_email
475 498 assert mail.bcc.include?('dlopper@somenet.foo')
476 499 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
477 500 end
478 501
479 502 def last_email
480 503 mail = ActionMailer::Base.deliveries.last
481 504 assert_not_nil mail
482 505 mail
483 506 end
484 507
485 508 def test_mailer_should_not_change_locale
486 509 Setting.default_language = 'en'
487 510 # Set current language to italian
488 511 set_language_if_valid 'it'
489 512 # Send an email to a french user
490 513 user = User.find(1)
491 514 user.language = 'fr'
492 515 Mailer.deliver_account_activated(user)
493 mail = ActionMailer::Base.deliveries.last
516 mail = last_email
494 517 assert mail.body.include?('Votre compte')
495 518
496 519 assert_equal :it, current_language
497 520 end
498 521
499 522 def test_with_deliveries_off
500 523 Mailer.with_deliveries false do
501 524 Mailer.deliver_test(User.find(1))
502 525 end
503 526 assert ActionMailer::Base.deliveries.empty?
504 527 # should restore perform_deliveries
505 528 assert ActionMailer::Base.perform_deliveries
506 529 end
507 530
508 531 def test_tmail_to_header_field_should_not_include_blank_lines
509 532 mail = TMail::Mail.new
510 533 mail.to = ["a.user@example.com", "v.user2@example.com", "e.smith@example.com", "info@example.com", "v.pupkin@example.com",
511 534 "b.user@example.com", "w.user2@example.com", "f.smith@example.com", "info2@example.com", "w.pupkin@example.com"]
512 535
513 536 assert !mail.encoded.strip.split("\r\n").detect(&:blank?), "#{mail.encoded} malformed"
514 537 end
515 538
516 539 def test_layout_should_include_the_emails_header
517 540 with_settings :emails_header => "*Header content*" do
518 541 assert Mailer.deliver_test(User.find(1))
519 542 assert_select_email do
520 543 assert_select ".header" do
521 544 assert_select "strong", :text => "Header content"
522 545 end
523 546 end
524 547 end
525 548 end
526 549 end
General Comments 0
You need to be logged in to leave comments. Login now