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