##// END OF EJS Templates
Do not use @:skip_relative_url_root@ to generate urls in Mailer (#2122)....
Jean-Philippe Lang -
r1990:077723c90a97
parent child
Show More
@@ -1,243 +1,247
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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 class Mailer < ActionMailer::Base
18 class Mailer < ActionMailer::Base
19 helper :application
19 helper :application
20 helper :issues
20 helper :issues
21 helper :custom_fields
21 helper :custom_fields
22
22
23 include ActionController::UrlWriter
23 include ActionController::UrlWriter
24
24
25 def issue_add(issue)
25 def issue_add(issue)
26 redmine_headers 'Project' => issue.project.identifier,
26 redmine_headers 'Project' => issue.project.identifier,
27 'Issue-Id' => issue.id,
27 'Issue-Id' => issue.id,
28 'Issue-Author' => issue.author.login
28 'Issue-Author' => issue.author.login
29 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
29 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
30 recipients issue.recipients
30 recipients issue.recipients
31 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
31 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
32 body :issue => issue,
32 body :issue => issue,
33 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
33 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
34 end
34 end
35
35
36 def issue_edit(journal)
36 def issue_edit(journal)
37 issue = journal.journalized
37 issue = journal.journalized
38 redmine_headers 'Project' => issue.project.identifier,
38 redmine_headers 'Project' => issue.project.identifier,
39 'Issue-Id' => issue.id,
39 'Issue-Id' => issue.id,
40 'Issue-Author' => issue.author.login
40 'Issue-Author' => issue.author.login
41 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
41 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
42 recipients issue.recipients
42 recipients issue.recipients
43 # Watchers in cc
43 # Watchers in cc
44 cc(issue.watcher_recipients - @recipients)
44 cc(issue.watcher_recipients - @recipients)
45 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
45 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
46 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
46 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
47 s << issue.subject
47 s << issue.subject
48 subject s
48 subject s
49 body :issue => issue,
49 body :issue => issue,
50 :journal => journal,
50 :journal => journal,
51 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
51 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
52 end
52 end
53
53
54 def reminder(user, issues, days)
54 def reminder(user, issues, days)
55 set_language_if_valid user.language
55 set_language_if_valid user.language
56 recipients user.mail
56 recipients user.mail
57 subject l(:mail_subject_reminder, issues.size)
57 subject l(:mail_subject_reminder, issues.size)
58 body :issues => issues,
58 body :issues => issues,
59 :days => days,
59 :days => days,
60 :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'issues.due_date', :sort_order => 'asc')
60 :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'issues.due_date', :sort_order => 'asc')
61 end
61 end
62
62
63 def document_added(document)
63 def document_added(document)
64 redmine_headers 'Project' => document.project.identifier
64 redmine_headers 'Project' => document.project.identifier
65 recipients document.project.recipients
65 recipients document.project.recipients
66 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
66 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
67 body :document => document,
67 body :document => document,
68 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
68 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
69 end
69 end
70
70
71 def attachments_added(attachments)
71 def attachments_added(attachments)
72 container = attachments.first.container
72 container = attachments.first.container
73 added_to = ''
73 added_to = ''
74 added_to_url = ''
74 added_to_url = ''
75 case container.class.name
75 case container.class.name
76 when 'Version'
76 when 'Version'
77 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
77 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
78 added_to = "#{l(:label_version)}: #{container.name}"
78 added_to = "#{l(:label_version)}: #{container.name}"
79 when 'Document'
79 when 'Document'
80 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
80 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
81 added_to = "#{l(:label_document)}: #{container.title}"
81 added_to = "#{l(:label_document)}: #{container.title}"
82 end
82 end
83 redmine_headers 'Project' => container.project.identifier
83 redmine_headers 'Project' => container.project.identifier
84 recipients container.project.recipients
84 recipients container.project.recipients
85 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
85 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
86 body :attachments => attachments,
86 body :attachments => attachments,
87 :added_to => added_to,
87 :added_to => added_to,
88 :added_to_url => added_to_url
88 :added_to_url => added_to_url
89 end
89 end
90
90
91 def news_added(news)
91 def news_added(news)
92 redmine_headers 'Project' => news.project.identifier
92 redmine_headers 'Project' => news.project.identifier
93 recipients news.project.recipients
93 recipients news.project.recipients
94 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
94 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
95 body :news => news,
95 body :news => news,
96 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
96 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
97 end
97 end
98
98
99 def message_posted(message, recipients)
99 def message_posted(message, recipients)
100 redmine_headers 'Project' => message.project.identifier,
100 redmine_headers 'Project' => message.project.identifier,
101 'Topic-Id' => (message.parent_id || message.id)
101 'Topic-Id' => (message.parent_id || message.id)
102 recipients(recipients)
102 recipients(recipients)
103 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
103 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
104 body :message => message,
104 body :message => message,
105 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
105 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
106 end
106 end
107
107
108 def account_information(user, password)
108 def account_information(user, password)
109 set_language_if_valid user.language
109 set_language_if_valid user.language
110 recipients user.mail
110 recipients user.mail
111 subject l(:mail_subject_register, Setting.app_title)
111 subject l(:mail_subject_register, Setting.app_title)
112 body :user => user,
112 body :user => user,
113 :password => password,
113 :password => password,
114 :login_url => url_for(:controller => 'account', :action => 'login')
114 :login_url => url_for(:controller => 'account', :action => 'login')
115 end
115 end
116
116
117 def account_activation_request(user)
117 def account_activation_request(user)
118 # Send the email to all active administrators
118 # Send the email to all active administrators
119 recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
119 recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
120 subject l(:mail_subject_account_activation_request, Setting.app_title)
120 subject l(:mail_subject_account_activation_request, Setting.app_title)
121 body :user => user,
121 body :user => user,
122 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
122 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
123 end
123 end
124
124
125 def lost_password(token)
125 def lost_password(token)
126 set_language_if_valid(token.user.language)
126 set_language_if_valid(token.user.language)
127 recipients token.user.mail
127 recipients token.user.mail
128 subject l(:mail_subject_lost_password, Setting.app_title)
128 subject l(:mail_subject_lost_password, Setting.app_title)
129 body :token => token,
129 body :token => token,
130 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
130 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
131 end
131 end
132
132
133 def register(token)
133 def register(token)
134 set_language_if_valid(token.user.language)
134 set_language_if_valid(token.user.language)
135 recipients token.user.mail
135 recipients token.user.mail
136 subject l(:mail_subject_register, Setting.app_title)
136 subject l(:mail_subject_register, Setting.app_title)
137 body :token => token,
137 body :token => token,
138 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
138 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
139 end
139 end
140
140
141 def test(user)
141 def test(user)
142 set_language_if_valid(user.language)
142 set_language_if_valid(user.language)
143 recipients user.mail
143 recipients user.mail
144 subject 'Redmine test'
144 subject 'Redmine test'
145 body :url => url_for(:controller => 'welcome')
145 body :url => url_for(:controller => 'welcome')
146 end
146 end
147
147
148 # Overrides default deliver! method to prevent from sending an email
148 # Overrides default deliver! method to prevent from sending an email
149 # with no recipient, cc or bcc
149 # with no recipient, cc or bcc
150 def deliver!(mail = @mail)
150 def deliver!(mail = @mail)
151 return false if (recipients.nil? || recipients.empty?) &&
151 return false if (recipients.nil? || recipients.empty?) &&
152 (cc.nil? || cc.empty?) &&
152 (cc.nil? || cc.empty?) &&
153 (bcc.nil? || bcc.empty?)
153 (bcc.nil? || bcc.empty?)
154 super
154 super
155 end
155 end
156
156
157 # Sends reminders to issue assignees
157 # Sends reminders to issue assignees
158 # Available options:
158 # Available options:
159 # * :days => how many days in the future to remind about (defaults to 7)
159 # * :days => how many days in the future to remind about (defaults to 7)
160 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
160 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
161 # * :project => id or identifier of project to process (defaults to all projects)
161 # * :project => id or identifier of project to process (defaults to all projects)
162 def self.reminders(options={})
162 def self.reminders(options={})
163 days = options[:days] || 7
163 days = options[:days] || 7
164 project = options[:project] ? Project.find(options[:project]) : nil
164 project = options[:project] ? Project.find(options[:project]) : nil
165 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
165 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
166
166
167 s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
167 s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
168 s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
168 s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
169 s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
169 s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
170 s << "#{Issue.table_name}.project_id = #{project.id}" if project
170 s << "#{Issue.table_name}.project_id = #{project.id}" if project
171 s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
171 s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
172
172
173 issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
173 issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
174 :conditions => s.conditions
174 :conditions => s.conditions
175 ).group_by(&:assigned_to)
175 ).group_by(&:assigned_to)
176 issues_by_assignee.each do |assignee, issues|
176 issues_by_assignee.each do |assignee, issues|
177 deliver_reminder(assignee, issues, days) unless assignee.nil?
177 deliver_reminder(assignee, issues, days) unless assignee.nil?
178 end
178 end
179 end
179 end
180
180
181 private
181 private
182 def initialize_defaults(method_name)
182 def initialize_defaults(method_name)
183 super
183 super
184 set_language_if_valid Setting.default_language
184 set_language_if_valid Setting.default_language
185 from Setting.mail_from
185 from Setting.mail_from
186 default_url_options[:host] = Setting.host_name
186
187 # URL options
188 h = Setting.host_name
189 h = h.to_s.gsub(%r{\/.*$}, '') unless ActionController::AbstractRequest.relative_url_root.blank?
190 default_url_options[:host] = h
187 default_url_options[:protocol] = Setting.protocol
191 default_url_options[:protocol] = Setting.protocol
188 default_url_options[:skip_relative_url_root] = true
192
189 # Common headers
193 # Common headers
190 headers 'X-Mailer' => 'Redmine',
194 headers 'X-Mailer' => 'Redmine',
191 'X-Redmine-Host' => Setting.host_name,
195 'X-Redmine-Host' => Setting.host_name,
192 'X-Redmine-Site' => Setting.app_title
196 'X-Redmine-Site' => Setting.app_title
193 end
197 end
194
198
195 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
199 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
196 def redmine_headers(h)
200 def redmine_headers(h)
197 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
201 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
198 end
202 end
199
203
200 # Overrides the create_mail method
204 # Overrides the create_mail method
201 def create_mail
205 def create_mail
202 # Removes the current user from the recipients and cc
206 # Removes the current user from the recipients and cc
203 # if he doesn't want to receive notifications about what he does
207 # if he doesn't want to receive notifications about what he does
204 if User.current.pref[:no_self_notified]
208 if User.current.pref[:no_self_notified]
205 recipients.delete(User.current.mail) if recipients
209 recipients.delete(User.current.mail) if recipients
206 cc.delete(User.current.mail) if cc
210 cc.delete(User.current.mail) if cc
207 end
211 end
208 # Blind carbon copy recipients
212 # Blind carbon copy recipients
209 if Setting.bcc_recipients?
213 if Setting.bcc_recipients?
210 bcc([recipients, cc].flatten.compact.uniq)
214 bcc([recipients, cc].flatten.compact.uniq)
211 recipients []
215 recipients []
212 cc []
216 cc []
213 end
217 end
214 super
218 super
215 end
219 end
216
220
217 # Renders a message with the corresponding layout
221 # Renders a message with the corresponding layout
218 def render_message(method_name, body)
222 def render_message(method_name, body)
219 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
223 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
220 body[:content_for_layout] = render(:file => method_name, :body => body)
224 body[:content_for_layout] = render(:file => method_name, :body => body)
221 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
225 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
222 end
226 end
223
227
224 # for the case of plain text only
228 # for the case of plain text only
225 def body(*params)
229 def body(*params)
226 value = super(*params)
230 value = super(*params)
227 if Setting.plain_text_mail?
231 if Setting.plain_text_mail?
228 templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}")
232 templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}")
229 unless String === @body or templates.empty?
233 unless String === @body or templates.empty?
230 template = File.basename(templates.first)
234 template = File.basename(templates.first)
231 @body[:content_for_layout] = render(:file => template, :body => @body)
235 @body[:content_for_layout] = render(:file => template, :body => @body)
232 @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true)
236 @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true)
233 return @body
237 return @body
234 end
238 end
235 end
239 end
236 return value
240 return value
237 end
241 end
238
242
239 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
243 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
240 def self.controller_path
244 def self.controller_path
241 ''
245 ''
242 end unless respond_to?('controller_path')
246 end unless respond_to?('controller_path')
243 end
247 end
@@ -1,138 +1,186
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class MailerTest < Test::Unit::TestCase
20 class MailerTest < Test::Unit::TestCase
21 fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories
21 fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories
22
22
23 def test_generated_links_in_emails
23 def test_generated_links_in_emails
24 ActionMailer::Base.deliveries.clear
24 ActionMailer::Base.deliveries.clear
25 Setting.host_name = 'mydomain.foo'
25 Setting.host_name = 'mydomain.foo'
26 Setting.protocol = 'https'
26 Setting.protocol = 'https'
27
27
28 journal = Journal.find(2)
28 journal = Journal.find(2)
29 assert Mailer.deliver_issue_edit(journal)
29 assert Mailer.deliver_issue_edit(journal)
30
30
31 mail = ActionMailer::Base.deliveries.last
31 mail = ActionMailer::Base.deliveries.last
32 assert_kind_of TMail::Mail, mail
32 assert_kind_of TMail::Mail, mail
33 # link to the main ticket
33 # link to the main ticket
34 assert mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>')
34 assert mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>')
35
35
36 # link to a referenced ticket
36 # link to a referenced ticket
37 assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
37 assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
38 # link to a changeset
38 # link to a changeset
39 assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
39 assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
40 end
40 end
41
41
42 def test_generated_links_with_prefix
43 relative_url_root = ActionController::AbstractRequest.relative_url_root
44 ActionMailer::Base.deliveries.clear
45 Setting.host_name = 'mydomain.foo/rdm'
46 Setting.protocol = 'http'
47 ActionController::AbstractRequest.relative_url_root = '/rdm'
48
49 journal = Journal.find(2)
50 assert Mailer.deliver_issue_edit(journal)
51
52 mail = ActionMailer::Base.deliveries.last
53 assert_kind_of TMail::Mail, mail
54 # link to the main ticket
55 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>')
56
57 # link to a referenced ticket
58 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
59 # link to a changeset
60 assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
61 ensure
62 # restore it
63 ActionController::AbstractRequest.relative_url_root = relative_url_root
64 end
65
66 def test_generated_links_with_prefix_and_no_relative_url_root
67 relative_url_root = ActionController::AbstractRequest.relative_url_root
68 ActionMailer::Base.deliveries.clear
69 Setting.host_name = 'mydomain.foo/rdm'
70 Setting.protocol = 'http'
71 ActionController::AbstractRequest.relative_url_root = nil
72
73 journal = Journal.find(2)
74 assert Mailer.deliver_issue_edit(journal)
75
76 mail = ActionMailer::Base.deliveries.last
77 assert_kind_of TMail::Mail, mail
78 # link to the main ticket
79 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>')
80
81 # link to a referenced ticket
82 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
83 # link to a changeset
84 assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
85 ensure
86 # restore it
87 ActionController::AbstractRequest.relative_url_root = relative_url_root
88 end
89
42 def test_plain_text_mail
90 def test_plain_text_mail
43 Setting.plain_text_mail = 1
91 Setting.plain_text_mail = 1
44 journal = Journal.find(2)
92 journal = Journal.find(2)
45 Mailer.deliver_issue_edit(journal)
93 Mailer.deliver_issue_edit(journal)
46 mail = ActionMailer::Base.deliveries.last
94 mail = ActionMailer::Base.deliveries.last
47 assert !mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>')
95 assert !mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>')
48 end
96 end
49
97
50
98
51
99
52 # test mailer methods for each language
100 # test mailer methods for each language
53 def test_issue_add
101 def test_issue_add
54 issue = Issue.find(1)
102 issue = Issue.find(1)
55 GLoc.valid_languages.each do |lang|
103 GLoc.valid_languages.each do |lang|
56 Setting.default_language = lang.to_s
104 Setting.default_language = lang.to_s
57 assert Mailer.deliver_issue_add(issue)
105 assert Mailer.deliver_issue_add(issue)
58 end
106 end
59 end
107 end
60
108
61 def test_issue_edit
109 def test_issue_edit
62 journal = Journal.find(1)
110 journal = Journal.find(1)
63 GLoc.valid_languages.each do |lang|
111 GLoc.valid_languages.each do |lang|
64 Setting.default_language = lang.to_s
112 Setting.default_language = lang.to_s
65 assert Mailer.deliver_issue_edit(journal)
113 assert Mailer.deliver_issue_edit(journal)
66 end
114 end
67 end
115 end
68
116
69 def test_document_added
117 def test_document_added
70 document = Document.find(1)
118 document = Document.find(1)
71 GLoc.valid_languages.each do |lang|
119 GLoc.valid_languages.each do |lang|
72 Setting.default_language = lang.to_s
120 Setting.default_language = lang.to_s
73 assert Mailer.deliver_document_added(document)
121 assert Mailer.deliver_document_added(document)
74 end
122 end
75 end
123 end
76
124
77 def test_attachments_added
125 def test_attachments_added
78 attachements = [ Attachment.find_by_container_type('Document') ]
126 attachements = [ Attachment.find_by_container_type('Document') ]
79 GLoc.valid_languages.each do |lang|
127 GLoc.valid_languages.each do |lang|
80 Setting.default_language = lang.to_s
128 Setting.default_language = lang.to_s
81 assert Mailer.deliver_attachments_added(attachements)
129 assert Mailer.deliver_attachments_added(attachements)
82 end
130 end
83 end
131 end
84
132
85 def test_news_added
133 def test_news_added
86 news = News.find(:first)
134 news = News.find(:first)
87 GLoc.valid_languages.each do |lang|
135 GLoc.valid_languages.each do |lang|
88 Setting.default_language = lang.to_s
136 Setting.default_language = lang.to_s
89 assert Mailer.deliver_news_added(news)
137 assert Mailer.deliver_news_added(news)
90 end
138 end
91 end
139 end
92
140
93 def test_message_posted
141 def test_message_posted
94 message = Message.find(:first)
142 message = Message.find(:first)
95 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
143 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
96 recipients = recipients.compact.uniq
144 recipients = recipients.compact.uniq
97 GLoc.valid_languages.each do |lang|
145 GLoc.valid_languages.each do |lang|
98 Setting.default_language = lang.to_s
146 Setting.default_language = lang.to_s
99 assert Mailer.deliver_message_posted(message, recipients)
147 assert Mailer.deliver_message_posted(message, recipients)
100 end
148 end
101 end
149 end
102
150
103 def test_account_information
151 def test_account_information
104 user = User.find(:first)
152 user = User.find(:first)
105 GLoc.valid_languages.each do |lang|
153 GLoc.valid_languages.each do |lang|
106 user.update_attribute :language, lang.to_s
154 user.update_attribute :language, lang.to_s
107 user.reload
155 user.reload
108 assert Mailer.deliver_account_information(user, 'pAsswORd')
156 assert Mailer.deliver_account_information(user, 'pAsswORd')
109 end
157 end
110 end
158 end
111
159
112 def test_lost_password
160 def test_lost_password
113 token = Token.find(2)
161 token = Token.find(2)
114 GLoc.valid_languages.each do |lang|
162 GLoc.valid_languages.each do |lang|
115 token.user.update_attribute :language, lang.to_s
163 token.user.update_attribute :language, lang.to_s
116 token.reload
164 token.reload
117 assert Mailer.deliver_lost_password(token)
165 assert Mailer.deliver_lost_password(token)
118 end
166 end
119 end
167 end
120
168
121 def test_register
169 def test_register
122 token = Token.find(1)
170 token = Token.find(1)
123 GLoc.valid_languages.each do |lang|
171 GLoc.valid_languages.each do |lang|
124 token.user.update_attribute :language, lang.to_s
172 token.user.update_attribute :language, lang.to_s
125 token.reload
173 token.reload
126 assert Mailer.deliver_register(token)
174 assert Mailer.deliver_register(token)
127 end
175 end
128 end
176 end
129
177
130 def test_reminders
178 def test_reminders
131 ActionMailer::Base.deliveries.clear
179 ActionMailer::Base.deliveries.clear
132 Mailer.reminders(:days => 42)
180 Mailer.reminders(:days => 42)
133 assert_equal 1, ActionMailer::Base.deliveries.size
181 assert_equal 1, ActionMailer::Base.deliveries.size
134 mail = ActionMailer::Base.deliveries.last
182 mail = ActionMailer::Base.deliveries.last
135 assert mail.bcc.include?('dlopper@somenet.foo')
183 assert mail.bcc.include?('dlopper@somenet.foo')
136 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
184 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
137 end
185 end
138 end
186 end
General Comments 0
You need to be logged in to leave comments. Login now