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