Mercurial > hg > soundsoftware-site
comparison test/unit/.svn/text-base/mail_handler_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2
Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author | Chris Cannam |
---|---|
date | Mon, 06 Jun 2011 14:24:13 +0100 |
parents | 8661b858af72 |
children | 0c939c159af4 |
comparison
equal
deleted
inserted
replaced
245:051f544170fe | 441:cbce1fd3b1b7 |
---|---|
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.expand_path('../../test_helper', __FILE__) | 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, |
37 :custom_fields, | 37 :custom_fields, |
38 :custom_fields_trackers, | 38 :custom_fields_trackers, |
39 :custom_fields_projects, | 39 :custom_fields_projects, |
40 :boards, | 40 :boards, |
41 :messages | 41 :messages |
42 | 42 |
43 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' | 43 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' |
44 | 44 |
45 def setup | 45 def setup |
46 ActionMailer::Base.deliveries.clear | 46 ActionMailer::Base.deliveries.clear |
47 Setting.notified_events = Redmine::Notifiable.all.collect(&:name) | 47 Setting.notified_events = Redmine::Notifiable.all.collect(&:name) |
48 end | 48 end |
49 | 49 |
50 def test_add_issue | 50 def test_add_issue |
51 ActionMailer::Base.deliveries.clear | 51 ActionMailer::Base.deliveries.clear |
52 # This email contains: 'Project: onlinestore' | 52 # This email contains: 'Project: onlinestore' |
53 issue = submit_email('ticket_on_given_project.eml') | 53 issue = submit_email('ticket_on_given_project.eml') |
54 assert issue.is_a?(Issue) | 54 assert issue.is_a?(Issue) |
68 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] | 69 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt] |
70 # keywords should be removed from the email body | 70 # keywords should be removed from the email body |
71 assert !issue.description.match(/^Project:/i) | 71 assert !issue.description.match(/^Project:/i) |
72 assert !issue.description.match(/^Status:/i) | 72 assert !issue.description.match(/^Status:/i) |
73 assert !issue.description.match(/^Start Date:/i) | |
73 # Email notification should be sent | 74 # Email notification should be sent |
74 mail = ActionMailer::Base.deliveries.last | 75 mail = ActionMailer::Base.deliveries.last |
75 assert_not_nil mail | 76 assert_not_nil mail |
76 assert mail.subject.include?('New ticket on a given project') | 77 assert mail.subject.include?('New ticket on a given project') |
77 end | 78 end |
78 | 79 |
79 def test_add_issue_with_default_tracker | 80 def test_add_issue_with_default_tracker |
80 # This email contains: 'Project: onlinestore' | 81 # This email contains: 'Project: onlinestore' |
81 issue = submit_email('ticket_on_given_project.eml', :issue => {:tracker => 'Support request'}) | 82 issue = submit_email('ticket_on_given_project.eml', :issue => {:tracker => 'Support request'}) |
82 assert issue.is_a?(Issue) | 83 assert issue.is_a?(Issue) |
83 assert !issue.new_record? | 84 assert !issue.new_record? |
92 assert !issue.new_record? | 93 assert !issue.new_record? |
93 issue.reload | 94 issue.reload |
94 assert_equal Project.find(2), issue.project | 95 assert_equal Project.find(2), issue.project |
95 assert_equal IssueStatus.find_by_name("Resolved"), issue.status | 96 assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
96 end | 97 end |
97 | 98 |
98 def test_add_issue_with_attributes_override | 99 def test_add_issue_with_attributes_override |
99 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') |
100 assert issue.is_a?(Issue) | 101 assert issue.is_a?(Issue) |
101 assert !issue.new_record? | 102 assert !issue.new_record? |
102 issue.reload | 103 issue.reload |
106 assert_equal 'Feature request', issue.tracker.to_s | 107 assert_equal 'Feature request', issue.tracker.to_s |
107 assert_equal 'Stock management', issue.category.to_s | 108 assert_equal 'Stock management', issue.category.to_s |
108 assert_equal 'Urgent', issue.priority.to_s | 109 assert_equal 'Urgent', issue.priority.to_s |
109 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.') |
110 end | 111 end |
111 | 112 |
112 def test_add_issue_with_partial_attributes_override | 113 def test_add_issue_with_partial_attributes_override |
113 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']) |
114 assert issue.is_a?(Issue) | 115 assert issue.is_a?(Issue) |
115 assert !issue.new_record? | 116 assert !issue.new_record? |
116 issue.reload | 117 issue.reload |
120 assert_equal 'Feature request', issue.tracker.to_s | 121 assert_equal 'Feature request', issue.tracker.to_s |
121 assert_nil issue.category | 122 assert_nil issue.category |
122 assert_equal 'High', issue.priority.to_s | 123 assert_equal 'High', issue.priority.to_s |
123 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.') |
124 end | 125 end |
125 | 126 |
126 def test_add_issue_with_spaces_between_attribute_and_separator | 127 def test_add_issue_with_spaces_between_attribute_and_separator |
127 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') |
128 assert issue.is_a?(Issue) | 129 assert issue.is_a?(Issue) |
129 assert !issue.new_record? | 130 assert !issue.new_record? |
130 issue.reload | 131 issue.reload |
135 assert_equal 'Stock management', issue.category.to_s | 136 assert_equal 'Stock management', issue.category.to_s |
136 assert_equal 'Urgent', issue.priority.to_s | 137 assert_equal 'Urgent', issue.priority.to_s |
137 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.') |
138 end | 139 end |
139 | 140 |
140 | |
141 def test_add_issue_with_attachment_to_specific_project | 141 def test_add_issue_with_attachment_to_specific_project |
142 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) | 142 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) |
143 assert issue.is_a?(Issue) | 143 assert issue.is_a?(Issue) |
144 assert !issue.new_record? | 144 assert !issue.new_record? |
145 issue.reload | 145 issue.reload |
151 assert_equal 1, issue.attachments.size | 151 assert_equal 1, issue.attachments.size |
152 assert_equal 'Paella.jpg', issue.attachments.first.filename | 152 assert_equal 'Paella.jpg', issue.attachments.first.filename |
153 assert_equal 'image/jpeg', issue.attachments.first.content_type | 153 assert_equal 'image/jpeg', issue.attachments.first.content_type |
154 assert_equal 10790, issue.attachments.first.filesize | 154 assert_equal 10790, issue.attachments.first.filesize |
155 end | 155 end |
156 | 156 |
157 def test_add_issue_with_custom_fields | 157 def test_add_issue_with_custom_fields |
158 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) | 158 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) |
159 assert issue.is_a?(Issue) | 159 assert issue.is_a?(Issue) |
160 assert !issue.new_record? | 160 assert !issue.new_record? |
161 issue.reload | 161 issue.reload |
162 assert_equal 'New ticket with custom field values', issue.subject | 162 assert_equal 'New ticket with custom field values', issue.subject |
163 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 |
164 assert !issue.description.match(/^searchable field:/i) | 164 assert !issue.description.match(/^searchable field:/i) |
165 end | 165 end |
166 | 166 |
167 def test_add_issue_with_cc | 167 def test_add_issue_with_cc |
168 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) | 168 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) |
169 assert issue.is_a?(Issue) | 169 assert issue.is_a?(Issue) |
170 assert !issue.new_record? | 170 assert !issue.new_record? |
171 issue.reload | 171 issue.reload |
172 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) | 172 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) |
173 assert_equal 1, issue.watcher_user_ids.size | 173 assert_equal 1, issue.watcher_user_ids.size |
174 end | 174 end |
175 | 175 |
176 def test_add_issue_by_unknown_user | 176 def test_add_issue_by_unknown_user |
177 assert_no_difference 'User.count' do | 177 assert_no_difference 'User.count' do |
178 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'}) |
179 end | 179 end |
180 end | 180 end |
181 | 181 |
182 def test_add_issue_by_anonymous_user | 182 def test_add_issue_by_anonymous_user |
183 Role.anonymous.add_permission!(:add_issues) | 183 Role.anonymous.add_permission!(:add_issues) |
184 assert_no_difference 'User.count' do | 184 assert_no_difference 'User.count' do |
185 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') |
186 assert issue.is_a?(Issue) | 186 assert issue.is_a?(Issue) |
194 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') |
195 assert issue.is_a?(Issue) | 195 assert issue.is_a?(Issue) |
196 assert issue.author.anonymous? | 196 assert issue.author.anonymous? |
197 end | 197 end |
198 end | 198 end |
199 | 199 |
200 def test_add_issue_by_anonymous_user_on_private_project | 200 def test_add_issue_by_anonymous_user_on_private_project |
201 Role.anonymous.add_permission!(:add_issues) | 201 Role.anonymous.add_permission!(:add_issues) |
202 assert_no_difference 'User.count' do | 202 assert_no_difference 'User.count' do |
203 assert_no_difference 'Issue.count' do | 203 assert_no_difference 'Issue.count' do |
204 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') |
205 end | 205 end |
206 end | 206 end |
207 end | 207 end |
208 | 208 |
209 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 |
210 assert_no_difference 'User.count' do | 210 assert_no_difference 'User.count' do |
211 assert_difference 'Issue.count' do | 211 assert_difference 'Issue.count' do |
212 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') |
213 assert issue.is_a?(Issue) | 213 assert issue.is_a?(Issue) |
215 assert !issue.project.is_public? | 215 assert !issue.project.is_public? |
216 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt] | 216 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt] |
217 end | 217 end |
218 end | 218 end |
219 end | 219 end |
220 | 220 |
221 def test_add_issue_by_created_user | 221 def test_add_issue_by_created_user |
222 Setting.default_language = 'en' | 222 Setting.default_language = 'en' |
223 assert_difference 'User.count' do | 223 assert_difference 'User.count' do |
224 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') |
225 assert issue.is_a?(Issue) | 225 assert issue.is_a?(Issue) |
226 assert issue.author.active? | 226 assert issue.author.active? |
227 assert_equal 'john.doe@somenet.foo', issue.author.mail | 227 assert_equal 'john.doe@somenet.foo', issue.author.mail |
228 assert_equal 'John', issue.author.firstname | 228 assert_equal 'John', issue.author.firstname |
229 assert_equal 'Doe', issue.author.lastname | 229 assert_equal 'Doe', issue.author.lastname |
230 | 230 |
231 # account information | 231 # account information |
232 email = ActionMailer::Base.deliveries.first | 232 email = ActionMailer::Base.deliveries.first |
233 assert_not_nil email | 233 assert_not_nil email |
234 assert email.subject.include?('account activation') | 234 assert email.subject.include?('account activation') |
235 login = email.body.match(/\* Login: (.*)$/)[1] | 235 login = email.body.match(/\* Login: (.*)$/)[1] |
236 password = email.body.match(/\* Password: (.*)$/)[1] | 236 password = email.body.match(/\* Password: (.*)$/)[1] |
237 assert_equal issue.author, User.try_to_login(login, password) | 237 assert_equal issue.author, User.try_to_login(login, password) |
238 end | 238 end |
239 end | 239 end |
240 | 240 |
241 def test_add_issue_without_from_header | 241 def test_add_issue_without_from_header |
242 Role.anonymous.add_permission!(:add_issues) | 242 Role.anonymous.add_permission!(:add_issues) |
243 assert_equal false, submit_email('ticket_without_from_header.eml') | 243 assert_equal false, submit_email('ticket_without_from_header.eml') |
244 end | 244 end |
245 | 245 |
268 assert_equal 'Feature request', issue.tracker.to_s | 268 assert_equal 'Feature request', issue.tracker.to_s |
269 assert_equal 'Stock management', issue.category.to_s | 269 assert_equal 'Stock management', issue.category.to_s |
270 assert_equal 'Urgent', issue.priority.to_s | 270 assert_equal 'Urgent', issue.priority.to_s |
271 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.') |
272 end | 272 end |
273 | 273 |
274 def test_add_issue_with_japanese_keywords | 274 def test_add_issue_with_japanese_keywords |
275 tracker = Tracker.create!(:name => '開発') | 275 tracker = Tracker.create!(:name => '開発') |
276 Project.find(1).trackers << tracker | 276 Project.find(1).trackers << tracker |
277 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') |
278 assert_kind_of Issue, issue | 278 assert_kind_of Issue, issue |
292 # This email contains: 'Project: onlinestore' | 292 # This email contains: 'Project: onlinestore' |
293 issue = submit_email('ticket_on_given_project.eml') | 293 issue = submit_email('ticket_on_given_project.eml') |
294 assert issue.is_a?(Issue) | 294 assert issue.is_a?(Issue) |
295 assert_equal 1, ActionMailer::Base.deliveries.size | 295 assert_equal 1, ActionMailer::Base.deliveries.size |
296 end | 296 end |
297 | 297 |
298 def test_add_issue_note | 298 def test_add_issue_note |
299 journal = submit_email('ticket_reply.eml') | 299 journal = submit_email('ticket_reply.eml') |
300 assert journal.is_a?(Journal) | 300 assert journal.is_a?(Journal) |
301 assert_equal User.find_by_login('jsmith'), journal.user | 301 assert_equal User.find_by_login('jsmith'), journal.user |
302 assert_equal Issue.find(2), journal.journalized | 302 assert_equal Issue.find(2), journal.journalized |
316 assert_equal IssueStatus.find_by_name("Resolved"), issue.status | 316 assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
317 assert_equal '2010-01-01', issue.start_date.to_s | 317 assert_equal '2010-01-01', issue.start_date.to_s |
318 assert_equal '2010-12-31', issue.due_date.to_s | 318 assert_equal '2010-12-31', issue.due_date.to_s |
319 assert_equal User.find_by_login('jsmith'), issue.assigned_to | 319 assert_equal User.find_by_login('jsmith'), issue.assigned_to |
320 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float 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) | |
321 end | 324 end |
322 | 325 |
323 def test_add_issue_note_should_send_email_notification | 326 def test_add_issue_note_should_send_email_notification |
324 ActionMailer::Base.deliveries.clear | 327 ActionMailer::Base.deliveries.clear |
325 journal = submit_email('ticket_reply.eml') | 328 journal = submit_email('ticket_reply.eml') |
326 assert journal.is_a?(Journal) | 329 assert journal.is_a?(Journal) |
327 assert_equal 1, ActionMailer::Base.deliveries.size | 330 assert_equal 1, ActionMailer::Base.deliveries.size |
328 end | 331 end |
329 | 332 |
330 def test_add_issue_note_should_not_set_defaults | 333 def test_add_issue_note_should_not_set_defaults |
331 journal = submit_email('ticket_reply.eml', :issue => {:tracker => 'Support request', :priority => 'High'}) | 334 journal = submit_email('ticket_reply.eml', :issue => {:tracker => 'Support request', :priority => 'High'}) |
332 assert journal.is_a?(Journal) | 335 assert journal.is_a?(Journal) |
333 assert_match /This is reply/, journal.notes | 336 assert_match /This is reply/, journal.notes |
334 assert_equal 'Feature request', journal.issue.tracker.name | 337 assert_equal 'Feature request', journal.issue.tracker.name |
335 assert_equal 'Normal', journal.issue.priority.name | 338 assert_equal 'Normal', journal.issue.priority.name |
336 end | 339 end |
337 | 340 |
338 def test_reply_to_a_message | 341 def test_reply_to_a_message |
339 m = submit_email('message_reply.eml') | 342 m = submit_email('message_reply.eml') |
340 assert m.is_a?(Message) | 343 assert m.is_a?(Message) |
341 assert !m.new_record? | 344 assert !m.new_record? |
342 m.reload | 345 m.reload |
343 assert_equal 'Reply via email', m.subject | 346 assert_equal 'Reply via email', m.subject |
344 # 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 |
345 assert_equal Message.find(1), m.parent | 348 assert_equal Message.find(1), m.parent |
346 end | 349 end |
347 | 350 |
348 def test_reply_to_a_message_by_subject | 351 def test_reply_to_a_message_by_subject |
349 m = submit_email('message_reply_by_subject.eml') | 352 m = submit_email('message_reply_by_subject.eml') |
350 assert m.is_a?(Message) | 353 assert m.is_a?(Message) |
351 assert !m.new_record? | 354 assert !m.new_record? |
352 m.reload | 355 m.reload |
353 assert_equal 'Reply to the first post', m.subject | 356 assert_equal 'Reply to the first post', m.subject |
354 assert_equal Message.find(1), m.parent | 357 assert_equal Message.find(1), m.parent |
355 end | 358 end |
356 | 359 |
357 def test_should_strip_tags_of_html_only_emails | 360 def test_should_strip_tags_of_html_only_emails |
358 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) | 361 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) |
359 assert issue.is_a?(Issue) | 362 assert issue.is_a?(Issue) |
360 assert !issue.new_record? | 363 assert !issue.new_record? |
361 issue.reload | 364 issue.reload |
379 | 382 |
380 context "with a single string" do | 383 context "with a single string" do |
381 setup do | 384 setup do |
382 Setting.mail_handler_body_delimiters = '---' | 385 Setting.mail_handler_body_delimiters = '---' |
383 end | 386 end |
384 | |
385 should "truncate the email at the delimiter for the issue" do | 387 should "truncate the email at the delimiter for the issue" do |
386 issue = submit_email('ticket_on_given_project.eml') | 388 issue = submit_email('ticket_on_given_project.eml') |
387 assert_issue_created(issue) | 389 assert_issue_created(issue) |
388 assert issue.description.include?('This paragraph is before delimiters') | 390 assert issue.description.include?('This paragraph is before delimiters') |
389 assert issue.description.include?('--- This line starts with a delimiter') | 391 assert issue.description.include?('--- This line starts with a delimiter') |
394 | 396 |
395 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 |
396 setup do | 398 setup do |
397 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. ---' |
398 end | 400 end |
399 | |
400 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 |
401 journal = submit_email('issue_update_with_quoted_reply_above.eml') | 402 journal = submit_email('issue_update_with_quoted_reply_above.eml') |
402 assert journal.is_a?(Journal) | 403 assert journal.is_a?(Journal) |
403 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.') |
404 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. ---")) |
405 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.') |
406 | 407 end |
407 end | 408 end |
408 | 409 |
409 end | |
410 | |
411 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 |
412 setup do | 411 setup do |
413 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. ---' |
414 end | 413 end |
415 | |
416 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 |
417 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') | 415 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') |
418 assert journal.is_a?(Journal) | 416 assert journal.is_a?(Journal) |
419 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.') |
420 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. ---")) |
421 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.') |
422 | 420 end |
423 end | |
424 | |
425 end | 421 end |
426 | 422 |
427 context "with multiple strings" do | 423 context "with multiple strings" do |
428 setup do | 424 setup do |
429 Setting.mail_handler_body_delimiters = "---\nBREAK" | 425 Setting.mail_handler_body_delimiters = "---\nBREAK" |
430 end | 426 end |
431 | |
432 should "truncate the email at the first delimiter found (BREAK)" do | 427 should "truncate the email at the first delimiter found (BREAK)" do |
433 issue = submit_email('ticket_on_given_project.eml') | 428 issue = submit_email('ticket_on_given_project.eml') |
434 assert_issue_created(issue) | 429 assert_issue_created(issue) |
435 assert issue.description.include?('This paragraph is before delimiters') | 430 assert issue.description.include?('This paragraph is before delimiters') |
436 assert !issue.description.include?('BREAK') | 431 assert !issue.description.include?('BREAK') |
438 assert !issue.description.match(/^---$/) | 433 assert !issue.description.match(/^---$/) |
439 assert !issue.description.include?('This paragraph is after the delimiter') | 434 assert !issue.description.include?('This paragraph is after the delimiter') |
440 end | 435 end |
441 end | 436 end |
442 end | 437 end |
443 | 438 |
444 def test_email_with_long_subject_line | 439 def test_email_with_long_subject_line |
445 issue = submit_email('ticket_with_long_subject.eml') | 440 issue = submit_email('ticket_with_long_subject.eml') |
446 assert issue.is_a?(Issue) | 441 assert issue.is_a?(Issue) |
447 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] |
448 end | 443 end |
449 | 444 |
450 private | 445 private |
451 | 446 |
452 def submit_email(filename, options={}) | 447 def submit_email(filename, options={}) |
453 raw = IO.read(File.join(FIXTURES_PATH, filename)) | 448 raw = IO.read(File.join(FIXTURES_PATH, filename)) |
454 MailHandler.receive(raw, options) | 449 MailHandler.receive(raw, options) |
455 end | 450 end |
456 | 451 |