@@ -1,529 +1,538 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 | layout 'mailer' |
|
19 | layout 'mailer' | |
20 | helper :application |
|
20 | helper :application | |
21 | helper :issues |
|
21 | helper :issues | |
22 | helper :custom_fields |
|
22 | helper :custom_fields | |
23 |
|
23 | |||
24 | include Redmine::I18n |
|
24 | include Redmine::I18n | |
25 |
|
25 | |||
26 | def self.default_url_options |
|
26 | def self.default_url_options | |
27 |
|
|
27 | options = {:protocol => Setting.protocol} | |
|
28 | if Setting.host_name.to_s =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i | |||
|
29 | host, port, prefix = $2, $4, $5 | |||
|
30 | options.merge!({ | |||
|
31 | :host => host, :port => port, :script_name => prefix | |||
|
32 | }) | |||
|
33 | else | |||
|
34 | options[:host] = Setting.host_name | |||
|
35 | end | |||
|
36 | options | |||
28 | end |
|
37 | end | |
29 |
|
38 | |||
30 | # Builds a mail for notifying to_users and cc_users about a new issue |
|
39 | # Builds a mail for notifying to_users and cc_users about a new issue | |
31 | def issue_add(issue, to_users, cc_users) |
|
40 | def issue_add(issue, to_users, cc_users) | |
32 | redmine_headers 'Project' => issue.project.identifier, |
|
41 | redmine_headers 'Project' => issue.project.identifier, | |
33 | 'Issue-Id' => issue.id, |
|
42 | 'Issue-Id' => issue.id, | |
34 | 'Issue-Author' => issue.author.login |
|
43 | 'Issue-Author' => issue.author.login | |
35 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
44 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to | |
36 | message_id issue |
|
45 | message_id issue | |
37 | references issue |
|
46 | references issue | |
38 | @author = issue.author |
|
47 | @author = issue.author | |
39 | @issue = issue |
|
48 | @issue = issue | |
40 | @users = to_users + cc_users |
|
49 | @users = to_users + cc_users | |
41 | @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
50 | @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) | |
42 | mail :to => to_users, |
|
51 | mail :to => to_users, | |
43 | :cc => cc_users, |
|
52 | :cc => cc_users, | |
44 | :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" |
|
53 | :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" | |
45 | end |
|
54 | end | |
46 |
|
55 | |||
47 | # Notifies users about a new issue |
|
56 | # Notifies users about a new issue | |
48 | def self.deliver_issue_add(issue) |
|
57 | def self.deliver_issue_add(issue) | |
49 | to = issue.notified_users |
|
58 | to = issue.notified_users | |
50 | cc = issue.notified_watchers - to |
|
59 | cc = issue.notified_watchers - to | |
51 | issue.each_notification(to + cc) do |users| |
|
60 | issue.each_notification(to + cc) do |users| | |
52 | Mailer.issue_add(issue, to & users, cc & users).deliver |
|
61 | Mailer.issue_add(issue, to & users, cc & users).deliver | |
53 | end |
|
62 | end | |
54 | end |
|
63 | end | |
55 |
|
64 | |||
56 | # Builds a mail for notifying to_users and cc_users about an issue update |
|
65 | # Builds a mail for notifying to_users and cc_users about an issue update | |
57 | def issue_edit(journal, to_users, cc_users) |
|
66 | def issue_edit(journal, to_users, cc_users) | |
58 | issue = journal.journalized |
|
67 | issue = journal.journalized | |
59 | redmine_headers 'Project' => issue.project.identifier, |
|
68 | redmine_headers 'Project' => issue.project.identifier, | |
60 | 'Issue-Id' => issue.id, |
|
69 | 'Issue-Id' => issue.id, | |
61 | 'Issue-Author' => issue.author.login |
|
70 | 'Issue-Author' => issue.author.login | |
62 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
71 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to | |
63 | message_id journal |
|
72 | message_id journal | |
64 | references issue |
|
73 | references issue | |
65 | @author = journal.user |
|
74 | @author = journal.user | |
66 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " |
|
75 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " | |
67 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') |
|
76 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') | |
68 | s << issue.subject |
|
77 | s << issue.subject | |
69 | @issue = issue |
|
78 | @issue = issue | |
70 | @users = to_users + cc_users |
|
79 | @users = to_users + cc_users | |
71 | @journal = journal |
|
80 | @journal = journal | |
72 | @journal_details = journal.visible_details(@users.first) |
|
81 | @journal_details = journal.visible_details(@users.first) | |
73 | @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") |
|
82 | @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") | |
74 | mail :to => to_users, |
|
83 | mail :to => to_users, | |
75 | :cc => cc_users, |
|
84 | :cc => cc_users, | |
76 | :subject => s |
|
85 | :subject => s | |
77 | end |
|
86 | end | |
78 |
|
87 | |||
79 | # Notifies users about an issue update |
|
88 | # Notifies users about an issue update | |
80 | def self.deliver_issue_edit(journal) |
|
89 | def self.deliver_issue_edit(journal) | |
81 | issue = journal.journalized.reload |
|
90 | issue = journal.journalized.reload | |
82 | to = journal.notified_users |
|
91 | to = journal.notified_users | |
83 | cc = journal.notified_watchers - to |
|
92 | cc = journal.notified_watchers - to | |
84 | journal.each_notification(to + cc) do |users| |
|
93 | journal.each_notification(to + cc) do |users| | |
85 | issue.each_notification(users) do |users2| |
|
94 | issue.each_notification(users) do |users2| | |
86 | Mailer.issue_edit(journal, to & users2, cc & users2).deliver |
|
95 | Mailer.issue_edit(journal, to & users2, cc & users2).deliver | |
87 | end |
|
96 | end | |
88 | end |
|
97 | end | |
89 | end |
|
98 | end | |
90 |
|
99 | |||
91 | def reminder(user, issues, days) |
|
100 | def reminder(user, issues, days) | |
92 | set_language_if_valid user.language |
|
101 | set_language_if_valid user.language | |
93 | @issues = issues |
|
102 | @issues = issues | |
94 | @days = days |
|
103 | @days = days | |
95 | @issues_url = url_for(:controller => 'issues', :action => 'index', |
|
104 | @issues_url = url_for(:controller => 'issues', :action => 'index', | |
96 | :set_filter => 1, :assigned_to_id => user.id, |
|
105 | :set_filter => 1, :assigned_to_id => user.id, | |
97 | :sort => 'due_date:asc') |
|
106 | :sort => 'due_date:asc') | |
98 | mail :to => user, |
|
107 | mail :to => user, | |
99 | :subject => l(:mail_subject_reminder, :count => issues.size, :days => days) |
|
108 | :subject => l(:mail_subject_reminder, :count => issues.size, :days => days) | |
100 | end |
|
109 | end | |
101 |
|
110 | |||
102 | # Builds a Mail::Message object used to email users belonging to the added document's project. |
|
111 | # Builds a Mail::Message object used to email users belonging to the added document's project. | |
103 | # |
|
112 | # | |
104 | # Example: |
|
113 | # Example: | |
105 | # document_added(document) => Mail::Message object |
|
114 | # document_added(document) => Mail::Message object | |
106 | # Mailer.document_added(document).deliver => sends an email to the document's project recipients |
|
115 | # Mailer.document_added(document).deliver => sends an email to the document's project recipients | |
107 | def document_added(document) |
|
116 | def document_added(document) | |
108 | redmine_headers 'Project' => document.project.identifier |
|
117 | redmine_headers 'Project' => document.project.identifier | |
109 | @author = User.current |
|
118 | @author = User.current | |
110 | @document = document |
|
119 | @document = document | |
111 | @document_url = url_for(:controller => 'documents', :action => 'show', :id => document) |
|
120 | @document_url = url_for(:controller => 'documents', :action => 'show', :id => document) | |
112 | mail :to => document.notified_users, |
|
121 | mail :to => document.notified_users, | |
113 | :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
122 | :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" | |
114 | end |
|
123 | end | |
115 |
|
124 | |||
116 | # Builds a Mail::Message object used to email recipients of a project when an attachements are added. |
|
125 | # Builds a Mail::Message object used to email recipients of a project when an attachements are added. | |
117 | # |
|
126 | # | |
118 | # Example: |
|
127 | # Example: | |
119 | # attachments_added(attachments) => Mail::Message object |
|
128 | # attachments_added(attachments) => Mail::Message object | |
120 | # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients |
|
129 | # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients | |
121 | def attachments_added(attachments) |
|
130 | def attachments_added(attachments) | |
122 | container = attachments.first.container |
|
131 | container = attachments.first.container | |
123 | added_to = '' |
|
132 | added_to = '' | |
124 | added_to_url = '' |
|
133 | added_to_url = '' | |
125 | @author = attachments.first.author |
|
134 | @author = attachments.first.author | |
126 | case container.class.name |
|
135 | case container.class.name | |
127 | when 'Project' |
|
136 | when 'Project' | |
128 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container) |
|
137 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container) | |
129 | added_to = "#{l(:label_project)}: #{container}" |
|
138 | added_to = "#{l(:label_project)}: #{container}" | |
130 | recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} |
|
139 | recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} | |
131 | when 'Version' |
|
140 | when 'Version' | |
132 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project) |
|
141 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project) | |
133 | added_to = "#{l(:label_version)}: #{container.name}" |
|
142 | added_to = "#{l(:label_version)}: #{container.name}" | |
134 | recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} |
|
143 | recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} | |
135 | when 'Document' |
|
144 | when 'Document' | |
136 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
145 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) | |
137 | added_to = "#{l(:label_document)}: #{container.title}" |
|
146 | added_to = "#{l(:label_document)}: #{container.title}" | |
138 | recipients = container.notified_users |
|
147 | recipients = container.notified_users | |
139 | end |
|
148 | end | |
140 | redmine_headers 'Project' => container.project.identifier |
|
149 | redmine_headers 'Project' => container.project.identifier | |
141 | @attachments = attachments |
|
150 | @attachments = attachments | |
142 | @added_to = added_to |
|
151 | @added_to = added_to | |
143 | @added_to_url = added_to_url |
|
152 | @added_to_url = added_to_url | |
144 | mail :to => recipients, |
|
153 | mail :to => recipients, | |
145 | :subject => "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
154 | :subject => "[#{container.project.name}] #{l(:label_attachment_new)}" | |
146 | end |
|
155 | end | |
147 |
|
156 | |||
148 | # Builds a Mail::Message object used to email recipients of a news' project when a news item is added. |
|
157 | # Builds a Mail::Message object used to email recipients of a news' project when a news item is added. | |
149 | # |
|
158 | # | |
150 | # Example: |
|
159 | # Example: | |
151 | # news_added(news) => Mail::Message object |
|
160 | # news_added(news) => Mail::Message object | |
152 | # Mailer.news_added(news).deliver => sends an email to the news' project recipients |
|
161 | # Mailer.news_added(news).deliver => sends an email to the news' project recipients | |
153 | def news_added(news) |
|
162 | def news_added(news) | |
154 | redmine_headers 'Project' => news.project.identifier |
|
163 | redmine_headers 'Project' => news.project.identifier | |
155 | @author = news.author |
|
164 | @author = news.author | |
156 | message_id news |
|
165 | message_id news | |
157 | references news |
|
166 | references news | |
158 | @news = news |
|
167 | @news = news | |
159 | @news_url = url_for(:controller => 'news', :action => 'show', :id => news) |
|
168 | @news_url = url_for(:controller => 'news', :action => 'show', :id => news) | |
160 | mail :to => news.notified_users, |
|
169 | mail :to => news.notified_users, | |
161 | :cc => news.notified_watchers_for_added_news, |
|
170 | :cc => news.notified_watchers_for_added_news, | |
162 | :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
171 | :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}" | |
163 | end |
|
172 | end | |
164 |
|
173 | |||
165 | # Builds a Mail::Message object used to email recipients of a news' project when a news comment is added. |
|
174 | # Builds a Mail::Message object used to email recipients of a news' project when a news comment is added. | |
166 | # |
|
175 | # | |
167 | # Example: |
|
176 | # Example: | |
168 | # news_comment_added(comment) => Mail::Message object |
|
177 | # news_comment_added(comment) => Mail::Message object | |
169 | # Mailer.news_comment_added(comment) => sends an email to the news' project recipients |
|
178 | # Mailer.news_comment_added(comment) => sends an email to the news' project recipients | |
170 | def news_comment_added(comment) |
|
179 | def news_comment_added(comment) | |
171 | news = comment.commented |
|
180 | news = comment.commented | |
172 | redmine_headers 'Project' => news.project.identifier |
|
181 | redmine_headers 'Project' => news.project.identifier | |
173 | @author = comment.author |
|
182 | @author = comment.author | |
174 | message_id comment |
|
183 | message_id comment | |
175 | references news |
|
184 | references news | |
176 | @news = news |
|
185 | @news = news | |
177 | @comment = comment |
|
186 | @comment = comment | |
178 | @news_url = url_for(:controller => 'news', :action => 'show', :id => news) |
|
187 | @news_url = url_for(:controller => 'news', :action => 'show', :id => news) | |
179 | mail :to => news.notified_users, |
|
188 | mail :to => news.notified_users, | |
180 | :cc => news.notified_watchers, |
|
189 | :cc => news.notified_watchers, | |
181 | :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
190 | :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" | |
182 | end |
|
191 | end | |
183 |
|
192 | |||
184 | # Builds a Mail::Message object used to email the recipients of the specified message that was posted. |
|
193 | # Builds a Mail::Message object used to email the recipients of the specified message that was posted. | |
185 | # |
|
194 | # | |
186 | # Example: |
|
195 | # Example: | |
187 | # message_posted(message) => Mail::Message object |
|
196 | # message_posted(message) => Mail::Message object | |
188 | # Mailer.message_posted(message).deliver => sends an email to the recipients |
|
197 | # Mailer.message_posted(message).deliver => sends an email to the recipients | |
189 | def message_posted(message) |
|
198 | def message_posted(message) | |
190 | redmine_headers 'Project' => message.project.identifier, |
|
199 | redmine_headers 'Project' => message.project.identifier, | |
191 | 'Topic-Id' => (message.parent_id || message.id) |
|
200 | 'Topic-Id' => (message.parent_id || message.id) | |
192 | @author = message.author |
|
201 | @author = message.author | |
193 | message_id message |
|
202 | message_id message | |
194 | references message.root |
|
203 | references message.root | |
195 | recipients = message.notified_users |
|
204 | recipients = message.notified_users | |
196 | cc = ((message.root.notified_watchers + message.board.notified_watchers).uniq - recipients) |
|
205 | cc = ((message.root.notified_watchers + message.board.notified_watchers).uniq - recipients) | |
197 | @message = message |
|
206 | @message = message | |
198 | @message_url = url_for(message.event_url) |
|
207 | @message_url = url_for(message.event_url) | |
199 | mail :to => recipients, |
|
208 | mail :to => recipients, | |
200 | :cc => cc, |
|
209 | :cc => cc, | |
201 | :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" |
|
210 | :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" | |
202 | end |
|
211 | end | |
203 |
|
212 | |||
204 | # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added. |
|
213 | # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added. | |
205 | # |
|
214 | # | |
206 | # Example: |
|
215 | # Example: | |
207 | # wiki_content_added(wiki_content) => Mail::Message object |
|
216 | # wiki_content_added(wiki_content) => Mail::Message object | |
208 | # Mailer.wiki_content_added(wiki_content).deliver => sends an email to the project's recipients |
|
217 | # Mailer.wiki_content_added(wiki_content).deliver => sends an email to the project's recipients | |
209 | def wiki_content_added(wiki_content) |
|
218 | def wiki_content_added(wiki_content) | |
210 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
219 | redmine_headers 'Project' => wiki_content.project.identifier, | |
211 | 'Wiki-Page-Id' => wiki_content.page.id |
|
220 | 'Wiki-Page-Id' => wiki_content.page.id | |
212 | @author = wiki_content.author |
|
221 | @author = wiki_content.author | |
213 | message_id wiki_content |
|
222 | message_id wiki_content | |
214 | recipients = wiki_content.notified_users |
|
223 | recipients = wiki_content.notified_users | |
215 | cc = wiki_content.page.wiki.notified_watchers - recipients |
|
224 | cc = wiki_content.page.wiki.notified_watchers - recipients | |
216 | @wiki_content = wiki_content |
|
225 | @wiki_content = wiki_content | |
217 | @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', |
|
226 | @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', | |
218 | :project_id => wiki_content.project, |
|
227 | :project_id => wiki_content.project, | |
219 | :id => wiki_content.page.title) |
|
228 | :id => wiki_content.page.title) | |
220 | mail :to => recipients, |
|
229 | mail :to => recipients, | |
221 | :cc => cc, |
|
230 | :cc => cc, | |
222 | :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}" |
|
231 | :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}" | |
223 | end |
|
232 | end | |
224 |
|
233 | |||
225 | # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated. |
|
234 | # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated. | |
226 | # |
|
235 | # | |
227 | # Example: |
|
236 | # Example: | |
228 | # wiki_content_updated(wiki_content) => Mail::Message object |
|
237 | # wiki_content_updated(wiki_content) => Mail::Message object | |
229 | # Mailer.wiki_content_updated(wiki_content).deliver => sends an email to the project's recipients |
|
238 | # Mailer.wiki_content_updated(wiki_content).deliver => sends an email to the project's recipients | |
230 | def wiki_content_updated(wiki_content) |
|
239 | def wiki_content_updated(wiki_content) | |
231 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
240 | redmine_headers 'Project' => wiki_content.project.identifier, | |
232 | 'Wiki-Page-Id' => wiki_content.page.id |
|
241 | 'Wiki-Page-Id' => wiki_content.page.id | |
233 | @author = wiki_content.author |
|
242 | @author = wiki_content.author | |
234 | message_id wiki_content |
|
243 | message_id wiki_content | |
235 | recipients = wiki_content.notified_users |
|
244 | recipients = wiki_content.notified_users | |
236 | cc = wiki_content.page.wiki.notified_watchers + wiki_content.page.notified_watchers - recipients |
|
245 | cc = wiki_content.page.wiki.notified_watchers + wiki_content.page.notified_watchers - recipients | |
237 | @wiki_content = wiki_content |
|
246 | @wiki_content = wiki_content | |
238 | @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', |
|
247 | @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', | |
239 | :project_id => wiki_content.project, |
|
248 | :project_id => wiki_content.project, | |
240 | :id => wiki_content.page.title) |
|
249 | :id => wiki_content.page.title) | |
241 | @wiki_diff_url = url_for(:controller => 'wiki', :action => 'diff', |
|
250 | @wiki_diff_url = url_for(:controller => 'wiki', :action => 'diff', | |
242 | :project_id => wiki_content.project, :id => wiki_content.page.title, |
|
251 | :project_id => wiki_content.project, :id => wiki_content.page.title, | |
243 | :version => wiki_content.version) |
|
252 | :version => wiki_content.version) | |
244 | mail :to => recipients, |
|
253 | mail :to => recipients, | |
245 | :cc => cc, |
|
254 | :cc => cc, | |
246 | :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}" |
|
255 | :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}" | |
247 | end |
|
256 | end | |
248 |
|
257 | |||
249 | # Builds a Mail::Message object used to email the specified user their account information. |
|
258 | # Builds a Mail::Message object used to email the specified user their account information. | |
250 | # |
|
259 | # | |
251 | # Example: |
|
260 | # Example: | |
252 | # account_information(user, password) => Mail::Message object |
|
261 | # account_information(user, password) => Mail::Message object | |
253 | # Mailer.account_information(user, password).deliver => sends account information to the user |
|
262 | # Mailer.account_information(user, password).deliver => sends account information to the user | |
254 | def account_information(user, password) |
|
263 | def account_information(user, password) | |
255 | set_language_if_valid user.language |
|
264 | set_language_if_valid user.language | |
256 | @user = user |
|
265 | @user = user | |
257 | @password = password |
|
266 | @password = password | |
258 | @login_url = url_for(:controller => 'account', :action => 'login') |
|
267 | @login_url = url_for(:controller => 'account', :action => 'login') | |
259 | mail :to => user.mail, |
|
268 | mail :to => user.mail, | |
260 | :subject => l(:mail_subject_register, Setting.app_title) |
|
269 | :subject => l(:mail_subject_register, Setting.app_title) | |
261 | end |
|
270 | end | |
262 |
|
271 | |||
263 | # Builds a Mail::Message object used to email all active administrators of an account activation request. |
|
272 | # Builds a Mail::Message object used to email all active administrators of an account activation request. | |
264 | # |
|
273 | # | |
265 | # Example: |
|
274 | # Example: | |
266 | # account_activation_request(user) => Mail::Message object |
|
275 | # account_activation_request(user) => Mail::Message object | |
267 | # Mailer.account_activation_request(user).deliver => sends an email to all active administrators |
|
276 | # Mailer.account_activation_request(user).deliver => sends an email to all active administrators | |
268 | def account_activation_request(user) |
|
277 | def account_activation_request(user) | |
269 | # Send the email to all active administrators |
|
278 | # Send the email to all active administrators | |
270 | recipients = User.active.where(:admin => true) |
|
279 | recipients = User.active.where(:admin => true) | |
271 | @user = user |
|
280 | @user = user | |
272 | @url = url_for(:controller => 'users', :action => 'index', |
|
281 | @url = url_for(:controller => 'users', :action => 'index', | |
273 | :status => User::STATUS_REGISTERED, |
|
282 | :status => User::STATUS_REGISTERED, | |
274 | :sort_key => 'created_on', :sort_order => 'desc') |
|
283 | :sort_key => 'created_on', :sort_order => 'desc') | |
275 | mail :to => recipients, |
|
284 | mail :to => recipients, | |
276 | :subject => l(:mail_subject_account_activation_request, Setting.app_title) |
|
285 | :subject => l(:mail_subject_account_activation_request, Setting.app_title) | |
277 | end |
|
286 | end | |
278 |
|
287 | |||
279 | # Builds a Mail::Message object used to email the specified user that their account was activated by an administrator. |
|
288 | # Builds a Mail::Message object used to email the specified user that their account was activated by an administrator. | |
280 | # |
|
289 | # | |
281 | # Example: |
|
290 | # Example: | |
282 | # account_activated(user) => Mail::Message object |
|
291 | # account_activated(user) => Mail::Message object | |
283 | # Mailer.account_activated(user).deliver => sends an email to the registered user |
|
292 | # Mailer.account_activated(user).deliver => sends an email to the registered user | |
284 | def account_activated(user) |
|
293 | def account_activated(user) | |
285 | set_language_if_valid user.language |
|
294 | set_language_if_valid user.language | |
286 | @user = user |
|
295 | @user = user | |
287 | @login_url = url_for(:controller => 'account', :action => 'login') |
|
296 | @login_url = url_for(:controller => 'account', :action => 'login') | |
288 | mail :to => user.mail, |
|
297 | mail :to => user.mail, | |
289 | :subject => l(:mail_subject_register, Setting.app_title) |
|
298 | :subject => l(:mail_subject_register, Setting.app_title) | |
290 | end |
|
299 | end | |
291 |
|
300 | |||
292 | def lost_password(token, recipient=nil) |
|
301 | def lost_password(token, recipient=nil) | |
293 | set_language_if_valid(token.user.language) |
|
302 | set_language_if_valid(token.user.language) | |
294 | recipient ||= token.user.mail |
|
303 | recipient ||= token.user.mail | |
295 | @token = token |
|
304 | @token = token | |
296 | @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value) |
|
305 | @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value) | |
297 | mail :to => recipient, |
|
306 | mail :to => recipient, | |
298 | :subject => l(:mail_subject_lost_password, Setting.app_title) |
|
307 | :subject => l(:mail_subject_lost_password, Setting.app_title) | |
299 | end |
|
308 | end | |
300 |
|
309 | |||
301 | def register(token) |
|
310 | def register(token) | |
302 | set_language_if_valid(token.user.language) |
|
311 | set_language_if_valid(token.user.language) | |
303 | @token = token |
|
312 | @token = token | |
304 | @url = url_for(:controller => 'account', :action => 'activate', :token => token.value) |
|
313 | @url = url_for(:controller => 'account', :action => 'activate', :token => token.value) | |
305 | mail :to => token.user.mail, |
|
314 | mail :to => token.user.mail, | |
306 | :subject => l(:mail_subject_register, Setting.app_title) |
|
315 | :subject => l(:mail_subject_register, Setting.app_title) | |
307 | end |
|
316 | end | |
308 |
|
317 | |||
309 | def test_email(user) |
|
318 | def test_email(user) | |
310 | set_language_if_valid(user.language) |
|
319 | set_language_if_valid(user.language) | |
311 | @url = url_for(:controller => 'welcome') |
|
320 | @url = url_for(:controller => 'welcome') | |
312 | mail :to => user.mail, |
|
321 | mail :to => user.mail, | |
313 | :subject => 'Redmine test' |
|
322 | :subject => 'Redmine test' | |
314 | end |
|
323 | end | |
315 |
|
324 | |||
316 | # Sends reminders to issue assignees |
|
325 | # Sends reminders to issue assignees | |
317 | # Available options: |
|
326 | # Available options: | |
318 | # * :days => how many days in the future to remind about (defaults to 7) |
|
327 | # * :days => how many days in the future to remind about (defaults to 7) | |
319 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
328 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) | |
320 | # * :project => id or identifier of project to process (defaults to all projects) |
|
329 | # * :project => id or identifier of project to process (defaults to all projects) | |
321 | # * :users => array of user/group ids who should be reminded |
|
330 | # * :users => array of user/group ids who should be reminded | |
322 | # * :version => name of target version for filtering issues (defaults to none) |
|
331 | # * :version => name of target version for filtering issues (defaults to none) | |
323 | def self.reminders(options={}) |
|
332 | def self.reminders(options={}) | |
324 | days = options[:days] || 7 |
|
333 | days = options[:days] || 7 | |
325 | project = options[:project] ? Project.find(options[:project]) : nil |
|
334 | project = options[:project] ? Project.find(options[:project]) : nil | |
326 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
335 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil | |
327 | target_version_id = options[:version] ? Version.named(options[:version]).pluck(:id) : nil |
|
336 | target_version_id = options[:version] ? Version.named(options[:version]).pluck(:id) : nil | |
328 | if options[:version] && target_version_id.blank? |
|
337 | if options[:version] && target_version_id.blank? | |
329 | raise ActiveRecord::RecordNotFound.new("Couldn't find Version with named #{options[:version]}") |
|
338 | raise ActiveRecord::RecordNotFound.new("Couldn't find Version with named #{options[:version]}") | |
330 | end |
|
339 | end | |
331 | user_ids = options[:users] |
|
340 | user_ids = options[:users] | |
332 |
|
341 | |||
333 | scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + |
|
342 | scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + | |
334 | " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" + |
|
343 | " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" + | |
335 | " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date |
|
344 | " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date | |
336 | ) |
|
345 | ) | |
337 | scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? |
|
346 | scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? | |
338 | scope = scope.where(:project_id => project.id) if project |
|
347 | scope = scope.where(:project_id => project.id) if project | |
339 | scope = scope.where(:fixed_version_id => target_version_id) if target_version_id.present? |
|
348 | scope = scope.where(:fixed_version_id => target_version_id) if target_version_id.present? | |
340 | scope = scope.where(:tracker_id => tracker.id) if tracker |
|
349 | scope = scope.where(:tracker_id => tracker.id) if tracker | |
341 | issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker). |
|
350 | issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker). | |
342 | group_by(&:assigned_to) |
|
351 | group_by(&:assigned_to) | |
343 | issues_by_assignee.keys.each do |assignee| |
|
352 | issues_by_assignee.keys.each do |assignee| | |
344 | if assignee.is_a?(Group) |
|
353 | if assignee.is_a?(Group) | |
345 | assignee.users.each do |user| |
|
354 | assignee.users.each do |user| | |
346 | issues_by_assignee[user] ||= [] |
|
355 | issues_by_assignee[user] ||= [] | |
347 | issues_by_assignee[user] += issues_by_assignee[assignee] |
|
356 | issues_by_assignee[user] += issues_by_assignee[assignee] | |
348 | end |
|
357 | end | |
349 | end |
|
358 | end | |
350 | end |
|
359 | end | |
351 |
|
360 | |||
352 | issues_by_assignee.each do |assignee, issues| |
|
361 | issues_by_assignee.each do |assignee, issues| | |
353 | reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active? |
|
362 | reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active? | |
354 | end |
|
363 | end | |
355 | end |
|
364 | end | |
356 |
|
365 | |||
357 | # Activates/desactivates email deliveries during +block+ |
|
366 | # Activates/desactivates email deliveries during +block+ | |
358 | def self.with_deliveries(enabled = true, &block) |
|
367 | def self.with_deliveries(enabled = true, &block) | |
359 | was_enabled = ActionMailer::Base.perform_deliveries |
|
368 | was_enabled = ActionMailer::Base.perform_deliveries | |
360 | ActionMailer::Base.perform_deliveries = !!enabled |
|
369 | ActionMailer::Base.perform_deliveries = !!enabled | |
361 | yield |
|
370 | yield | |
362 | ensure |
|
371 | ensure | |
363 | ActionMailer::Base.perform_deliveries = was_enabled |
|
372 | ActionMailer::Base.perform_deliveries = was_enabled | |
364 | end |
|
373 | end | |
365 |
|
374 | |||
366 | # Sends emails synchronously in the given block |
|
375 | # Sends emails synchronously in the given block | |
367 | def self.with_synched_deliveries(&block) |
|
376 | def self.with_synched_deliveries(&block) | |
368 | saved_method = ActionMailer::Base.delivery_method |
|
377 | saved_method = ActionMailer::Base.delivery_method | |
369 | if m = saved_method.to_s.match(%r{^async_(.+)$}) |
|
378 | if m = saved_method.to_s.match(%r{^async_(.+)$}) | |
370 | synched_method = m[1] |
|
379 | synched_method = m[1] | |
371 | ActionMailer::Base.delivery_method = synched_method.to_sym |
|
380 | ActionMailer::Base.delivery_method = synched_method.to_sym | |
372 | ActionMailer::Base.send "#{synched_method}_settings=", ActionMailer::Base.send("async_#{synched_method}_settings") |
|
381 | ActionMailer::Base.send "#{synched_method}_settings=", ActionMailer::Base.send("async_#{synched_method}_settings") | |
373 | end |
|
382 | end | |
374 | yield |
|
383 | yield | |
375 | ensure |
|
384 | ensure | |
376 | ActionMailer::Base.delivery_method = saved_method |
|
385 | ActionMailer::Base.delivery_method = saved_method | |
377 | end |
|
386 | end | |
378 |
|
387 | |||
379 | def mail(headers={}, &block) |
|
388 | def mail(headers={}, &block) | |
380 | headers.reverse_merge! 'X-Mailer' => 'Redmine', |
|
389 | headers.reverse_merge! 'X-Mailer' => 'Redmine', | |
381 | 'X-Redmine-Host' => Setting.host_name, |
|
390 | 'X-Redmine-Host' => Setting.host_name, | |
382 | 'X-Redmine-Site' => Setting.app_title, |
|
391 | 'X-Redmine-Site' => Setting.app_title, | |
383 | 'X-Auto-Response-Suppress' => 'OOF', |
|
392 | 'X-Auto-Response-Suppress' => 'OOF', | |
384 | 'Auto-Submitted' => 'auto-generated', |
|
393 | 'Auto-Submitted' => 'auto-generated', | |
385 | 'From' => Setting.mail_from, |
|
394 | 'From' => Setting.mail_from, | |
386 | 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" |
|
395 | 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" | |
387 |
|
396 | |||
388 | # Replaces users with their email addresses |
|
397 | # Replaces users with their email addresses | |
389 | [:to, :cc, :bcc].each do |key| |
|
398 | [:to, :cc, :bcc].each do |key| | |
390 | if headers[key].present? |
|
399 | if headers[key].present? | |
391 | headers[key] = self.class.email_addresses(headers[key]) |
|
400 | headers[key] = self.class.email_addresses(headers[key]) | |
392 | end |
|
401 | end | |
393 | end |
|
402 | end | |
394 |
|
403 | |||
395 | # Removes the author from the recipients and cc |
|
404 | # Removes the author from the recipients and cc | |
396 | # if the author does not want to receive notifications |
|
405 | # if the author does not want to receive notifications | |
397 | # about what the author do |
|
406 | # about what the author do | |
398 | if @author && @author.logged? && @author.pref.no_self_notified |
|
407 | if @author && @author.logged? && @author.pref.no_self_notified | |
399 | addresses = @author.mails |
|
408 | addresses = @author.mails | |
400 | headers[:to] -= addresses if headers[:to].is_a?(Array) |
|
409 | headers[:to] -= addresses if headers[:to].is_a?(Array) | |
401 | headers[:cc] -= addresses if headers[:cc].is_a?(Array) |
|
410 | headers[:cc] -= addresses if headers[:cc].is_a?(Array) | |
402 | end |
|
411 | end | |
403 |
|
412 | |||
404 | if @author && @author.logged? |
|
413 | if @author && @author.logged? | |
405 | redmine_headers 'Sender' => @author.login |
|
414 | redmine_headers 'Sender' => @author.login | |
406 | end |
|
415 | end | |
407 |
|
416 | |||
408 | # Blind carbon copy recipients |
|
417 | # Blind carbon copy recipients | |
409 | if Setting.bcc_recipients? |
|
418 | if Setting.bcc_recipients? | |
410 | headers[:bcc] = [headers[:to], headers[:cc]].flatten.uniq.reject(&:blank?) |
|
419 | headers[:bcc] = [headers[:to], headers[:cc]].flatten.uniq.reject(&:blank?) | |
411 | headers[:to] = nil |
|
420 | headers[:to] = nil | |
412 | headers[:cc] = nil |
|
421 | headers[:cc] = nil | |
413 | end |
|
422 | end | |
414 |
|
423 | |||
415 | if @message_id_object |
|
424 | if @message_id_object | |
416 | headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>" |
|
425 | headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>" | |
417 | end |
|
426 | end | |
418 | if @references_objects |
|
427 | if @references_objects | |
419 | headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') |
|
428 | headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') | |
420 | end |
|
429 | end | |
421 |
|
430 | |||
422 | m = if block_given? |
|
431 | m = if block_given? | |
423 | super headers, &block |
|
432 | super headers, &block | |
424 | else |
|
433 | else | |
425 | super headers do |format| |
|
434 | super headers do |format| | |
426 | format.text |
|
435 | format.text | |
427 | format.html unless Setting.plain_text_mail? |
|
436 | format.html unless Setting.plain_text_mail? | |
428 | end |
|
437 | end | |
429 | end |
|
438 | end | |
430 | set_language_if_valid @initial_language |
|
439 | set_language_if_valid @initial_language | |
431 |
|
440 | |||
432 | m |
|
441 | m | |
433 | end |
|
442 | end | |
434 |
|
443 | |||
435 | def initialize(*args) |
|
444 | def initialize(*args) | |
436 | @initial_language = current_language |
|
445 | @initial_language = current_language | |
437 | set_language_if_valid Setting.default_language |
|
446 | set_language_if_valid Setting.default_language | |
438 | super |
|
447 | super | |
439 | end |
|
448 | end | |
440 |
|
449 | |||
441 | def self.deliver_mail(mail) |
|
450 | def self.deliver_mail(mail) | |
442 | return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank? |
|
451 | return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank? | |
443 | begin |
|
452 | begin | |
444 | # Log errors when raise_delivery_errors is set to false, Rails does not |
|
453 | # Log errors when raise_delivery_errors is set to false, Rails does not | |
445 | mail.raise_delivery_errors = true |
|
454 | mail.raise_delivery_errors = true | |
446 | super |
|
455 | super | |
447 | rescue Exception => e |
|
456 | rescue Exception => e | |
448 | if ActionMailer::Base.raise_delivery_errors |
|
457 | if ActionMailer::Base.raise_delivery_errors | |
449 | raise e |
|
458 | raise e | |
450 | else |
|
459 | else | |
451 | Rails.logger.error "Email delivery error: #{e.message}" |
|
460 | Rails.logger.error "Email delivery error: #{e.message}" | |
452 | end |
|
461 | end | |
453 | end |
|
462 | end | |
454 | end |
|
463 | end | |
455 |
|
464 | |||
456 | def self.method_missing(method, *args, &block) |
|
465 | def self.method_missing(method, *args, &block) | |
457 | if m = method.to_s.match(%r{^deliver_(.+)$}) |
|
466 | if m = method.to_s.match(%r{^deliver_(.+)$}) | |
458 | ActiveSupport::Deprecation.warn "Mailer.deliver_#{m[1]}(*args) is deprecated. Use Mailer.#{m[1]}(*args).deliver instead." |
|
467 | ActiveSupport::Deprecation.warn "Mailer.deliver_#{m[1]}(*args) is deprecated. Use Mailer.#{m[1]}(*args).deliver instead." | |
459 | send(m[1], *args).deliver |
|
468 | send(m[1], *args).deliver | |
460 | else |
|
469 | else | |
461 | super |
|
470 | super | |
462 | end |
|
471 | end | |
463 | end |
|
472 | end | |
464 |
|
473 | |||
465 | # Returns an array of email addresses to notify by |
|
474 | # Returns an array of email addresses to notify by | |
466 | # replacing users in arg with their notified email addresses |
|
475 | # replacing users in arg with their notified email addresses | |
467 | # |
|
476 | # | |
468 | # Example: |
|
477 | # Example: | |
469 | # Mailer.email_addresses(users) |
|
478 | # Mailer.email_addresses(users) | |
470 | # => ["foo@example.net", "bar@example.net"] |
|
479 | # => ["foo@example.net", "bar@example.net"] | |
471 | def self.email_addresses(arg) |
|
480 | def self.email_addresses(arg) | |
472 | arr = Array.wrap(arg) |
|
481 | arr = Array.wrap(arg) | |
473 | mails = arr.reject {|a| a.is_a? Principal} |
|
482 | mails = arr.reject {|a| a.is_a? Principal} | |
474 | users = arr - mails |
|
483 | users = arr - mails | |
475 | if users.any? |
|
484 | if users.any? | |
476 | mails += EmailAddress. |
|
485 | mails += EmailAddress. | |
477 | where(:user_id => users.map(&:id)). |
|
486 | where(:user_id => users.map(&:id)). | |
478 | where("is_default = ? OR notify = ?", true, true). |
|
487 | where("is_default = ? OR notify = ?", true, true). | |
479 | pluck(:address) |
|
488 | pluck(:address) | |
480 | end |
|
489 | end | |
481 | mails |
|
490 | mails | |
482 | end |
|
491 | end | |
483 |
|
492 | |||
484 | private |
|
493 | private | |
485 |
|
494 | |||
486 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') |
|
495 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') | |
487 | def redmine_headers(h) |
|
496 | def redmine_headers(h) | |
488 | h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s } |
|
497 | h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s } | |
489 | end |
|
498 | end | |
490 |
|
499 | |||
491 | def self.token_for(object, rand=true) |
|
500 | def self.token_for(object, rand=true) | |
492 | timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) |
|
501 | timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) | |
493 | hash = [ |
|
502 | hash = [ | |
494 | "redmine", |
|
503 | "redmine", | |
495 | "#{object.class.name.demodulize.underscore}-#{object.id}", |
|
504 | "#{object.class.name.demodulize.underscore}-#{object.id}", | |
496 | timestamp.strftime("%Y%m%d%H%M%S") |
|
505 | timestamp.strftime("%Y%m%d%H%M%S") | |
497 | ] |
|
506 | ] | |
498 | if rand |
|
507 | if rand | |
499 | hash << Redmine::Utils.random_hex(8) |
|
508 | hash << Redmine::Utils.random_hex(8) | |
500 | end |
|
509 | end | |
501 | host = Setting.mail_from.to_s.strip.gsub(%r{^.*@|>}, '') |
|
510 | host = Setting.mail_from.to_s.strip.gsub(%r{^.*@|>}, '') | |
502 | host = "#{::Socket.gethostname}.redmine" if host.empty? |
|
511 | host = "#{::Socket.gethostname}.redmine" if host.empty? | |
503 | "#{hash.join('.')}@#{host}" |
|
512 | "#{hash.join('.')}@#{host}" | |
504 | end |
|
513 | end | |
505 |
|
514 | |||
506 | # Returns a Message-Id for the given object |
|
515 | # Returns a Message-Id for the given object | |
507 | def self.message_id_for(object) |
|
516 | def self.message_id_for(object) | |
508 | token_for(object, true) |
|
517 | token_for(object, true) | |
509 | end |
|
518 | end | |
510 |
|
519 | |||
511 | # Returns a uniq token for a given object referenced by all notifications |
|
520 | # Returns a uniq token for a given object referenced by all notifications | |
512 | # related to this object |
|
521 | # related to this object | |
513 | def self.references_for(object) |
|
522 | def self.references_for(object) | |
514 | token_for(object, false) |
|
523 | token_for(object, false) | |
515 | end |
|
524 | end | |
516 |
|
525 | |||
517 | def message_id(object) |
|
526 | def message_id(object) | |
518 | @message_id_object = object |
|
527 | @message_id_object = object | |
519 | end |
|
528 | end | |
520 |
|
529 | |||
521 | def references(object) |
|
530 | def references(object) | |
522 | @references_objects ||= [] |
|
531 | @references_objects ||= [] | |
523 | @references_objects << object |
|
532 | @references_objects << object | |
524 | end |
|
533 | end | |
525 |
|
534 | |||
526 | def mylogger |
|
535 | def mylogger | |
527 | Rails.logger |
|
536 | Rails.logger | |
528 | end |
|
537 | end | |
529 | end |
|
538 | end |
@@ -1,835 +1,853 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 Rails::Dom::Testing::Assertions |
|
22 | include Rails::Dom::Testing::Assertions | |
23 | fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :members, |
|
23 | fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :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 | Setting.default_language = 'en' |
|
37 | Setting.default_language = 'en' | |
38 | User.current = nil |
|
38 | User.current = nil | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_generated_links_in_emails |
|
41 | def test_generated_links_in_emails | |
42 | Setting.host_name = 'mydomain.foo' |
|
42 | Setting.host_name = 'mydomain.foo' | |
43 | Setting.protocol = 'https' |
|
43 | Setting.protocol = 'https' | |
44 |
|
44 | |||
45 | journal = Journal.find(3) |
|
45 | journal = Journal.find(3) | |
46 | assert Mailer.deliver_issue_edit(journal) |
|
46 | assert Mailer.deliver_issue_edit(journal) | |
47 |
|
47 | |||
48 | mail = last_email |
|
48 | mail = last_email | |
49 | assert_not_nil mail |
|
49 | assert_not_nil mail | |
50 |
|
50 | |||
51 | assert_select_email do |
|
51 | assert_select_email do | |
52 | # link to the main ticket |
|
52 | # link to the main ticket | |
53 | assert_select 'a[href=?]', |
|
53 | assert_select 'a[href=?]', | |
54 | 'https://mydomain.foo/issues/2#change-3', |
|
54 | 'https://mydomain.foo/issues/2#change-3', | |
55 | :text => 'Feature request #2: Add ingredients categories' |
|
55 | :text => 'Feature request #2: Add ingredients categories' | |
56 | # link to a referenced ticket |
|
56 | # link to a referenced ticket | |
57 | assert_select 'a[href=?][title=?]', |
|
57 | assert_select 'a[href=?][title=?]', | |
58 | 'https://mydomain.foo/issues/1', |
|
58 | 'https://mydomain.foo/issues/1', | |
59 | "Cannot print recipes (New)", |
|
59 | "Cannot print recipes (New)", | |
60 | :text => '#1' |
|
60 | :text => '#1' | |
61 | # link to a changeset |
|
61 | # link to a changeset | |
62 | assert_select 'a[href=?][title=?]', |
|
62 | assert_select 'a[href=?][title=?]', | |
63 | 'https://mydomain.foo/projects/ecookbook/repository/revisions/2', |
|
63 | 'https://mydomain.foo/projects/ecookbook/repository/revisions/2', | |
64 | 'This commit fixes #1, #2 and references #1 & #3', |
|
64 | 'This commit fixes #1, #2 and references #1 & #3', | |
65 | :text => 'r2' |
|
65 | :text => 'r2' | |
66 | # link to a description diff |
|
66 | # link to a description diff | |
67 | assert_select 'a[href^=?][title=?]', |
|
67 | assert_select 'a[href^=?][title=?]', | |
68 | # should be https://mydomain.foo/journals/diff/3?detail_id=4 |
|
68 | # should be https://mydomain.foo/journals/diff/3?detail_id=4 | |
69 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the |
|
69 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the | |
70 | # attribute value |
|
70 | # attribute value | |
71 | 'https://mydomain.foo/journals/diff/3', |
|
71 | 'https://mydomain.foo/journals/diff/3', | |
72 | 'View differences', |
|
72 | 'View differences', | |
73 | :text => 'diff' |
|
73 | :text => 'diff' | |
74 | # link to an attachment |
|
74 | # link to an attachment | |
75 | assert_select 'a[href=?]', |
|
75 | assert_select 'a[href=?]', | |
76 | 'https://mydomain.foo/attachments/download/4/source.rb', |
|
76 | 'https://mydomain.foo/attachments/download/4/source.rb', | |
77 | :text => 'source.rb' |
|
77 | :text => 'source.rb' | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_generated_links_with_prefix |
|
81 | def test_generated_links_with_prefix | |
82 | relative_url_root = Redmine::Utils.relative_url_root |
|
82 | relative_url_root = Redmine::Utils.relative_url_root | |
83 | Setting.host_name = 'mydomain.foo/rdm' |
|
83 | Setting.host_name = 'mydomain.foo/rdm' | |
84 | Setting.protocol = 'http' |
|
84 | Setting.protocol = 'http' | |
85 |
|
85 | |||
86 | journal = Journal.find(3) |
|
86 | journal = Journal.find(3) | |
87 | assert Mailer.deliver_issue_edit(journal) |
|
87 | assert Mailer.deliver_issue_edit(journal) | |
88 |
|
88 | |||
89 | mail = last_email |
|
89 | mail = last_email | |
90 | assert_not_nil mail |
|
90 | assert_not_nil mail | |
91 |
|
91 | |||
92 | assert_select_email do |
|
92 | assert_select_email do | |
93 | # link to the main ticket |
|
93 | # link to the main ticket | |
94 | assert_select 'a[href=?]', |
|
94 | assert_select 'a[href=?]', | |
95 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
95 | 'http://mydomain.foo/rdm/issues/2#change-3', | |
96 | :text => 'Feature request #2: Add ingredients categories' |
|
96 | :text => 'Feature request #2: Add ingredients categories' | |
97 | # link to a referenced ticket |
|
97 | # link to a referenced ticket | |
98 | assert_select 'a[href=?][title=?]', |
|
98 | assert_select 'a[href=?][title=?]', | |
99 | 'http://mydomain.foo/rdm/issues/1', |
|
99 | 'http://mydomain.foo/rdm/issues/1', | |
100 | "Cannot print recipes (New)", |
|
100 | "Cannot print recipes (New)", | |
101 | :text => '#1' |
|
101 | :text => '#1' | |
102 | # link to a changeset |
|
102 | # link to a changeset | |
103 | assert_select 'a[href=?][title=?]', |
|
103 | assert_select 'a[href=?][title=?]', | |
104 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
104 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', | |
105 | 'This commit fixes #1, #2 and references #1 & #3', |
|
105 | 'This commit fixes #1, #2 and references #1 & #3', | |
106 | :text => 'r2' |
|
106 | :text => 'r2' | |
107 | # link to a description diff |
|
107 | # link to a description diff | |
108 | assert_select 'a[href^=?][title=?]', |
|
108 | assert_select 'a[href^=?][title=?]', | |
109 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 |
|
109 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 | |
110 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the |
|
110 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the | |
111 | # attribute value |
|
111 | # attribute value | |
112 | 'http://mydomain.foo/rdm/journals/diff/3', |
|
112 | 'http://mydomain.foo/rdm/journals/diff/3', | |
113 | 'View differences', |
|
113 | 'View differences', | |
114 | :text => 'diff' |
|
114 | :text => 'diff' | |
115 | # link to an attachment |
|
115 | # link to an attachment | |
116 | assert_select 'a[href=?]', |
|
116 | assert_select 'a[href=?]', | |
117 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
117 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', | |
118 | :text => 'source.rb' |
|
118 | :text => 'source.rb' | |
119 | end |
|
119 | end | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
|
122 | def test_generated_links_with_port_and_prefix | |||
|
123 | with_settings :host_name => '10.0.0.1:81/redmine', :protocol => 'http' do | |||
|
124 | Mailer.test_email(User.find(1)).deliver | |||
|
125 | mail = last_email | |||
|
126 | assert_not_nil mail | |||
|
127 | assert_include 'http://10.0.0.1:81/redmine', mail_body(mail) | |||
|
128 | end | |||
|
129 | end | |||
|
130 | ||||
|
131 | def test_generated_links_with_port | |||
|
132 | with_settings :host_name => '10.0.0.1:81', :protocol => 'http' do | |||
|
133 | Mailer.test_email(User.find(1)).deliver | |||
|
134 | mail = last_email | |||
|
135 | assert_not_nil mail | |||
|
136 | assert_include 'http://10.0.0.1:81', mail_body(mail) | |||
|
137 | end | |||
|
138 | end | |||
|
139 | ||||
122 | def test_issue_edit_should_generate_url_with_hostname_for_relations |
|
140 | def test_issue_edit_should_generate_url_with_hostname_for_relations | |
123 | journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now) |
|
141 | journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now) | |
124 | journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2) |
|
142 | journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2) | |
125 | Mailer.deliver_issue_edit(journal) |
|
143 | Mailer.deliver_issue_edit(journal) | |
126 | assert_not_nil last_email |
|
144 | assert_not_nil last_email | |
127 | assert_select_email do |
|
145 | assert_select_email do | |
128 | assert_select 'a[href=?]', 'http://mydomain.foo/issues/2', :text => 'Feature request #2' |
|
146 | assert_select 'a[href=?]', 'http://mydomain.foo/issues/2', :text => 'Feature request #2' | |
129 | end |
|
147 | end | |
130 | end |
|
148 | end | |
131 |
|
149 | |||
132 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
150 | def test_generated_links_with_prefix_and_no_relative_url_root | |
133 | relative_url_root = Redmine::Utils.relative_url_root |
|
151 | relative_url_root = Redmine::Utils.relative_url_root | |
134 | Setting.host_name = 'mydomain.foo/rdm' |
|
152 | Setting.host_name = 'mydomain.foo/rdm' | |
135 | Setting.protocol = 'http' |
|
153 | Setting.protocol = 'http' | |
136 | Redmine::Utils.relative_url_root = nil |
|
154 | Redmine::Utils.relative_url_root = nil | |
137 |
|
155 | |||
138 | journal = Journal.find(3) |
|
156 | journal = Journal.find(3) | |
139 | assert Mailer.deliver_issue_edit(journal) |
|
157 | assert Mailer.deliver_issue_edit(journal) | |
140 |
|
158 | |||
141 | mail = last_email |
|
159 | mail = last_email | |
142 | assert_not_nil mail |
|
160 | assert_not_nil mail | |
143 |
|
161 | |||
144 | assert_select_email do |
|
162 | assert_select_email do | |
145 | # link to the main ticket |
|
163 | # link to the main ticket | |
146 | assert_select 'a[href=?]', |
|
164 | assert_select 'a[href=?]', | |
147 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
165 | 'http://mydomain.foo/rdm/issues/2#change-3', | |
148 | :text => 'Feature request #2: Add ingredients categories' |
|
166 | :text => 'Feature request #2: Add ingredients categories' | |
149 | # link to a referenced ticket |
|
167 | # link to a referenced ticket | |
150 | assert_select 'a[href=?][title=?]', |
|
168 | assert_select 'a[href=?][title=?]', | |
151 | 'http://mydomain.foo/rdm/issues/1', |
|
169 | 'http://mydomain.foo/rdm/issues/1', | |
152 | "Cannot print recipes (New)", |
|
170 | "Cannot print recipes (New)", | |
153 | :text => '#1' |
|
171 | :text => '#1' | |
154 | # link to a changeset |
|
172 | # link to a changeset | |
155 | assert_select 'a[href=?][title=?]', |
|
173 | assert_select 'a[href=?][title=?]', | |
156 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
174 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', | |
157 | 'This commit fixes #1, #2 and references #1 & #3', |
|
175 | 'This commit fixes #1, #2 and references #1 & #3', | |
158 | :text => 'r2' |
|
176 | :text => 'r2' | |
159 | # link to a description diff |
|
177 | # link to a description diff | |
160 | assert_select 'a[href^=?][title=?]', |
|
178 | assert_select 'a[href^=?][title=?]', | |
161 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 |
|
179 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 | |
162 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the |
|
180 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the | |
163 | # attribute value |
|
181 | # attribute value | |
164 | 'http://mydomain.foo/rdm/journals/diff/3', |
|
182 | 'http://mydomain.foo/rdm/journals/diff/3', | |
165 | 'View differences', |
|
183 | 'View differences', | |
166 | :text => 'diff' |
|
184 | :text => 'diff' | |
167 | # link to an attachment |
|
185 | # link to an attachment | |
168 | assert_select 'a[href=?]', |
|
186 | assert_select 'a[href=?]', | |
169 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
187 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', | |
170 | :text => 'source.rb' |
|
188 | :text => 'source.rb' | |
171 | end |
|
189 | end | |
172 | ensure |
|
190 | ensure | |
173 | # restore it |
|
191 | # restore it | |
174 | Redmine::Utils.relative_url_root = relative_url_root |
|
192 | Redmine::Utils.relative_url_root = relative_url_root | |
175 | end |
|
193 | end | |
176 |
|
194 | |||
177 | def test_email_headers |
|
195 | def test_email_headers | |
178 | issue = Issue.find(1) |
|
196 | issue = Issue.find(1) | |
179 | Mailer.deliver_issue_add(issue) |
|
197 | Mailer.deliver_issue_add(issue) | |
180 | mail = last_email |
|
198 | mail = last_email | |
181 | assert_not_nil mail |
|
199 | assert_not_nil mail | |
182 | assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s |
|
200 | assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s | |
183 | assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s |
|
201 | assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s | |
184 | assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s |
|
202 | assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s | |
185 | end |
|
203 | end | |
186 |
|
204 | |||
187 | def test_email_headers_should_include_sender |
|
205 | def test_email_headers_should_include_sender | |
188 | issue = Issue.find(1) |
|
206 | issue = Issue.find(1) | |
189 | Mailer.deliver_issue_add(issue) |
|
207 | Mailer.deliver_issue_add(issue) | |
190 | mail = last_email |
|
208 | mail = last_email | |
191 | assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s |
|
209 | assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s | |
192 | end |
|
210 | end | |
193 |
|
211 | |||
194 | def test_plain_text_mail |
|
212 | def test_plain_text_mail | |
195 | Setting.plain_text_mail = 1 |
|
213 | Setting.plain_text_mail = 1 | |
196 | journal = Journal.find(2) |
|
214 | journal = Journal.find(2) | |
197 | Mailer.deliver_issue_edit(journal) |
|
215 | Mailer.deliver_issue_edit(journal) | |
198 | mail = last_email |
|
216 | mail = last_email | |
199 | assert_equal "text/plain; charset=UTF-8", mail.content_type |
|
217 | assert_equal "text/plain; charset=UTF-8", mail.content_type | |
200 | assert_equal 0, mail.parts.size |
|
218 | assert_equal 0, mail.parts.size | |
201 | assert !mail.encoded.include?('href') |
|
219 | assert !mail.encoded.include?('href') | |
202 | end |
|
220 | end | |
203 |
|
221 | |||
204 | def test_html_mail |
|
222 | def test_html_mail | |
205 | Setting.plain_text_mail = 0 |
|
223 | Setting.plain_text_mail = 0 | |
206 | journal = Journal.find(2) |
|
224 | journal = Journal.find(2) | |
207 | Mailer.deliver_issue_edit(journal) |
|
225 | Mailer.deliver_issue_edit(journal) | |
208 | mail = last_email |
|
226 | mail = last_email | |
209 | assert_equal 2, mail.parts.size |
|
227 | assert_equal 2, mail.parts.size | |
210 | assert mail.encoded.include?('href') |
|
228 | assert mail.encoded.include?('href') | |
211 | end |
|
229 | end | |
212 |
|
230 | |||
213 | def test_from_header |
|
231 | def test_from_header | |
214 | with_settings :mail_from => 'redmine@example.net' do |
|
232 | with_settings :mail_from => 'redmine@example.net' do | |
215 | Mailer.test_email(User.find(1)).deliver |
|
233 | Mailer.test_email(User.find(1)).deliver | |
216 | end |
|
234 | end | |
217 | mail = last_email |
|
235 | mail = last_email | |
218 | assert_equal 'redmine@example.net', mail.from_addrs.first |
|
236 | assert_equal 'redmine@example.net', mail.from_addrs.first | |
219 | end |
|
237 | end | |
220 |
|
238 | |||
221 | def test_from_header_with_phrase |
|
239 | def test_from_header_with_phrase | |
222 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do |
|
240 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do | |
223 | Mailer.test_email(User.find(1)).deliver |
|
241 | Mailer.test_email(User.find(1)).deliver | |
224 | end |
|
242 | end | |
225 | mail = last_email |
|
243 | mail = last_email | |
226 | assert_equal 'redmine@example.net', mail.from_addrs.first |
|
244 | assert_equal 'redmine@example.net', mail.from_addrs.first | |
227 | assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s |
|
245 | assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s | |
228 | end |
|
246 | end | |
229 |
|
247 | |||
230 | def test_should_not_send_email_without_recipient |
|
248 | def test_should_not_send_email_without_recipient | |
231 | news = News.first |
|
249 | news = News.first | |
232 | user = news.author |
|
250 | user = news.author | |
233 | # Remove members except news author |
|
251 | # Remove members except news author | |
234 | news.project.memberships.each {|m| m.destroy unless m.user == user} |
|
252 | news.project.memberships.each {|m| m.destroy unless m.user == user} | |
235 |
|
253 | |||
236 | user.pref.no_self_notified = false |
|
254 | user.pref.no_self_notified = false | |
237 | user.pref.save |
|
255 | user.pref.save | |
238 | User.current = user |
|
256 | User.current = user | |
239 | Mailer.news_added(news.reload).deliver |
|
257 | Mailer.news_added(news.reload).deliver | |
240 | assert_equal 1, last_email.bcc.size |
|
258 | assert_equal 1, last_email.bcc.size | |
241 |
|
259 | |||
242 | # nobody to notify |
|
260 | # nobody to notify | |
243 | user.pref.no_self_notified = true |
|
261 | user.pref.no_self_notified = true | |
244 | user.pref.save |
|
262 | user.pref.save | |
245 | User.current = user |
|
263 | User.current = user | |
246 | ActionMailer::Base.deliveries.clear |
|
264 | ActionMailer::Base.deliveries.clear | |
247 | Mailer.news_added(news.reload).deliver |
|
265 | Mailer.news_added(news.reload).deliver | |
248 | assert ActionMailer::Base.deliveries.empty? |
|
266 | assert ActionMailer::Base.deliveries.empty? | |
249 | end |
|
267 | end | |
250 |
|
268 | |||
251 | def test_issue_add_message_id |
|
269 | def test_issue_add_message_id | |
252 | issue = Issue.find(2) |
|
270 | issue = Issue.find(2) | |
253 | Mailer.deliver_issue_add(issue) |
|
271 | Mailer.deliver_issue_add(issue) | |
254 | mail = last_email |
|
272 | mail = last_email | |
255 | assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id |
|
273 | assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id | |
256 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
274 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references | |
257 | end |
|
275 | end | |
258 |
|
276 | |||
259 | def test_issue_edit_message_id |
|
277 | def test_issue_edit_message_id | |
260 | journal = Journal.find(3) |
|
278 | journal = Journal.find(3) | |
261 | journal.issue = Issue.find(2) |
|
279 | journal.issue = Issue.find(2) | |
262 |
|
280 | |||
263 | Mailer.deliver_issue_edit(journal) |
|
281 | Mailer.deliver_issue_edit(journal) | |
264 | mail = last_email |
|
282 | mail = last_email | |
265 | assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
283 | assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id | |
266 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
284 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references | |
267 | assert_select_email do |
|
285 | assert_select_email do | |
268 | # link to the update |
|
286 | # link to the update | |
269 | assert_select "a[href=?]", |
|
287 | assert_select "a[href=?]", | |
270 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" |
|
288 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" | |
271 | end |
|
289 | end | |
272 | end |
|
290 | end | |
273 |
|
291 | |||
274 | def test_message_posted_message_id |
|
292 | def test_message_posted_message_id | |
275 | message = Message.find(1) |
|
293 | message = Message.find(1) | |
276 | Mailer.message_posted(message).deliver |
|
294 | Mailer.message_posted(message).deliver | |
277 | mail = last_email |
|
295 | mail = last_email | |
278 | assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
296 | assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id | |
279 | assert_include "redmine.message-1.20070512151532@example.net", mail.references |
|
297 | assert_include "redmine.message-1.20070512151532@example.net", mail.references | |
280 | assert_select_email do |
|
298 | assert_select_email do | |
281 | # link to the message |
|
299 | # link to the message | |
282 | assert_select "a[href=?]", |
|
300 | assert_select "a[href=?]", | |
283 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", |
|
301 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", | |
284 | :text => message.subject |
|
302 | :text => message.subject | |
285 | end |
|
303 | end | |
286 | end |
|
304 | end | |
287 |
|
305 | |||
288 | def test_reply_posted_message_id |
|
306 | def test_reply_posted_message_id | |
289 | message = Message.find(3) |
|
307 | message = Message.find(3) | |
290 | Mailer.message_posted(message).deliver |
|
308 | Mailer.message_posted(message).deliver | |
291 | mail = last_email |
|
309 | mail = last_email | |
292 | assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
310 | assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id | |
293 | assert_include "redmine.message-1.20070512151532@example.net", mail.references |
|
311 | assert_include "redmine.message-1.20070512151532@example.net", mail.references | |
294 | assert_select_email do |
|
312 | assert_select_email do | |
295 | # link to the reply |
|
313 | # link to the reply | |
296 | assert_select "a[href=?]", |
|
314 | assert_select "a[href=?]", | |
297 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
|
315 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", | |
298 | :text => message.subject |
|
316 | :text => message.subject | |
299 | end |
|
317 | end | |
300 | end |
|
318 | end | |
301 |
|
319 | |||
302 | test "#issue_add should notify project members" do |
|
320 | test "#issue_add should notify project members" do | |
303 | issue = Issue.find(1) |
|
321 | issue = Issue.find(1) | |
304 | assert Mailer.deliver_issue_add(issue) |
|
322 | assert Mailer.deliver_issue_add(issue) | |
305 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
323 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
306 | end |
|
324 | end | |
307 |
|
325 | |||
308 | def test_issue_add_should_send_mail_to_all_user_email_address |
|
326 | def test_issue_add_should_send_mail_to_all_user_email_address | |
309 | EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo') |
|
327 | EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo') | |
310 | issue = Issue.find(1) |
|
328 | issue = Issue.find(1) | |
311 | assert Mailer.deliver_issue_add(issue) |
|
329 | assert Mailer.deliver_issue_add(issue) | |
312 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
330 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
313 | assert last_email.bcc.include?('otheremail@somenet.foo') |
|
331 | assert last_email.bcc.include?('otheremail@somenet.foo') | |
314 | end |
|
332 | end | |
315 |
|
333 | |||
316 | test "#issue_add should not notify project members that are not allow to view the issue" do |
|
334 | test "#issue_add should not notify project members that are not allow to view the issue" do | |
317 | issue = Issue.find(1) |
|
335 | issue = Issue.find(1) | |
318 | Role.find(2).remove_permission!(:view_issues) |
|
336 | Role.find(2).remove_permission!(:view_issues) | |
319 | assert Mailer.deliver_issue_add(issue) |
|
337 | assert Mailer.deliver_issue_add(issue) | |
320 | assert !last_email.bcc.include?('dlopper@somenet.foo') |
|
338 | assert !last_email.bcc.include?('dlopper@somenet.foo') | |
321 | end |
|
339 | end | |
322 |
|
340 | |||
323 | test "#issue_add should notify issue watchers" do |
|
341 | test "#issue_add should notify issue watchers" do | |
324 | issue = Issue.find(1) |
|
342 | issue = Issue.find(1) | |
325 | user = User.find(9) |
|
343 | user = User.find(9) | |
326 | # minimal email notification options |
|
344 | # minimal email notification options | |
327 | user.pref.no_self_notified = '1' |
|
345 | user.pref.no_self_notified = '1' | |
328 | user.pref.save |
|
346 | user.pref.save | |
329 | user.mail_notification = false |
|
347 | user.mail_notification = false | |
330 | user.save |
|
348 | user.save | |
331 |
|
349 | |||
332 | Watcher.create!(:watchable => issue, :user => user) |
|
350 | Watcher.create!(:watchable => issue, :user => user) | |
333 | assert Mailer.deliver_issue_add(issue) |
|
351 | assert Mailer.deliver_issue_add(issue) | |
334 | assert last_email.bcc.include?(user.mail) |
|
352 | assert last_email.bcc.include?(user.mail) | |
335 | end |
|
353 | end | |
336 |
|
354 | |||
337 | test "#issue_add should not notify watchers not allowed to view the issue" do |
|
355 | test "#issue_add should not notify watchers not allowed to view the issue" do | |
338 | issue = Issue.find(1) |
|
356 | issue = Issue.find(1) | |
339 | user = User.find(9) |
|
357 | user = User.find(9) | |
340 | Watcher.create!(:watchable => issue, :user => user) |
|
358 | Watcher.create!(:watchable => issue, :user => user) | |
341 | Role.non_member.remove_permission!(:view_issues) |
|
359 | Role.non_member.remove_permission!(:view_issues) | |
342 | assert Mailer.deliver_issue_add(issue) |
|
360 | assert Mailer.deliver_issue_add(issue) | |
343 | assert !last_email.bcc.include?(user.mail) |
|
361 | assert !last_email.bcc.include?(user.mail) | |
344 | end |
|
362 | end | |
345 |
|
363 | |||
346 | def test_issue_add_should_include_enabled_fields |
|
364 | def test_issue_add_should_include_enabled_fields | |
347 | issue = Issue.find(2) |
|
365 | issue = Issue.find(2) | |
348 | assert Mailer.deliver_issue_add(issue) |
|
366 | assert Mailer.deliver_issue_add(issue) | |
349 | assert_mail_body_match '* Target version: 1.0', last_email |
|
367 | assert_mail_body_match '* Target version: 1.0', last_email | |
350 | assert_select_email do |
|
368 | assert_select_email do | |
351 | assert_select 'li', :text => 'Target version: 1.0' |
|
369 | assert_select 'li', :text => 'Target version: 1.0' | |
352 | end |
|
370 | end | |
353 | end |
|
371 | end | |
354 |
|
372 | |||
355 | def test_issue_add_should_not_include_disabled_fields |
|
373 | def test_issue_add_should_not_include_disabled_fields | |
356 | issue = Issue.find(2) |
|
374 | issue = Issue.find(2) | |
357 | tracker = issue.tracker |
|
375 | tracker = issue.tracker | |
358 | tracker.core_fields -= ['fixed_version_id'] |
|
376 | tracker.core_fields -= ['fixed_version_id'] | |
359 | tracker.save! |
|
377 | tracker.save! | |
360 | assert Mailer.deliver_issue_add(issue) |
|
378 | assert Mailer.deliver_issue_add(issue) | |
361 | assert_mail_body_no_match 'Target version', last_email |
|
379 | assert_mail_body_no_match 'Target version', last_email | |
362 | assert_select_email do |
|
380 | assert_select_email do | |
363 | assert_select 'li', :text => /Target version/, :count => 0 |
|
381 | assert_select 'li', :text => /Target version/, :count => 0 | |
364 | end |
|
382 | end | |
365 | end |
|
383 | end | |
366 |
|
384 | |||
367 | # test mailer methods for each language |
|
385 | # test mailer methods for each language | |
368 | def test_issue_add |
|
386 | def test_issue_add | |
369 | issue = Issue.find(1) |
|
387 | issue = Issue.find(1) | |
370 | with_each_language_as_default do |
|
388 | with_each_language_as_default do | |
371 | assert Mailer.deliver_issue_add(issue) |
|
389 | assert Mailer.deliver_issue_add(issue) | |
372 | end |
|
390 | end | |
373 | end |
|
391 | end | |
374 |
|
392 | |||
375 | def test_issue_edit |
|
393 | def test_issue_edit | |
376 | journal = Journal.find(1) |
|
394 | journal = Journal.find(1) | |
377 | with_each_language_as_default do |
|
395 | with_each_language_as_default do | |
378 | assert Mailer.deliver_issue_edit(journal) |
|
396 | assert Mailer.deliver_issue_edit(journal) | |
379 | end |
|
397 | end | |
380 | end |
|
398 | end | |
381 |
|
399 | |||
382 | def test_issue_edit_should_send_private_notes_to_users_with_permission_only |
|
400 | def test_issue_edit_should_send_private_notes_to_users_with_permission_only | |
383 | journal = Journal.find(1) |
|
401 | journal = Journal.find(1) | |
384 | journal.private_notes = true |
|
402 | journal.private_notes = true | |
385 | journal.save! |
|
403 | journal.save! | |
386 |
|
404 | |||
387 | Role.find(2).add_permission! :view_private_notes |
|
405 | Role.find(2).add_permission! :view_private_notes | |
388 | Mailer.deliver_issue_edit(journal) |
|
406 | Mailer.deliver_issue_edit(journal) | |
389 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort |
|
407 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort | |
390 |
|
408 | |||
391 | Role.find(2).remove_permission! :view_private_notes |
|
409 | Role.find(2).remove_permission! :view_private_notes | |
392 | Mailer.deliver_issue_edit(journal) |
|
410 | Mailer.deliver_issue_edit(journal) | |
393 | assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort |
|
411 | assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort | |
394 | end |
|
412 | end | |
395 |
|
413 | |||
396 | def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only |
|
414 | def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only | |
397 | Issue.find(1).set_watcher(User.find_by_login('someone')) |
|
415 | Issue.find(1).set_watcher(User.find_by_login('someone')) | |
398 | journal = Journal.find(1) |
|
416 | journal = Journal.find(1) | |
399 | journal.private_notes = true |
|
417 | journal.private_notes = true | |
400 | journal.save! |
|
418 | journal.save! | |
401 |
|
419 | |||
402 | Role.non_member.add_permission! :view_private_notes |
|
420 | Role.non_member.add_permission! :view_private_notes | |
403 | Mailer.deliver_issue_edit(journal) |
|
421 | Mailer.deliver_issue_edit(journal) | |
404 | assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort |
|
422 | assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort | |
405 |
|
423 | |||
406 | Role.non_member.remove_permission! :view_private_notes |
|
424 | Role.non_member.remove_permission! :view_private_notes | |
407 | Mailer.deliver_issue_edit(journal) |
|
425 | Mailer.deliver_issue_edit(journal) | |
408 | assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort |
|
426 | assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort | |
409 | end |
|
427 | end | |
410 |
|
428 | |||
411 | def test_issue_edit_should_mark_private_notes |
|
429 | def test_issue_edit_should_mark_private_notes | |
412 | journal = Journal.find(2) |
|
430 | journal = Journal.find(2) | |
413 | journal.private_notes = true |
|
431 | journal.private_notes = true | |
414 | journal.save! |
|
432 | journal.save! | |
415 |
|
433 | |||
416 | with_settings :default_language => 'en' do |
|
434 | with_settings :default_language => 'en' do | |
417 | Mailer.deliver_issue_edit(journal) |
|
435 | Mailer.deliver_issue_edit(journal) | |
418 | end |
|
436 | end | |
419 | assert_mail_body_match '(Private notes)', last_email |
|
437 | assert_mail_body_match '(Private notes)', last_email | |
420 | end |
|
438 | end | |
421 |
|
439 | |||
422 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue |
|
440 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue | |
423 | issue = Issue.generate! |
|
441 | issue = Issue.generate! | |
424 | issue.init_journal(User.find(1)) |
|
442 | issue.init_journal(User.find(1)) | |
425 | private_issue = Issue.generate!(:is_private => true) |
|
443 | private_issue = Issue.generate!(:is_private => true) | |
426 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') |
|
444 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') | |
427 | issue.reload |
|
445 | issue.reload | |
428 | assert_equal 1, issue.journals.size |
|
446 | assert_equal 1, issue.journals.size | |
429 | journal = issue.journals.first |
|
447 | journal = issue.journals.first | |
430 | ActionMailer::Base.deliveries.clear |
|
448 | ActionMailer::Base.deliveries.clear | |
431 |
|
449 | |||
432 | Mailer.deliver_issue_edit(journal) |
|
450 | Mailer.deliver_issue_edit(journal) | |
433 | last_email.bcc.each do |email| |
|
451 | last_email.bcc.each do |email| | |
434 | user = User.find_by_mail(email) |
|
452 | user = User.find_by_mail(email) | |
435 | assert private_issue.visible?(user), "Issue was not visible to #{user}" |
|
453 | assert private_issue.visible?(user), "Issue was not visible to #{user}" | |
436 | end |
|
454 | end | |
437 | end |
|
455 | end | |
438 |
|
456 | |||
439 | def test_document_added |
|
457 | def test_document_added | |
440 | document = Document.find(1) |
|
458 | document = Document.find(1) | |
441 | with_each_language_as_default do |
|
459 | with_each_language_as_default do | |
442 | assert Mailer.document_added(document).deliver |
|
460 | assert Mailer.document_added(document).deliver | |
443 | end |
|
461 | end | |
444 | end |
|
462 | end | |
445 |
|
463 | |||
446 | def test_attachments_added |
|
464 | def test_attachments_added | |
447 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
465 | attachements = [ Attachment.find_by_container_type('Document') ] | |
448 | with_each_language_as_default do |
|
466 | with_each_language_as_default do | |
449 | assert Mailer.attachments_added(attachements).deliver |
|
467 | assert Mailer.attachments_added(attachements).deliver | |
450 | end |
|
468 | end | |
451 | end |
|
469 | end | |
452 |
|
470 | |||
453 | def test_version_file_added |
|
471 | def test_version_file_added | |
454 | attachements = [ Attachment.find_by_container_type('Version') ] |
|
472 | attachements = [ Attachment.find_by_container_type('Version') ] | |
455 | assert Mailer.attachments_added(attachements).deliver |
|
473 | assert Mailer.attachments_added(attachements).deliver | |
456 | assert_not_nil last_email.bcc |
|
474 | assert_not_nil last_email.bcc | |
457 | assert last_email.bcc.any? |
|
475 | assert last_email.bcc.any? | |
458 | assert_select_email do |
|
476 | assert_select_email do | |
459 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
477 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | |
460 | end |
|
478 | end | |
461 | end |
|
479 | end | |
462 |
|
480 | |||
463 | def test_project_file_added |
|
481 | def test_project_file_added | |
464 | attachements = [ Attachment.find_by_container_type('Project') ] |
|
482 | attachements = [ Attachment.find_by_container_type('Project') ] | |
465 | assert Mailer.attachments_added(attachements).deliver |
|
483 | assert Mailer.attachments_added(attachements).deliver | |
466 | assert_not_nil last_email.bcc |
|
484 | assert_not_nil last_email.bcc | |
467 | assert last_email.bcc.any? |
|
485 | assert last_email.bcc.any? | |
468 | assert_select_email do |
|
486 | assert_select_email do | |
469 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
487 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | |
470 | end |
|
488 | end | |
471 | end |
|
489 | end | |
472 |
|
490 | |||
473 | def test_news_added |
|
491 | def test_news_added | |
474 | news = News.first |
|
492 | news = News.first | |
475 | with_each_language_as_default do |
|
493 | with_each_language_as_default do | |
476 | assert Mailer.news_added(news).deliver |
|
494 | assert Mailer.news_added(news).deliver | |
477 | end |
|
495 | end | |
478 | end |
|
496 | end | |
479 |
|
497 | |||
480 | def test_news_added_should_notify_project_news_watchers |
|
498 | def test_news_added_should_notify_project_news_watchers | |
481 | user1 = User.generate! |
|
499 | user1 = User.generate! | |
482 | user2 = User.generate! |
|
500 | user2 = User.generate! | |
483 | news = News.find(1) |
|
501 | news = News.find(1) | |
484 | news.project.enabled_module('news').add_watcher(user1) |
|
502 | news.project.enabled_module('news').add_watcher(user1) | |
485 |
|
503 | |||
486 | Mailer.news_added(news).deliver |
|
504 | Mailer.news_added(news).deliver | |
487 | assert_include user1.mail, last_email.bcc |
|
505 | assert_include user1.mail, last_email.bcc | |
488 | assert_not_include user2.mail, last_email.bcc |
|
506 | assert_not_include user2.mail, last_email.bcc | |
489 | end |
|
507 | end | |
490 |
|
508 | |||
491 | def test_news_comment_added |
|
509 | def test_news_comment_added | |
492 | comment = Comment.find(2) |
|
510 | comment = Comment.find(2) | |
493 | with_each_language_as_default do |
|
511 | with_each_language_as_default do | |
494 | assert Mailer.news_comment_added(comment).deliver |
|
512 | assert Mailer.news_comment_added(comment).deliver | |
495 | end |
|
513 | end | |
496 | end |
|
514 | end | |
497 |
|
515 | |||
498 | def test_message_posted |
|
516 | def test_message_posted | |
499 | message = Message.first |
|
517 | message = Message.first | |
500 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
518 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} | |
501 | recipients = recipients.compact.uniq |
|
519 | recipients = recipients.compact.uniq | |
502 | with_each_language_as_default do |
|
520 | with_each_language_as_default do | |
503 | assert Mailer.message_posted(message).deliver |
|
521 | assert Mailer.message_posted(message).deliver | |
504 | end |
|
522 | end | |
505 | end |
|
523 | end | |
506 |
|
524 | |||
507 | def test_wiki_content_added |
|
525 | def test_wiki_content_added | |
508 | content = WikiContent.find(1) |
|
526 | content = WikiContent.find(1) | |
509 | with_each_language_as_default do |
|
527 | with_each_language_as_default do | |
510 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
528 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
511 | assert Mailer.wiki_content_added(content).deliver |
|
529 | assert Mailer.wiki_content_added(content).deliver | |
512 | assert_select_email do |
|
530 | assert_select_email do | |
513 | assert_select 'a[href=?]', |
|
531 | assert_select 'a[href=?]', | |
514 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', |
|
532 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', | |
515 | :text => 'CookBook documentation' |
|
533 | :text => 'CookBook documentation' | |
516 | end |
|
534 | end | |
517 | end |
|
535 | end | |
518 | end |
|
536 | end | |
519 | end |
|
537 | end | |
520 |
|
538 | |||
521 | def test_wiki_content_updated |
|
539 | def test_wiki_content_updated | |
522 | content = WikiContent.find(1) |
|
540 | content = WikiContent.find(1) | |
523 | with_each_language_as_default do |
|
541 | with_each_language_as_default do | |
524 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
542 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
525 | assert Mailer.wiki_content_updated(content).deliver |
|
543 | assert Mailer.wiki_content_updated(content).deliver | |
526 | assert_select_email do |
|
544 | assert_select_email do | |
527 | assert_select 'a[href=?]', |
|
545 | assert_select 'a[href=?]', | |
528 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', |
|
546 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', | |
529 | :text => 'CookBook documentation' |
|
547 | :text => 'CookBook documentation' | |
530 | end |
|
548 | end | |
531 | end |
|
549 | end | |
532 | end |
|
550 | end | |
533 | end |
|
551 | end | |
534 |
|
552 | |||
535 | def test_account_information |
|
553 | def test_account_information | |
536 | user = User.find(2) |
|
554 | user = User.find(2) | |
537 | valid_languages.each do |lang| |
|
555 | valid_languages.each do |lang| | |
538 | user.update_attribute :language, lang.to_s |
|
556 | user.update_attribute :language, lang.to_s | |
539 | user.reload |
|
557 | user.reload | |
540 | assert Mailer.account_information(user, 'pAsswORd').deliver |
|
558 | assert Mailer.account_information(user, 'pAsswORd').deliver | |
541 | end |
|
559 | end | |
542 | end |
|
560 | end | |
543 |
|
561 | |||
544 | def test_lost_password |
|
562 | def test_lost_password | |
545 | token = Token.find(2) |
|
563 | token = Token.find(2) | |
546 | valid_languages.each do |lang| |
|
564 | valid_languages.each do |lang| | |
547 | token.user.update_attribute :language, lang.to_s |
|
565 | token.user.update_attribute :language, lang.to_s | |
548 | token.reload |
|
566 | token.reload | |
549 | assert Mailer.lost_password(token).deliver |
|
567 | assert Mailer.lost_password(token).deliver | |
550 | end |
|
568 | end | |
551 | end |
|
569 | end | |
552 |
|
570 | |||
553 | def test_register |
|
571 | def test_register | |
554 | token = Token.find(1) |
|
572 | token = Token.find(1) | |
555 | Setting.host_name = 'redmine.foo' |
|
573 | Setting.host_name = 'redmine.foo' | |
556 | Setting.protocol = 'https' |
|
574 | Setting.protocol = 'https' | |
557 |
|
575 | |||
558 | valid_languages.each do |lang| |
|
576 | valid_languages.each do |lang| | |
559 | token.user.update_attribute :language, lang.to_s |
|
577 | token.user.update_attribute :language, lang.to_s | |
560 | token.reload |
|
578 | token.reload | |
561 | ActionMailer::Base.deliveries.clear |
|
579 | ActionMailer::Base.deliveries.clear | |
562 | assert Mailer.register(token).deliver |
|
580 | assert Mailer.register(token).deliver | |
563 | mail = last_email |
|
581 | mail = last_email | |
564 | assert_select_email do |
|
582 | assert_select_email do | |
565 | assert_select "a[href=?]", |
|
583 | assert_select "a[href=?]", | |
566 | "https://redmine.foo/account/activate?token=#{token.value}", |
|
584 | "https://redmine.foo/account/activate?token=#{token.value}", | |
567 | :text => "https://redmine.foo/account/activate?token=#{token.value}" |
|
585 | :text => "https://redmine.foo/account/activate?token=#{token.value}" | |
568 | end |
|
586 | end | |
569 | end |
|
587 | end | |
570 | end |
|
588 | end | |
571 |
|
589 | |||
572 | def test_test |
|
590 | def test_test | |
573 | user = User.find(1) |
|
591 | user = User.find(1) | |
574 | valid_languages.each do |lang| |
|
592 | valid_languages.each do |lang| | |
575 | user.update_attribute :language, lang.to_s |
|
593 | user.update_attribute :language, lang.to_s | |
576 | assert Mailer.test_email(user).deliver |
|
594 | assert Mailer.test_email(user).deliver | |
577 | end |
|
595 | end | |
578 | end |
|
596 | end | |
579 |
|
597 | |||
580 | def test_reminders |
|
598 | def test_reminders | |
581 | Mailer.reminders(:days => 42) |
|
599 | Mailer.reminders(:days => 42) | |
582 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
600 | assert_equal 1, ActionMailer::Base.deliveries.size | |
583 | mail = last_email |
|
601 | mail = last_email | |
584 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
602 | assert mail.bcc.include?('dlopper@somenet.foo') | |
585 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail |
|
603 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail | |
586 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
604 | assert_equal '1 issue(s) due in the next 42 days', mail.subject | |
587 | end |
|
605 | end | |
588 |
|
606 | |||
589 | def test_reminders_should_not_include_closed_issues |
|
607 | def test_reminders_should_not_include_closed_issues | |
590 | with_settings :default_language => 'en' do |
|
608 | with_settings :default_language => 'en' do | |
591 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, |
|
609 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, | |
592 | :subject => 'Closed issue', :assigned_to_id => 3, |
|
610 | :subject => 'Closed issue', :assigned_to_id => 3, | |
593 | :due_date => 5.days.from_now, |
|
611 | :due_date => 5.days.from_now, | |
594 | :author_id => 2) |
|
612 | :author_id => 2) | |
595 | ActionMailer::Base.deliveries.clear |
|
613 | ActionMailer::Base.deliveries.clear | |
596 |
|
614 | |||
597 | Mailer.reminders(:days => 42) |
|
615 | Mailer.reminders(:days => 42) | |
598 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
616 | assert_equal 1, ActionMailer::Base.deliveries.size | |
599 | mail = last_email |
|
617 | mail = last_email | |
600 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
618 | assert mail.bcc.include?('dlopper@somenet.foo') | |
601 | assert_mail_body_no_match 'Closed issue', mail |
|
619 | assert_mail_body_no_match 'Closed issue', mail | |
602 | end |
|
620 | end | |
603 | end |
|
621 | end | |
604 |
|
622 | |||
605 | def test_reminders_for_users |
|
623 | def test_reminders_for_users | |
606 | Mailer.reminders(:days => 42, :users => ['5']) |
|
624 | Mailer.reminders(:days => 42, :users => ['5']) | |
607 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
625 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper | |
608 | Mailer.reminders(:days => 42, :users => ['3']) |
|
626 | Mailer.reminders(:days => 42, :users => ['3']) | |
609 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
627 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper | |
610 | mail = last_email |
|
628 | mail = last_email | |
611 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
629 | assert mail.bcc.include?('dlopper@somenet.foo') | |
612 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail |
|
630 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail | |
613 | end |
|
631 | end | |
614 |
|
632 | |||
615 | def test_reminder_should_include_issues_assigned_to_groups |
|
633 | def test_reminder_should_include_issues_assigned_to_groups | |
616 | with_settings :default_language => 'en' do |
|
634 | with_settings :default_language => 'en' do | |
617 | group = Group.generate! |
|
635 | group = Group.generate! | |
618 | group.users << User.find(2) |
|
636 | group.users << User.find(2) | |
619 | group.users << User.find(3) |
|
637 | group.users << User.find(3) | |
620 |
|
638 | |||
621 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, |
|
639 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, | |
622 | :subject => 'Assigned to group', :assigned_to => group, |
|
640 | :subject => 'Assigned to group', :assigned_to => group, | |
623 | :due_date => 5.days.from_now, |
|
641 | :due_date => 5.days.from_now, | |
624 | :author_id => 2) |
|
642 | :author_id => 2) | |
625 | ActionMailer::Base.deliveries.clear |
|
643 | ActionMailer::Base.deliveries.clear | |
626 |
|
644 | |||
627 | Mailer.reminders(:days => 7) |
|
645 | Mailer.reminders(:days => 7) | |
628 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
646 | assert_equal 2, ActionMailer::Base.deliveries.size | |
629 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort |
|
647 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort | |
630 | ActionMailer::Base.deliveries.each do |mail| |
|
648 | ActionMailer::Base.deliveries.each do |mail| | |
631 | assert_mail_body_match 'Assigned to group', mail |
|
649 | assert_mail_body_match 'Assigned to group', mail | |
632 | end |
|
650 | end | |
633 | end |
|
651 | end | |
634 | end |
|
652 | end | |
635 |
|
653 | |||
636 | def test_reminders_with_version_option |
|
654 | def test_reminders_with_version_option | |
637 | with_settings :default_language => 'en' do |
|
655 | with_settings :default_language => 'en' do | |
638 | version = Version.generate!(:name => 'Acme', :project_id => 1) |
|
656 | version = Version.generate!(:name => 'Acme', :project_id => 1) | |
639 | Issue.generate!(:assigned_to => User.find(2), :due_date => 5.days.from_now) |
|
657 | Issue.generate!(:assigned_to => User.find(2), :due_date => 5.days.from_now) | |
640 | Issue.generate!(:assigned_to => User.find(3), :due_date => 5.days.from_now, :fixed_version => version) |
|
658 | Issue.generate!(:assigned_to => User.find(3), :due_date => 5.days.from_now, :fixed_version => version) | |
641 | ActionMailer::Base.deliveries.clear |
|
659 | ActionMailer::Base.deliveries.clear | |
642 |
|
660 | |||
643 | Mailer.reminders(:days => 42, :version => 'acme') |
|
661 | Mailer.reminders(:days => 42, :version => 'acme') | |
644 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
662 | assert_equal 1, ActionMailer::Base.deliveries.size | |
645 |
|
663 | |||
646 | mail = last_email |
|
664 | mail = last_email | |
647 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
665 | assert mail.bcc.include?('dlopper@somenet.foo') | |
648 | end |
|
666 | end | |
649 | end |
|
667 | end | |
650 |
|
668 | |||
651 | def test_mailer_should_not_change_locale |
|
669 | def test_mailer_should_not_change_locale | |
652 | # Set current language to italian |
|
670 | # Set current language to italian | |
653 | set_language_if_valid 'it' |
|
671 | set_language_if_valid 'it' | |
654 | # Send an email to a french user |
|
672 | # Send an email to a french user | |
655 | user = User.find(1) |
|
673 | user = User.find(1) | |
656 | user.language = 'fr' |
|
674 | user.language = 'fr' | |
657 | Mailer.account_activated(user).deliver |
|
675 | Mailer.account_activated(user).deliver | |
658 | mail = last_email |
|
676 | mail = last_email | |
659 | assert_mail_body_match 'Votre compte', mail |
|
677 | assert_mail_body_match 'Votre compte', mail | |
660 |
|
678 | |||
661 | assert_equal :it, current_language |
|
679 | assert_equal :it, current_language | |
662 | end |
|
680 | end | |
663 |
|
681 | |||
664 | def test_with_deliveries_off |
|
682 | def test_with_deliveries_off | |
665 | Mailer.with_deliveries false do |
|
683 | Mailer.with_deliveries false do | |
666 | Mailer.test_email(User.find(1)).deliver |
|
684 | Mailer.test_email(User.find(1)).deliver | |
667 | end |
|
685 | end | |
668 | assert ActionMailer::Base.deliveries.empty? |
|
686 | assert ActionMailer::Base.deliveries.empty? | |
669 | # should restore perform_deliveries |
|
687 | # should restore perform_deliveries | |
670 | assert ActionMailer::Base.perform_deliveries |
|
688 | assert ActionMailer::Base.perform_deliveries | |
671 | end |
|
689 | end | |
672 |
|
690 | |||
673 | def test_token_for_should_strip_trailing_gt_from_address_with_full_name |
|
691 | def test_token_for_should_strip_trailing_gt_from_address_with_full_name | |
674 | with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do |
|
692 | with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do | |
675 | assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!) |
|
693 | assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!) | |
676 | end |
|
694 | end | |
677 | end |
|
695 | end | |
678 |
|
696 | |||
679 | def test_layout_should_include_the_emails_header |
|
697 | def test_layout_should_include_the_emails_header | |
680 | with_settings :emails_header => "*Header content*" do |
|
698 | with_settings :emails_header => "*Header content*" do | |
681 | with_settings :plain_text_mail => 0 do |
|
699 | with_settings :plain_text_mail => 0 do | |
682 | assert Mailer.test_email(User.find(1)).deliver |
|
700 | assert Mailer.test_email(User.find(1)).deliver | |
683 | assert_select_email do |
|
701 | assert_select_email do | |
684 | assert_select ".header" do |
|
702 | assert_select ".header" do | |
685 | assert_select "strong", :text => "Header content" |
|
703 | assert_select "strong", :text => "Header content" | |
686 | end |
|
704 | end | |
687 | end |
|
705 | end | |
688 | end |
|
706 | end | |
689 | with_settings :plain_text_mail => 1 do |
|
707 | with_settings :plain_text_mail => 1 do | |
690 | assert Mailer.test_email(User.find(1)).deliver |
|
708 | assert Mailer.test_email(User.find(1)).deliver | |
691 | mail = last_email |
|
709 | mail = last_email | |
692 | assert_not_nil mail |
|
710 | assert_not_nil mail | |
693 | assert_include "*Header content*", mail.body.decoded |
|
711 | assert_include "*Header content*", mail.body.decoded | |
694 | end |
|
712 | end | |
695 | end |
|
713 | end | |
696 | end |
|
714 | end | |
697 |
|
715 | |||
698 | def test_layout_should_not_include_empty_emails_header |
|
716 | def test_layout_should_not_include_empty_emails_header | |
699 | with_settings :emails_header => "", :plain_text_mail => 0 do |
|
717 | with_settings :emails_header => "", :plain_text_mail => 0 do | |
700 | assert Mailer.test_email(User.find(1)).deliver |
|
718 | assert Mailer.test_email(User.find(1)).deliver | |
701 | assert_select_email do |
|
719 | assert_select_email do | |
702 | assert_select ".header", false |
|
720 | assert_select ".header", false | |
703 | end |
|
721 | end | |
704 | end |
|
722 | end | |
705 | end |
|
723 | end | |
706 |
|
724 | |||
707 | def test_layout_should_include_the_emails_footer |
|
725 | def test_layout_should_include_the_emails_footer | |
708 | with_settings :emails_footer => "*Footer content*" do |
|
726 | with_settings :emails_footer => "*Footer content*" do | |
709 | with_settings :plain_text_mail => 0 do |
|
727 | with_settings :plain_text_mail => 0 do | |
710 | assert Mailer.test_email(User.find(1)).deliver |
|
728 | assert Mailer.test_email(User.find(1)).deliver | |
711 | assert_select_email do |
|
729 | assert_select_email do | |
712 | assert_select ".footer" do |
|
730 | assert_select ".footer" do | |
713 | assert_select "strong", :text => "Footer content" |
|
731 | assert_select "strong", :text => "Footer content" | |
714 | end |
|
732 | end | |
715 | end |
|
733 | end | |
716 | end |
|
734 | end | |
717 | with_settings :plain_text_mail => 1 do |
|
735 | with_settings :plain_text_mail => 1 do | |
718 | assert Mailer.test_email(User.find(1)).deliver |
|
736 | assert Mailer.test_email(User.find(1)).deliver | |
719 | mail = last_email |
|
737 | mail = last_email | |
720 | assert_not_nil mail |
|
738 | assert_not_nil mail | |
721 | assert_include "\n-- \n", mail.body.decoded |
|
739 | assert_include "\n-- \n", mail.body.decoded | |
722 | assert_include "*Footer content*", mail.body.decoded |
|
740 | assert_include "*Footer content*", mail.body.decoded | |
723 | end |
|
741 | end | |
724 | end |
|
742 | end | |
725 | end |
|
743 | end | |
726 |
|
744 | |||
727 | def test_layout_should_not_include_empty_emails_footer |
|
745 | def test_layout_should_not_include_empty_emails_footer | |
728 | with_settings :emails_footer => "" do |
|
746 | with_settings :emails_footer => "" do | |
729 | with_settings :plain_text_mail => 0 do |
|
747 | with_settings :plain_text_mail => 0 do | |
730 | assert Mailer.test_email(User.find(1)).deliver |
|
748 | assert Mailer.test_email(User.find(1)).deliver | |
731 | assert_select_email do |
|
749 | assert_select_email do | |
732 | assert_select ".footer", false |
|
750 | assert_select ".footer", false | |
733 | end |
|
751 | end | |
734 | end |
|
752 | end | |
735 | with_settings :plain_text_mail => 1 do |
|
753 | with_settings :plain_text_mail => 1 do | |
736 | assert Mailer.test_email(User.find(1)).deliver |
|
754 | assert Mailer.test_email(User.find(1)).deliver | |
737 | mail = last_email |
|
755 | mail = last_email | |
738 | assert_not_nil mail |
|
756 | assert_not_nil mail | |
739 | assert_not_include "\n-- \n", mail.body.decoded |
|
757 | assert_not_include "\n-- \n", mail.body.decoded | |
740 | end |
|
758 | end | |
741 | end |
|
759 | end | |
742 | end |
|
760 | end | |
743 |
|
761 | |||
744 | def test_should_escape_html_templates_only |
|
762 | def test_should_escape_html_templates_only | |
745 | Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>') |
|
763 | Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>') | |
746 | mail = last_email |
|
764 | mail = last_email | |
747 | assert_equal 2, mail.parts.size |
|
765 | assert_equal 2, mail.parts.size | |
748 | assert_include '<tag>', text_part.body.encoded |
|
766 | assert_include '<tag>', text_part.body.encoded | |
749 | assert_include '<tag>', html_part.body.encoded |
|
767 | assert_include '<tag>', html_part.body.encoded | |
750 | end |
|
768 | end | |
751 |
|
769 | |||
752 | def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true |
|
770 | def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true | |
753 | mail = Mailer.test_email(User.find(1)) |
|
771 | mail = Mailer.test_email(User.find(1)) | |
754 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) |
|
772 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) | |
755 |
|
773 | |||
756 | ActionMailer::Base.raise_delivery_errors = true |
|
774 | ActionMailer::Base.raise_delivery_errors = true | |
757 | assert_raise Exception, "delivery error" do |
|
775 | assert_raise Exception, "delivery error" do | |
758 | mail.deliver |
|
776 | mail.deliver | |
759 | end |
|
777 | end | |
760 | ensure |
|
778 | ensure | |
761 | ActionMailer::Base.raise_delivery_errors = false |
|
779 | ActionMailer::Base.raise_delivery_errors = false | |
762 | end |
|
780 | end | |
763 |
|
781 | |||
764 | def test_should_log_delivery_errors_when_raise_delivery_errors_is_false |
|
782 | def test_should_log_delivery_errors_when_raise_delivery_errors_is_false | |
765 | mail = Mailer.test_email(User.find(1)) |
|
783 | mail = Mailer.test_email(User.find(1)) | |
766 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) |
|
784 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) | |
767 |
|
785 | |||
768 | Rails.logger.expects(:error).with("Email delivery error: delivery error") |
|
786 | Rails.logger.expects(:error).with("Email delivery error: delivery error") | |
769 | ActionMailer::Base.raise_delivery_errors = false |
|
787 | ActionMailer::Base.raise_delivery_errors = false | |
770 | assert_nothing_raised do |
|
788 | assert_nothing_raised do | |
771 | mail.deliver |
|
789 | mail.deliver | |
772 | end |
|
790 | end | |
773 | end |
|
791 | end | |
774 |
|
792 | |||
775 | def test_with_synched_deliveries_should_yield_with_synced_deliveries |
|
793 | def test_with_synched_deliveries_should_yield_with_synced_deliveries | |
776 | ActionMailer::Base.delivery_method = :async_smtp |
|
794 | ActionMailer::Base.delivery_method = :async_smtp | |
777 | ActionMailer::Base.async_smtp_settings = {:foo => 'bar'} |
|
795 | ActionMailer::Base.async_smtp_settings = {:foo => 'bar'} | |
778 |
|
796 | |||
779 | Mailer.with_synched_deliveries do |
|
797 | Mailer.with_synched_deliveries do | |
780 | assert_equal :smtp, ActionMailer::Base.delivery_method |
|
798 | assert_equal :smtp, ActionMailer::Base.delivery_method | |
781 | assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings) |
|
799 | assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings) | |
782 | end |
|
800 | end | |
783 | assert_equal :async_smtp, ActionMailer::Base.delivery_method |
|
801 | assert_equal :async_smtp, ActionMailer::Base.delivery_method | |
784 | ensure |
|
802 | ensure | |
785 | ActionMailer::Base.delivery_method = :test |
|
803 | ActionMailer::Base.delivery_method = :test | |
786 | end |
|
804 | end | |
787 |
|
805 | |||
788 | def test_email_addresses_should_keep_addresses |
|
806 | def test_email_addresses_should_keep_addresses | |
789 | assert_equal ["foo@example.net"], |
|
807 | assert_equal ["foo@example.net"], | |
790 | Mailer.email_addresses("foo@example.net") |
|
808 | Mailer.email_addresses("foo@example.net") | |
791 |
|
809 | |||
792 | assert_equal ["foo@example.net", "bar@example.net"], |
|
810 | assert_equal ["foo@example.net", "bar@example.net"], | |
793 | Mailer.email_addresses(["foo@example.net", "bar@example.net"]) |
|
811 | Mailer.email_addresses(["foo@example.net", "bar@example.net"]) | |
794 | end |
|
812 | end | |
795 |
|
813 | |||
796 | def test_email_addresses_should_replace_users_with_their_email_addresses |
|
814 | def test_email_addresses_should_replace_users_with_their_email_addresses | |
797 | assert_equal ["admin@somenet.foo"], |
|
815 | assert_equal ["admin@somenet.foo"], | |
798 | Mailer.email_addresses(User.find(1)) |
|
816 | Mailer.email_addresses(User.find(1)) | |
799 |
|
817 | |||
800 | assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"], |
|
818 | assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"], | |
801 | Mailer.email_addresses(User.where(:id => [1,2])).sort |
|
819 | Mailer.email_addresses(User.where(:id => [1,2])).sort | |
802 | end |
|
820 | end | |
803 |
|
821 | |||
804 | def test_email_addresses_should_include_notified_emails_addresses_only |
|
822 | def test_email_addresses_should_include_notified_emails_addresses_only | |
805 | EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false) |
|
823 | EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false) | |
806 | EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo") |
|
824 | EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo") | |
807 |
|
825 | |||
808 | assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"], |
|
826 | assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"], | |
809 | Mailer.email_addresses(User.find(2)).sort |
|
827 | Mailer.email_addresses(User.find(2)).sort | |
810 | end |
|
828 | end | |
811 |
|
829 | |||
812 | private |
|
830 | private | |
813 |
|
831 | |||
814 | def last_email |
|
832 | def last_email | |
815 | mail = ActionMailer::Base.deliveries.last |
|
833 | mail = ActionMailer::Base.deliveries.last | |
816 | assert_not_nil mail |
|
834 | assert_not_nil mail | |
817 |
|
835 | |||
818 | end |
|
836 | end | |
819 |
|
837 | |||
820 | def text_part |
|
838 | def text_part | |
821 | last_email.parts.detect {|part| part.content_type.include?('text/plain')} |
|
839 | last_email.parts.detect {|part| part.content_type.include?('text/plain')} | |
822 | end |
|
840 | end | |
823 |
|
841 | |||
824 | def html_part |
|
842 | def html_part | |
825 | last_email.parts.detect {|part| part.content_type.include?('text/html')} |
|
843 | last_email.parts.detect {|part| part.content_type.include?('text/html')} | |
826 | end |
|
844 | end | |
827 |
|
845 | |||
828 | def with_each_language_as_default(&block) |
|
846 | def with_each_language_as_default(&block) | |
829 | valid_languages.each do |lang| |
|
847 | valid_languages.each do |lang| | |
830 | with_settings :default_language => lang.to_s do |
|
848 | with_settings :default_language => lang.to_s do | |
831 | yield lang |
|
849 | yield lang | |
832 | end |
|
850 | end | |
833 | end |
|
851 | end | |
834 | end |
|
852 | end | |
835 | end |
|
853 | end |
General Comments 0
You need to be logged in to leave comments.
Login now