##// END OF EJS Templates
Adds a test for not sending email without recipient (#4920)....
Jean-Philippe Lang -
r3404:ae55978515a4
parent child
Show More
@@ -1,333 +1,354
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
138 def test_should_not_send_email_without_recipient
139 news = News.find(:first)
140 user = news.author
141 # Remove members except news author
142 news.project.memberships.each {|m| m.destroy unless m.user == user}
143
144 user.pref[:no_self_notified] = false
145 user.pref.save
146 User.current = user
147 Mailer.deliver_news_added(news.reload)
148 assert_equal 1, last_email.bcc.size
149
150 # nobody to notify
151 user.pref[:no_self_notified] = true
152 user.pref.save
153 User.current = user
154 ActionMailer::Base.deliveries.clear
155 Mailer.deliver_news_added(news.reload)
156 assert ActionMailer::Base.deliveries.empty?
157 end
137
158
138 def test_issue_add_message_id
159 def test_issue_add_message_id
139 issue = Issue.find(1)
160 issue = Issue.find(1)
140 Mailer.deliver_issue_add(issue)
161 Mailer.deliver_issue_add(issue)
141 mail = ActionMailer::Base.deliveries.last
162 mail = ActionMailer::Base.deliveries.last
142 assert_not_nil mail
163 assert_not_nil mail
143 assert_equal Mailer.message_id_for(issue), mail.message_id
164 assert_equal Mailer.message_id_for(issue), mail.message_id
144 assert_nil mail.references
165 assert_nil mail.references
145 end
166 end
146
167
147 def test_issue_edit_message_id
168 def test_issue_edit_message_id
148 journal = Journal.find(1)
169 journal = Journal.find(1)
149 Mailer.deliver_issue_edit(journal)
170 Mailer.deliver_issue_edit(journal)
150 mail = ActionMailer::Base.deliveries.last
171 mail = ActionMailer::Base.deliveries.last
151 assert_not_nil mail
172 assert_not_nil mail
152 assert_equal Mailer.message_id_for(journal), mail.message_id
173 assert_equal Mailer.message_id_for(journal), mail.message_id
153 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
154 end
175 end
155
176
156 def test_message_posted_message_id
177 def test_message_posted_message_id
157 message = Message.find(1)
178 message = Message.find(1)
158 Mailer.deliver_message_posted(message)
179 Mailer.deliver_message_posted(message)
159 mail = ActionMailer::Base.deliveries.last
180 mail = ActionMailer::Base.deliveries.last
160 assert_not_nil mail
181 assert_not_nil mail
161 assert_equal Mailer.message_id_for(message), mail.message_id
182 assert_equal Mailer.message_id_for(message), mail.message_id
162 assert_nil mail.references
183 assert_nil mail.references
163 assert_select_email do
184 assert_select_email do
164 # link to the message
185 # link to the message
165 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
166 end
187 end
167 end
188 end
168
189
169 def test_reply_posted_message_id
190 def test_reply_posted_message_id
170 message = Message.find(3)
191 message = Message.find(3)
171 Mailer.deliver_message_posted(message)
192 Mailer.deliver_message_posted(message)
172 mail = ActionMailer::Base.deliveries.last
193 mail = ActionMailer::Base.deliveries.last
173 assert_not_nil mail
194 assert_not_nil mail
174 assert_equal Mailer.message_id_for(message), mail.message_id
195 assert_equal Mailer.message_id_for(message), mail.message_id
175 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
176 assert_select_email do
197 assert_select_email do
177 # link to the reply
198 # link to the reply
178 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
179 end
200 end
180 end
201 end
181
202
182 context("#issue_add") do
203 context("#issue_add") do
183 setup do
204 setup do
184 ActionMailer::Base.deliveries.clear
205 ActionMailer::Base.deliveries.clear
185 Setting.bcc_recipients = '1'
206 Setting.bcc_recipients = '1'
186 @issue = Issue.find(1)
207 @issue = Issue.find(1)
187 end
208 end
188
209
189 should "notify project members" do
210 should "notify project members" do
190 assert Mailer.deliver_issue_add(@issue)
211 assert Mailer.deliver_issue_add(@issue)
191 assert last_email.bcc.include?('dlopper@somenet.foo')
212 assert last_email.bcc.include?('dlopper@somenet.foo')
192 end
213 end
193
214
194 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
195 Role.find(2).remove_permission!(:view_issues)
216 Role.find(2).remove_permission!(:view_issues)
196 assert Mailer.deliver_issue_add(@issue)
217 assert Mailer.deliver_issue_add(@issue)
197 assert !last_email.bcc.include?('dlopper@somenet.foo')
218 assert !last_email.bcc.include?('dlopper@somenet.foo')
198 end
219 end
199
220
200 should "notify issue watchers" do
221 should "notify issue watchers" do
201 user = User.find(9)
222 user = User.find(9)
202 # minimal email notification options
223 # minimal email notification options
203 user.pref[:no_self_notified] = '1'
224 user.pref[:no_self_notified] = '1'
204 user.pref.save
225 user.pref.save
205 user.mail_notification = false
226 user.mail_notification = false
206 user.save
227 user.save
207
228
208 Watcher.create!(:watchable => @issue, :user => user)
229 Watcher.create!(:watchable => @issue, :user => user)
209 assert Mailer.deliver_issue_add(@issue)
230 assert Mailer.deliver_issue_add(@issue)
210 assert last_email.bcc.include?(user.mail)
231 assert last_email.bcc.include?(user.mail)
211 end
232 end
212
233
213 should "not notify watchers not allowed to view the issue" do
234 should "not notify watchers not allowed to view the issue" do
214 user = User.find(9)
235 user = User.find(9)
215 Watcher.create!(:watchable => @issue, :user => user)
236 Watcher.create!(:watchable => @issue, :user => user)
216 Role.non_member.remove_permission!(:view_issues)
237 Role.non_member.remove_permission!(:view_issues)
217 assert Mailer.deliver_issue_add(@issue)
238 assert Mailer.deliver_issue_add(@issue)
218 assert !last_email.bcc.include?(user.mail)
239 assert !last_email.bcc.include?(user.mail)
219 end
240 end
220 end
241 end
221
242
222 # test mailer methods for each language
243 # test mailer methods for each language
223 def test_issue_add
244 def test_issue_add
224 issue = Issue.find(1)
245 issue = Issue.find(1)
225 valid_languages.each do |lang|
246 valid_languages.each do |lang|
226 Setting.default_language = lang.to_s
247 Setting.default_language = lang.to_s
227 assert Mailer.deliver_issue_add(issue)
248 assert Mailer.deliver_issue_add(issue)
228 end
249 end
229 end
250 end
230
251
231 def test_issue_edit
252 def test_issue_edit
232 journal = Journal.find(1)
253 journal = Journal.find(1)
233 valid_languages.each do |lang|
254 valid_languages.each do |lang|
234 Setting.default_language = lang.to_s
255 Setting.default_language = lang.to_s
235 assert Mailer.deliver_issue_edit(journal)
256 assert Mailer.deliver_issue_edit(journal)
236 end
257 end
237 end
258 end
238
259
239 def test_document_added
260 def test_document_added
240 document = Document.find(1)
261 document = Document.find(1)
241 valid_languages.each do |lang|
262 valid_languages.each do |lang|
242 Setting.default_language = lang.to_s
263 Setting.default_language = lang.to_s
243 assert Mailer.deliver_document_added(document)
264 assert Mailer.deliver_document_added(document)
244 end
265 end
245 end
266 end
246
267
247 def test_attachments_added
268 def test_attachments_added
248 attachements = [ Attachment.find_by_container_type('Document') ]
269 attachements = [ Attachment.find_by_container_type('Document') ]
249 valid_languages.each do |lang|
270 valid_languages.each do |lang|
250 Setting.default_language = lang.to_s
271 Setting.default_language = lang.to_s
251 assert Mailer.deliver_attachments_added(attachements)
272 assert Mailer.deliver_attachments_added(attachements)
252 end
273 end
253 end
274 end
254
275
255 def test_news_added
276 def test_news_added
256 news = News.find(:first)
277 news = News.find(:first)
257 valid_languages.each do |lang|
278 valid_languages.each do |lang|
258 Setting.default_language = lang.to_s
279 Setting.default_language = lang.to_s
259 assert Mailer.deliver_news_added(news)
280 assert Mailer.deliver_news_added(news)
260 end
281 end
261 end
282 end
262
283
263 def test_message_posted
284 def test_message_posted
264 message = Message.find(:first)
285 message = Message.find(:first)
265 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
286 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
266 recipients = recipients.compact.uniq
287 recipients = recipients.compact.uniq
267 valid_languages.each do |lang|
288 valid_languages.each do |lang|
268 Setting.default_language = lang.to_s
289 Setting.default_language = lang.to_s
269 assert Mailer.deliver_message_posted(message)
290 assert Mailer.deliver_message_posted(message)
270 end
291 end
271 end
292 end
272
293
273 def test_account_information
294 def test_account_information
274 user = User.find(:first)
295 user = User.find(:first)
275 valid_languages.each do |lang|
296 valid_languages.each do |lang|
276 user.update_attribute :language, lang.to_s
297 user.update_attribute :language, lang.to_s
277 user.reload
298 user.reload
278 assert Mailer.deliver_account_information(user, 'pAsswORd')
299 assert Mailer.deliver_account_information(user, 'pAsswORd')
279 end
300 end
280 end
301 end
281
302
282 def test_lost_password
303 def test_lost_password
283 token = Token.find(2)
304 token = Token.find(2)
284 valid_languages.each do |lang|
305 valid_languages.each do |lang|
285 token.user.update_attribute :language, lang.to_s
306 token.user.update_attribute :language, lang.to_s
286 token.reload
307 token.reload
287 assert Mailer.deliver_lost_password(token)
308 assert Mailer.deliver_lost_password(token)
288 end
309 end
289 end
310 end
290
311
291 def test_register
312 def test_register
292 token = Token.find(1)
313 token = Token.find(1)
293 Setting.host_name = 'redmine.foo'
314 Setting.host_name = 'redmine.foo'
294 Setting.protocol = 'https'
315 Setting.protocol = 'https'
295
316
296 valid_languages.each do |lang|
317 valid_languages.each do |lang|
297 token.user.update_attribute :language, lang.to_s
318 token.user.update_attribute :language, lang.to_s
298 token.reload
319 token.reload
299 ActionMailer::Base.deliveries.clear
320 ActionMailer::Base.deliveries.clear
300 assert Mailer.deliver_register(token)
321 assert Mailer.deliver_register(token)
301 mail = ActionMailer::Base.deliveries.last
322 mail = ActionMailer::Base.deliveries.last
302 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}")
323 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}")
303 end
324 end
304 end
325 end
305
326
306 def test_reminders
327 def test_reminders
307 Mailer.reminders(:days => 42)
328 Mailer.reminders(:days => 42)
308 assert_equal 1, ActionMailer::Base.deliveries.size
329 assert_equal 1, ActionMailer::Base.deliveries.size
309 mail = ActionMailer::Base.deliveries.last
330 mail = ActionMailer::Base.deliveries.last
310 assert mail.bcc.include?('dlopper@somenet.foo')
331 assert mail.bcc.include?('dlopper@somenet.foo')
311 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
332 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
312 end
333 end
313
334
314 def last_email
335 def last_email
315 mail = ActionMailer::Base.deliveries.last
336 mail = ActionMailer::Base.deliveries.last
316 assert_not_nil mail
337 assert_not_nil mail
317 mail
338 mail
318 end
339 end
319
340
320 def test_mailer_should_not_change_locale
341 def test_mailer_should_not_change_locale
321 Setting.default_language = 'en'
342 Setting.default_language = 'en'
322 # Set current language to italian
343 # Set current language to italian
323 set_language_if_valid 'it'
344 set_language_if_valid 'it'
324 # Send an email to a french user
345 # Send an email to a french user
325 user = User.find(1)
346 user = User.find(1)
326 user.language = 'fr'
347 user.language = 'fr'
327 Mailer.deliver_account_activated(user)
348 Mailer.deliver_account_activated(user)
328 mail = ActionMailer::Base.deliveries.last
349 mail = ActionMailer::Base.deliveries.last
329 assert mail.body.include?('Votre compte')
350 assert mail.body.include?('Votre compte')
330
351
331 assert_equal :it, current_language
352 assert_equal :it, current_language
332 end
353 end
333 end
354 end
General Comments 0
You need to be logged in to leave comments. Login now