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