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