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