@@ -1,826 +1,820 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 Rails::Dom::Testing::Assertions |
|
22 | include Rails::Dom::Testing::Assertions | |
23 | fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :members, |
|
23 | fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :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 | Setting.default_language = 'en' | |||
37 | User.current = nil |
|
38 | User.current = nil | |
38 | end |
|
39 | end | |
39 |
|
40 | |||
40 | def test_generated_links_in_emails |
|
41 | def test_generated_links_in_emails | |
41 | Setting.default_language = 'en' |
|
|||
42 | Setting.host_name = 'mydomain.foo' |
|
42 | Setting.host_name = 'mydomain.foo' | |
43 | Setting.protocol = 'https' |
|
43 | Setting.protocol = 'https' | |
44 |
|
44 | |||
45 | journal = Journal.find(3) |
|
45 | journal = Journal.find(3) | |
46 | assert Mailer.deliver_issue_edit(journal) |
|
46 | assert Mailer.deliver_issue_edit(journal) | |
47 |
|
47 | |||
48 | mail = last_email |
|
48 | mail = last_email | |
49 | assert_not_nil mail |
|
49 | assert_not_nil mail | |
50 |
|
50 | |||
51 | assert_select_email do |
|
51 | assert_select_email do | |
52 | # link to the main ticket |
|
52 | # link to the main ticket | |
53 | assert_select 'a[href=?]', |
|
53 | assert_select 'a[href=?]', | |
54 | 'https://mydomain.foo/issues/2#change-3', |
|
54 | 'https://mydomain.foo/issues/2#change-3', | |
55 | :text => 'Feature request #2: Add ingredients categories' |
|
55 | :text => 'Feature request #2: Add ingredients categories' | |
56 | # link to a referenced ticket |
|
56 | # link to a referenced ticket | |
57 | assert_select 'a[href=?][title=?]', |
|
57 | assert_select 'a[href=?][title=?]', | |
58 | 'https://mydomain.foo/issues/1', |
|
58 | 'https://mydomain.foo/issues/1', | |
59 | "Cannot print recipes (New)", |
|
59 | "Cannot print recipes (New)", | |
60 | :text => '#1' |
|
60 | :text => '#1' | |
61 | # link to a changeset |
|
61 | # link to a changeset | |
62 | assert_select 'a[href=?][title=?]', |
|
62 | assert_select 'a[href=?][title=?]', | |
63 | 'https://mydomain.foo/projects/ecookbook/repository/revisions/2', |
|
63 | 'https://mydomain.foo/projects/ecookbook/repository/revisions/2', | |
64 | 'This commit fixes #1, #2 and references #1 & #3', |
|
64 | 'This commit fixes #1, #2 and references #1 & #3', | |
65 | :text => 'r2' |
|
65 | :text => 'r2' | |
66 | # link to a description diff |
|
66 | # link to a description diff | |
67 | assert_select 'a[href^=?][title=?]', |
|
67 | assert_select 'a[href^=?][title=?]', | |
68 | # should be https://mydomain.foo/journals/diff/3?detail_id=4 |
|
68 | # should be https://mydomain.foo/journals/diff/3?detail_id=4 | |
69 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the |
|
69 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the | |
70 | # attribute value |
|
70 | # attribute value | |
71 | 'https://mydomain.foo/journals/diff/3', |
|
71 | 'https://mydomain.foo/journals/diff/3', | |
72 | 'View differences', |
|
72 | 'View differences', | |
73 | :text => 'diff' |
|
73 | :text => 'diff' | |
74 | # link to an attachment |
|
74 | # link to an attachment | |
75 | assert_select 'a[href=?]', |
|
75 | assert_select 'a[href=?]', | |
76 | 'https://mydomain.foo/attachments/download/4/source.rb', |
|
76 | 'https://mydomain.foo/attachments/download/4/source.rb', | |
77 | :text => 'source.rb' |
|
77 | :text => 'source.rb' | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_generated_links_with_prefix |
|
81 | def test_generated_links_with_prefix | |
82 | Setting.default_language = 'en' |
|
|||
83 | relative_url_root = Redmine::Utils.relative_url_root |
|
82 | relative_url_root = Redmine::Utils.relative_url_root | |
84 | Setting.host_name = 'mydomain.foo/rdm' |
|
83 | Setting.host_name = 'mydomain.foo/rdm' | |
85 | Setting.protocol = 'http' |
|
84 | Setting.protocol = 'http' | |
86 |
|
85 | |||
87 | journal = Journal.find(3) |
|
86 | journal = Journal.find(3) | |
88 | assert Mailer.deliver_issue_edit(journal) |
|
87 | assert Mailer.deliver_issue_edit(journal) | |
89 |
|
88 | |||
90 | mail = last_email |
|
89 | mail = last_email | |
91 | assert_not_nil mail |
|
90 | assert_not_nil mail | |
92 |
|
91 | |||
93 | assert_select_email do |
|
92 | assert_select_email do | |
94 | # link to the main ticket |
|
93 | # link to the main ticket | |
95 | assert_select 'a[href=?]', |
|
94 | assert_select 'a[href=?]', | |
96 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
95 | 'http://mydomain.foo/rdm/issues/2#change-3', | |
97 | :text => 'Feature request #2: Add ingredients categories' |
|
96 | :text => 'Feature request #2: Add ingredients categories' | |
98 | # link to a referenced ticket |
|
97 | # link to a referenced ticket | |
99 | assert_select 'a[href=?][title=?]', |
|
98 | assert_select 'a[href=?][title=?]', | |
100 | 'http://mydomain.foo/rdm/issues/1', |
|
99 | 'http://mydomain.foo/rdm/issues/1', | |
101 | "Cannot print recipes (New)", |
|
100 | "Cannot print recipes (New)", | |
102 | :text => '#1' |
|
101 | :text => '#1' | |
103 | # link to a changeset |
|
102 | # link to a changeset | |
104 | assert_select 'a[href=?][title=?]', |
|
103 | assert_select 'a[href=?][title=?]', | |
105 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
104 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', | |
106 | 'This commit fixes #1, #2 and references #1 & #3', |
|
105 | 'This commit fixes #1, #2 and references #1 & #3', | |
107 | :text => 'r2' |
|
106 | :text => 'r2' | |
108 | # link to a description diff |
|
107 | # link to a description diff | |
109 | assert_select 'a[href^=?][title=?]', |
|
108 | assert_select 'a[href^=?][title=?]', | |
110 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 |
|
109 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 | |
111 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the |
|
110 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the | |
112 | # attribute value |
|
111 | # attribute value | |
113 | 'http://mydomain.foo/rdm/journals/diff/3', |
|
112 | 'http://mydomain.foo/rdm/journals/diff/3', | |
114 | 'View differences', |
|
113 | 'View differences', | |
115 | :text => 'diff' |
|
114 | :text => 'diff' | |
116 | # link to an attachment |
|
115 | # link to an attachment | |
117 | assert_select 'a[href=?]', |
|
116 | assert_select 'a[href=?]', | |
118 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
117 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', | |
119 | :text => 'source.rb' |
|
118 | :text => 'source.rb' | |
120 | end |
|
119 | end | |
121 | end |
|
120 | end | |
122 |
|
121 | |||
123 | def test_issue_edit_should_generate_url_with_hostname_for_relations |
|
122 | def test_issue_edit_should_generate_url_with_hostname_for_relations | |
124 | journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now) |
|
123 | journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now) | |
125 | journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2) |
|
124 | journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2) | |
126 | Mailer.deliver_issue_edit(journal) |
|
125 | Mailer.deliver_issue_edit(journal) | |
127 | assert_not_nil last_email |
|
126 | assert_not_nil last_email | |
128 | assert_select_email do |
|
127 | assert_select_email do | |
129 | assert_select 'a[href=?]', 'http://mydomain.foo/issues/2', :text => 'Feature request #2' |
|
128 | assert_select 'a[href=?]', 'http://mydomain.foo/issues/2', :text => 'Feature request #2' | |
130 | end |
|
129 | end | |
131 | end |
|
130 | end | |
132 |
|
131 | |||
133 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
132 | def test_generated_links_with_prefix_and_no_relative_url_root | |
134 | Setting.default_language = 'en' |
|
|||
135 | relative_url_root = Redmine::Utils.relative_url_root |
|
133 | relative_url_root = Redmine::Utils.relative_url_root | |
136 | Setting.host_name = 'mydomain.foo/rdm' |
|
134 | Setting.host_name = 'mydomain.foo/rdm' | |
137 | Setting.protocol = 'http' |
|
135 | Setting.protocol = 'http' | |
138 | Redmine::Utils.relative_url_root = nil |
|
136 | Redmine::Utils.relative_url_root = nil | |
139 |
|
137 | |||
140 | journal = Journal.find(3) |
|
138 | journal = Journal.find(3) | |
141 | assert Mailer.deliver_issue_edit(journal) |
|
139 | assert Mailer.deliver_issue_edit(journal) | |
142 |
|
140 | |||
143 | mail = last_email |
|
141 | mail = last_email | |
144 | assert_not_nil mail |
|
142 | assert_not_nil mail | |
145 |
|
143 | |||
146 | assert_select_email do |
|
144 | assert_select_email do | |
147 | # link to the main ticket |
|
145 | # link to the main ticket | |
148 | assert_select 'a[href=?]', |
|
146 | assert_select 'a[href=?]', | |
149 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
147 | 'http://mydomain.foo/rdm/issues/2#change-3', | |
150 | :text => 'Feature request #2: Add ingredients categories' |
|
148 | :text => 'Feature request #2: Add ingredients categories' | |
151 | # link to a referenced ticket |
|
149 | # link to a referenced ticket | |
152 | assert_select 'a[href=?][title=?]', |
|
150 | assert_select 'a[href=?][title=?]', | |
153 | 'http://mydomain.foo/rdm/issues/1', |
|
151 | 'http://mydomain.foo/rdm/issues/1', | |
154 | "Cannot print recipes (New)", |
|
152 | "Cannot print recipes (New)", | |
155 | :text => '#1' |
|
153 | :text => '#1' | |
156 | # link to a changeset |
|
154 | # link to a changeset | |
157 | assert_select 'a[href=?][title=?]', |
|
155 | assert_select 'a[href=?][title=?]', | |
158 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
156 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', | |
159 | 'This commit fixes #1, #2 and references #1 & #3', |
|
157 | 'This commit fixes #1, #2 and references #1 & #3', | |
160 | :text => 'r2' |
|
158 | :text => 'r2' | |
161 | # link to a description diff |
|
159 | # link to a description diff | |
162 | assert_select 'a[href^=?][title=?]', |
|
160 | assert_select 'a[href^=?][title=?]', | |
163 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 |
|
161 | # should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4 | |
164 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the |
|
162 | # but the Rails 4.2 DOM assertion doesn't handle the ? in the | |
165 | # attribute value |
|
163 | # attribute value | |
166 | 'http://mydomain.foo/rdm/journals/diff/3', |
|
164 | 'http://mydomain.foo/rdm/journals/diff/3', | |
167 | 'View differences', |
|
165 | 'View differences', | |
168 | :text => 'diff' |
|
166 | :text => 'diff' | |
169 | # link to an attachment |
|
167 | # link to an attachment | |
170 | assert_select 'a[href=?]', |
|
168 | assert_select 'a[href=?]', | |
171 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
169 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', | |
172 | :text => 'source.rb' |
|
170 | :text => 'source.rb' | |
173 | end |
|
171 | end | |
174 | ensure |
|
172 | ensure | |
175 | # restore it |
|
173 | # restore it | |
176 | Redmine::Utils.relative_url_root = relative_url_root |
|
174 | Redmine::Utils.relative_url_root = relative_url_root | |
177 | end |
|
175 | end | |
178 |
|
176 | |||
179 | def test_email_headers |
|
177 | def test_email_headers | |
180 | issue = Issue.find(1) |
|
178 | issue = Issue.find(1) | |
181 | Mailer.deliver_issue_add(issue) |
|
179 | Mailer.deliver_issue_add(issue) | |
182 | mail = last_email |
|
180 | mail = last_email | |
183 | assert_not_nil mail |
|
181 | assert_not_nil mail | |
184 | assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s |
|
182 | assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s | |
185 | assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s |
|
183 | assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s | |
186 | assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s |
|
184 | assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s | |
187 | end |
|
185 | end | |
188 |
|
186 | |||
189 | def test_email_headers_should_include_sender |
|
187 | def test_email_headers_should_include_sender | |
190 | issue = Issue.find(1) |
|
188 | issue = Issue.find(1) | |
191 | Mailer.deliver_issue_add(issue) |
|
189 | Mailer.deliver_issue_add(issue) | |
192 | mail = last_email |
|
190 | mail = last_email | |
193 | assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s |
|
191 | assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s | |
194 | end |
|
192 | end | |
195 |
|
193 | |||
196 | def test_plain_text_mail |
|
194 | def test_plain_text_mail | |
197 | Setting.plain_text_mail = 1 |
|
195 | Setting.plain_text_mail = 1 | |
198 | journal = Journal.find(2) |
|
196 | journal = Journal.find(2) | |
199 | Mailer.deliver_issue_edit(journal) |
|
197 | Mailer.deliver_issue_edit(journal) | |
200 | mail = last_email |
|
198 | mail = last_email | |
201 | assert_equal "text/plain; charset=UTF-8", mail.content_type |
|
199 | assert_equal "text/plain; charset=UTF-8", mail.content_type | |
202 | assert_equal 0, mail.parts.size |
|
200 | assert_equal 0, mail.parts.size | |
203 | assert !mail.encoded.include?('href') |
|
201 | assert !mail.encoded.include?('href') | |
204 | end |
|
202 | end | |
205 |
|
203 | |||
206 | def test_html_mail |
|
204 | def test_html_mail | |
207 | Setting.plain_text_mail = 0 |
|
205 | Setting.plain_text_mail = 0 | |
208 | journal = Journal.find(2) |
|
206 | journal = Journal.find(2) | |
209 | Mailer.deliver_issue_edit(journal) |
|
207 | Mailer.deliver_issue_edit(journal) | |
210 | mail = last_email |
|
208 | mail = last_email | |
211 | assert_equal 2, mail.parts.size |
|
209 | assert_equal 2, mail.parts.size | |
212 | assert mail.encoded.include?('href') |
|
210 | assert mail.encoded.include?('href') | |
213 | end |
|
211 | end | |
214 |
|
212 | |||
215 | def test_from_header |
|
213 | def test_from_header | |
216 | with_settings :mail_from => 'redmine@example.net' do |
|
214 | with_settings :mail_from => 'redmine@example.net' do | |
217 | Mailer.test_email(User.find(1)).deliver |
|
215 | Mailer.test_email(User.find(1)).deliver | |
218 | end |
|
216 | end | |
219 | mail = last_email |
|
217 | mail = last_email | |
220 | assert_equal 'redmine@example.net', mail.from_addrs.first |
|
218 | assert_equal 'redmine@example.net', mail.from_addrs.first | |
221 | end |
|
219 | end | |
222 |
|
220 | |||
223 | def test_from_header_with_phrase |
|
221 | def test_from_header_with_phrase | |
224 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do |
|
222 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do | |
225 | Mailer.test_email(User.find(1)).deliver |
|
223 | Mailer.test_email(User.find(1)).deliver | |
226 | end |
|
224 | end | |
227 | mail = last_email |
|
225 | mail = last_email | |
228 | assert_equal 'redmine@example.net', mail.from_addrs.first |
|
226 | assert_equal 'redmine@example.net', mail.from_addrs.first | |
229 | assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s |
|
227 | assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s | |
230 | end |
|
228 | end | |
231 |
|
229 | |||
232 | def test_should_not_send_email_without_recipient |
|
230 | def test_should_not_send_email_without_recipient | |
233 | news = News.first |
|
231 | news = News.first | |
234 | user = news.author |
|
232 | user = news.author | |
235 | # Remove members except news author |
|
233 | # Remove members except news author | |
236 | news.project.memberships.each {|m| m.destroy unless m.user == user} |
|
234 | news.project.memberships.each {|m| m.destroy unless m.user == user} | |
237 |
|
235 | |||
238 | user.pref.no_self_notified = false |
|
236 | user.pref.no_self_notified = false | |
239 | user.pref.save |
|
237 | user.pref.save | |
240 | User.current = user |
|
238 | User.current = user | |
241 | Mailer.news_added(news.reload).deliver |
|
239 | Mailer.news_added(news.reload).deliver | |
242 | assert_equal 1, last_email.bcc.size |
|
240 | assert_equal 1, last_email.bcc.size | |
243 |
|
241 | |||
244 | # nobody to notify |
|
242 | # nobody to notify | |
245 | user.pref.no_self_notified = true |
|
243 | user.pref.no_self_notified = true | |
246 | user.pref.save |
|
244 | user.pref.save | |
247 | User.current = user |
|
245 | User.current = user | |
248 | ActionMailer::Base.deliveries.clear |
|
246 | ActionMailer::Base.deliveries.clear | |
249 | Mailer.news_added(news.reload).deliver |
|
247 | Mailer.news_added(news.reload).deliver | |
250 | assert ActionMailer::Base.deliveries.empty? |
|
248 | assert ActionMailer::Base.deliveries.empty? | |
251 | end |
|
249 | end | |
252 |
|
250 | |||
253 | def test_issue_add_message_id |
|
251 | def test_issue_add_message_id | |
254 | issue = Issue.find(2) |
|
252 | issue = Issue.find(2) | |
255 | Mailer.deliver_issue_add(issue) |
|
253 | Mailer.deliver_issue_add(issue) | |
256 | mail = last_email |
|
254 | mail = last_email | |
257 | assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id |
|
255 | assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id | |
258 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
256 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references | |
259 | end |
|
257 | end | |
260 |
|
258 | |||
261 | def test_issue_edit_message_id |
|
259 | def test_issue_edit_message_id | |
262 | journal = Journal.find(3) |
|
260 | journal = Journal.find(3) | |
263 | journal.issue = Issue.find(2) |
|
261 | journal.issue = Issue.find(2) | |
264 |
|
262 | |||
265 | Mailer.deliver_issue_edit(journal) |
|
263 | Mailer.deliver_issue_edit(journal) | |
266 | mail = last_email |
|
264 | mail = last_email | |
267 | assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
265 | assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id | |
268 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
266 | assert_include "redmine.issue-2.20060719190421@example.net", mail.references | |
269 | assert_select_email do |
|
267 | assert_select_email do | |
270 | # link to the update |
|
268 | # link to the update | |
271 | assert_select "a[href=?]", |
|
269 | assert_select "a[href=?]", | |
272 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" |
|
270 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" | |
273 | end |
|
271 | end | |
274 | end |
|
272 | end | |
275 |
|
273 | |||
276 | def test_message_posted_message_id |
|
274 | def test_message_posted_message_id | |
277 | message = Message.find(1) |
|
275 | message = Message.find(1) | |
278 | Mailer.message_posted(message).deliver |
|
276 | Mailer.message_posted(message).deliver | |
279 | mail = last_email |
|
277 | mail = last_email | |
280 | assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
278 | assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id | |
281 | assert_include "redmine.message-1.20070512151532@example.net", mail.references |
|
279 | assert_include "redmine.message-1.20070512151532@example.net", mail.references | |
282 | assert_select_email do |
|
280 | assert_select_email do | |
283 | # link to the message |
|
281 | # link to the message | |
284 | assert_select "a[href=?]", |
|
282 | assert_select "a[href=?]", | |
285 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", |
|
283 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", | |
286 | :text => message.subject |
|
284 | :text => message.subject | |
287 | end |
|
285 | end | |
288 | end |
|
286 | end | |
289 |
|
287 | |||
290 | def test_reply_posted_message_id |
|
288 | def test_reply_posted_message_id | |
291 | message = Message.find(3) |
|
289 | message = Message.find(3) | |
292 | Mailer.message_posted(message).deliver |
|
290 | Mailer.message_posted(message).deliver | |
293 | mail = last_email |
|
291 | mail = last_email | |
294 | assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
|
292 | assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id | |
295 | assert_include "redmine.message-1.20070512151532@example.net", mail.references |
|
293 | assert_include "redmine.message-1.20070512151532@example.net", mail.references | |
296 | assert_select_email do |
|
294 | assert_select_email do | |
297 | # link to the reply |
|
295 | # link to the reply | |
298 | assert_select "a[href=?]", |
|
296 | assert_select "a[href=?]", | |
299 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
|
297 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", | |
300 | :text => message.subject |
|
298 | :text => message.subject | |
301 | end |
|
299 | end | |
302 | end |
|
300 | end | |
303 |
|
301 | |||
304 | test "#issue_add should notify project members" do |
|
302 | test "#issue_add should notify project members" do | |
305 | issue = Issue.find(1) |
|
303 | issue = Issue.find(1) | |
306 | assert Mailer.deliver_issue_add(issue) |
|
304 | assert Mailer.deliver_issue_add(issue) | |
307 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
305 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
308 | end |
|
306 | end | |
309 |
|
307 | |||
310 | def test_issue_add_should_send_mail_to_all_user_email_address |
|
308 | def test_issue_add_should_send_mail_to_all_user_email_address | |
311 | EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo') |
|
309 | EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo') | |
312 | issue = Issue.find(1) |
|
310 | issue = Issue.find(1) | |
313 | assert Mailer.deliver_issue_add(issue) |
|
311 | assert Mailer.deliver_issue_add(issue) | |
314 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
312 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
315 | assert last_email.bcc.include?('otheremail@somenet.foo') |
|
313 | assert last_email.bcc.include?('otheremail@somenet.foo') | |
316 | end |
|
314 | end | |
317 |
|
315 | |||
318 | test "#issue_add should not notify project members that are not allow to view the issue" do |
|
316 | test "#issue_add should not notify project members that are not allow to view the issue" do | |
319 | issue = Issue.find(1) |
|
317 | issue = Issue.find(1) | |
320 | Role.find(2).remove_permission!(:view_issues) |
|
318 | Role.find(2).remove_permission!(:view_issues) | |
321 | assert Mailer.deliver_issue_add(issue) |
|
319 | assert Mailer.deliver_issue_add(issue) | |
322 | assert !last_email.bcc.include?('dlopper@somenet.foo') |
|
320 | assert !last_email.bcc.include?('dlopper@somenet.foo') | |
323 | end |
|
321 | end | |
324 |
|
322 | |||
325 | test "#issue_add should notify issue watchers" do |
|
323 | test "#issue_add should notify issue watchers" do | |
326 | issue = Issue.find(1) |
|
324 | issue = Issue.find(1) | |
327 | user = User.find(9) |
|
325 | user = User.find(9) | |
328 | # minimal email notification options |
|
326 | # minimal email notification options | |
329 | user.pref.no_self_notified = '1' |
|
327 | user.pref.no_self_notified = '1' | |
330 | user.pref.save |
|
328 | user.pref.save | |
331 | user.mail_notification = false |
|
329 | user.mail_notification = false | |
332 | user.save |
|
330 | user.save | |
333 |
|
331 | |||
334 | Watcher.create!(:watchable => issue, :user => user) |
|
332 | Watcher.create!(:watchable => issue, :user => user) | |
335 | assert Mailer.deliver_issue_add(issue) |
|
333 | assert Mailer.deliver_issue_add(issue) | |
336 | assert last_email.bcc.include?(user.mail) |
|
334 | assert last_email.bcc.include?(user.mail) | |
337 | end |
|
335 | end | |
338 |
|
336 | |||
339 | test "#issue_add should not notify watchers not allowed to view the issue" do |
|
337 | test "#issue_add should not notify watchers not allowed to view the issue" do | |
340 | issue = Issue.find(1) |
|
338 | issue = Issue.find(1) | |
341 | user = User.find(9) |
|
339 | user = User.find(9) | |
342 | Watcher.create!(:watchable => issue, :user => user) |
|
340 | Watcher.create!(:watchable => issue, :user => user) | |
343 | Role.non_member.remove_permission!(:view_issues) |
|
341 | Role.non_member.remove_permission!(:view_issues) | |
344 | assert Mailer.deliver_issue_add(issue) |
|
342 | assert Mailer.deliver_issue_add(issue) | |
345 | assert !last_email.bcc.include?(user.mail) |
|
343 | assert !last_email.bcc.include?(user.mail) | |
346 | end |
|
344 | end | |
347 |
|
345 | |||
348 | def test_issue_add_should_include_enabled_fields |
|
346 | def test_issue_add_should_include_enabled_fields | |
349 | Setting.default_language = 'en' |
|
|||
350 | issue = Issue.find(2) |
|
347 | issue = Issue.find(2) | |
351 | assert Mailer.deliver_issue_add(issue) |
|
348 | assert Mailer.deliver_issue_add(issue) | |
352 | assert_mail_body_match '* Target version: 1.0', last_email |
|
349 | assert_mail_body_match '* Target version: 1.0', last_email | |
353 | assert_select_email do |
|
350 | assert_select_email do | |
354 | assert_select 'li', :text => 'Target version: 1.0' |
|
351 | assert_select 'li', :text => 'Target version: 1.0' | |
355 | end |
|
352 | end | |
356 | end |
|
353 | end | |
357 |
|
354 | |||
358 | def test_issue_add_should_not_include_disabled_fields |
|
355 | def test_issue_add_should_not_include_disabled_fields | |
359 | Setting.default_language = 'en' |
|
|||
360 | issue = Issue.find(2) |
|
356 | issue = Issue.find(2) | |
361 | tracker = issue.tracker |
|
357 | tracker = issue.tracker | |
362 | tracker.core_fields -= ['fixed_version_id'] |
|
358 | tracker.core_fields -= ['fixed_version_id'] | |
363 | tracker.save! |
|
359 | tracker.save! | |
364 | assert Mailer.deliver_issue_add(issue) |
|
360 | assert Mailer.deliver_issue_add(issue) | |
365 | assert_mail_body_no_match 'Target version', last_email |
|
361 | assert_mail_body_no_match 'Target version', last_email | |
366 | assert_select_email do |
|
362 | assert_select_email do | |
367 | assert_select 'li', :text => /Target version/, :count => 0 |
|
363 | assert_select 'li', :text => /Target version/, :count => 0 | |
368 | end |
|
364 | end | |
369 | end |
|
365 | end | |
370 |
|
366 | |||
371 | # test mailer methods for each language |
|
367 | # test mailer methods for each language | |
372 | def test_issue_add |
|
368 | def test_issue_add | |
373 | issue = Issue.find(1) |
|
369 | issue = Issue.find(1) | |
374 | valid_languages.each do |lang| |
|
370 | with_each_language_as_default do | |
375 | Setting.default_language = lang.to_s |
|
|||
376 | assert Mailer.deliver_issue_add(issue) |
|
371 | assert Mailer.deliver_issue_add(issue) | |
377 | end |
|
372 | end | |
378 | end |
|
373 | end | |
379 |
|
374 | |||
380 | def test_issue_edit |
|
375 | def test_issue_edit | |
381 | journal = Journal.find(1) |
|
376 | journal = Journal.find(1) | |
382 | valid_languages.each do |lang| |
|
377 | with_each_language_as_default do | |
383 | Setting.default_language = lang.to_s |
|
|||
384 | assert Mailer.deliver_issue_edit(journal) |
|
378 | assert Mailer.deliver_issue_edit(journal) | |
385 | end |
|
379 | end | |
386 | end |
|
380 | end | |
387 |
|
381 | |||
388 | def test_issue_edit_should_send_private_notes_to_users_with_permission_only |
|
382 | def test_issue_edit_should_send_private_notes_to_users_with_permission_only | |
389 | journal = Journal.find(1) |
|
383 | journal = Journal.find(1) | |
390 | journal.private_notes = true |
|
384 | journal.private_notes = true | |
391 | journal.save! |
|
385 | journal.save! | |
392 |
|
386 | |||
393 | Role.find(2).add_permission! :view_private_notes |
|
387 | Role.find(2).add_permission! :view_private_notes | |
394 | Mailer.deliver_issue_edit(journal) |
|
388 | Mailer.deliver_issue_edit(journal) | |
395 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort |
|
389 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort | |
396 |
|
390 | |||
397 | Role.find(2).remove_permission! :view_private_notes |
|
391 | Role.find(2).remove_permission! :view_private_notes | |
398 | Mailer.deliver_issue_edit(journal) |
|
392 | Mailer.deliver_issue_edit(journal) | |
399 | assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort |
|
393 | assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort | |
400 | end |
|
394 | end | |
401 |
|
395 | |||
402 | def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only |
|
396 | def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only | |
403 | Issue.find(1).set_watcher(User.find_by_login('someone')) |
|
397 | Issue.find(1).set_watcher(User.find_by_login('someone')) | |
404 | journal = Journal.find(1) |
|
398 | journal = Journal.find(1) | |
405 | journal.private_notes = true |
|
399 | journal.private_notes = true | |
406 | journal.save! |
|
400 | journal.save! | |
407 |
|
401 | |||
408 | Role.non_member.add_permission! :view_private_notes |
|
402 | Role.non_member.add_permission! :view_private_notes | |
409 | Mailer.deliver_issue_edit(journal) |
|
403 | Mailer.deliver_issue_edit(journal) | |
410 | assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort |
|
404 | assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort | |
411 |
|
405 | |||
412 | Role.non_member.remove_permission! :view_private_notes |
|
406 | Role.non_member.remove_permission! :view_private_notes | |
413 | Mailer.deliver_issue_edit(journal) |
|
407 | Mailer.deliver_issue_edit(journal) | |
414 | assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort |
|
408 | assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort | |
415 | end |
|
409 | end | |
416 |
|
410 | |||
417 | def test_issue_edit_should_mark_private_notes |
|
411 | def test_issue_edit_should_mark_private_notes | |
418 | journal = Journal.find(2) |
|
412 | journal = Journal.find(2) | |
419 | journal.private_notes = true |
|
413 | journal.private_notes = true | |
420 | journal.save! |
|
414 | journal.save! | |
421 |
|
415 | |||
422 | with_settings :default_language => 'en' do |
|
416 | with_settings :default_language => 'en' do | |
423 | Mailer.deliver_issue_edit(journal) |
|
417 | Mailer.deliver_issue_edit(journal) | |
424 | end |
|
418 | end | |
425 | assert_mail_body_match '(Private notes)', last_email |
|
419 | assert_mail_body_match '(Private notes)', last_email | |
426 | end |
|
420 | end | |
427 |
|
421 | |||
428 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue |
|
422 | def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue | |
429 | issue = Issue.generate! |
|
423 | issue = Issue.generate! | |
430 | issue.init_journal(User.find(1)) |
|
424 | issue.init_journal(User.find(1)) | |
431 | private_issue = Issue.generate!(:is_private => true) |
|
425 | private_issue = Issue.generate!(:is_private => true) | |
432 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') |
|
426 | IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates') | |
433 | issue.reload |
|
427 | issue.reload | |
434 | assert_equal 1, issue.journals.size |
|
428 | assert_equal 1, issue.journals.size | |
435 | journal = issue.journals.first |
|
429 | journal = issue.journals.first | |
436 | ActionMailer::Base.deliveries.clear |
|
430 | ActionMailer::Base.deliveries.clear | |
437 |
|
431 | |||
438 | Mailer.deliver_issue_edit(journal) |
|
432 | Mailer.deliver_issue_edit(journal) | |
439 | last_email.bcc.each do |email| |
|
433 | last_email.bcc.each do |email| | |
440 | user = User.find_by_mail(email) |
|
434 | user = User.find_by_mail(email) | |
441 | assert private_issue.visible?(user), "Issue was not visible to #{user}" |
|
435 | assert private_issue.visible?(user), "Issue was not visible to #{user}" | |
442 | end |
|
436 | end | |
443 | end |
|
437 | end | |
444 |
|
438 | |||
445 | def test_document_added |
|
439 | def test_document_added | |
446 | document = Document.find(1) |
|
440 | document = Document.find(1) | |
447 | valid_languages.each do |lang| |
|
441 | with_each_language_as_default do | |
448 | Setting.default_language = lang.to_s |
|
|||
449 | assert Mailer.document_added(document).deliver |
|
442 | assert Mailer.document_added(document).deliver | |
450 | end |
|
443 | end | |
451 | end |
|
444 | end | |
452 |
|
445 | |||
453 | def test_attachments_added |
|
446 | def test_attachments_added | |
454 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
447 | attachements = [ Attachment.find_by_container_type('Document') ] | |
455 | valid_languages.each do |lang| |
|
448 | with_each_language_as_default do | |
456 | Setting.default_language = lang.to_s |
|
|||
457 | assert Mailer.attachments_added(attachements).deliver |
|
449 | assert Mailer.attachments_added(attachements).deliver | |
458 | end |
|
450 | end | |
459 | end |
|
451 | end | |
460 |
|
452 | |||
461 | def test_version_file_added |
|
453 | def test_version_file_added | |
462 | attachements = [ Attachment.find_by_container_type('Version') ] |
|
454 | attachements = [ Attachment.find_by_container_type('Version') ] | |
463 | assert Mailer.attachments_added(attachements).deliver |
|
455 | assert Mailer.attachments_added(attachements).deliver | |
464 | assert_not_nil last_email.bcc |
|
456 | assert_not_nil last_email.bcc | |
465 | assert last_email.bcc.any? |
|
457 | assert last_email.bcc.any? | |
466 | assert_select_email do |
|
458 | assert_select_email do | |
467 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
459 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | |
468 | end |
|
460 | end | |
469 | end |
|
461 | end | |
470 |
|
462 | |||
471 | def test_project_file_added |
|
463 | def test_project_file_added | |
472 | attachements = [ Attachment.find_by_container_type('Project') ] |
|
464 | attachements = [ Attachment.find_by_container_type('Project') ] | |
473 | assert Mailer.attachments_added(attachements).deliver |
|
465 | assert Mailer.attachments_added(attachements).deliver | |
474 | assert_not_nil last_email.bcc |
|
466 | assert_not_nil last_email.bcc | |
475 | assert last_email.bcc.any? |
|
467 | assert last_email.bcc.any? | |
476 | assert_select_email do |
|
468 | assert_select_email do | |
477 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
469 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | |
478 | end |
|
470 | end | |
479 | end |
|
471 | end | |
480 |
|
472 | |||
481 | def test_news_added |
|
473 | def test_news_added | |
482 | news = News.first |
|
474 | news = News.first | |
483 | valid_languages.each do |lang| |
|
475 | with_each_language_as_default do | |
484 | Setting.default_language = lang.to_s |
|
|||
485 | assert Mailer.news_added(news).deliver |
|
476 | assert Mailer.news_added(news).deliver | |
486 | end |
|
477 | end | |
487 | end |
|
478 | end | |
488 |
|
479 | |||
489 | def test_news_added_should_notify_project_news_watchers |
|
480 | def test_news_added_should_notify_project_news_watchers | |
490 | user1 = User.generate! |
|
481 | user1 = User.generate! | |
491 | user2 = User.generate! |
|
482 | user2 = User.generate! | |
492 | news = News.find(1) |
|
483 | news = News.find(1) | |
493 | news.project.enabled_module('news').add_watcher(user1) |
|
484 | news.project.enabled_module('news').add_watcher(user1) | |
494 |
|
485 | |||
495 | Mailer.news_added(news).deliver |
|
486 | Mailer.news_added(news).deliver | |
496 | assert_include user1.mail, last_email.bcc |
|
487 | assert_include user1.mail, last_email.bcc | |
497 | assert_not_include user2.mail, last_email.bcc |
|
488 | assert_not_include user2.mail, last_email.bcc | |
498 | end |
|
489 | end | |
499 |
|
490 | |||
500 | def test_news_comment_added |
|
491 | def test_news_comment_added | |
501 | comment = Comment.find(2) |
|
492 | comment = Comment.find(2) | |
502 | valid_languages.each do |lang| |
|
493 | with_each_language_as_default do | |
503 | Setting.default_language = lang.to_s |
|
|||
504 | assert Mailer.news_comment_added(comment).deliver |
|
494 | assert Mailer.news_comment_added(comment).deliver | |
505 | end |
|
495 | end | |
506 | end |
|
496 | end | |
507 |
|
497 | |||
508 | def test_message_posted |
|
498 | def test_message_posted | |
509 | message = Message.first |
|
499 | message = Message.first | |
510 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
500 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} | |
511 | recipients = recipients.compact.uniq |
|
501 | recipients = recipients.compact.uniq | |
512 | valid_languages.each do |lang| |
|
502 | with_each_language_as_default do | |
513 | Setting.default_language = lang.to_s |
|
|||
514 | assert Mailer.message_posted(message).deliver |
|
503 | assert Mailer.message_posted(message).deliver | |
515 | end |
|
504 | end | |
516 | end |
|
505 | end | |
517 |
|
506 | |||
518 | def test_wiki_content_added |
|
507 | def test_wiki_content_added | |
519 | content = WikiContent.find(1) |
|
508 | content = WikiContent.find(1) | |
520 | valid_languages.each do |lang| |
|
509 | with_each_language_as_default do | |
521 | Setting.default_language = lang.to_s |
|
|||
522 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
510 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
523 | assert Mailer.wiki_content_added(content).deliver |
|
511 | assert Mailer.wiki_content_added(content).deliver | |
524 | assert_select_email do |
|
512 | assert_select_email do | |
525 | assert_select 'a[href=?]', |
|
513 | assert_select 'a[href=?]', | |
526 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', |
|
514 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', | |
527 | :text => 'CookBook documentation' |
|
515 | :text => 'CookBook documentation' | |
528 | end |
|
516 | end | |
529 | end |
|
517 | end | |
530 | end |
|
518 | end | |
531 | end |
|
519 | end | |
532 |
|
520 | |||
533 | def test_wiki_content_updated |
|
521 | def test_wiki_content_updated | |
534 | content = WikiContent.find(1) |
|
522 | content = WikiContent.find(1) | |
535 | valid_languages.each do |lang| |
|
523 | with_each_language_as_default do | |
536 | Setting.default_language = lang.to_s |
|
|||
537 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
524 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
538 | assert Mailer.wiki_content_updated(content).deliver |
|
525 | assert Mailer.wiki_content_updated(content).deliver | |
539 | assert_select_email do |
|
526 | assert_select_email do | |
540 | assert_select 'a[href=?]', |
|
527 | assert_select 'a[href=?]', | |
541 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', |
|
528 | 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation', | |
542 | :text => 'CookBook documentation' |
|
529 | :text => 'CookBook documentation' | |
543 | end |
|
530 | end | |
544 | end |
|
531 | end | |
545 | end |
|
532 | end | |
546 | end |
|
533 | end | |
547 |
|
534 | |||
548 | def test_account_information |
|
535 | def test_account_information | |
549 | user = User.find(2) |
|
536 | user = User.find(2) | |
550 | valid_languages.each do |lang| |
|
537 | valid_languages.each do |lang| | |
551 | user.update_attribute :language, lang.to_s |
|
538 | user.update_attribute :language, lang.to_s | |
552 | user.reload |
|
539 | user.reload | |
553 | assert Mailer.account_information(user, 'pAsswORd').deliver |
|
540 | assert Mailer.account_information(user, 'pAsswORd').deliver | |
554 | end |
|
541 | end | |
555 | end |
|
542 | end | |
556 |
|
543 | |||
557 | def test_lost_password |
|
544 | def test_lost_password | |
558 | token = Token.find(2) |
|
545 | token = Token.find(2) | |
559 | valid_languages.each do |lang| |
|
546 | valid_languages.each do |lang| | |
560 | token.user.update_attribute :language, lang.to_s |
|
547 | token.user.update_attribute :language, lang.to_s | |
561 | token.reload |
|
548 | token.reload | |
562 | assert Mailer.lost_password(token).deliver |
|
549 | assert Mailer.lost_password(token).deliver | |
563 | end |
|
550 | end | |
564 | end |
|
551 | end | |
565 |
|
552 | |||
566 | def test_register |
|
553 | def test_register | |
567 | token = Token.find(1) |
|
554 | token = Token.find(1) | |
568 | Setting.host_name = 'redmine.foo' |
|
555 | Setting.host_name = 'redmine.foo' | |
569 | Setting.protocol = 'https' |
|
556 | Setting.protocol = 'https' | |
570 |
|
557 | |||
571 | valid_languages.each do |lang| |
|
558 | valid_languages.each do |lang| | |
572 | token.user.update_attribute :language, lang.to_s |
|
559 | token.user.update_attribute :language, lang.to_s | |
573 | token.reload |
|
560 | token.reload | |
574 | ActionMailer::Base.deliveries.clear |
|
561 | ActionMailer::Base.deliveries.clear | |
575 | assert Mailer.register(token).deliver |
|
562 | assert Mailer.register(token).deliver | |
576 | mail = last_email |
|
563 | mail = last_email | |
577 | assert_select_email do |
|
564 | assert_select_email do | |
578 | assert_select "a[href=?]", |
|
565 | assert_select "a[href=?]", | |
579 | "https://redmine.foo/account/activate?token=#{token.value}", |
|
566 | "https://redmine.foo/account/activate?token=#{token.value}", | |
580 | :text => "https://redmine.foo/account/activate?token=#{token.value}" |
|
567 | :text => "https://redmine.foo/account/activate?token=#{token.value}" | |
581 | end |
|
568 | end | |
582 | end |
|
569 | end | |
583 | end |
|
570 | end | |
584 |
|
571 | |||
585 | def test_test |
|
572 | def test_test | |
586 | user = User.find(1) |
|
573 | user = User.find(1) | |
587 | valid_languages.each do |lang| |
|
574 | valid_languages.each do |lang| | |
588 | user.update_attribute :language, lang.to_s |
|
575 | user.update_attribute :language, lang.to_s | |
589 | assert Mailer.test_email(user).deliver |
|
576 | assert Mailer.test_email(user).deliver | |
590 | end |
|
577 | end | |
591 | end |
|
578 | end | |
592 |
|
579 | |||
593 | def test_reminders |
|
580 | def test_reminders | |
594 | Mailer.reminders(:days => 42) |
|
581 | Mailer.reminders(:days => 42) | |
595 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
582 | assert_equal 1, ActionMailer::Base.deliveries.size | |
596 | mail = last_email |
|
583 | mail = last_email | |
597 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
584 | assert mail.bcc.include?('dlopper@somenet.foo') | |
598 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail |
|
585 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail | |
599 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
586 | assert_equal '1 issue(s) due in the next 42 days', mail.subject | |
600 | end |
|
587 | end | |
601 |
|
588 | |||
602 | def test_reminders_should_not_include_closed_issues |
|
589 | def test_reminders_should_not_include_closed_issues | |
603 | with_settings :default_language => 'en' do |
|
590 | with_settings :default_language => 'en' do | |
604 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, |
|
591 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, | |
605 | :subject => 'Closed issue', :assigned_to_id => 3, |
|
592 | :subject => 'Closed issue', :assigned_to_id => 3, | |
606 | :due_date => 5.days.from_now, |
|
593 | :due_date => 5.days.from_now, | |
607 | :author_id => 2) |
|
594 | :author_id => 2) | |
608 | ActionMailer::Base.deliveries.clear |
|
595 | ActionMailer::Base.deliveries.clear | |
609 |
|
596 | |||
610 | Mailer.reminders(:days => 42) |
|
597 | Mailer.reminders(:days => 42) | |
611 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
598 | assert_equal 1, ActionMailer::Base.deliveries.size | |
612 | mail = last_email |
|
599 | mail = last_email | |
613 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
600 | assert mail.bcc.include?('dlopper@somenet.foo') | |
614 | assert_mail_body_no_match 'Closed issue', mail |
|
601 | assert_mail_body_no_match 'Closed issue', mail | |
615 | end |
|
602 | end | |
616 | end |
|
603 | end | |
617 |
|
604 | |||
618 | def test_reminders_for_users |
|
605 | def test_reminders_for_users | |
619 | Mailer.reminders(:days => 42, :users => ['5']) |
|
606 | Mailer.reminders(:days => 42, :users => ['5']) | |
620 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
607 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper | |
621 | Mailer.reminders(:days => 42, :users => ['3']) |
|
608 | Mailer.reminders(:days => 42, :users => ['3']) | |
622 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
609 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper | |
623 | mail = last_email |
|
610 | mail = last_email | |
624 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
611 | assert mail.bcc.include?('dlopper@somenet.foo') | |
625 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail |
|
612 | assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail | |
626 | end |
|
613 | end | |
627 |
|
614 | |||
628 | def test_reminder_should_include_issues_assigned_to_groups |
|
615 | def test_reminder_should_include_issues_assigned_to_groups | |
629 | with_settings :default_language => 'en' do |
|
616 | with_settings :default_language => 'en' do | |
630 | group = Group.generate! |
|
617 | group = Group.generate! | |
631 | group.users << User.find(2) |
|
618 | group.users << User.find(2) | |
632 | group.users << User.find(3) |
|
619 | group.users << User.find(3) | |
633 |
|
620 | |||
634 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, |
|
621 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, | |
635 | :subject => 'Assigned to group', :assigned_to => group, |
|
622 | :subject => 'Assigned to group', :assigned_to => group, | |
636 | :due_date => 5.days.from_now, |
|
623 | :due_date => 5.days.from_now, | |
637 | :author_id => 2) |
|
624 | :author_id => 2) | |
638 | ActionMailer::Base.deliveries.clear |
|
625 | ActionMailer::Base.deliveries.clear | |
639 |
|
626 | |||
640 | Mailer.reminders(:days => 7) |
|
627 | Mailer.reminders(:days => 7) | |
641 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
628 | assert_equal 2, ActionMailer::Base.deliveries.size | |
642 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort |
|
629 | assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort | |
643 | ActionMailer::Base.deliveries.each do |mail| |
|
630 | ActionMailer::Base.deliveries.each do |mail| | |
644 | assert_mail_body_match 'Assigned to group', mail |
|
631 | assert_mail_body_match 'Assigned to group', mail | |
645 | end |
|
632 | end | |
646 | end |
|
633 | end | |
647 | end |
|
634 | end | |
648 |
|
635 | |||
649 | def test_mailer_should_not_change_locale |
|
636 | def test_mailer_should_not_change_locale | |
650 | Setting.default_language = 'en' |
|
|||
651 | # Set current language to italian |
|
637 | # Set current language to italian | |
652 | set_language_if_valid 'it' |
|
638 | set_language_if_valid 'it' | |
653 | # Send an email to a french user |
|
639 | # Send an email to a french user | |
654 | user = User.find(1) |
|
640 | user = User.find(1) | |
655 | user.language = 'fr' |
|
641 | user.language = 'fr' | |
656 | Mailer.account_activated(user).deliver |
|
642 | Mailer.account_activated(user).deliver | |
657 | mail = last_email |
|
643 | mail = last_email | |
658 | assert_mail_body_match 'Votre compte', mail |
|
644 | assert_mail_body_match 'Votre compte', mail | |
659 |
|
645 | |||
660 | assert_equal :it, current_language |
|
646 | assert_equal :it, current_language | |
661 | end |
|
647 | end | |
662 |
|
648 | |||
663 | def test_with_deliveries_off |
|
649 | def test_with_deliveries_off | |
664 | Mailer.with_deliveries false do |
|
650 | Mailer.with_deliveries false do | |
665 | Mailer.test_email(User.find(1)).deliver |
|
651 | Mailer.test_email(User.find(1)).deliver | |
666 | end |
|
652 | end | |
667 | assert ActionMailer::Base.deliveries.empty? |
|
653 | assert ActionMailer::Base.deliveries.empty? | |
668 | # should restore perform_deliveries |
|
654 | # should restore perform_deliveries | |
669 | assert ActionMailer::Base.perform_deliveries |
|
655 | assert ActionMailer::Base.perform_deliveries | |
670 | end |
|
656 | end | |
671 |
|
657 | |||
672 | def test_token_for_should_strip_trailing_gt_from_address_with_full_name |
|
658 | def test_token_for_should_strip_trailing_gt_from_address_with_full_name | |
673 | with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do |
|
659 | with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do | |
674 | assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!) |
|
660 | assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!) | |
675 | end |
|
661 | end | |
676 | end |
|
662 | end | |
677 |
|
663 | |||
678 | def test_layout_should_include_the_emails_header |
|
664 | def test_layout_should_include_the_emails_header | |
679 | with_settings :emails_header => "*Header content*" do |
|
665 | with_settings :emails_header => "*Header content*" do | |
680 | with_settings :plain_text_mail => 0 do |
|
666 | with_settings :plain_text_mail => 0 do | |
681 | assert Mailer.test_email(User.find(1)).deliver |
|
667 | assert Mailer.test_email(User.find(1)).deliver | |
682 | assert_select_email do |
|
668 | assert_select_email do | |
683 | assert_select ".header" do |
|
669 | assert_select ".header" do | |
684 | assert_select "strong", :text => "Header content" |
|
670 | assert_select "strong", :text => "Header content" | |
685 | end |
|
671 | end | |
686 | end |
|
672 | end | |
687 | end |
|
673 | end | |
688 | with_settings :plain_text_mail => 1 do |
|
674 | with_settings :plain_text_mail => 1 do | |
689 | assert Mailer.test_email(User.find(1)).deliver |
|
675 | assert Mailer.test_email(User.find(1)).deliver | |
690 | mail = last_email |
|
676 | mail = last_email | |
691 | assert_not_nil mail |
|
677 | assert_not_nil mail | |
692 | assert_include "*Header content*", mail.body.decoded |
|
678 | assert_include "*Header content*", mail.body.decoded | |
693 | end |
|
679 | end | |
694 | end |
|
680 | end | |
695 | end |
|
681 | end | |
696 |
|
682 | |||
697 | def test_layout_should_not_include_empty_emails_header |
|
683 | def test_layout_should_not_include_empty_emails_header | |
698 | with_settings :emails_header => "", :plain_text_mail => 0 do |
|
684 | with_settings :emails_header => "", :plain_text_mail => 0 do | |
699 | assert Mailer.test_email(User.find(1)).deliver |
|
685 | assert Mailer.test_email(User.find(1)).deliver | |
700 | assert_select_email do |
|
686 | assert_select_email do | |
701 | assert_select ".header", false |
|
687 | assert_select ".header", false | |
702 | end |
|
688 | end | |
703 | end |
|
689 | end | |
704 | end |
|
690 | end | |
705 |
|
691 | |||
706 | def test_layout_should_include_the_emails_footer |
|
692 | def test_layout_should_include_the_emails_footer | |
707 | with_settings :emails_footer => "*Footer content*" do |
|
693 | with_settings :emails_footer => "*Footer content*" do | |
708 | with_settings :plain_text_mail => 0 do |
|
694 | with_settings :plain_text_mail => 0 do | |
709 | assert Mailer.test_email(User.find(1)).deliver |
|
695 | assert Mailer.test_email(User.find(1)).deliver | |
710 | assert_select_email do |
|
696 | assert_select_email do | |
711 | assert_select ".footer" do |
|
697 | assert_select ".footer" do | |
712 | assert_select "strong", :text => "Footer content" |
|
698 | assert_select "strong", :text => "Footer content" | |
713 | end |
|
699 | end | |
714 | end |
|
700 | end | |
715 | end |
|
701 | end | |
716 | with_settings :plain_text_mail => 1 do |
|
702 | with_settings :plain_text_mail => 1 do | |
717 | assert Mailer.test_email(User.find(1)).deliver |
|
703 | assert Mailer.test_email(User.find(1)).deliver | |
718 | mail = last_email |
|
704 | mail = last_email | |
719 | assert_not_nil mail |
|
705 | assert_not_nil mail | |
720 | assert_include "\n-- \n", mail.body.decoded |
|
706 | assert_include "\n-- \n", mail.body.decoded | |
721 | assert_include "*Footer content*", mail.body.decoded |
|
707 | assert_include "*Footer content*", mail.body.decoded | |
722 | end |
|
708 | end | |
723 | end |
|
709 | end | |
724 | end |
|
710 | end | |
725 |
|
711 | |||
726 | def test_layout_should_not_include_empty_emails_footer |
|
712 | def test_layout_should_not_include_empty_emails_footer | |
727 | with_settings :emails_footer => "" do |
|
713 | with_settings :emails_footer => "" do | |
728 | with_settings :plain_text_mail => 0 do |
|
714 | with_settings :plain_text_mail => 0 do | |
729 | assert Mailer.test_email(User.find(1)).deliver |
|
715 | assert Mailer.test_email(User.find(1)).deliver | |
730 | assert_select_email do |
|
716 | assert_select_email do | |
731 | assert_select ".footer", false |
|
717 | assert_select ".footer", false | |
732 | end |
|
718 | end | |
733 | end |
|
719 | end | |
734 | with_settings :plain_text_mail => 1 do |
|
720 | with_settings :plain_text_mail => 1 do | |
735 | assert Mailer.test_email(User.find(1)).deliver |
|
721 | assert Mailer.test_email(User.find(1)).deliver | |
736 | mail = last_email |
|
722 | mail = last_email | |
737 | assert_not_nil mail |
|
723 | assert_not_nil mail | |
738 | assert_not_include "\n-- \n", mail.body.decoded |
|
724 | assert_not_include "\n-- \n", mail.body.decoded | |
739 | end |
|
725 | end | |
740 | end |
|
726 | end | |
741 | end |
|
727 | end | |
742 |
|
728 | |||
743 | def test_should_escape_html_templates_only |
|
729 | def test_should_escape_html_templates_only | |
744 | Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>') |
|
730 | Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>') | |
745 | mail = last_email |
|
731 | mail = last_email | |
746 | assert_equal 2, mail.parts.size |
|
732 | assert_equal 2, mail.parts.size | |
747 | assert_include '<tag>', text_part.body.encoded |
|
733 | assert_include '<tag>', text_part.body.encoded | |
748 | assert_include '<tag>', html_part.body.encoded |
|
734 | assert_include '<tag>', html_part.body.encoded | |
749 | end |
|
735 | end | |
750 |
|
736 | |||
751 | def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true |
|
737 | def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true | |
752 | mail = Mailer.test_email(User.find(1)) |
|
738 | mail = Mailer.test_email(User.find(1)) | |
753 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) |
|
739 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) | |
754 |
|
740 | |||
755 | ActionMailer::Base.raise_delivery_errors = true |
|
741 | ActionMailer::Base.raise_delivery_errors = true | |
756 | assert_raise Exception, "delivery error" do |
|
742 | assert_raise Exception, "delivery error" do | |
757 | mail.deliver |
|
743 | mail.deliver | |
758 | end |
|
744 | end | |
759 | ensure |
|
745 | ensure | |
760 | ActionMailer::Base.raise_delivery_errors = false |
|
746 | ActionMailer::Base.raise_delivery_errors = false | |
761 | end |
|
747 | end | |
762 |
|
748 | |||
763 | def test_should_log_delivery_errors_when_raise_delivery_errors_is_false |
|
749 | def test_should_log_delivery_errors_when_raise_delivery_errors_is_false | |
764 | mail = Mailer.test_email(User.find(1)) |
|
750 | mail = Mailer.test_email(User.find(1)) | |
765 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) |
|
751 | mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error")) | |
766 |
|
752 | |||
767 | Rails.logger.expects(:error).with("Email delivery error: delivery error") |
|
753 | Rails.logger.expects(:error).with("Email delivery error: delivery error") | |
768 | ActionMailer::Base.raise_delivery_errors = false |
|
754 | ActionMailer::Base.raise_delivery_errors = false | |
769 | assert_nothing_raised do |
|
755 | assert_nothing_raised do | |
770 | mail.deliver |
|
756 | mail.deliver | |
771 | end |
|
757 | end | |
772 | end |
|
758 | end | |
773 |
|
759 | |||
774 | def test_with_synched_deliveries_should_yield_with_synced_deliveries |
|
760 | def test_with_synched_deliveries_should_yield_with_synced_deliveries | |
775 | ActionMailer::Base.delivery_method = :async_smtp |
|
761 | ActionMailer::Base.delivery_method = :async_smtp | |
776 | ActionMailer::Base.async_smtp_settings = {:foo => 'bar'} |
|
762 | ActionMailer::Base.async_smtp_settings = {:foo => 'bar'} | |
777 |
|
763 | |||
778 | Mailer.with_synched_deliveries do |
|
764 | Mailer.with_synched_deliveries do | |
779 | assert_equal :smtp, ActionMailer::Base.delivery_method |
|
765 | assert_equal :smtp, ActionMailer::Base.delivery_method | |
780 | assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings) |
|
766 | assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings) | |
781 | end |
|
767 | end | |
782 | assert_equal :async_smtp, ActionMailer::Base.delivery_method |
|
768 | assert_equal :async_smtp, ActionMailer::Base.delivery_method | |
783 | ensure |
|
769 | ensure | |
784 | ActionMailer::Base.delivery_method = :test |
|
770 | ActionMailer::Base.delivery_method = :test | |
785 | end |
|
771 | end | |
786 |
|
772 | |||
787 | def test_email_addresses_should_keep_addresses |
|
773 | def test_email_addresses_should_keep_addresses | |
788 | assert_equal ["foo@example.net"], |
|
774 | assert_equal ["foo@example.net"], | |
789 | Mailer.email_addresses("foo@example.net") |
|
775 | Mailer.email_addresses("foo@example.net") | |
790 |
|
776 | |||
791 | assert_equal ["foo@example.net", "bar@example.net"], |
|
777 | assert_equal ["foo@example.net", "bar@example.net"], | |
792 | Mailer.email_addresses(["foo@example.net", "bar@example.net"]) |
|
778 | Mailer.email_addresses(["foo@example.net", "bar@example.net"]) | |
793 | end |
|
779 | end | |
794 |
|
780 | |||
795 | def test_email_addresses_should_replace_users_with_their_email_addresses |
|
781 | def test_email_addresses_should_replace_users_with_their_email_addresses | |
796 | assert_equal ["admin@somenet.foo"], |
|
782 | assert_equal ["admin@somenet.foo"], | |
797 | Mailer.email_addresses(User.find(1)) |
|
783 | Mailer.email_addresses(User.find(1)) | |
798 |
|
784 | |||
799 | assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"], |
|
785 | assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"], | |
800 | Mailer.email_addresses(User.where(:id => [1,2])).sort |
|
786 | Mailer.email_addresses(User.where(:id => [1,2])).sort | |
801 | end |
|
787 | end | |
802 |
|
788 | |||
803 | def test_email_addresses_should_include_notified_emails_addresses_only |
|
789 | def test_email_addresses_should_include_notified_emails_addresses_only | |
804 | EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false) |
|
790 | EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false) | |
805 | EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo") |
|
791 | EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo") | |
806 |
|
792 | |||
807 | assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"], |
|
793 | assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"], | |
808 | Mailer.email_addresses(User.find(2)).sort |
|
794 | Mailer.email_addresses(User.find(2)).sort | |
809 | end |
|
795 | end | |
810 |
|
796 | |||
811 | private |
|
797 | private | |
812 |
|
798 | |||
813 | def last_email |
|
799 | def last_email | |
814 | mail = ActionMailer::Base.deliveries.last |
|
800 | mail = ActionMailer::Base.deliveries.last | |
815 | assert_not_nil mail |
|
801 | assert_not_nil mail | |
816 |
|
802 | |||
817 | end |
|
803 | end | |
818 |
|
804 | |||
819 | def text_part |
|
805 | def text_part | |
820 | last_email.parts.detect {|part| part.content_type.include?('text/plain')} |
|
806 | last_email.parts.detect {|part| part.content_type.include?('text/plain')} | |
821 | end |
|
807 | end | |
822 |
|
808 | |||
823 | def html_part |
|
809 | def html_part | |
824 | last_email.parts.detect {|part| part.content_type.include?('text/html')} |
|
810 | last_email.parts.detect {|part| part.content_type.include?('text/html')} | |
825 | end |
|
811 | end | |
|
812 | ||||
|
813 | def with_each_language_as_default(&block) | |||
|
814 | valid_languages.each do |lang| | |||
|
815 | with_settings :default_language => lang.to_s do | |||
|
816 | yield lang | |||
|
817 | end | |||
|
818 | end | |||
|
819 | end | |||
826 | end |
|
820 | end |
General Comments 0
You need to be logged in to leave comments.
Login now