Mercurial > hg > soundsoftware-site
comparison test/unit/mailer_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 5f33065ddc4b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
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 ActionController::Assertions::SelectorAssertions | 22 include ActionController::Assertions::SelectorAssertions |
23 fixtures :all | 23 fixtures :projects, :enabled_modules, :issues, :users, :members, |
24 | 24 :member_roles, :roles, :documents, :attachments, :news, |
25 :tokens, :journals, :journal_details, :changesets, :trackers, | |
26 :issue_statuses, :enumerations, :messages, :boards, :repositories, | |
27 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, | |
28 :versions, | |
29 :comments | |
30 | |
25 def setup | 31 def setup |
26 ActionMailer::Base.deliveries.clear | 32 ActionMailer::Base.deliveries.clear |
27 Setting.host_name = 'mydomain.foo' | 33 Setting.host_name = 'mydomain.foo' |
28 Setting.protocol = 'http' | 34 Setting.protocol = 'http' |
29 Setting.plain_text_mail = '0' | 35 Setting.plain_text_mail = '0' |
30 end | 36 end |
31 | 37 |
32 def test_generated_links_in_emails | 38 def test_generated_links_in_emails |
33 Setting.host_name = 'mydomain.foo' | 39 Setting.host_name = 'mydomain.foo' |
34 Setting.protocol = 'https' | 40 Setting.protocol = 'https' |
35 | 41 |
36 journal = Journal.find(2) | 42 journal = Journal.find(2) |
37 assert Mailer.deliver_issue_edit(journal) | 43 assert Mailer.deliver_issue_edit(journal) |
38 | 44 |
39 mail = ActionMailer::Base.deliveries.last | 45 mail = ActionMailer::Base.deliveries.last |
40 assert_kind_of TMail::Mail, mail | 46 assert_kind_of TMail::Mail, mail |
41 | 47 |
42 assert_select_email do | 48 assert_select_email do |
43 # link to the main ticket | 49 # link to the main ticket |
44 assert_select "a[href=?]", "https://mydomain.foo/issues/1", :text => "Bug #1: Can't print recipes" | 50 assert_select "a[href=?]", |
51 "https://mydomain.foo/issues/1#change-2", | |
52 :text => "Bug #1: Can't print recipes" | |
45 # link to a referenced ticket | 53 # link to a referenced ticket |
46 assert_select "a[href=?][title=?]", "https://mydomain.foo/issues/2", "Add ingredients categories (Assigned)", :text => "#2" | 54 assert_select "a[href=?][title=?]", |
55 "https://mydomain.foo/issues/2", | |
56 "Add ingredients categories (Assigned)", | |
57 :text => "#2" | |
47 # link to a changeset | 58 # link to a changeset |
48 assert_select "a[href=?][title=?]", "https://mydomain.foo/projects/ecookbook/repository/revisions/2", "This commit fixes #1, #2 and references #1 & #3", :text => "r2" | 59 assert_select "a[href=?][title=?]", |
49 end | 60 "https://mydomain.foo/projects/ecookbook/repository/revisions/2", |
50 end | 61 "This commit fixes #1, #2 and references #1 & #3", |
51 | 62 :text => "r2" |
63 end | |
64 end | |
65 | |
52 def test_generated_links_with_prefix | 66 def test_generated_links_with_prefix |
53 relative_url_root = Redmine::Utils.relative_url_root | 67 relative_url_root = Redmine::Utils.relative_url_root |
54 Setting.host_name = 'mydomain.foo/rdm' | 68 Setting.host_name = 'mydomain.foo/rdm' |
55 Setting.protocol = 'http' | 69 Setting.protocol = 'http' |
56 Redmine::Utils.relative_url_root = '/rdm' | 70 Redmine::Utils.relative_url_root = '/rdm' |
57 | 71 |
58 journal = Journal.find(2) | 72 journal = Journal.find(2) |
59 assert Mailer.deliver_issue_edit(journal) | 73 assert Mailer.deliver_issue_edit(journal) |
60 | 74 |
61 mail = ActionMailer::Base.deliveries.last | 75 mail = ActionMailer::Base.deliveries.last |
62 assert_kind_of TMail::Mail, mail | 76 assert_kind_of TMail::Mail, mail |
63 | 77 |
64 assert_select_email do | 78 assert_select_email do |
65 # link to the main ticket | 79 # link to the main ticket |
66 assert_select "a[href=?]", "http://mydomain.foo/rdm/issues/1", :text => "Bug #1: Can't print recipes" | 80 assert_select "a[href=?]", |
81 "http://mydomain.foo/rdm/issues/1#change-2", | |
82 :text => "Bug #1: Can't print recipes" | |
67 # link to a referenced ticket | 83 # link to a referenced ticket |
68 assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/issues/2", "Add ingredients categories (Assigned)", :text => "#2" | 84 assert_select "a[href=?][title=?]", |
85 "http://mydomain.foo/rdm/issues/2", | |
86 "Add ingredients categories (Assigned)", | |
87 :text => "#2" | |
69 # link to a changeset | 88 # link to a changeset |
70 assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", "This commit fixes #1, #2 and references #1 & #3", :text => "r2" | 89 assert_select "a[href=?][title=?]", |
90 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", | |
91 "This commit fixes #1, #2 and references #1 & #3", | |
92 :text => "r2" | |
71 end | 93 end |
72 ensure | 94 ensure |
73 # restore it | 95 # restore it |
74 Redmine::Utils.relative_url_root = relative_url_root | 96 Redmine::Utils.relative_url_root = relative_url_root |
75 end | 97 end |
76 | 98 |
77 def test_generated_links_with_prefix_and_no_relative_url_root | 99 def test_generated_links_with_prefix_and_no_relative_url_root |
78 relative_url_root = Redmine::Utils.relative_url_root | 100 relative_url_root = Redmine::Utils.relative_url_root |
79 Setting.host_name = 'mydomain.foo/rdm' | 101 Setting.host_name = 'mydomain.foo/rdm' |
80 Setting.protocol = 'http' | 102 Setting.protocol = 'http' |
81 Redmine::Utils.relative_url_root = nil | 103 Redmine::Utils.relative_url_root = nil |
82 | 104 |
83 journal = Journal.find(2) | 105 journal = Journal.find(2) |
84 assert Mailer.deliver_issue_edit(journal) | 106 assert Mailer.deliver_issue_edit(journal) |
85 | 107 |
86 mail = ActionMailer::Base.deliveries.last | 108 mail = ActionMailer::Base.deliveries.last |
87 assert_kind_of TMail::Mail, mail | 109 assert_kind_of TMail::Mail, mail |
88 | 110 |
89 assert_select_email do | 111 assert_select_email do |
90 # link to the main ticket | 112 # link to the main ticket |
91 assert_select "a[href=?]", "http://mydomain.foo/rdm/issues/1", :text => "Bug #1: Can't print recipes" | 113 assert_select "a[href=?]", |
114 "http://mydomain.foo/rdm/issues/1#change-2", | |
115 :text => "Bug #1: Can't print recipes" | |
92 # link to a referenced ticket | 116 # link to a referenced ticket |
93 assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/issues/2", "Add ingredients categories (Assigned)", :text => "#2" | 117 assert_select "a[href=?][title=?]", |
118 "http://mydomain.foo/rdm/issues/2", | |
119 "Add ingredients categories (Assigned)", | |
120 :text => "#2" | |
94 # link to a changeset | 121 # link to a changeset |
95 assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", "This commit fixes #1, #2 and references #1 & #3", :text => "r2" | 122 assert_select "a[href=?][title=?]", |
123 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", | |
124 "This commit fixes #1, #2 and references #1 & #3", | |
125 :text => "r2" | |
96 end | 126 end |
97 ensure | 127 ensure |
98 # restore it | 128 # restore it |
99 Redmine::Utils.relative_url_root = relative_url_root | 129 Redmine::Utils.relative_url_root = relative_url_root |
100 end | 130 end |
101 | 131 |
102 def test_email_headers | 132 def test_email_headers |
103 issue = Issue.find(1) | 133 issue = Issue.find(1) |
104 Mailer.deliver_issue_add(issue) | 134 Mailer.deliver_issue_add(issue) |
105 mail = ActionMailer::Base.deliveries.last | 135 mail = ActionMailer::Base.deliveries.last |
106 assert_not_nil mail | 136 assert_not_nil mail |
107 assert_equal 'bulk', mail.header_string('Precedence') | 137 assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress') |
108 assert_equal 'auto-generated', mail.header_string('Auto-Submitted') | 138 assert_equal 'auto-generated', mail.header_string('Auto-Submitted') |
109 end | 139 end |
110 | 140 |
111 def test_plain_text_mail | 141 def test_plain_text_mail |
112 Setting.plain_text_mail = 1 | 142 Setting.plain_text_mail = 1 |
124 Mailer.deliver_issue_edit(journal) | 154 Mailer.deliver_issue_edit(journal) |
125 mail = ActionMailer::Base.deliveries.last | 155 mail = ActionMailer::Base.deliveries.last |
126 assert_equal 2, mail.parts.size | 156 assert_equal 2, mail.parts.size |
127 assert mail.encoded.include?('href') | 157 assert mail.encoded.include?('href') |
128 end | 158 end |
129 | 159 |
130 def test_mail_from_with_phrase | 160 def test_from_header |
161 with_settings :mail_from => 'redmine@example.net' do | |
162 Mailer.deliver_test(User.find(1)) | |
163 end | |
164 mail = ActionMailer::Base.deliveries.last | |
165 assert_not_nil mail | |
166 assert_equal 'redmine@example.net', mail.from_addrs.first.address | |
167 end | |
168 | |
169 def test_from_header_with_phrase | |
131 with_settings :mail_from => 'Redmine app <redmine@example.net>' do | 170 with_settings :mail_from => 'Redmine app <redmine@example.net>' do |
132 Mailer.deliver_test(User.find(1)) | 171 Mailer.deliver_test(User.find(1)) |
133 end | 172 end |
134 mail = ActionMailer::Base.deliveries.last | 173 mail = ActionMailer::Base.deliveries.last |
135 assert_not_nil mail | 174 assert_not_nil mail |
175 assert_equal 'redmine@example.net', mail.from_addrs.first.address | |
136 assert_equal 'Redmine app', mail.from_addrs.first.name | 176 assert_equal 'Redmine app', mail.from_addrs.first.name |
137 end | 177 end |
138 | 178 |
139 def test_should_not_send_email_without_recipient | 179 def test_should_not_send_email_without_recipient |
140 news = News.find(:first) | 180 news = News.find(:first) |
141 user = news.author | 181 user = news.author |
142 # Remove members except news author | 182 # Remove members except news author |
143 news.project.memberships.each {|m| m.destroy unless m.user == user} | 183 news.project.memberships.each {|m| m.destroy unless m.user == user} |
144 | 184 |
145 user.pref[:no_self_notified] = false | 185 user.pref[:no_self_notified] = false |
146 user.pref.save | 186 user.pref.save |
147 User.current = user | 187 User.current = user |
148 Mailer.deliver_news_added(news.reload) | 188 Mailer.deliver_news_added(news.reload) |
149 assert_equal 1, last_email.bcc.size | 189 assert_equal 1, last_email.bcc.size |
163 mail = ActionMailer::Base.deliveries.last | 203 mail = ActionMailer::Base.deliveries.last |
164 assert_not_nil mail | 204 assert_not_nil mail |
165 assert_equal Mailer.message_id_for(issue), mail.message_id | 205 assert_equal Mailer.message_id_for(issue), mail.message_id |
166 assert_nil mail.references | 206 assert_nil mail.references |
167 end | 207 end |
168 | 208 |
169 def test_issue_edit_message_id | 209 def test_issue_edit_message_id |
170 journal = Journal.find(1) | 210 journal = Journal.find(1) |
171 Mailer.deliver_issue_edit(journal) | 211 Mailer.deliver_issue_edit(journal) |
172 mail = ActionMailer::Base.deliveries.last | 212 mail = ActionMailer::Base.deliveries.last |
173 assert_not_nil mail | 213 assert_not_nil mail |
174 assert_equal Mailer.message_id_for(journal), mail.message_id | 214 assert_equal Mailer.message_id_for(journal), mail.message_id |
175 assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s | 215 assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s |
176 end | 216 assert_select_email do |
177 | 217 # link to the update |
218 assert_select "a[href=?]", | |
219 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" | |
220 end | |
221 end | |
222 | |
178 def test_message_posted_message_id | 223 def test_message_posted_message_id |
179 message = Message.find(1) | 224 message = Message.find(1) |
180 Mailer.deliver_message_posted(message) | 225 Mailer.deliver_message_posted(message) |
181 mail = ActionMailer::Base.deliveries.last | 226 mail = ActionMailer::Base.deliveries.last |
182 assert_not_nil mail | 227 assert_not_nil mail |
183 assert_equal Mailer.message_id_for(message), mail.message_id | 228 assert_equal Mailer.message_id_for(message), mail.message_id |
184 assert_nil mail.references | 229 assert_nil mail.references |
185 assert_select_email do | 230 assert_select_email do |
186 # link to the message | 231 # link to the message |
187 assert_select "a[href=?]", "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", :text => message.subject | 232 assert_select "a[href=?]", |
188 end | 233 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", |
189 end | 234 :text => message.subject |
190 | 235 end |
236 end | |
237 | |
191 def test_reply_posted_message_id | 238 def test_reply_posted_message_id |
192 message = Message.find(3) | 239 message = Message.find(3) |
193 Mailer.deliver_message_posted(message) | 240 Mailer.deliver_message_posted(message) |
194 mail = ActionMailer::Base.deliveries.last | 241 mail = ActionMailer::Base.deliveries.last |
195 assert_not_nil mail | 242 assert_not_nil mail |
196 assert_equal Mailer.message_id_for(message), mail.message_id | 243 assert_equal Mailer.message_id_for(message), mail.message_id |
197 assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s | 244 assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s |
198 assert_select_email do | 245 assert_select_email do |
199 # link to the reply | 246 # link to the reply |
200 assert_select "a[href=?]", "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", :text => message.subject | 247 assert_select "a[href=?]", |
201 end | 248 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
202 end | 249 :text => message.subject |
203 | 250 end |
251 end | |
252 | |
204 context("#issue_add") do | 253 context("#issue_add") do |
205 setup do | 254 setup do |
206 ActionMailer::Base.deliveries.clear | 255 ActionMailer::Base.deliveries.clear |
207 Setting.bcc_recipients = '1' | 256 Setting.bcc_recipients = '1' |
208 @issue = Issue.find(1) | 257 @issue = Issue.find(1) |
209 end | 258 end |
210 | 259 |
211 should "notify project members" do | 260 should "notify project members" do |
212 assert Mailer.deliver_issue_add(@issue) | 261 assert Mailer.deliver_issue_add(@issue) |
213 assert last_email.bcc.include?('dlopper@somenet.foo') | 262 assert last_email.bcc.include?('dlopper@somenet.foo') |
214 end | 263 end |
215 | 264 |
216 should "not notify project members that are not allow to view the issue" do | 265 should "not notify project members that are not allow to view the issue" do |
217 Role.find(2).remove_permission!(:view_issues) | 266 Role.find(2).remove_permission!(:view_issues) |
218 assert Mailer.deliver_issue_add(@issue) | 267 assert Mailer.deliver_issue_add(@issue) |
219 assert !last_email.bcc.include?('dlopper@somenet.foo') | 268 assert !last_email.bcc.include?('dlopper@somenet.foo') |
220 end | 269 end |
221 | 270 |
222 should "notify issue watchers" do | 271 should "notify issue watchers" do |
223 user = User.find(9) | 272 user = User.find(9) |
224 # minimal email notification options | 273 # minimal email notification options |
225 user.pref[:no_self_notified] = '1' | 274 user.pref[:no_self_notified] = '1' |
226 user.pref.save | 275 user.pref.save |
227 user.mail_notification = false | 276 user.mail_notification = false |
228 user.save | 277 user.save |
229 | 278 |
230 Watcher.create!(:watchable => @issue, :user => user) | 279 Watcher.create!(:watchable => @issue, :user => user) |
231 assert Mailer.deliver_issue_add(@issue) | 280 assert Mailer.deliver_issue_add(@issue) |
232 assert last_email.bcc.include?(user.mail) | 281 assert last_email.bcc.include?(user.mail) |
233 end | 282 end |
234 | 283 |
235 should "not notify watchers not allowed to view the issue" do | 284 should "not notify watchers not allowed to view the issue" do |
236 user = User.find(9) | 285 user = User.find(9) |
237 Watcher.create!(:watchable => @issue, :user => user) | 286 Watcher.create!(:watchable => @issue, :user => user) |
238 Role.non_member.remove_permission!(:view_issues) | 287 Role.non_member.remove_permission!(:view_issues) |
239 assert Mailer.deliver_issue_add(@issue) | 288 assert Mailer.deliver_issue_add(@issue) |
240 assert !last_email.bcc.include?(user.mail) | 289 assert !last_email.bcc.include?(user.mail) |
241 end | 290 end |
242 end | 291 end |
243 | 292 |
244 # test mailer methods for each language | 293 # test mailer methods for each language |
245 def test_issue_add | 294 def test_issue_add |
246 issue = Issue.find(1) | 295 issue = Issue.find(1) |
247 valid_languages.each do |lang| | 296 valid_languages.each do |lang| |
248 Setting.default_language = lang.to_s | 297 Setting.default_language = lang.to_s |
255 valid_languages.each do |lang| | 304 valid_languages.each do |lang| |
256 Setting.default_language = lang.to_s | 305 Setting.default_language = lang.to_s |
257 assert Mailer.deliver_issue_edit(journal) | 306 assert Mailer.deliver_issue_edit(journal) |
258 end | 307 end |
259 end | 308 end |
260 | 309 |
261 def test_document_added | 310 def test_document_added |
262 document = Document.find(1) | 311 document = Document.find(1) |
263 valid_languages.each do |lang| | 312 valid_languages.each do |lang| |
264 Setting.default_language = lang.to_s | 313 Setting.default_language = lang.to_s |
265 assert Mailer.deliver_document_added(document) | 314 assert Mailer.deliver_document_added(document) |
266 end | 315 end |
267 end | 316 end |
268 | 317 |
269 def test_attachments_added | 318 def test_attachments_added |
270 attachements = [ Attachment.find_by_container_type('Document') ] | 319 attachements = [ Attachment.find_by_container_type('Document') ] |
271 valid_languages.each do |lang| | 320 valid_languages.each do |lang| |
272 Setting.default_language = lang.to_s | 321 Setting.default_language = lang.to_s |
273 assert Mailer.deliver_attachments_added(attachements) | 322 assert Mailer.deliver_attachments_added(attachements) |
274 end | 323 end |
275 end | 324 end |
276 | 325 |
277 def test_version_file_added | 326 def test_version_file_added |
278 attachements = [ Attachment.find_by_container_type('Version') ] | 327 attachements = [ Attachment.find_by_container_type('Version') ] |
279 assert Mailer.deliver_attachments_added(attachements) | 328 assert Mailer.deliver_attachments_added(attachements) |
280 assert_not_nil last_email.bcc | 329 assert_not_nil last_email.bcc |
281 assert last_email.bcc.any? | 330 assert last_email.bcc.any? |
282 assert_select_email do | 331 assert_select_email do |
283 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | 332 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
284 end | 333 end |
285 end | 334 end |
286 | 335 |
287 def test_project_file_added | 336 def test_project_file_added |
288 attachements = [ Attachment.find_by_container_type('Project') ] | 337 attachements = [ Attachment.find_by_container_type('Project') ] |
289 assert Mailer.deliver_attachments_added(attachements) | 338 assert Mailer.deliver_attachments_added(attachements) |
290 assert_not_nil last_email.bcc | 339 assert_not_nil last_email.bcc |
291 assert last_email.bcc.any? | 340 assert last_email.bcc.any? |
292 assert_select_email do | 341 assert_select_email do |
293 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | 342 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
294 end | 343 end |
295 end | 344 end |
296 | 345 |
297 def test_news_added | 346 def test_news_added |
298 news = News.find(:first) | 347 news = News.find(:first) |
299 valid_languages.each do |lang| | 348 valid_languages.each do |lang| |
300 Setting.default_language = lang.to_s | 349 Setting.default_language = lang.to_s |
301 assert Mailer.deliver_news_added(news) | 350 assert Mailer.deliver_news_added(news) |
302 end | 351 end |
303 end | 352 end |
304 | 353 |
305 def test_news_comment_added | 354 def test_news_comment_added |
306 comment = Comment.find(2) | 355 comment = Comment.find(2) |
307 valid_languages.each do |lang| | 356 valid_languages.each do |lang| |
308 Setting.default_language = lang.to_s | 357 Setting.default_language = lang.to_s |
309 assert Mailer.deliver_news_comment_added(comment) | 358 assert Mailer.deliver_news_comment_added(comment) |
310 end | 359 end |
311 end | 360 end |
312 | 361 |
313 def test_message_posted | 362 def test_message_posted |
314 message = Message.find(:first) | 363 message = Message.find(:first) |
315 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} | 364 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
316 recipients = recipients.compact.uniq | 365 recipients = recipients.compact.uniq |
317 valid_languages.each do |lang| | 366 valid_languages.each do |lang| |
318 Setting.default_language = lang.to_s | 367 Setting.default_language = lang.to_s |
319 assert Mailer.deliver_message_posted(message) | 368 assert Mailer.deliver_message_posted(message) |
320 end | 369 end |
321 end | 370 end |
322 | 371 |
323 def test_wiki_content_added | 372 def test_wiki_content_added |
324 content = WikiContent.find(:first) | 373 content = WikiContent.find(:first) |
325 valid_languages.each do |lang| | 374 valid_languages.each do |lang| |
326 Setting.default_language = lang.to_s | 375 Setting.default_language = lang.to_s |
327 assert_difference 'ActionMailer::Base.deliveries.size' do | 376 assert_difference 'ActionMailer::Base.deliveries.size' do |
328 assert Mailer.deliver_wiki_content_added(content) | 377 assert Mailer.deliver_wiki_content_added(content) |
329 end | 378 end |
330 end | 379 end |
331 end | 380 end |
332 | 381 |
333 def test_wiki_content_updated | 382 def test_wiki_content_updated |
334 content = WikiContent.find(:first) | 383 content = WikiContent.find(:first) |
335 valid_languages.each do |lang| | 384 valid_languages.each do |lang| |
336 Setting.default_language = lang.to_s | 385 Setting.default_language = lang.to_s |
337 assert_difference 'ActionMailer::Base.deliveries.size' do | 386 assert_difference 'ActionMailer::Base.deliveries.size' do |
338 assert Mailer.deliver_wiki_content_updated(content) | 387 assert Mailer.deliver_wiki_content_updated(content) |
339 end | 388 end |
340 end | 389 end |
341 end | 390 end |
342 | 391 |
343 def test_account_information | 392 def test_account_information |
344 user = User.find(2) | 393 user = User.find(2) |
345 valid_languages.each do |lang| | 394 valid_languages.each do |lang| |
346 user.update_attribute :language, lang.to_s | 395 user.update_attribute :language, lang.to_s |
347 user.reload | 396 user.reload |
360 | 409 |
361 def test_register | 410 def test_register |
362 token = Token.find(1) | 411 token = Token.find(1) |
363 Setting.host_name = 'redmine.foo' | 412 Setting.host_name = 'redmine.foo' |
364 Setting.protocol = 'https' | 413 Setting.protocol = 'https' |
365 | 414 |
366 valid_languages.each do |lang| | 415 valid_languages.each do |lang| |
367 token.user.update_attribute :language, lang.to_s | 416 token.user.update_attribute :language, lang.to_s |
368 token.reload | 417 token.reload |
369 ActionMailer::Base.deliveries.clear | 418 ActionMailer::Base.deliveries.clear |
370 assert Mailer.deliver_register(token) | 419 assert Mailer.deliver_register(token) |
371 mail = ActionMailer::Base.deliveries.last | 420 mail = ActionMailer::Base.deliveries.last |
372 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}") | 421 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}") |
373 end | 422 end |
374 end | 423 end |
375 | 424 |
376 def test_test | 425 def test_test |
377 user = User.find(1) | 426 user = User.find(1) |
378 valid_languages.each do |lang| | 427 valid_languages.each do |lang| |
379 user.update_attribute :language, lang.to_s | 428 user.update_attribute :language, lang.to_s |
380 assert Mailer.deliver_test(user) | 429 assert Mailer.deliver_test(user) |
381 end | 430 end |
382 end | 431 end |
383 | 432 |
384 def test_reminders | 433 def test_reminders |
385 Mailer.reminders(:days => 42) | 434 Mailer.reminders(:days => 42) |
386 assert_equal 1, ActionMailer::Base.deliveries.size | 435 assert_equal 1, ActionMailer::Base.deliveries.size |
387 mail = ActionMailer::Base.deliveries.last | 436 mail = ActionMailer::Base.deliveries.last |
388 assert mail.bcc.include?('dlopper@somenet.foo') | 437 assert mail.bcc.include?('dlopper@somenet.foo') |
389 assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | 438 assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
390 assert_equal '1 issue(s) due in the next 42 days', mail.subject | 439 assert_equal '1 issue(s) due in the next 42 days', mail.subject |
391 end | 440 end |
392 | 441 |
393 def test_reminders_for_users | 442 def test_reminders_for_users |
394 Mailer.reminders(:days => 42, :users => ['5']) | 443 Mailer.reminders(:days => 42, :users => ['5']) |
395 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper | 444 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper |
396 Mailer.reminders(:days => 42, :users => ['3']) | 445 Mailer.reminders(:days => 42, :users => ['3']) |
397 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper | 446 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper |
398 mail = ActionMailer::Base.deliveries.last | 447 mail = ActionMailer::Base.deliveries.last |
399 assert mail.bcc.include?('dlopper@somenet.foo') | 448 assert mail.bcc.include?('dlopper@somenet.foo') |
400 assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | 449 assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
401 end | 450 end |
402 | 451 |
403 def last_email | 452 def last_email |
404 mail = ActionMailer::Base.deliveries.last | 453 mail = ActionMailer::Base.deliveries.last |
405 assert_not_nil mail | 454 assert_not_nil mail |
406 mail | 455 mail |
407 end | 456 end |
408 | 457 |
409 def test_mailer_should_not_change_locale | 458 def test_mailer_should_not_change_locale |
410 Setting.default_language = 'en' | 459 Setting.default_language = 'en' |
411 # Set current language to italian | 460 # Set current language to italian |
412 set_language_if_valid 'it' | 461 set_language_if_valid 'it' |
413 # Send an email to a french user | 462 # Send an email to a french user |
414 user = User.find(1) | 463 user = User.find(1) |
415 user.language = 'fr' | 464 user.language = 'fr' |
416 Mailer.deliver_account_activated(user) | 465 Mailer.deliver_account_activated(user) |
417 mail = ActionMailer::Base.deliveries.last | 466 mail = ActionMailer::Base.deliveries.last |
418 assert mail.body.include?('Votre compte') | 467 assert mail.body.include?('Votre compte') |
419 | 468 |
420 assert_equal :it, current_language | 469 assert_equal :it, current_language |
421 end | 470 end |
422 | 471 |
423 def test_with_deliveries_off | 472 def test_with_deliveries_off |
424 Mailer.with_deliveries false do | 473 Mailer.with_deliveries false do |
425 Mailer.deliver_test(User.find(1)) | 474 Mailer.deliver_test(User.find(1)) |
426 end | 475 end |
427 assert ActionMailer::Base.deliveries.empty? | 476 assert ActionMailer::Base.deliveries.empty? |
428 # should restore perform_deliveries | 477 # should restore perform_deliveries |
429 assert ActionMailer::Base.perform_deliveries | 478 assert ActionMailer::Base.perform_deliveries |
479 end | |
480 | |
481 def test_tmail_to_header_field_should_not_include_blank_lines | |
482 mail = TMail::Mail.new | |
483 mail.to = ["a.user@example.com", "v.user2@example.com", "e.smith@example.com", "info@example.com", "v.pupkin@example.com", | |
484 "b.user@example.com", "w.user2@example.com", "f.smith@example.com", "info2@example.com", "w.pupkin@example.com"] | |
485 | |
486 assert !mail.encoded.strip.split("\r\n").detect(&:blank?), "#{mail.encoded} malformed" | |
430 end | 487 end |
431 | 488 |
432 context "layout" do | 489 context "layout" do |
433 should "include the emails_header" do | 490 should "include the emails_header" do |
434 with_settings(:emails_header => "*Header content*") do | 491 with_settings(:emails_header => "*Header content*") do |