##// END OF EJS Templates
Adds markings to emails generated by private comments (#12888)....
Jean-Philippe Lang -
r11639:1093454193bd
parent child
Show More
@@ -1,11 +1,14
1 <% if @journal.private_notes? %>
2 (<%= l(:field_private_notes) %>)
3 <% end %>
1 <%= l(:text_issue_updated, :id => "##{@issue.id}", :author => h(@journal.user)) %>
4 <%= l(:text_issue_updated, :id => "##{@issue.id}", :author => h(@journal.user)) %>
2
5
3 <ul>
6 <ul>
4 <% details_to_strings(@journal.details, false, :only_path => false).each do |string| %>
7 <% details_to_strings(@journal.details, false, :only_path => false).each do |string| %>
5 <li><%= string %></li>
8 <li><%= string %></li>
6 <% end %>
9 <% end %>
7 </ul>
10 </ul>
8
11
9 <%= textilizable(@journal, :notes, :only_path => false) %>
12 <%= textilizable(@journal, :notes, :only_path => false) %>
10 <hr />
13 <hr />
11 <%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>
14 <%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,12 +1,12
1 <%= l(:text_issue_updated, :id => "##{@issue.id}", :author => @journal.user) %>
1 <%= "(#{l(:field_private_notes)}) " if @journal.private_notes? -%><%= l(:text_issue_updated, :id => "##{@issue.id}", :author => @journal.user) %>
2
2
3 <% details_to_strings(@journal.details, true).each do |string| -%>
3 <% details_to_strings(@journal.details, true).each do |string| -%>
4 <%= string %>
4 <%= string %>
5 <% end -%>
5 <% end -%>
6
6
7 <% if @journal.notes? -%>
7 <% if @journal.notes? -%>
8 <%= @journal.notes %>
8 <%= @journal.notes %>
9
9
10 <% end -%>
10 <% end -%>
11 ----------------------------------------
11 ----------------------------------------
12 <%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :issue_url => @issue_url } %>
12 <%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,668 +1,679
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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 ActionDispatch::Assertions::SelectorAssertions
22 include ActionDispatch::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,
25 :tokens, :journals, :journal_details, :changesets,
26 :trackers, :projects_trackers,
26 :trackers, :projects_trackers,
27 :issue_statuses, :enumerations, :messages, :boards, :repositories,
27 :issue_statuses, :enumerations, :messages, :boards, :repositories,
28 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
28 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
29 :versions,
29 :versions,
30 :comments
30 :comments
31
31
32 def setup
32 def setup
33 ActionMailer::Base.deliveries.clear
33 ActionMailer::Base.deliveries.clear
34 Setting.host_name = 'mydomain.foo'
34 Setting.host_name = 'mydomain.foo'
35 Setting.protocol = 'http'
35 Setting.protocol = 'http'
36 Setting.plain_text_mail = '0'
36 Setting.plain_text_mail = '0'
37 end
37 end
38
38
39 def test_generated_links_in_emails
39 def test_generated_links_in_emails
40 Setting.default_language = 'en'
40 Setting.default_language = 'en'
41 Setting.host_name = 'mydomain.foo'
41 Setting.host_name = 'mydomain.foo'
42 Setting.protocol = 'https'
42 Setting.protocol = 'https'
43
43
44 journal = Journal.find(3)
44 journal = Journal.find(3)
45 assert Mailer.issue_edit(journal).deliver
45 assert Mailer.issue_edit(journal).deliver
46
46
47 mail = last_email
47 mail = last_email
48 assert_not_nil mail
48 assert_not_nil mail
49
49
50 assert_select_email do
50 assert_select_email do
51 # link to the main ticket
51 # link to the main ticket
52 assert_select 'a[href=?]',
52 assert_select 'a[href=?]',
53 'https://mydomain.foo/issues/2#change-3',
53 'https://mydomain.foo/issues/2#change-3',
54 :text => 'Feature request #2: Add ingredients categories'
54 :text => 'Feature request #2: Add ingredients categories'
55 # link to a referenced ticket
55 # link to a referenced ticket
56 assert_select 'a[href=?][title=?]',
56 assert_select 'a[href=?][title=?]',
57 'https://mydomain.foo/issues/1',
57 'https://mydomain.foo/issues/1',
58 'Can&#x27;t print recipes (New)',
58 'Can&#x27;t print recipes (New)',
59 :text => '#1'
59 :text => '#1'
60 # link to a changeset
60 # link to a changeset
61 assert_select 'a[href=?][title=?]',
61 assert_select 'a[href=?][title=?]',
62 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
62 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
63 'This commit fixes #1, #2 and references #1 &amp; #3',
63 'This commit fixes #1, #2 and references #1 &amp; #3',
64 :text => 'r2'
64 :text => 'r2'
65 # link to a description diff
65 # link to a description diff
66 assert_select 'a[href=?][title=?]',
66 assert_select 'a[href=?][title=?]',
67 'https://mydomain.foo/journals/diff/3?detail_id=4',
67 'https://mydomain.foo/journals/diff/3?detail_id=4',
68 'View differences',
68 'View differences',
69 :text => 'diff'
69 :text => 'diff'
70 # link to an attachment
70 # link to an attachment
71 assert_select 'a[href=?]',
71 assert_select 'a[href=?]',
72 'https://mydomain.foo/attachments/download/4/source.rb',
72 'https://mydomain.foo/attachments/download/4/source.rb',
73 :text => 'source.rb'
73 :text => 'source.rb'
74 end
74 end
75 end
75 end
76
76
77 def test_generated_links_with_prefix
77 def test_generated_links_with_prefix
78 Setting.default_language = 'en'
78 Setting.default_language = 'en'
79 relative_url_root = Redmine::Utils.relative_url_root
79 relative_url_root = Redmine::Utils.relative_url_root
80 Setting.host_name = 'mydomain.foo/rdm'
80 Setting.host_name = 'mydomain.foo/rdm'
81 Setting.protocol = 'http'
81 Setting.protocol = 'http'
82
82
83 journal = Journal.find(3)
83 journal = Journal.find(3)
84 assert Mailer.issue_edit(journal).deliver
84 assert Mailer.issue_edit(journal).deliver
85
85
86 mail = last_email
86 mail = last_email
87 assert_not_nil mail
87 assert_not_nil mail
88
88
89 assert_select_email do
89 assert_select_email do
90 # link to the main ticket
90 # link to the main ticket
91 assert_select 'a[href=?]',
91 assert_select 'a[href=?]',
92 'http://mydomain.foo/rdm/issues/2#change-3',
92 'http://mydomain.foo/rdm/issues/2#change-3',
93 :text => 'Feature request #2: Add ingredients categories'
93 :text => 'Feature request #2: Add ingredients categories'
94 # link to a referenced ticket
94 # link to a referenced ticket
95 assert_select 'a[href=?][title=?]',
95 assert_select 'a[href=?][title=?]',
96 'http://mydomain.foo/rdm/issues/1',
96 'http://mydomain.foo/rdm/issues/1',
97 'Can&#x27;t print recipes (New)',
97 'Can&#x27;t print recipes (New)',
98 :text => '#1'
98 :text => '#1'
99 # link to a changeset
99 # link to a changeset
100 assert_select 'a[href=?][title=?]',
100 assert_select 'a[href=?][title=?]',
101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
102 'This commit fixes #1, #2 and references #1 &amp; #3',
102 'This commit fixes #1, #2 and references #1 &amp; #3',
103 :text => 'r2'
103 :text => 'r2'
104 # link to a description diff
104 # link to a description diff
105 assert_select 'a[href=?][title=?]',
105 assert_select 'a[href=?][title=?]',
106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
107 'View differences',
107 'View differences',
108 :text => 'diff'
108 :text => 'diff'
109 # link to an attachment
109 # link to an attachment
110 assert_select 'a[href=?]',
110 assert_select 'a[href=?]',
111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
112 :text => 'source.rb'
112 :text => 'source.rb'
113 end
113 end
114 end
114 end
115
115
116 def test_generated_links_with_prefix_and_no_relative_url_root
116 def test_generated_links_with_prefix_and_no_relative_url_root
117 Setting.default_language = 'en'
117 Setting.default_language = 'en'
118 relative_url_root = Redmine::Utils.relative_url_root
118 relative_url_root = Redmine::Utils.relative_url_root
119 Setting.host_name = 'mydomain.foo/rdm'
119 Setting.host_name = 'mydomain.foo/rdm'
120 Setting.protocol = 'http'
120 Setting.protocol = 'http'
121 Redmine::Utils.relative_url_root = nil
121 Redmine::Utils.relative_url_root = nil
122
122
123 journal = Journal.find(3)
123 journal = Journal.find(3)
124 assert Mailer.issue_edit(journal).deliver
124 assert Mailer.issue_edit(journal).deliver
125
125
126 mail = last_email
126 mail = last_email
127 assert_not_nil mail
127 assert_not_nil mail
128
128
129 assert_select_email do
129 assert_select_email do
130 # link to the main ticket
130 # link to the main ticket
131 assert_select 'a[href=?]',
131 assert_select 'a[href=?]',
132 'http://mydomain.foo/rdm/issues/2#change-3',
132 'http://mydomain.foo/rdm/issues/2#change-3',
133 :text => 'Feature request #2: Add ingredients categories'
133 :text => 'Feature request #2: Add ingredients categories'
134 # link to a referenced ticket
134 # link to a referenced ticket
135 assert_select 'a[href=?][title=?]',
135 assert_select 'a[href=?][title=?]',
136 'http://mydomain.foo/rdm/issues/1',
136 'http://mydomain.foo/rdm/issues/1',
137 'Can&#x27;t print recipes (New)',
137 'Can&#x27;t print recipes (New)',
138 :text => '#1'
138 :text => '#1'
139 # link to a changeset
139 # link to a changeset
140 assert_select 'a[href=?][title=?]',
140 assert_select 'a[href=?][title=?]',
141 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
141 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
142 'This commit fixes #1, #2 and references #1 &amp; #3',
142 'This commit fixes #1, #2 and references #1 &amp; #3',
143 :text => 'r2'
143 :text => 'r2'
144 # link to a description diff
144 # link to a description diff
145 assert_select 'a[href=?][title=?]',
145 assert_select 'a[href=?][title=?]',
146 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
146 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
147 'View differences',
147 'View differences',
148 :text => 'diff'
148 :text => 'diff'
149 # link to an attachment
149 # link to an attachment
150 assert_select 'a[href=?]',
150 assert_select 'a[href=?]',
151 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
151 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
152 :text => 'source.rb'
152 :text => 'source.rb'
153 end
153 end
154 ensure
154 ensure
155 # restore it
155 # restore it
156 Redmine::Utils.relative_url_root = relative_url_root
156 Redmine::Utils.relative_url_root = relative_url_root
157 end
157 end
158
158
159 def test_email_headers
159 def test_email_headers
160 issue = Issue.find(1)
160 issue = Issue.find(1)
161 Mailer.issue_add(issue).deliver
161 Mailer.issue_add(issue).deliver
162 mail = last_email
162 mail = last_email
163 assert_not_nil mail
163 assert_not_nil mail
164 assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s
164 assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s
165 assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
165 assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
166 assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
166 assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
167 end
167 end
168
168
169 def test_email_headers_should_include_sender
169 def test_email_headers_should_include_sender
170 issue = Issue.find(1)
170 issue = Issue.find(1)
171 Mailer.issue_add(issue).deliver
171 Mailer.issue_add(issue).deliver
172 mail = last_email
172 mail = last_email
173 assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
173 assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
174 end
174 end
175
175
176 def test_plain_text_mail
176 def test_plain_text_mail
177 Setting.plain_text_mail = 1
177 Setting.plain_text_mail = 1
178 journal = Journal.find(2)
178 journal = Journal.find(2)
179 Mailer.issue_edit(journal).deliver
179 Mailer.issue_edit(journal).deliver
180 mail = last_email
180 mail = last_email
181 assert_equal "text/plain; charset=UTF-8", mail.content_type
181 assert_equal "text/plain; charset=UTF-8", mail.content_type
182 assert_equal 0, mail.parts.size
182 assert_equal 0, mail.parts.size
183 assert !mail.encoded.include?('href')
183 assert !mail.encoded.include?('href')
184 end
184 end
185
185
186 def test_html_mail
186 def test_html_mail
187 Setting.plain_text_mail = 0
187 Setting.plain_text_mail = 0
188 journal = Journal.find(2)
188 journal = Journal.find(2)
189 Mailer.issue_edit(journal).deliver
189 Mailer.issue_edit(journal).deliver
190 mail = last_email
190 mail = last_email
191 assert_equal 2, mail.parts.size
191 assert_equal 2, mail.parts.size
192 assert mail.encoded.include?('href')
192 assert mail.encoded.include?('href')
193 end
193 end
194
194
195 def test_from_header
195 def test_from_header
196 with_settings :mail_from => 'redmine@example.net' do
196 with_settings :mail_from => 'redmine@example.net' do
197 Mailer.test_email(User.find(1)).deliver
197 Mailer.test_email(User.find(1)).deliver
198 end
198 end
199 mail = last_email
199 mail = last_email
200 assert_equal 'redmine@example.net', mail.from_addrs.first
200 assert_equal 'redmine@example.net', mail.from_addrs.first
201 end
201 end
202
202
203 def test_from_header_with_phrase
203 def test_from_header_with_phrase
204 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
204 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
205 Mailer.test_email(User.find(1)).deliver
205 Mailer.test_email(User.find(1)).deliver
206 end
206 end
207 mail = last_email
207 mail = last_email
208 assert_equal 'redmine@example.net', mail.from_addrs.first
208 assert_equal 'redmine@example.net', mail.from_addrs.first
209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
210 end
210 end
211
211
212 def test_should_not_send_email_without_recipient
212 def test_should_not_send_email_without_recipient
213 news = News.first
213 news = News.first
214 user = news.author
214 user = news.author
215 # Remove members except news author
215 # Remove members except news author
216 news.project.memberships.each {|m| m.destroy unless m.user == user}
216 news.project.memberships.each {|m| m.destroy unless m.user == user}
217
217
218 user.pref.no_self_notified = false
218 user.pref.no_self_notified = false
219 user.pref.save
219 user.pref.save
220 User.current = user
220 User.current = user
221 Mailer.news_added(news.reload).deliver
221 Mailer.news_added(news.reload).deliver
222 assert_equal 1, last_email.bcc.size
222 assert_equal 1, last_email.bcc.size
223
223
224 # nobody to notify
224 # nobody to notify
225 user.pref.no_self_notified = true
225 user.pref.no_self_notified = true
226 user.pref.save
226 user.pref.save
227 User.current = user
227 User.current = user
228 ActionMailer::Base.deliveries.clear
228 ActionMailer::Base.deliveries.clear
229 Mailer.news_added(news.reload).deliver
229 Mailer.news_added(news.reload).deliver
230 assert ActionMailer::Base.deliveries.empty?
230 assert ActionMailer::Base.deliveries.empty?
231 end
231 end
232
232
233 def test_issue_add_message_id
233 def test_issue_add_message_id
234 issue = Issue.find(1)
234 issue = Issue.find(1)
235 Mailer.issue_add(issue).deliver
235 Mailer.issue_add(issue).deliver
236 mail = last_email
236 mail = last_email
237 assert_equal Mailer.message_id_for(issue), mail.message_id
237 assert_equal Mailer.message_id_for(issue), mail.message_id
238 assert_nil mail.references
238 assert_nil mail.references
239 end
239 end
240
240
241 def test_issue_edit_message_id
241 def test_issue_edit_message_id
242 journal = Journal.find(1)
242 journal = Journal.find(1)
243 Mailer.issue_edit(journal).deliver
243 Mailer.issue_edit(journal).deliver
244 mail = last_email
244 mail = last_email
245 assert_equal Mailer.message_id_for(journal), mail.message_id
245 assert_equal Mailer.message_id_for(journal), mail.message_id
246 assert_include Mailer.message_id_for(journal.issue), mail.references
246 assert_include Mailer.message_id_for(journal.issue), mail.references
247 assert_select_email do
247 assert_select_email do
248 # link to the update
248 # link to the update
249 assert_select "a[href=?]",
249 assert_select "a[href=?]",
250 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}"
250 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}"
251 end
251 end
252 end
252 end
253
253
254 def test_message_posted_message_id
254 def test_message_posted_message_id
255 message = Message.find(1)
255 message = Message.find(1)
256 Mailer.message_posted(message).deliver
256 Mailer.message_posted(message).deliver
257 mail = last_email
257 mail = last_email
258 assert_equal Mailer.message_id_for(message), mail.message_id
258 assert_equal Mailer.message_id_for(message), mail.message_id
259 assert_nil mail.references
259 assert_nil mail.references
260 assert_select_email do
260 assert_select_email do
261 # link to the message
261 # link to the message
262 assert_select "a[href=?]",
262 assert_select "a[href=?]",
263 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
263 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
264 :text => message.subject
264 :text => message.subject
265 end
265 end
266 end
266 end
267
267
268 def test_reply_posted_message_id
268 def test_reply_posted_message_id
269 message = Message.find(3)
269 message = Message.find(3)
270 Mailer.message_posted(message).deliver
270 Mailer.message_posted(message).deliver
271 mail = last_email
271 mail = last_email
272 assert_equal Mailer.message_id_for(message), mail.message_id
272 assert_equal Mailer.message_id_for(message), mail.message_id
273 assert_include Mailer.message_id_for(message.parent), mail.references
273 assert_include Mailer.message_id_for(message.parent), mail.references
274 assert_select_email do
274 assert_select_email do
275 # link to the reply
275 # link to the reply
276 assert_select "a[href=?]",
276 assert_select "a[href=?]",
277 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
277 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
278 :text => message.subject
278 :text => message.subject
279 end
279 end
280 end
280 end
281
281
282 test "#issue_add should notify project members" do
282 test "#issue_add should notify project members" do
283 issue = Issue.find(1)
283 issue = Issue.find(1)
284 assert Mailer.issue_add(issue).deliver
284 assert Mailer.issue_add(issue).deliver
285 assert last_email.bcc.include?('dlopper@somenet.foo')
285 assert last_email.bcc.include?('dlopper@somenet.foo')
286 end
286 end
287
287
288 test "#issue_add should not notify project members that are not allow to view the issue" do
288 test "#issue_add should not notify project members that are not allow to view the issue" do
289 issue = Issue.find(1)
289 issue = Issue.find(1)
290 Role.find(2).remove_permission!(:view_issues)
290 Role.find(2).remove_permission!(:view_issues)
291 assert Mailer.issue_add(issue).deliver
291 assert Mailer.issue_add(issue).deliver
292 assert !last_email.bcc.include?('dlopper@somenet.foo')
292 assert !last_email.bcc.include?('dlopper@somenet.foo')
293 end
293 end
294
294
295 test "#issue_add should notify issue watchers" do
295 test "#issue_add should notify issue watchers" do
296 issue = Issue.find(1)
296 issue = Issue.find(1)
297 user = User.find(9)
297 user = User.find(9)
298 # minimal email notification options
298 # minimal email notification options
299 user.pref.no_self_notified = '1'
299 user.pref.no_self_notified = '1'
300 user.pref.save
300 user.pref.save
301 user.mail_notification = false
301 user.mail_notification = false
302 user.save
302 user.save
303
303
304 Watcher.create!(:watchable => issue, :user => user)
304 Watcher.create!(:watchable => issue, :user => user)
305 assert Mailer.issue_add(issue).deliver
305 assert Mailer.issue_add(issue).deliver
306 assert last_email.bcc.include?(user.mail)
306 assert last_email.bcc.include?(user.mail)
307 end
307 end
308
308
309 test "#issue_add should not notify watchers not allowed to view the issue" do
309 test "#issue_add should not notify watchers not allowed to view the issue" do
310 issue = Issue.find(1)
310 issue = Issue.find(1)
311 user = User.find(9)
311 user = User.find(9)
312 Watcher.create!(:watchable => issue, :user => user)
312 Watcher.create!(:watchable => issue, :user => user)
313 Role.non_member.remove_permission!(:view_issues)
313 Role.non_member.remove_permission!(:view_issues)
314 assert Mailer.issue_add(issue).deliver
314 assert Mailer.issue_add(issue).deliver
315 assert !last_email.bcc.include?(user.mail)
315 assert !last_email.bcc.include?(user.mail)
316 end
316 end
317
317
318 # test mailer methods for each language
318 # test mailer methods for each language
319 def test_issue_add
319 def test_issue_add
320 issue = Issue.find(1)
320 issue = Issue.find(1)
321 valid_languages.each do |lang|
321 valid_languages.each do |lang|
322 Setting.default_language = lang.to_s
322 Setting.default_language = lang.to_s
323 assert Mailer.issue_add(issue).deliver
323 assert Mailer.issue_add(issue).deliver
324 end
324 end
325 end
325 end
326
326
327 def test_issue_edit
327 def test_issue_edit
328 journal = Journal.find(1)
328 journal = Journal.find(1)
329 valid_languages.each do |lang|
329 valid_languages.each do |lang|
330 Setting.default_language = lang.to_s
330 Setting.default_language = lang.to_s
331 assert Mailer.issue_edit(journal).deliver
331 assert Mailer.issue_edit(journal).deliver
332 end
332 end
333 end
333 end
334
334
335 def test_issue_edit_should_send_private_notes_to_users_with_permission_only
335 def test_issue_edit_should_send_private_notes_to_users_with_permission_only
336 journal = Journal.find(1)
336 journal = Journal.find(1)
337 journal.private_notes = true
337 journal.private_notes = true
338 journal.save!
338 journal.save!
339
339
340 Role.find(2).add_permission! :view_private_notes
340 Role.find(2).add_permission! :view_private_notes
341 Mailer.issue_edit(journal).deliver
341 Mailer.issue_edit(journal).deliver
342 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
342 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
343
343
344 Role.find(2).remove_permission! :view_private_notes
344 Role.find(2).remove_permission! :view_private_notes
345 Mailer.issue_edit(journal).deliver
345 Mailer.issue_edit(journal).deliver
346 assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
346 assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
347 end
347 end
348
348
349 def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
349 def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
350 Issue.find(1).set_watcher(User.find_by_login('someone'))
350 Issue.find(1).set_watcher(User.find_by_login('someone'))
351 journal = Journal.find(1)
351 journal = Journal.find(1)
352 journal.private_notes = true
352 journal.private_notes = true
353 journal.save!
353 journal.save!
354
354
355 Role.non_member.add_permission! :view_private_notes
355 Role.non_member.add_permission! :view_private_notes
356 Mailer.issue_edit(journal).deliver
356 Mailer.issue_edit(journal).deliver
357 assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
357 assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
358
358
359 Role.non_member.remove_permission! :view_private_notes
359 Role.non_member.remove_permission! :view_private_notes
360 Mailer.issue_edit(journal).deliver
360 Mailer.issue_edit(journal).deliver
361 assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
361 assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
362 end
362 end
363
363
364 def test_issue_edit_should_mark_private_notes
365 journal = Journal.find(2)
366 journal.private_notes = true
367 journal.save!
368
369 with_settings :default_language => 'en' do
370 Mailer.issue_edit(journal).deliver
371 end
372 assert_mail_body_match '(Private notes)', last_email
373 end
374
364 def test_document_added
375 def test_document_added
365 document = Document.find(1)
376 document = Document.find(1)
366 valid_languages.each do |lang|
377 valid_languages.each do |lang|
367 Setting.default_language = lang.to_s
378 Setting.default_language = lang.to_s
368 assert Mailer.document_added(document).deliver
379 assert Mailer.document_added(document).deliver
369 end
380 end
370 end
381 end
371
382
372 def test_attachments_added
383 def test_attachments_added
373 attachements = [ Attachment.find_by_container_type('Document') ]
384 attachements = [ Attachment.find_by_container_type('Document') ]
374 valid_languages.each do |lang|
385 valid_languages.each do |lang|
375 Setting.default_language = lang.to_s
386 Setting.default_language = lang.to_s
376 assert Mailer.attachments_added(attachements).deliver
387 assert Mailer.attachments_added(attachements).deliver
377 end
388 end
378 end
389 end
379
390
380 def test_version_file_added
391 def test_version_file_added
381 attachements = [ Attachment.find_by_container_type('Version') ]
392 attachements = [ Attachment.find_by_container_type('Version') ]
382 assert Mailer.attachments_added(attachements).deliver
393 assert Mailer.attachments_added(attachements).deliver
383 assert_not_nil last_email.bcc
394 assert_not_nil last_email.bcc
384 assert last_email.bcc.any?
395 assert last_email.bcc.any?
385 assert_select_email do
396 assert_select_email do
386 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
397 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
387 end
398 end
388 end
399 end
389
400
390 def test_project_file_added
401 def test_project_file_added
391 attachements = [ Attachment.find_by_container_type('Project') ]
402 attachements = [ Attachment.find_by_container_type('Project') ]
392 assert Mailer.attachments_added(attachements).deliver
403 assert Mailer.attachments_added(attachements).deliver
393 assert_not_nil last_email.bcc
404 assert_not_nil last_email.bcc
394 assert last_email.bcc.any?
405 assert last_email.bcc.any?
395 assert_select_email do
406 assert_select_email do
396 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
407 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
397 end
408 end
398 end
409 end
399
410
400 def test_news_added
411 def test_news_added
401 news = News.first
412 news = News.first
402 valid_languages.each do |lang|
413 valid_languages.each do |lang|
403 Setting.default_language = lang.to_s
414 Setting.default_language = lang.to_s
404 assert Mailer.news_added(news).deliver
415 assert Mailer.news_added(news).deliver
405 end
416 end
406 end
417 end
407
418
408 def test_news_comment_added
419 def test_news_comment_added
409 comment = Comment.find(2)
420 comment = Comment.find(2)
410 valid_languages.each do |lang|
421 valid_languages.each do |lang|
411 Setting.default_language = lang.to_s
422 Setting.default_language = lang.to_s
412 assert Mailer.news_comment_added(comment).deliver
423 assert Mailer.news_comment_added(comment).deliver
413 end
424 end
414 end
425 end
415
426
416 def test_message_posted
427 def test_message_posted
417 message = Message.first
428 message = Message.first
418 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
429 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
419 recipients = recipients.compact.uniq
430 recipients = recipients.compact.uniq
420 valid_languages.each do |lang|
431 valid_languages.each do |lang|
421 Setting.default_language = lang.to_s
432 Setting.default_language = lang.to_s
422 assert Mailer.message_posted(message).deliver
433 assert Mailer.message_posted(message).deliver
423 end
434 end
424 end
435 end
425
436
426 def test_wiki_content_added
437 def test_wiki_content_added
427 content = WikiContent.find(1)
438 content = WikiContent.find(1)
428 valid_languages.each do |lang|
439 valid_languages.each do |lang|
429 Setting.default_language = lang.to_s
440 Setting.default_language = lang.to_s
430 assert_difference 'ActionMailer::Base.deliveries.size' do
441 assert_difference 'ActionMailer::Base.deliveries.size' do
431 assert Mailer.wiki_content_added(content).deliver
442 assert Mailer.wiki_content_added(content).deliver
432 assert_select_email do
443 assert_select_email do
433 assert_select 'a[href=?]',
444 assert_select 'a[href=?]',
434 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
445 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
435 :text => 'CookBook documentation'
446 :text => 'CookBook documentation'
436 end
447 end
437 end
448 end
438 end
449 end
439 end
450 end
440
451
441 def test_wiki_content_updated
452 def test_wiki_content_updated
442 content = WikiContent.find(1)
453 content = WikiContent.find(1)
443 valid_languages.each do |lang|
454 valid_languages.each do |lang|
444 Setting.default_language = lang.to_s
455 Setting.default_language = lang.to_s
445 assert_difference 'ActionMailer::Base.deliveries.size' do
456 assert_difference 'ActionMailer::Base.deliveries.size' do
446 assert Mailer.wiki_content_updated(content).deliver
457 assert Mailer.wiki_content_updated(content).deliver
447 assert_select_email do
458 assert_select_email do
448 assert_select 'a[href=?]',
459 assert_select 'a[href=?]',
449 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
460 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
450 :text => 'CookBook documentation'
461 :text => 'CookBook documentation'
451 end
462 end
452 end
463 end
453 end
464 end
454 end
465 end
455
466
456 def test_account_information
467 def test_account_information
457 user = User.find(2)
468 user = User.find(2)
458 valid_languages.each do |lang|
469 valid_languages.each do |lang|
459 user.update_attribute :language, lang.to_s
470 user.update_attribute :language, lang.to_s
460 user.reload
471 user.reload
461 assert Mailer.account_information(user, 'pAsswORd').deliver
472 assert Mailer.account_information(user, 'pAsswORd').deliver
462 end
473 end
463 end
474 end
464
475
465 def test_lost_password
476 def test_lost_password
466 token = Token.find(2)
477 token = Token.find(2)
467 valid_languages.each do |lang|
478 valid_languages.each do |lang|
468 token.user.update_attribute :language, lang.to_s
479 token.user.update_attribute :language, lang.to_s
469 token.reload
480 token.reload
470 assert Mailer.lost_password(token).deliver
481 assert Mailer.lost_password(token).deliver
471 end
482 end
472 end
483 end
473
484
474 def test_register
485 def test_register
475 token = Token.find(1)
486 token = Token.find(1)
476 Setting.host_name = 'redmine.foo'
487 Setting.host_name = 'redmine.foo'
477 Setting.protocol = 'https'
488 Setting.protocol = 'https'
478
489
479 valid_languages.each do |lang|
490 valid_languages.each do |lang|
480 token.user.update_attribute :language, lang.to_s
491 token.user.update_attribute :language, lang.to_s
481 token.reload
492 token.reload
482 ActionMailer::Base.deliveries.clear
493 ActionMailer::Base.deliveries.clear
483 assert Mailer.register(token).deliver
494 assert Mailer.register(token).deliver
484 mail = last_email
495 mail = last_email
485 assert_select_email do
496 assert_select_email do
486 assert_select "a[href=?]",
497 assert_select "a[href=?]",
487 "https://redmine.foo/account/activate?token=#{token.value}",
498 "https://redmine.foo/account/activate?token=#{token.value}",
488 :text => "https://redmine.foo/account/activate?token=#{token.value}"
499 :text => "https://redmine.foo/account/activate?token=#{token.value}"
489 end
500 end
490 end
501 end
491 end
502 end
492
503
493 def test_test
504 def test_test
494 user = User.find(1)
505 user = User.find(1)
495 valid_languages.each do |lang|
506 valid_languages.each do |lang|
496 user.update_attribute :language, lang.to_s
507 user.update_attribute :language, lang.to_s
497 assert Mailer.test_email(user).deliver
508 assert Mailer.test_email(user).deliver
498 end
509 end
499 end
510 end
500
511
501 def test_reminders
512 def test_reminders
502 Mailer.reminders(:days => 42)
513 Mailer.reminders(:days => 42)
503 assert_equal 1, ActionMailer::Base.deliveries.size
514 assert_equal 1, ActionMailer::Base.deliveries.size
504 mail = last_email
515 mail = last_email
505 assert mail.bcc.include?('dlopper@somenet.foo')
516 assert mail.bcc.include?('dlopper@somenet.foo')
506 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
517 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
507 assert_equal '1 issue(s) due in the next 42 days', mail.subject
518 assert_equal '1 issue(s) due in the next 42 days', mail.subject
508 end
519 end
509
520
510 def test_reminders_should_not_include_closed_issues
521 def test_reminders_should_not_include_closed_issues
511 with_settings :default_language => 'en' do
522 with_settings :default_language => 'en' do
512 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
523 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
513 :subject => 'Closed issue', :assigned_to_id => 3,
524 :subject => 'Closed issue', :assigned_to_id => 3,
514 :due_date => 5.days.from_now,
525 :due_date => 5.days.from_now,
515 :author_id => 2)
526 :author_id => 2)
516 ActionMailer::Base.deliveries.clear
527 ActionMailer::Base.deliveries.clear
517
528
518 Mailer.reminders(:days => 42)
529 Mailer.reminders(:days => 42)
519 assert_equal 1, ActionMailer::Base.deliveries.size
530 assert_equal 1, ActionMailer::Base.deliveries.size
520 mail = last_email
531 mail = last_email
521 assert mail.bcc.include?('dlopper@somenet.foo')
532 assert mail.bcc.include?('dlopper@somenet.foo')
522 assert_mail_body_no_match 'Closed issue', mail
533 assert_mail_body_no_match 'Closed issue', mail
523 end
534 end
524 end
535 end
525
536
526 def test_reminders_for_users
537 def test_reminders_for_users
527 Mailer.reminders(:days => 42, :users => ['5'])
538 Mailer.reminders(:days => 42, :users => ['5'])
528 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
539 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
529 Mailer.reminders(:days => 42, :users => ['3'])
540 Mailer.reminders(:days => 42, :users => ['3'])
530 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
541 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
531 mail = last_email
542 mail = last_email
532 assert mail.bcc.include?('dlopper@somenet.foo')
543 assert mail.bcc.include?('dlopper@somenet.foo')
533 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
544 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
534 end
545 end
535
546
536 def test_reminder_should_include_issues_assigned_to_groups
547 def test_reminder_should_include_issues_assigned_to_groups
537 with_settings :default_language => 'en' do
548 with_settings :default_language => 'en' do
538 group = Group.generate!
549 group = Group.generate!
539 group.users << User.find(2)
550 group.users << User.find(2)
540 group.users << User.find(3)
551 group.users << User.find(3)
541
552
542 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
553 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
543 :subject => 'Assigned to group', :assigned_to => group,
554 :subject => 'Assigned to group', :assigned_to => group,
544 :due_date => 5.days.from_now,
555 :due_date => 5.days.from_now,
545 :author_id => 2)
556 :author_id => 2)
546 ActionMailer::Base.deliveries.clear
557 ActionMailer::Base.deliveries.clear
547
558
548 Mailer.reminders(:days => 7)
559 Mailer.reminders(:days => 7)
549 assert_equal 2, ActionMailer::Base.deliveries.size
560 assert_equal 2, ActionMailer::Base.deliveries.size
550 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
561 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
551 ActionMailer::Base.deliveries.each do |mail|
562 ActionMailer::Base.deliveries.each do |mail|
552 assert_mail_body_match 'Assigned to group', mail
563 assert_mail_body_match 'Assigned to group', mail
553 end
564 end
554 end
565 end
555 end
566 end
556
567
557 def test_mailer_should_not_change_locale
568 def test_mailer_should_not_change_locale
558 Setting.default_language = 'en'
569 Setting.default_language = 'en'
559 # Set current language to italian
570 # Set current language to italian
560 set_language_if_valid 'it'
571 set_language_if_valid 'it'
561 # Send an email to a french user
572 # Send an email to a french user
562 user = User.find(1)
573 user = User.find(1)
563 user.language = 'fr'
574 user.language = 'fr'
564 Mailer.account_activated(user).deliver
575 Mailer.account_activated(user).deliver
565 mail = last_email
576 mail = last_email
566 assert_mail_body_match 'Votre compte', mail
577 assert_mail_body_match 'Votre compte', mail
567
578
568 assert_equal :it, current_language
579 assert_equal :it, current_language
569 end
580 end
570
581
571 def test_with_deliveries_off
582 def test_with_deliveries_off
572 Mailer.with_deliveries false do
583 Mailer.with_deliveries false do
573 Mailer.test_email(User.find(1)).deliver
584 Mailer.test_email(User.find(1)).deliver
574 end
585 end
575 assert ActionMailer::Base.deliveries.empty?
586 assert ActionMailer::Base.deliveries.empty?
576 # should restore perform_deliveries
587 # should restore perform_deliveries
577 assert ActionMailer::Base.perform_deliveries
588 assert ActionMailer::Base.perform_deliveries
578 end
589 end
579
590
580 def test_layout_should_include_the_emails_header
591 def test_layout_should_include_the_emails_header
581 with_settings :emails_header => "*Header content*" do
592 with_settings :emails_header => "*Header content*" do
582 with_settings :plain_text_mail => 0 do
593 with_settings :plain_text_mail => 0 do
583 assert Mailer.test_email(User.find(1)).deliver
594 assert Mailer.test_email(User.find(1)).deliver
584 assert_select_email do
595 assert_select_email do
585 assert_select ".header" do
596 assert_select ".header" do
586 assert_select "strong", :text => "Header content"
597 assert_select "strong", :text => "Header content"
587 end
598 end
588 end
599 end
589 end
600 end
590 with_settings :plain_text_mail => 1 do
601 with_settings :plain_text_mail => 1 do
591 assert Mailer.test_email(User.find(1)).deliver
602 assert Mailer.test_email(User.find(1)).deliver
592 mail = last_email
603 mail = last_email
593 assert_not_nil mail
604 assert_not_nil mail
594 assert_include "*Header content*", mail.body.decoded
605 assert_include "*Header content*", mail.body.decoded
595 end
606 end
596 end
607 end
597 end
608 end
598
609
599 def test_layout_should_not_include_empty_emails_header
610 def test_layout_should_not_include_empty_emails_header
600 with_settings :emails_header => "", :plain_text_mail => 0 do
611 with_settings :emails_header => "", :plain_text_mail => 0 do
601 assert Mailer.test_email(User.find(1)).deliver
612 assert Mailer.test_email(User.find(1)).deliver
602 assert_select_email do
613 assert_select_email do
603 assert_select ".header", false
614 assert_select ".header", false
604 end
615 end
605 end
616 end
606 end
617 end
607
618
608 def test_layout_should_include_the_emails_footer
619 def test_layout_should_include_the_emails_footer
609 with_settings :emails_footer => "*Footer content*" do
620 with_settings :emails_footer => "*Footer content*" do
610 with_settings :plain_text_mail => 0 do
621 with_settings :plain_text_mail => 0 do
611 assert Mailer.test_email(User.find(1)).deliver
622 assert Mailer.test_email(User.find(1)).deliver
612 assert_select_email do
623 assert_select_email do
613 assert_select ".footer" do
624 assert_select ".footer" do
614 assert_select "strong", :text => "Footer content"
625 assert_select "strong", :text => "Footer content"
615 end
626 end
616 end
627 end
617 end
628 end
618 with_settings :plain_text_mail => 1 do
629 with_settings :plain_text_mail => 1 do
619 assert Mailer.test_email(User.find(1)).deliver
630 assert Mailer.test_email(User.find(1)).deliver
620 mail = last_email
631 mail = last_email
621 assert_not_nil mail
632 assert_not_nil mail
622 assert_include "\n-- \n", mail.body.decoded
633 assert_include "\n-- \n", mail.body.decoded
623 assert_include "*Footer content*", mail.body.decoded
634 assert_include "*Footer content*", mail.body.decoded
624 end
635 end
625 end
636 end
626 end
637 end
627
638
628 def test_layout_should_not_include_empty_emails_footer
639 def test_layout_should_not_include_empty_emails_footer
629 with_settings :emails_footer => "" do
640 with_settings :emails_footer => "" do
630 with_settings :plain_text_mail => 0 do
641 with_settings :plain_text_mail => 0 do
631 assert Mailer.test_email(User.find(1)).deliver
642 assert Mailer.test_email(User.find(1)).deliver
632 assert_select_email do
643 assert_select_email do
633 assert_select ".footer", false
644 assert_select ".footer", false
634 end
645 end
635 end
646 end
636 with_settings :plain_text_mail => 1 do
647 with_settings :plain_text_mail => 1 do
637 assert Mailer.test_email(User.find(1)).deliver
648 assert Mailer.test_email(User.find(1)).deliver
638 mail = last_email
649 mail = last_email
639 assert_not_nil mail
650 assert_not_nil mail
640 assert_not_include "\n-- \n", mail.body.decoded
651 assert_not_include "\n-- \n", mail.body.decoded
641 end
652 end
642 end
653 end
643 end
654 end
644
655
645 def test_should_escape_html_templates_only
656 def test_should_escape_html_templates_only
646 Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
657 Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
647 mail = last_email
658 mail = last_email
648 assert_equal 2, mail.parts.size
659 assert_equal 2, mail.parts.size
649 assert_include '<tag>', text_part.body.encoded
660 assert_include '<tag>', text_part.body.encoded
650 assert_include '&lt;tag&gt;', html_part.body.encoded
661 assert_include '&lt;tag&gt;', html_part.body.encoded
651 end
662 end
652
663
653 private
664 private
654
665
655 def last_email
666 def last_email
656 mail = ActionMailer::Base.deliveries.last
667 mail = ActionMailer::Base.deliveries.last
657 assert_not_nil mail
668 assert_not_nil mail
658 mail
669 mail
659 end
670 end
660
671
661 def text_part
672 def text_part
662 last_email.parts.detect {|part| part.content_type.include?('text/plain')}
673 last_email.parts.detect {|part| part.content_type.include?('text/plain')}
663 end
674 end
664
675
665 def html_part
676 def html_part
666 last_email.parts.detect {|part| part.content_type.include?('text/html')}
677 last_email.parts.detect {|part| part.content_type.include?('text/html')}
667 end
678 end
668 end
679 end
General Comments 0
You need to be logged in to leave comments. Login now