Mercurial > hg > soundsoftware-site
comparison test/unit/mail_handler_test.rb @ 524:1248a47e81b3 feature_36
Merge from branch "luisf"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:39:38 +0100 |
parents | 0c939c159af4 |
children | cbb26bc654de |
comparison
equal
deleted
inserted
replaced
519:3be6bc3c2a17 | 524:1248a47e81b3 |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # | 2 # |
3 # Redmine - project management software | 3 # Redmine - project management software |
4 # Copyright (C) 2006-2009 Jean-Philippe Lang | 4 # Copyright (C) 2006-2011 Jean-Philippe Lang |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; either version 2 | 8 # as published by the Free Software Foundation; either version 2 |
9 # of the License, or (at your option) any later version. | 9 # of the License, or (at your option) any later version. |
10 # | 10 # |
11 # This program is distributed in the hope that it will be useful, | 11 # This program is distributed in the hope that it will be useful, |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 # GNU General Public License for more details. | 14 # GNU General Public License for more details. |
15 # | 15 # |
16 # You should have received a copy of the GNU General Public License | 16 # You should have received a copy of the GNU General Public License |
17 # along with this program; if not, write to the Free Software | 17 # along with this program; if not, write to the Free Software |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | 19 |
20 require File.dirname(__FILE__) + '/../test_helper' | 20 require File.expand_path('../../test_helper', __FILE__) |
21 | 21 |
22 class MailHandlerTest < ActiveSupport::TestCase | 22 class MailHandlerTest < ActiveSupport::TestCase |
23 fixtures :users, :projects, | 23 fixtures :users, :projects, |
24 :enabled_modules, | 24 :enabled_modules, |
25 :roles, | 25 :roles, |
26 :members, | 26 :members, |
27 :member_roles, | 27 :member_roles, |
28 :users, | 28 :users, |
34 :versions, | 34 :versions, |
35 :enumerations, | 35 :enumerations, |
36 :issue_categories, | 36 :issue_categories, |
37 :custom_fields, | 37 :custom_fields, |
38 :custom_fields_trackers, | 38 :custom_fields_trackers, |
39 :custom_fields_projects, | |
39 :boards, | 40 :boards, |
40 :messages | 41 :messages |
41 | 42 |
42 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' | 43 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' |
43 | 44 |
44 def setup | 45 def setup |
45 ActionMailer::Base.deliveries.clear | 46 ActionMailer::Base.deliveries.clear |
46 Setting.notified_events = Redmine::Notifiable.all.collect(&:name) | 47 Setting.notified_events = Redmine::Notifiable.all.collect(&:name) |
47 end | 48 end |
48 | 49 |
49 def test_add_issue | 50 def test_add_issue |
50 ActionMailer::Base.deliveries.clear | 51 ActionMailer::Base.deliveries.clear |
51 # This email contains: 'Project: onlinestore' | 52 # This email contains: 'Project: onlinestore' |
52 issue = submit_email('ticket_on_given_project.eml') | 53 issue = submit_email('ticket_on_given_project.eml') |
53 assert issue.is_a?(Issue) | 54 assert issue.is_a?(Issue) |
54 assert !issue.new_record? | 55 assert !issue.new_record? |
55 issue.reload | 56 issue.reload |
57 assert_equal Project.find(2), issue.project | |
58 assert_equal issue.project.trackers.first, issue.tracker | |
56 assert_equal 'New ticket on a given project', issue.subject | 59 assert_equal 'New ticket on a given project', issue.subject |
57 assert_equal User.find_by_login('jsmith'), issue.author | 60 assert_equal User.find_by_login('jsmith'), issue.author |
58 assert_equal Project.find(2), issue.project | |
59 assert_equal IssueStatus.find_by_name('Resolved'), issue.status | 61 assert_equal IssueStatus.find_by_name('Resolved'), issue.status |
60 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | 62 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
61 assert_equal '2010-01-01', issue.start_date.to_s | 63 assert_equal '2010-01-01', issue.start_date.to_s |
62 assert_equal '2010-12-31', issue.due_date.to_s | 64 assert_equal '2010-12-31', issue.due_date.to_s |
63 assert_equal User.find_by_login('jsmith'), issue.assigned_to | 65 assert_equal User.find_by_login('jsmith'), issue.assigned_to |
64 assert_equal Version.find_by_name('alpha'), issue.fixed_version | 66 assert_equal Version.find_by_name('Alpha'), issue.fixed_version |
65 assert_equal 2.5, issue.estimated_hours | 67 assert_equal 2.5, issue.estimated_hours |
66 assert_equal 30, issue.done_ratio | 68 assert_equal 30, issue.done_ratio |
69 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt] | |
67 # keywords should be removed from the email body | 70 # keywords should be removed from the email body |
68 assert !issue.description.match(/^Project:/i) | 71 assert !issue.description.match(/^Project:/i) |
69 assert !issue.description.match(/^Status:/i) | 72 assert !issue.description.match(/^Status:/i) |
73 assert !issue.description.match(/^Start Date:/i) | |
70 # Email notification should be sent | 74 # Email notification should be sent |
71 mail = ActionMailer::Base.deliveries.last | 75 mail = ActionMailer::Base.deliveries.last |
72 assert_not_nil mail | 76 assert_not_nil mail |
73 assert mail.subject.include?('New ticket on a given project') | 77 assert mail.subject.include?('New ticket on a given project') |
74 end | 78 end |
75 | 79 |
80 def test_add_issue_with_default_tracker | |
81 # This email contains: 'Project: onlinestore' | |
82 issue = submit_email('ticket_on_given_project.eml', :issue => {:tracker => 'Support request'}) | |
83 assert issue.is_a?(Issue) | |
84 assert !issue.new_record? | |
85 issue.reload | |
86 assert_equal 'Support request', issue.tracker.name | |
87 end | |
88 | |
76 def test_add_issue_with_status | 89 def test_add_issue_with_status |
77 # This email contains: 'Project: onlinestore' and 'Status: Resolved' | 90 # This email contains: 'Project: onlinestore' and 'Status: Resolved' |
78 issue = submit_email('ticket_on_given_project.eml') | 91 issue = submit_email('ticket_on_given_project.eml') |
79 assert issue.is_a?(Issue) | 92 assert issue.is_a?(Issue) |
80 assert !issue.new_record? | 93 assert !issue.new_record? |
81 issue.reload | 94 issue.reload |
82 assert_equal Project.find(2), issue.project | 95 assert_equal Project.find(2), issue.project |
83 assert_equal IssueStatus.find_by_name("Resolved"), issue.status | 96 assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
84 end | 97 end |
85 | 98 |
86 def test_add_issue_with_attributes_override | 99 def test_add_issue_with_attributes_override |
87 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority') | 100 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority') |
88 assert issue.is_a?(Issue) | 101 assert issue.is_a?(Issue) |
89 assert !issue.new_record? | 102 assert !issue.new_record? |
90 issue.reload | 103 issue.reload |
94 assert_equal 'Feature request', issue.tracker.to_s | 107 assert_equal 'Feature request', issue.tracker.to_s |
95 assert_equal 'Stock management', issue.category.to_s | 108 assert_equal 'Stock management', issue.category.to_s |
96 assert_equal 'Urgent', issue.priority.to_s | 109 assert_equal 'Urgent', issue.priority.to_s |
97 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | 110 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
98 end | 111 end |
99 | 112 |
100 def test_add_issue_with_partial_attributes_override | 113 def test_add_issue_with_partial_attributes_override |
101 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker']) | 114 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker']) |
102 assert issue.is_a?(Issue) | 115 assert issue.is_a?(Issue) |
103 assert !issue.new_record? | 116 assert !issue.new_record? |
104 issue.reload | 117 issue.reload |
108 assert_equal 'Feature request', issue.tracker.to_s | 121 assert_equal 'Feature request', issue.tracker.to_s |
109 assert_nil issue.category | 122 assert_nil issue.category |
110 assert_equal 'High', issue.priority.to_s | 123 assert_equal 'High', issue.priority.to_s |
111 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | 124 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
112 end | 125 end |
113 | 126 |
114 def test_add_issue_with_spaces_between_attribute_and_separator | 127 def test_add_issue_with_spaces_between_attribute_and_separator |
115 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority') | 128 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority') |
116 assert issue.is_a?(Issue) | 129 assert issue.is_a?(Issue) |
117 assert !issue.new_record? | 130 assert !issue.new_record? |
118 issue.reload | 131 issue.reload |
123 assert_equal 'Stock management', issue.category.to_s | 136 assert_equal 'Stock management', issue.category.to_s |
124 assert_equal 'Urgent', issue.priority.to_s | 137 assert_equal 'Urgent', issue.priority.to_s |
125 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | 138 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
126 end | 139 end |
127 | 140 |
128 | |
129 def test_add_issue_with_attachment_to_specific_project | 141 def test_add_issue_with_attachment_to_specific_project |
130 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) | 142 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) |
131 assert issue.is_a?(Issue) | 143 assert issue.is_a?(Issue) |
132 assert !issue.new_record? | 144 assert !issue.new_record? |
133 issue.reload | 145 issue.reload |
139 assert_equal 1, issue.attachments.size | 151 assert_equal 1, issue.attachments.size |
140 assert_equal 'Paella.jpg', issue.attachments.first.filename | 152 assert_equal 'Paella.jpg', issue.attachments.first.filename |
141 assert_equal 'image/jpeg', issue.attachments.first.content_type | 153 assert_equal 'image/jpeg', issue.attachments.first.content_type |
142 assert_equal 10790, issue.attachments.first.filesize | 154 assert_equal 10790, issue.attachments.first.filesize |
143 end | 155 end |
144 | 156 |
145 def test_add_issue_with_custom_fields | 157 def test_add_issue_with_custom_fields |
146 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) | 158 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) |
147 assert issue.is_a?(Issue) | 159 assert issue.is_a?(Issue) |
148 assert !issue.new_record? | 160 assert !issue.new_record? |
149 issue.reload | 161 issue.reload |
150 assert_equal 'New ticket with custom field values', issue.subject | 162 assert_equal 'New ticket with custom field values', issue.subject |
151 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value | 163 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value |
152 assert !issue.description.match(/^searchable field:/i) | 164 assert !issue.description.match(/^searchable field:/i) |
153 end | 165 end |
154 | 166 |
155 def test_add_issue_with_cc | 167 def test_add_issue_with_cc |
156 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) | 168 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) |
157 assert issue.is_a?(Issue) | 169 assert issue.is_a?(Issue) |
158 assert !issue.new_record? | 170 assert !issue.new_record? |
159 issue.reload | 171 issue.reload |
160 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) | 172 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) |
161 assert_equal 1, issue.watcher_user_ids.size | 173 assert_equal 1, issue.watcher_user_ids.size |
162 end | 174 end |
163 | 175 |
164 def test_add_issue_by_unknown_user | 176 def test_add_issue_by_unknown_user |
165 assert_no_difference 'User.count' do | 177 assert_no_difference 'User.count' do |
166 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) | 178 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) |
167 end | 179 end |
168 end | 180 end |
169 | 181 |
170 def test_add_issue_by_anonymous_user | 182 def test_add_issue_by_anonymous_user |
171 Role.anonymous.add_permission!(:add_issues) | 183 Role.anonymous.add_permission!(:add_issues) |
172 assert_no_difference 'User.count' do | 184 assert_no_difference 'User.count' do |
173 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept') | 185 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept') |
174 assert issue.is_a?(Issue) | 186 assert issue.is_a?(Issue) |
182 issue = submit_email('ticket_by_empty_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept') | 194 issue = submit_email('ticket_by_empty_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept') |
183 assert issue.is_a?(Issue) | 195 assert issue.is_a?(Issue) |
184 assert issue.author.anonymous? | 196 assert issue.author.anonymous? |
185 end | 197 end |
186 end | 198 end |
187 | 199 |
188 def test_add_issue_by_anonymous_user_on_private_project | 200 def test_add_issue_by_anonymous_user_on_private_project |
189 Role.anonymous.add_permission!(:add_issues) | 201 Role.anonymous.add_permission!(:add_issues) |
190 assert_no_difference 'User.count' do | 202 assert_no_difference 'User.count' do |
191 assert_no_difference 'Issue.count' do | 203 assert_no_difference 'Issue.count' do |
192 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept') | 204 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept') |
193 end | 205 end |
194 end | 206 end |
195 end | 207 end |
196 | 208 |
197 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check | 209 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check |
198 assert_no_difference 'User.count' do | 210 assert_no_difference 'User.count' do |
199 assert_difference 'Issue.count' do | 211 assert_difference 'Issue.count' do |
200 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept') | 212 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept') |
201 assert issue.is_a?(Issue) | 213 assert issue.is_a?(Issue) |
202 assert issue.author.anonymous? | 214 assert issue.author.anonymous? |
203 assert !issue.project.is_public? | 215 assert !issue.project.is_public? |
204 end | 216 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt] |
205 end | 217 end |
206 end | 218 end |
207 | 219 end |
220 | |
208 def test_add_issue_by_created_user | 221 def test_add_issue_by_created_user |
209 Setting.default_language = 'en' | 222 Setting.default_language = 'en' |
210 assert_difference 'User.count' do | 223 assert_difference 'User.count' do |
211 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') | 224 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') |
212 assert issue.is_a?(Issue) | 225 assert issue.is_a?(Issue) |
213 assert issue.author.active? | 226 assert issue.author.active? |
214 assert_equal 'john.doe@somenet.foo', issue.author.mail | 227 assert_equal 'john.doe@somenet.foo', issue.author.mail |
215 assert_equal 'John', issue.author.firstname | 228 assert_equal 'John', issue.author.firstname |
216 assert_equal 'Doe', issue.author.lastname | 229 assert_equal 'Doe', issue.author.lastname |
217 | 230 |
218 # account information | 231 # account information |
219 email = ActionMailer::Base.deliveries.first | 232 email = ActionMailer::Base.deliveries.first |
220 assert_not_nil email | 233 assert_not_nil email |
221 assert email.subject.include?('account activation') | 234 assert email.subject.include?('account activation') |
222 login = email.body.match(/\* Login: (.*)$/)[1] | 235 login = email.body.match(/\* Login: (.*)$/)[1] |
223 password = email.body.match(/\* Password: (.*)$/)[1] | 236 password = email.body.match(/\* Password: (.*)$/)[1] |
224 assert_equal issue.author, User.try_to_login(login, password) | 237 assert_equal issue.author, User.try_to_login(login, password) |
225 end | 238 end |
226 end | 239 end |
227 | 240 |
228 def test_add_issue_without_from_header | 241 def test_add_issue_without_from_header |
229 Role.anonymous.add_permission!(:add_issues) | 242 Role.anonymous.add_permission!(:add_issues) |
230 assert_equal false, submit_email('ticket_without_from_header.eml') | 243 assert_equal false, submit_email('ticket_without_from_header.eml') |
231 end | 244 end |
232 | 245 |
255 assert_equal 'Feature request', issue.tracker.to_s | 268 assert_equal 'Feature request', issue.tracker.to_s |
256 assert_equal 'Stock management', issue.category.to_s | 269 assert_equal 'Stock management', issue.category.to_s |
257 assert_equal 'Urgent', issue.priority.to_s | 270 assert_equal 'Urgent', issue.priority.to_s |
258 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | 271 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
259 end | 272 end |
260 | 273 |
261 def test_add_issue_with_japanese_keywords | 274 def test_add_issue_with_japanese_keywords |
262 tracker = Tracker.create!(:name => '開発') | 275 tracker = Tracker.create!(:name => '開発') |
263 Project.find(1).trackers << tracker | 276 Project.find(1).trackers << tracker |
264 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker') | 277 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker') |
265 assert_kind_of Issue, issue | 278 assert_kind_of Issue, issue |
279 # This email contains: 'Project: onlinestore' | 292 # This email contains: 'Project: onlinestore' |
280 issue = submit_email('ticket_on_given_project.eml') | 293 issue = submit_email('ticket_on_given_project.eml') |
281 assert issue.is_a?(Issue) | 294 assert issue.is_a?(Issue) |
282 assert_equal 1, ActionMailer::Base.deliveries.size | 295 assert_equal 1, ActionMailer::Base.deliveries.size |
283 end | 296 end |
284 | 297 |
285 def test_add_issue_note | 298 def test_add_issue_note |
286 journal = submit_email('ticket_reply.eml') | 299 journal = submit_email('ticket_reply.eml') |
287 assert journal.is_a?(Journal) | 300 assert journal.is_a?(Journal) |
288 assert_equal User.find_by_login('jsmith'), journal.user | 301 assert_equal User.find_by_login('jsmith'), journal.user |
289 assert_equal Issue.find(2), journal.journalized | 302 assert_equal Issue.find(2), journal.journalized |
290 assert_match /This is reply/, journal.notes | 303 assert_match /This is reply/, journal.notes |
304 assert_equal 'Feature request', journal.issue.tracker.name | |
291 end | 305 end |
292 | 306 |
293 def test_add_issue_note_with_attribute_changes | 307 def test_add_issue_note_with_attribute_changes |
294 # This email contains: 'Status: Resolved' | 308 # This email contains: 'Status: Resolved' |
295 journal = submit_email('ticket_reply_with_status.eml') | 309 journal = submit_email('ticket_reply_with_status.eml') |
296 assert journal.is_a?(Journal) | 310 assert journal.is_a?(Journal) |
297 issue = Issue.find(journal.issue.id) | 311 issue = Issue.find(journal.issue.id) |
298 assert_equal User.find_by_login('jsmith'), journal.user | 312 assert_equal User.find_by_login('jsmith'), journal.user |
299 assert_equal Issue.find(2), journal.journalized | 313 assert_equal Issue.find(2), journal.journalized |
300 assert_match /This is reply/, journal.notes | 314 assert_match /This is reply/, journal.notes |
315 assert_equal 'Feature request', journal.issue.tracker.name | |
301 assert_equal IssueStatus.find_by_name("Resolved"), issue.status | 316 assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
302 assert_equal '2010-01-01', issue.start_date.to_s | 317 assert_equal '2010-01-01', issue.start_date.to_s |
303 assert_equal '2010-12-31', issue.due_date.to_s | 318 assert_equal '2010-12-31', issue.due_date.to_s |
304 assert_equal User.find_by_login('jsmith'), issue.assigned_to | 319 assert_equal User.find_by_login('jsmith'), issue.assigned_to |
305 assert_equal 'Updated custom value', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value | 320 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value |
321 # keywords should be removed from the email body | |
322 assert !journal.notes.match(/^Status:/i) | |
323 assert !journal.notes.match(/^Start Date:/i) | |
306 end | 324 end |
307 | 325 |
308 def test_add_issue_note_should_send_email_notification | 326 def test_add_issue_note_should_send_email_notification |
309 ActionMailer::Base.deliveries.clear | 327 ActionMailer::Base.deliveries.clear |
310 journal = submit_email('ticket_reply.eml') | 328 journal = submit_email('ticket_reply.eml') |
311 assert journal.is_a?(Journal) | 329 assert journal.is_a?(Journal) |
312 assert_equal 1, ActionMailer::Base.deliveries.size | 330 assert_equal 1, ActionMailer::Base.deliveries.size |
313 end | 331 end |
314 | 332 |
333 def test_add_issue_note_should_not_set_defaults | |
334 journal = submit_email('ticket_reply.eml', :issue => {:tracker => 'Support request', :priority => 'High'}) | |
335 assert journal.is_a?(Journal) | |
336 assert_match /This is reply/, journal.notes | |
337 assert_equal 'Feature request', journal.issue.tracker.name | |
338 assert_equal 'Normal', journal.issue.priority.name | |
339 end | |
340 | |
315 def test_reply_to_a_message | 341 def test_reply_to_a_message |
316 m = submit_email('message_reply.eml') | 342 m = submit_email('message_reply.eml') |
317 assert m.is_a?(Message) | 343 assert m.is_a?(Message) |
318 assert !m.new_record? | 344 assert !m.new_record? |
319 m.reload | 345 m.reload |
320 assert_equal 'Reply via email', m.subject | 346 assert_equal 'Reply via email', m.subject |
321 # The email replies to message #2 which is part of the thread of message #1 | 347 # The email replies to message #2 which is part of the thread of message #1 |
322 assert_equal Message.find(1), m.parent | 348 assert_equal Message.find(1), m.parent |
323 end | 349 end |
324 | 350 |
325 def test_reply_to_a_message_by_subject | 351 def test_reply_to_a_message_by_subject |
326 m = submit_email('message_reply_by_subject.eml') | 352 m = submit_email('message_reply_by_subject.eml') |
327 assert m.is_a?(Message) | 353 assert m.is_a?(Message) |
328 assert !m.new_record? | 354 assert !m.new_record? |
329 m.reload | 355 m.reload |
330 assert_equal 'Reply to the first post', m.subject | 356 assert_equal 'Reply to the first post', m.subject |
331 assert_equal Message.find(1), m.parent | 357 assert_equal Message.find(1), m.parent |
332 end | 358 end |
333 | 359 |
334 def test_should_strip_tags_of_html_only_emails | 360 def test_should_strip_tags_of_html_only_emails |
335 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) | 361 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) |
336 assert issue.is_a?(Issue) | 362 assert issue.is_a?(Issue) |
337 assert !issue.new_record? | 363 assert !issue.new_record? |
338 issue.reload | 364 issue.reload |
356 | 382 |
357 context "with a single string" do | 383 context "with a single string" do |
358 setup do | 384 setup do |
359 Setting.mail_handler_body_delimiters = '---' | 385 Setting.mail_handler_body_delimiters = '---' |
360 end | 386 end |
361 | |
362 should "truncate the email at the delimiter for the issue" do | 387 should "truncate the email at the delimiter for the issue" do |
363 issue = submit_email('ticket_on_given_project.eml') | 388 issue = submit_email('ticket_on_given_project.eml') |
364 assert_issue_created(issue) | 389 assert_issue_created(issue) |
365 assert issue.description.include?('This paragraph is before delimiters') | 390 assert issue.description.include?('This paragraph is before delimiters') |
366 assert issue.description.include?('--- This line starts with a delimiter') | 391 assert issue.description.include?('--- This line starts with a delimiter') |
371 | 396 |
372 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do | 397 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do |
373 setup do | 398 setup do |
374 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | 399 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' |
375 end | 400 end |
376 | |
377 should "truncate the email at the delimiter with the quoted reply symbols (>)" do | 401 should "truncate the email at the delimiter with the quoted reply symbols (>)" do |
378 journal = submit_email('issue_update_with_quoted_reply_above.eml') | 402 journal = submit_email('issue_update_with_quoted_reply_above.eml') |
379 assert journal.is_a?(Journal) | 403 assert journal.is_a?(Journal) |
380 assert journal.notes.include?('An update to the issue by the sender.') | 404 assert journal.notes.include?('An update to the issue by the sender.') |
381 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | 405 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) |
382 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | 406 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') |
383 | 407 end |
384 end | 408 end |
385 | 409 |
386 end | |
387 | |
388 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do | 410 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do |
389 setup do | 411 setup do |
390 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | 412 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' |
391 end | 413 end |
392 | |
393 should "truncate the email at the delimiter with the quoted reply symbols (>)" do | 414 should "truncate the email at the delimiter with the quoted reply symbols (>)" do |
394 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') | 415 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') |
395 assert journal.is_a?(Journal) | 416 assert journal.is_a?(Journal) |
396 assert journal.notes.include?('An update to the issue by the sender.') | 417 assert journal.notes.include?('An update to the issue by the sender.') |
397 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | 418 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) |
398 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | 419 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') |
399 | 420 end |
400 end | |
401 | |
402 end | 421 end |
403 | 422 |
404 context "with multiple strings" do | 423 context "with multiple strings" do |
405 setup do | 424 setup do |
406 Setting.mail_handler_body_delimiters = "---\nBREAK" | 425 Setting.mail_handler_body_delimiters = "---\nBREAK" |
407 end | 426 end |
408 | |
409 should "truncate the email at the first delimiter found (BREAK)" do | 427 should "truncate the email at the first delimiter found (BREAK)" do |
410 issue = submit_email('ticket_on_given_project.eml') | 428 issue = submit_email('ticket_on_given_project.eml') |
411 assert_issue_created(issue) | 429 assert_issue_created(issue) |
412 assert issue.description.include?('This paragraph is before delimiters') | 430 assert issue.description.include?('This paragraph is before delimiters') |
413 assert !issue.description.include?('BREAK') | 431 assert !issue.description.include?('BREAK') |
415 assert !issue.description.match(/^---$/) | 433 assert !issue.description.match(/^---$/) |
416 assert !issue.description.include?('This paragraph is after the delimiter') | 434 assert !issue.description.include?('This paragraph is after the delimiter') |
417 end | 435 end |
418 end | 436 end |
419 end | 437 end |
420 | 438 |
421 def test_email_with_long_subject_line | 439 def test_email_with_long_subject_line |
422 issue = submit_email('ticket_with_long_subject.eml') | 440 issue = submit_email('ticket_with_long_subject.eml') |
423 assert issue.is_a?(Issue) | 441 assert issue.is_a?(Issue) |
424 assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0,255] | 442 assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0,255] |
425 end | 443 end |
426 | 444 |
427 private | 445 private |
428 | 446 |
429 def submit_email(filename, options={}) | 447 def submit_email(filename, options={}) |
430 raw = IO.read(File.join(FIXTURES_PATH, filename)) | 448 raw = IO.read(File.join(FIXTURES_PATH, filename)) |
431 MailHandler.receive(raw, options) | 449 MailHandler.receive(raw, options) |
432 end | 450 end |
433 | 451 |