##// END OF EJS Templates
add test which ensure received mail text attachment keeps original encoding (#21742)...
Toshi MARUYAMA -
r14801:e28cc10a35a9
parent child
Show More
@@ -0,0 +1,31
1 Date: Thu, 14 Jan 2016 18:32:45 +0100
2 From: John Smith <JSmith@somenet.foo>
3 To: redmine@somenet.foo
4 Message-ID: <7A3.L9Yi.1Ki1}PMZiV5.1Mbzkz@seznam.cz>
5 Subject: issue #21742
6 Mime-Version: 1.0
7 Content-Type: multipart/mixed;
8 boundary="=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=";
9 charset=UTF-8
10 Content-Transfer-Encoding: 7bit
11 X-Mailer: szn-ebox-4.5.88
12
13
14 --=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=
15 Content-Type: text/plain;
16 charset=utf-8
17 Content-Transfer-Encoding: base64
18
19
20 --=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=
21 Content-Type: text/plain;
22 charset=UTF-8;
23 name=latin2.txt
24 Content-Transfer-Encoding: quoted-printable
25 Content-Disposition: attachment;
26 filename=latin2.txt;
27 size=19
28
29 p=F8=EDli=B9 =BEluou=E8k=FD k=F9n=
30
31 --=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=--
@@ -1,1068 +1,1084
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class MailHandlerTest < ActiveSupport::TestCase
23 23 fixtures :users, :projects, :enabled_modules, :roles,
24 24 :members, :member_roles, :users,
25 25 :email_addresses,
26 26 :issues, :issue_statuses,
27 27 :workflows, :trackers, :projects_trackers,
28 28 :versions, :enumerations, :issue_categories,
29 29 :custom_fields, :custom_fields_trackers, :custom_fields_projects,
30 30 :boards, :messages
31 31
32 32 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
33 33
34 34 def setup
35 35 ActionMailer::Base.deliveries.clear
36 36 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
37 37 end
38 38
39 39 def teardown
40 40 Setting.clear_cache
41 41 end
42 42
43 43 def test_add_issue_with_specific_overrides
44 44 issue = submit_email('ticket_on_given_project.eml',
45 45 :allow_override => ['status', 'start_date', 'due_date', 'assigned_to', 'fixed_version', 'estimated_hours', 'done_ratio']
46 46 )
47 47 assert issue.is_a?(Issue)
48 48 assert !issue.new_record?
49 49 issue.reload
50 50 assert_equal Project.find(2), issue.project
51 51 assert_equal issue.project.trackers.first, issue.tracker
52 52 assert_equal 'New ticket on a given project', issue.subject
53 53 assert_equal User.find_by_login('jsmith'), issue.author
54 54 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
55 55 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
56 56 assert_equal '2010-01-01', issue.start_date.to_s
57 57 assert_equal '2010-12-31', issue.due_date.to_s
58 58 assert_equal User.find_by_login('jsmith'), issue.assigned_to
59 59 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
60 60 assert_equal 2.5, issue.estimated_hours
61 61 assert_equal 30, issue.done_ratio
62 62 # keywords should be removed from the email body
63 63 assert !issue.description.match(/^Project:/i)
64 64 assert !issue.description.match(/^Status:/i)
65 65 assert !issue.description.match(/^Start Date:/i)
66 66 end
67 67
68 68 def test_add_issue_with_all_overrides
69 69 issue = submit_email('ticket_on_given_project.eml', :allow_override => 'all')
70 70 assert issue.is_a?(Issue)
71 71 assert !issue.new_record?
72 72 issue.reload
73 73 assert_equal Project.find(2), issue.project
74 74 assert_equal issue.project.trackers.first, issue.tracker
75 75 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
76 76 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
77 77 assert_equal '2010-01-01', issue.start_date.to_s
78 78 assert_equal '2010-12-31', issue.due_date.to_s
79 79 assert_equal User.find_by_login('jsmith'), issue.assigned_to
80 80 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
81 81 assert_equal 2.5, issue.estimated_hours
82 82 assert_equal 30, issue.done_ratio
83 83 end
84 84
85 85 def test_add_issue_without_overrides_should_ignore_attributes
86 86 WorkflowRule.delete_all
87 87 issue = submit_email('ticket_on_given_project.eml')
88 88 assert issue.is_a?(Issue)
89 89 assert !issue.new_record?
90 90 issue.reload
91 91 assert_equal Project.find(2), issue.project
92 92 assert_equal 'New ticket on a given project', issue.subject
93 93 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
94 94 assert_equal User.find_by_login('jsmith'), issue.author
95 95
96 96 assert_equal issue.project.trackers.first, issue.tracker
97 97 assert_equal 'New', issue.status.name
98 98 assert_not_equal '2010-01-01', issue.start_date.to_s
99 99 assert_nil issue.due_date
100 100 assert_nil issue.assigned_to
101 101 assert_nil issue.fixed_version
102 102 assert_nil issue.estimated_hours
103 103 assert_equal 0, issue.done_ratio
104 104 end
105 105
106 106 def test_add_issue_to_project_specified_by_subaddress
107 107 # This email has redmine+onlinestore@somenet.foo as 'To' header
108 108 issue = submit_email(
109 109 'ticket_on_project_given_by_to_header.eml',
110 110 :issue => {:tracker => 'Support request'},
111 111 :project_from_subaddress => 'redmine@somenet.foo'
112 112 )
113 113 assert issue.is_a?(Issue)
114 114 assert !issue.new_record?
115 115 issue.reload
116 116 assert_equal 'onlinestore', issue.project.identifier
117 117 assert_equal 'Support request', issue.tracker.name
118 118 end
119 119
120 120 def test_add_issue_with_default_tracker
121 121 # This email contains: 'Project: onlinestore'
122 122 issue = submit_email(
123 123 'ticket_on_given_project.eml',
124 124 :issue => {:tracker => 'Support request'}
125 125 )
126 126 assert issue.is_a?(Issue)
127 127 assert !issue.new_record?
128 128 issue.reload
129 129 assert_equal 'Support request', issue.tracker.name
130 130 end
131 131
132 132 def test_add_issue_with_default_version
133 133 # This email contains: 'Project: onlinestore'
134 134 issue = submit_email(
135 135 'ticket_on_given_project.eml',
136 136 :issue => {:fixed_version => 'Alpha'}
137 137 )
138 138 assert issue.is_a?(Issue)
139 139 assert !issue.new_record?
140 140 assert_equal 'Alpha', issue.reload.fixed_version.name
141 141 end
142 142
143 143 def test_add_issue_with_status_override
144 144 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
145 145 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['status'])
146 146 assert issue.is_a?(Issue)
147 147 assert !issue.new_record?
148 148 issue.reload
149 149 assert_equal Project.find(2), issue.project
150 150 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
151 151 end
152 152
153 153 def test_add_issue_should_accept_is_private_attribute
154 154 issue = submit_email('ticket_on_given_project.eml', :issue => {:is_private => '1'})
155 155 assert issue.is_a?(Issue)
156 156 assert !issue.new_record?
157 157 assert_equal true, issue.reload.is_private
158 158 end
159 159
160 160 def test_add_issue_with_group_assignment
161 161 with_settings :issue_group_assignment => '1' do
162 162 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
163 163 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
164 164 end
165 165 assert issue.is_a?(Issue)
166 166 assert !issue.new_record?
167 167 issue.reload
168 168 assert_equal Group.find(11), issue.assigned_to
169 169 end
170 170 end
171 171
172 172 def test_add_issue_with_partial_attributes_override
173 173 issue = submit_email(
174 174 'ticket_with_attributes.eml',
175 175 :issue => {:priority => 'High'},
176 176 :allow_override => ['tracker']
177 177 )
178 178 assert issue.is_a?(Issue)
179 179 assert !issue.new_record?
180 180 issue.reload
181 181 assert_equal 'New ticket on a given project', issue.subject
182 182 assert_equal User.find_by_login('jsmith'), issue.author
183 183 assert_equal Project.find(2), issue.project
184 184 assert_equal 'Feature request', issue.tracker.to_s
185 185 assert_nil issue.category
186 186 assert_equal 'High', issue.priority.to_s
187 187 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
188 188 end
189 189
190 190 def test_add_issue_with_spaces_between_attribute_and_separator
191 191 issue = submit_email(
192 192 'ticket_with_spaces_between_attribute_and_separator.eml',
193 193 :allow_override => 'tracker,category,priority'
194 194 )
195 195 assert issue.is_a?(Issue)
196 196 assert !issue.new_record?
197 197 issue.reload
198 198 assert_equal 'New ticket on a given project', issue.subject
199 199 assert_equal User.find_by_login('jsmith'), issue.author
200 200 assert_equal Project.find(2), issue.project
201 201 assert_equal 'Feature request', issue.tracker.to_s
202 202 assert_equal 'Stock management', issue.category.to_s
203 203 assert_equal 'Urgent', issue.priority.to_s
204 204 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
205 205 end
206 206
207 207 def test_add_issue_with_attachment_to_specific_project
208 208 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
209 209 assert issue.is_a?(Issue)
210 210 assert !issue.new_record?
211 211 issue.reload
212 212 assert_equal 'Ticket created by email with attachment', issue.subject
213 213 assert_equal User.find_by_login('jsmith'), issue.author
214 214 assert_equal Project.find(2), issue.project
215 215 assert_equal 'This is a new ticket with attachments', issue.description
216 216 # Attachment properties
217 217 assert_equal 1, issue.attachments.size
218 218 assert_equal 'Paella.jpg', issue.attachments.first.filename
219 219 assert_equal 'image/jpeg', issue.attachments.first.content_type
220 220 assert_equal 10790, issue.attachments.first.filesize
221 221 end
222 222
223 223 def test_add_issue_with_custom_fields
224 224 issue = submit_email('ticket_with_custom_fields.eml',
225 225 :issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable_field']
226 226 )
227 227 assert issue.is_a?(Issue)
228 228 assert !issue.new_record?
229 229 issue.reload
230 230 assert_equal 'New ticket with custom field values', issue.subject
231 231 assert_equal 'PostgreSQL', issue.custom_field_value(1)
232 232 assert_equal 'Value for a custom field', issue.custom_field_value(2)
233 233 assert !issue.description.match(/^searchable field:/i)
234 234 end
235 235
236 236 def test_add_issue_with_version_custom_fields
237 237 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
238 238
239 239 issue = submit_email('ticket_with_custom_fields.eml',
240 240 :issue => {:project => 'ecookbook'}, :allow_override => ['affected version']
241 241 ) do |email|
242 242 email << "Affected version: 1.0\n"
243 243 end
244 244 assert issue.is_a?(Issue)
245 245 assert !issue.new_record?
246 246 issue.reload
247 247 assert_equal '2', issue.custom_field_value(field)
248 248 end
249 249
250 250 def test_add_issue_should_match_assignee_on_display_name
251 251 user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
252 252 User.add_to_project(user, Project.find(2))
253 253 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
254 254 email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
255 255 end
256 256 assert issue.is_a?(Issue)
257 257 assert_equal user, issue.assigned_to
258 258 end
259 259
260 260 def test_add_issue_should_set_default_start_date
261 261 with_settings :default_issue_start_date_to_creation_date => '1' do
262 262 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
263 263 assert issue.is_a?(Issue)
264 264 assert_equal Date.today, issue.start_date
265 265 end
266 266 end
267 267
268 268 def test_add_issue_should_add_cc_as_watchers
269 269 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
270 270 assert issue.is_a?(Issue)
271 271 assert !issue.new_record?
272 272 issue.reload
273 273 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
274 274 assert_equal 1, issue.watcher_user_ids.size
275 275 end
276 276
277 277 def test_add_issue_from_additional_email_address
278 278 user = User.find(2)
279 279 user.mail = 'mainaddress@somenet.foo'
280 280 user.save!
281 281 EmailAddress.create!(:user => user, :address => 'jsmith@somenet.foo')
282 282
283 283 issue = submit_email('ticket_on_given_project.eml')
284 284 assert issue
285 285 assert_equal user, issue.author
286 286 end
287 287
288 288 def test_add_issue_by_unknown_user
289 289 assert_no_difference 'User.count' do
290 290 assert_equal false,
291 291 submit_email(
292 292 'ticket_by_unknown_user.eml',
293 293 :issue => {:project => 'ecookbook'}
294 294 )
295 295 end
296 296 end
297 297
298 298 def test_add_issue_by_anonymous_user
299 299 Role.anonymous.add_permission!(:add_issues)
300 300 assert_no_difference 'User.count' do
301 301 issue = submit_email(
302 302 'ticket_by_unknown_user.eml',
303 303 :issue => {:project => 'ecookbook'},
304 304 :unknown_user => 'accept'
305 305 )
306 306 assert issue.is_a?(Issue)
307 307 assert issue.author.anonymous?
308 308 end
309 309 end
310 310
311 311 def test_add_issue_by_anonymous_user_with_no_from_address
312 312 Role.anonymous.add_permission!(:add_issues)
313 313 assert_no_difference 'User.count' do
314 314 issue = submit_email(
315 315 'ticket_by_empty_user.eml',
316 316 :issue => {:project => 'ecookbook'},
317 317 :unknown_user => 'accept'
318 318 )
319 319 assert issue.is_a?(Issue)
320 320 assert issue.author.anonymous?
321 321 end
322 322 end
323 323
324 324 def test_add_issue_by_anonymous_user_on_private_project
325 325 Role.anonymous.add_permission!(:add_issues)
326 326 assert_no_difference 'User.count' do
327 327 assert_no_difference 'Issue.count' do
328 328 assert_equal false,
329 329 submit_email(
330 330 'ticket_by_unknown_user.eml',
331 331 :issue => {:project => 'onlinestore'},
332 332 :unknown_user => 'accept'
333 333 )
334 334 end
335 335 end
336 336 end
337 337
338 338 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
339 339 assert_no_difference 'User.count' do
340 340 assert_difference 'Issue.count' do
341 341 issue = submit_email(
342 342 'ticket_by_unknown_user.eml',
343 343 :issue => {:project => 'onlinestore'},
344 344 :no_permission_check => '1',
345 345 :unknown_user => 'accept'
346 346 )
347 347 assert issue.is_a?(Issue)
348 348 assert issue.author.anonymous?
349 349 assert !issue.project.is_public?
350 350 end
351 351 end
352 352 end
353 353
354 354 def test_add_issue_by_created_user
355 355 Setting.default_language = 'en'
356 356 assert_difference 'User.count' do
357 357 issue = submit_email(
358 358 'ticket_by_unknown_user.eml',
359 359 :issue => {:project => 'ecookbook'},
360 360 :unknown_user => 'create'
361 361 )
362 362 assert issue.is_a?(Issue)
363 363 assert issue.author.active?
364 364 assert_equal 'john.doe@somenet.foo', issue.author.mail
365 365 assert_equal 'John', issue.author.firstname
366 366 assert_equal 'Doe', issue.author.lastname
367 367
368 368 # account information
369 369 email = ActionMailer::Base.deliveries.first
370 370 assert_not_nil email
371 371 assert email.subject.include?('account activation')
372 372 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
373 373 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
374 374 assert_equal issue.author, User.try_to_login(login, password)
375 375 end
376 376 end
377 377
378 378 def test_add_issue_should_send_notification
379 379 issue = submit_email('ticket_on_given_project.eml', :allow_override => 'all')
380 380 assert issue.is_a?(Issue)
381 381 assert !issue.new_record?
382 382
383 383 mail = ActionMailer::Base.deliveries.last
384 384 assert_not_nil mail
385 385 assert mail.subject.include?("##{issue.id}")
386 386 assert mail.subject.include?('New ticket on a given project')
387 387 end
388 388
389 389 def test_created_user_should_be_added_to_groups
390 390 group1 = Group.generate!
391 391 group2 = Group.generate!
392 392
393 393 assert_difference 'User.count' do
394 394 submit_email(
395 395 'ticket_by_unknown_user.eml',
396 396 :issue => {:project => 'ecookbook'},
397 397 :unknown_user => 'create',
398 398 :default_group => "#{group1.name},#{group2.name}"
399 399 )
400 400 end
401 401 user = User.order('id DESC').first
402 402 assert_equal [group1, group2].sort, user.groups.sort
403 403 end
404 404
405 405 def test_created_user_should_not_receive_account_information_with_no_account_info_option
406 406 assert_difference 'User.count' do
407 407 submit_email(
408 408 'ticket_by_unknown_user.eml',
409 409 :issue => {:project => 'ecookbook'},
410 410 :unknown_user => 'create',
411 411 :no_account_notice => '1'
412 412 )
413 413 end
414 414
415 415 # only 1 email for the new issue notification
416 416 assert_equal 1, ActionMailer::Base.deliveries.size
417 417 email = ActionMailer::Base.deliveries.first
418 418 assert_include 'Ticket by unknown user', email.subject
419 419 end
420 420
421 421 def test_created_user_should_have_mail_notification_to_none_with_no_notification_option
422 422 assert_difference 'User.count' do
423 423 submit_email(
424 424 'ticket_by_unknown_user.eml',
425 425 :issue => {:project => 'ecookbook'},
426 426 :unknown_user => 'create',
427 427 :no_notification => '1'
428 428 )
429 429 end
430 430 user = User.order('id DESC').first
431 431 assert_equal 'none', user.mail_notification
432 432 end
433 433
434 434 def test_add_issue_without_from_header
435 435 Role.anonymous.add_permission!(:add_issues)
436 436 assert_equal false, submit_email('ticket_without_from_header.eml')
437 437 end
438 438
439 439 def test_add_issue_with_invalid_attributes
440 440 with_settings :default_issue_start_date_to_creation_date => '0' do
441 441 issue = submit_email(
442 442 'ticket_with_invalid_attributes.eml',
443 443 :allow_override => 'tracker,category,priority'
444 444 )
445 445 assert issue.is_a?(Issue)
446 446 assert !issue.new_record?
447 447 issue.reload
448 448 assert_nil issue.assigned_to
449 449 assert_nil issue.start_date
450 450 assert_nil issue.due_date
451 451 assert_equal 0, issue.done_ratio
452 452 assert_equal 'Normal', issue.priority.to_s
453 453 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
454 454 end
455 455 end
456 456
457 457 def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
458 458 issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
459 459 email.gsub!(/^Project:.+$/, 'Project: invalid')
460 460 end
461 461 assert issue.is_a?(Issue)
462 462 assert !issue.new_record?
463 463 assert_equal 'ecookbook', issue.project.identifier
464 464 end
465 465
466 466 def test_add_issue_with_localized_attributes
467 467 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
468 468 issue = submit_email(
469 469 'ticket_with_localized_attributes.eml',
470 470 :allow_override => 'tracker,category,priority'
471 471 )
472 472 assert issue.is_a?(Issue)
473 473 assert !issue.new_record?
474 474 issue.reload
475 475 assert_equal 'New ticket on a given project', issue.subject
476 476 assert_equal User.find_by_login('jsmith'), issue.author
477 477 assert_equal Project.find(2), issue.project
478 478 assert_equal 'Feature request', issue.tracker.to_s
479 479 assert_equal 'Stock management', issue.category.to_s
480 480 assert_equal 'Urgent', issue.priority.to_s
481 481 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
482 482 end
483 483
484 484 def test_add_issue_with_japanese_keywords
485 485 ja_dev = "\xe9\x96\x8b\xe7\x99\xba".force_encoding('UTF-8')
486 486 tracker = Tracker.generate!(:name => ja_dev)
487 487 Project.find(1).trackers << tracker
488 488 issue = submit_email(
489 489 'japanese_keywords_iso_2022_jp.eml',
490 490 :issue => {:project => 'ecookbook'},
491 491 :allow_override => 'tracker'
492 492 )
493 493 assert_kind_of Issue, issue
494 494 assert_equal tracker, issue.tracker
495 495 end
496 496
497 497 def test_add_issue_from_apple_mail
498 498 issue = submit_email(
499 499 'apple_mail_with_attachment.eml',
500 500 :issue => {:project => 'ecookbook'}
501 501 )
502 502 assert_kind_of Issue, issue
503 503 assert_equal 1, issue.attachments.size
504 504
505 505 attachment = issue.attachments.first
506 506 assert_equal 'paella.jpg', attachment.filename
507 507 assert_equal 10790, attachment.filesize
508 508 assert File.exist?(attachment.diskfile)
509 509 assert_equal 10790, File.size(attachment.diskfile)
510 510 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
511 511 end
512 512
513 513 def test_thunderbird_with_attachment_ja
514 514 issue = submit_email(
515 515 'thunderbird_with_attachment_ja.eml',
516 516 :issue => {:project => 'ecookbook'}
517 517 )
518 518 assert_kind_of Issue, issue
519 519 assert_equal 1, issue.attachments.size
520 520 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
521 521 attachment = issue.attachments.first
522 522 assert_equal ja, attachment.filename
523 523 assert_equal 5, attachment.filesize
524 524 assert File.exist?(attachment.diskfile)
525 525 assert_equal 5, File.size(attachment.diskfile)
526 526 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
527 527 end
528 528
529 529 def test_gmail_with_attachment_ja
530 530 issue = submit_email(
531 531 'gmail_with_attachment_ja.eml',
532 532 :issue => {:project => 'ecookbook'}
533 533 )
534 534 assert_kind_of Issue, issue
535 535 assert_equal 1, issue.attachments.size
536 536 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
537 537 attachment = issue.attachments.first
538 538 assert_equal ja, attachment.filename
539 539 assert_equal 5, attachment.filesize
540 540 assert File.exist?(attachment.diskfile)
541 541 assert_equal 5, File.size(attachment.diskfile)
542 542 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
543 543 end
544 544
545 545 def test_thunderbird_with_attachment_latin1
546 546 issue = submit_email(
547 547 'thunderbird_with_attachment_iso-8859-1.eml',
548 548 :issue => {:project => 'ecookbook'}
549 549 )
550 550 assert_kind_of Issue, issue
551 551 assert_equal 1, issue.attachments.size
552 552 u = "".force_encoding('UTF-8')
553 553 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
554 554 11.times { u << u1 }
555 555 attachment = issue.attachments.first
556 556 assert_equal "#{u}.png", attachment.filename
557 557 assert_equal 130, attachment.filesize
558 558 assert File.exist?(attachment.diskfile)
559 559 assert_equal 130, File.size(attachment.diskfile)
560 560 assert_equal '4d80e667ac37dddfe05502530f152abb', attachment.digest
561 561 end
562 562
563 563 def test_gmail_with_attachment_latin1
564 564 issue = submit_email(
565 565 'gmail_with_attachment_iso-8859-1.eml',
566 566 :issue => {:project => 'ecookbook'}
567 567 )
568 568 assert_kind_of Issue, issue
569 569 assert_equal 1, issue.attachments.size
570 570 u = "".force_encoding('UTF-8')
571 571 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
572 572 11.times { u << u1 }
573 573 attachment = issue.attachments.first
574 574 assert_equal "#{u}.txt", attachment.filename
575 575 assert_equal 5, attachment.filesize
576 576 assert File.exist?(attachment.diskfile)
577 577 assert_equal 5, File.size(attachment.diskfile)
578 578 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
579 579 end
580 580
581 def test_mail_with_attachment_latin2
582 issue = submit_email(
583 'ticket_with_text_attachment_iso-8859-2.eml',
584 :issue => {:project => 'ecookbook'}
585 )
586 assert_kind_of Issue, issue
587 assert_equal 1, issue.attachments.size
588 attachment = issue.attachments.first
589 assert_equal 'latin2.txt', attachment.filename
590 assert_equal 19, attachment.filesize
591 assert File.exist?(attachment.diskfile)
592 assert_equal 19, File.size(attachment.diskfile)
593 content = "p\xF8\xEDli\xB9 \xBEluou\xE8k\xFD k\xF9n".force_encoding('CP852')
594 assert_equal content, File.read(attachment.diskfile).force_encoding('CP852')
595 end
596
581 597 def test_multiple_inline_text_parts_should_be_appended_to_issue_description
582 598 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
583 599 assert_include 'first', issue.description
584 600 assert_include 'second', issue.description
585 601 assert_include 'third', issue.description
586 602 end
587 603
588 604 def test_attachment_text_part_should_be_added_as_issue_attachment
589 605 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
590 606 assert_not_include 'Plain text attachment', issue.description
591 607 attachment = issue.attachments.detect {|a| a.filename == 'textfile.txt'}
592 608 assert_not_nil attachment
593 609 assert_include 'Plain text attachment', File.read(attachment.diskfile)
594 610 end
595 611
596 612 def test_add_issue_with_iso_8859_1_subject
597 613 issue = submit_email(
598 614 'subject_as_iso-8859-1.eml',
599 615 :issue => {:project => 'ecookbook'}
600 616 )
601 617 str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc...".force_encoding('UTF-8')
602 618 assert_kind_of Issue, issue
603 619 assert_equal str, issue.subject
604 620 end
605 621
606 622 def test_quoted_printable_utf8
607 623 issue = submit_email(
608 624 'quoted_printable_utf8.eml',
609 625 :issue => {:project => 'ecookbook'}
610 626 )
611 627 assert_kind_of Issue, issue
612 628 str = "Freundliche Gr\xc3\xbcsse".force_encoding('UTF-8')
613 629 assert_equal str, issue.description
614 630 end
615 631
616 632 def test_gmail_iso8859_2
617 633 issue = submit_email(
618 634 'gmail-iso8859-2.eml',
619 635 :issue => {:project => 'ecookbook'}
620 636 )
621 637 assert_kind_of Issue, issue
622 638 str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87.".force_encoding('UTF-8')
623 639 assert issue.description.include?(str)
624 640 end
625 641
626 642 def test_add_issue_with_japanese_subject
627 643 issue = submit_email(
628 644 'subject_japanese_1.eml',
629 645 :issue => {:project => 'ecookbook'}
630 646 )
631 647 assert_kind_of Issue, issue
632 648 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
633 649 assert_equal ja, issue.subject
634 650 end
635 651
636 652 def test_add_issue_with_korean_body
637 653 # Make sure mail bodies with a charset unknown to Ruby
638 654 # but known to the Mail gem 2.5.4 are handled correctly
639 655 kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4.".force_encoding('UTF-8')
640 656 issue = submit_email(
641 657 'body_ks_c_5601-1987.eml',
642 658 :issue => {:project => 'ecookbook'}
643 659 )
644 660 assert_kind_of Issue, issue
645 661 assert_equal kr, issue.description
646 662 end
647 663
648 664 def test_add_issue_with_no_subject_header
649 665 issue = submit_email(
650 666 'no_subject_header.eml',
651 667 :issue => {:project => 'ecookbook'}
652 668 )
653 669 assert_kind_of Issue, issue
654 670 assert_equal '(no subject)', issue.subject
655 671 end
656 672
657 673 def test_add_issue_with_mixed_japanese_subject
658 674 issue = submit_email(
659 675 'subject_japanese_2.eml',
660 676 :issue => {:project => 'ecookbook'}
661 677 )
662 678 assert_kind_of Issue, issue
663 679 ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
664 680 assert_equal ja, issue.subject
665 681 end
666 682
667 683 def test_should_ignore_emails_from_locked_users
668 684 User.find(2).lock!
669 685
670 686 MailHandler.any_instance.expects(:dispatch).never
671 687 assert_no_difference 'Issue.count' do
672 688 assert_equal false, submit_email('ticket_on_given_project.eml')
673 689 end
674 690 end
675 691
676 692 def test_should_ignore_emails_from_emission_address
677 693 Role.anonymous.add_permission!(:add_issues)
678 694 assert_no_difference 'User.count' do
679 695 assert_equal false,
680 696 submit_email(
681 697 'ticket_from_emission_address.eml',
682 698 :issue => {:project => 'ecookbook'},
683 699 :unknown_user => 'create'
684 700 )
685 701 end
686 702 end
687 703
688 704 def test_should_ignore_auto_replied_emails
689 705 MailHandler.any_instance.expects(:dispatch).never
690 706 [
691 707 "Auto-Submitted: auto-replied",
692 708 "Auto-Submitted: Auto-Replied",
693 709 "Auto-Submitted: auto-generated",
694 710 'X-Autoreply: yes'
695 711 ].each do |header|
696 712 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
697 713 raw = header + "\n" + raw
698 714
699 715 assert_no_difference 'Issue.count' do
700 716 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
701 717 end
702 718 end
703 719 end
704 720
705 721 test "should not ignore Auto-Submitted headers not defined in RFC3834" do
706 722 [
707 723 "Auto-Submitted: auto-forwarded"
708 724 ].each do |header|
709 725 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
710 726 raw = header + "\n" + raw
711 727
712 728 assert_difference 'Issue.count', 1 do
713 729 assert_not_nil MailHandler.receive(raw), "email with #{header} header was ignored"
714 730 end
715 731 end
716 732 end
717 733
718 734 def test_add_issue_should_send_email_notification
719 735 Setting.notified_events = ['issue_added']
720 736 # This email contains: 'Project: onlinestore'
721 737 issue = submit_email('ticket_on_given_project.eml')
722 738 assert issue.is_a?(Issue)
723 739 assert_equal 1, ActionMailer::Base.deliveries.size
724 740 end
725 741
726 742 def test_update_issue
727 743 journal = submit_email('ticket_reply.eml')
728 744 assert journal.is_a?(Journal)
729 745 assert_equal User.find_by_login('jsmith'), journal.user
730 746 assert_equal Issue.find(2), journal.journalized
731 747 assert_match /This is reply/, journal.notes
732 748 assert_equal false, journal.private_notes
733 749 assert_equal 'Feature request', journal.issue.tracker.name
734 750 end
735 751
736 752 def test_update_issue_should_accept_issue_id_after_space_inside_brackets
737 753 journal = submit_email('ticket_reply_with_status.eml') do |email|
738 754 assert email.sub!(/^Subject:.*$/, "Subject: Re: [Feature request #2] Add ingredients categories")
739 755 end
740 756 assert journal.is_a?(Journal)
741 757 assert_equal Issue.find(2), journal.journalized
742 758 end
743 759
744 760 def test_update_issue_should_accept_issue_id_inside_brackets
745 761 journal = submit_email('ticket_reply_with_status.eml') do |email|
746 762 assert email.sub!(/^Subject:.*$/, "Subject: Re: [#2] Add ingredients categories")
747 763 end
748 764 assert journal.is_a?(Journal)
749 765 assert_equal Issue.find(2), journal.journalized
750 766 end
751 767
752 768 def test_update_issue_should_ignore_bogus_issue_ids_in_subject
753 769 journal = submit_email('ticket_reply_with_status.eml') do |email|
754 770 assert email.sub!(/^Subject:.*$/, "Subject: Re: [12345#1][bogus#1][Feature request #2] Add ingredients categories")
755 771 end
756 772 assert journal.is_a?(Journal)
757 773 assert_equal Issue.find(2), journal.journalized
758 774 end
759 775
760 776 def test_update_issue_with_attribute_changes
761 777 journal = submit_email('ticket_reply_with_status.eml', :allow_override => ['status','assigned_to','start_date','due_date', 'float field'])
762 778 assert journal.is_a?(Journal)
763 779 issue = Issue.find(journal.issue.id)
764 780 assert_equal User.find_by_login('jsmith'), journal.user
765 781 assert_equal Issue.find(2), journal.journalized
766 782 assert_match /This is reply/, journal.notes
767 783 assert_equal 'Feature request', journal.issue.tracker.name
768 784 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
769 785 assert_equal '2010-01-01', issue.start_date.to_s
770 786 assert_equal '2010-12-31', issue.due_date.to_s
771 787 assert_equal User.find_by_login('jsmith'), issue.assigned_to
772 788 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
773 789 # keywords should be removed from the email body
774 790 assert !journal.notes.match(/^Status:/i)
775 791 assert !journal.notes.match(/^Start Date:/i)
776 792 end
777 793
778 794 def test_update_issue_with_attachment
779 795 assert_difference 'Journal.count' do
780 796 assert_difference 'JournalDetail.count' do
781 797 assert_difference 'Attachment.count' do
782 798 assert_no_difference 'Issue.count' do
783 799 journal = submit_email('ticket_with_attachment.eml') do |raw|
784 800 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
785 801 end
786 802 end
787 803 end
788 804 end
789 805 end
790 806 journal = Journal.order('id DESC').first
791 807 assert_equal Issue.find(2), journal.journalized
792 808 assert_equal 1, journal.details.size
793 809
794 810 detail = journal.details.first
795 811 assert_equal 'attachment', detail.property
796 812 assert_equal 'Paella.jpg', detail.value
797 813 end
798 814
799 815 def test_update_issue_should_send_email_notification
800 816 journal = submit_email('ticket_reply.eml')
801 817 assert journal.is_a?(Journal)
802 818 assert_equal 1, ActionMailer::Base.deliveries.size
803 819 end
804 820
805 821 def test_update_issue_should_not_set_defaults
806 822 journal = submit_email(
807 823 'ticket_reply.eml',
808 824 :issue => {:tracker => 'Support request', :priority => 'High'}
809 825 )
810 826 assert journal.is_a?(Journal)
811 827 assert_match /This is reply/, journal.notes
812 828 assert_equal 'Feature request', journal.issue.tracker.name
813 829 assert_equal 'Normal', journal.issue.priority.name
814 830 end
815 831
816 832 def test_update_issue_should_add_cc_as_watchers
817 833 Watcher.delete_all
818 834 issue = Issue.find(2)
819 835
820 836 assert_difference 'Watcher.count' do
821 837 assert submit_email('issue_update_with_cc.eml')
822 838 end
823 839 issue.reload
824 840 assert_equal 1, issue.watcher_user_ids.size
825 841 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
826 842 end
827 843
828 844 def test_update_issue_should_not_add_cc_as_watchers_if_already_watching
829 845 Watcher.delete_all
830 846 issue = Issue.find(2)
831 847 Watcher.create!(:watchable => issue, :user => User.find_by_mail('dlopper@somenet.foo'))
832 848
833 849 assert_no_difference 'Watcher.count' do
834 850 assert submit_email('issue_update_with_cc.eml')
835 851 end
836 852 end
837 853
838 854 def test_replying_to_a_private_note_should_add_reply_as_private
839 855 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
840 856
841 857 assert_difference 'Journal.count' do
842 858 journal = submit_email('ticket_reply.eml') do |email|
843 859 email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{private_journal.id}.20060719210421@osiris>"
844 860 end
845 861
846 862 assert_kind_of Journal, journal
847 863 assert_match /This is reply/, journal.notes
848 864 assert_equal true, journal.private_notes
849 865 end
850 866 end
851 867
852 868 def test_reply_to_a_message
853 869 m = submit_email('message_reply.eml')
854 870 assert m.is_a?(Message)
855 871 assert !m.new_record?
856 872 m.reload
857 873 assert_equal 'Reply via email', m.subject
858 874 # The email replies to message #2 which is part of the thread of message #1
859 875 assert_equal Message.find(1), m.parent
860 876 end
861 877
862 878 def test_reply_to_a_message_by_subject
863 879 m = submit_email('message_reply_by_subject.eml')
864 880 assert m.is_a?(Message)
865 881 assert !m.new_record?
866 882 m.reload
867 883 assert_equal 'Reply to the first post', m.subject
868 884 assert_equal Message.find(1), m.parent
869 885 end
870 886
871 887 def test_should_convert_tags_of_html_only_emails
872 888 with_settings :text_formatting => 'textile' do
873 889 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
874 890 assert issue.is_a?(Issue)
875 891 assert !issue.new_record?
876 892 issue.reload
877 893 assert_equal 'HTML email', issue.subject
878 894 assert_equal "This is a *html-only* email.\r\n\r\nh1. With a title\r\n\r\nand a paragraph.", issue.description
879 895 end
880 896 end
881 897
882 898 def test_should_handle_outlook_web_access_2010_html_only
883 899 issue = submit_email('outlook_web_access_2010_html_only.eml', :issue => {:project => 'ecookbook'})
884 900 assert issue.is_a?(Issue)
885 901 issue.reload
886 902 assert_equal 'Upgrade Redmine to 3.0.x', issue.subject
887 903 assert_equal "A mess.\r\n\r\n--Geoff Maciolek\r\nMYCOMPANYNAME, LLC", issue.description
888 904 end
889 905
890 906 def test_should_handle_outlook_2010_html_only
891 907 issue = submit_email('outlook_2010_html_only.eml', :issue => {:project => 'ecookbook'})
892 908 assert issue.is_a?(Issue)
893 909 issue.reload
894 910 assert_equal 'Test email', issue.subject
895 911 assert_equal "Simple, unadorned test email generated by Outlook 2010. It is in HTML format, but" +
896 912 " no special formatting has been chosen. I’m going to save this as a draft and then manually" +
897 913 " drop it into the Inbox for scraping by Redmine 3.0.2.", issue.description
898 914 end
899 915
900 916 test "truncate emails with no setting should add the entire email into the issue" do
901 917 with_settings :mail_handler_body_delimiters => '' do
902 918 issue = submit_email('ticket_on_given_project.eml')
903 919 assert_issue_created(issue)
904 920 assert issue.description.include?('---')
905 921 assert issue.description.include?('This paragraph is after the delimiter')
906 922 end
907 923 end
908 924
909 925 test "truncate emails with a single string should truncate the email at the delimiter for the issue" do
910 926 with_settings :mail_handler_body_delimiters => '---' do
911 927 issue = submit_email('ticket_on_given_project.eml')
912 928 assert_issue_created(issue)
913 929 assert issue.description.include?('This paragraph is before delimiters')
914 930 assert issue.description.include?('--- This line starts with a delimiter')
915 931 assert !issue.description.match(/^---$/)
916 932 assert !issue.description.include?('This paragraph is after the delimiter')
917 933 end
918 934 end
919 935
920 936 test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do
921 937 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
922 938 journal = submit_email('issue_update_with_quoted_reply_above.eml')
923 939 assert journal.is_a?(Journal)
924 940 assert journal.notes.include?('An update to the issue by the sender.')
925 941 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
926 942 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
927 943 end
928 944 end
929 945
930 946 test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do
931 947 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
932 948 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
933 949 assert journal.is_a?(Journal)
934 950 assert journal.notes.include?('An update to the issue by the sender.')
935 951 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
936 952 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
937 953 end
938 954 end
939 955
940 956 test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do
941 957 with_settings :mail_handler_body_delimiters => "---\nBREAK" do
942 958 issue = submit_email('ticket_on_given_project.eml')
943 959 assert_issue_created(issue)
944 960 assert issue.description.include?('This paragraph is before delimiters')
945 961 assert !issue.description.include?('BREAK')
946 962 assert !issue.description.include?('This paragraph is between delimiters')
947 963 assert !issue.description.match(/^---$/)
948 964 assert !issue.description.include?('This paragraph is after the delimiter')
949 965 end
950 966 end
951 967
952 968 def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
953 969 with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do
954 970 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
955 971 assert issue.is_a?(Issue)
956 972 assert !issue.new_record?
957 973 assert_equal 0, issue.reload.attachments.size
958 974 end
959 975 end
960 976
961 977 def test_attachments_that_do_not_match_mail_handler_excluded_filenames_should_be_attached
962 978 with_settings :mail_handler_excluded_filenames => '*.vcf, *.gif' do
963 979 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
964 980 assert issue.is_a?(Issue)
965 981 assert !issue.new_record?
966 982 assert_equal 1, issue.reload.attachments.size
967 983 end
968 984 end
969 985
970 986 def test_email_with_long_subject_line
971 987 issue = submit_email('ticket_with_long_subject.eml')
972 988 assert issue.is_a?(Issue)
973 989 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]
974 990 end
975 991
976 992 def test_first_keyword_should_be_matched
977 993 issue = submit_email('ticket_with_duplicate_keyword.eml', :allow_override => 'priority')
978 994 assert issue.is_a?(Issue)
979 995 assert_equal 'High', issue.priority.name
980 996 end
981 997
982 998 def test_keyword_after_delimiter_should_be_ignored
983 999 with_settings :mail_handler_body_delimiters => "== DELIMITER ==" do
984 1000 issue = submit_email('ticket_with_keyword_after_delimiter.eml', :allow_override => 'priority')
985 1001 assert issue.is_a?(Issue)
986 1002 assert_equal 'Normal', issue.priority.name
987 1003 end
988 1004 end
989 1005
990 1006 def test_new_user_from_attributes_should_return_valid_user
991 1007 to_test = {
992 1008 # [address, name] => [login, firstname, lastname]
993 1009 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
994 1010 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
995 1011 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
996 1012 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
997 1013 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
998 1014 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
999 1015 }
1000 1016
1001 1017 to_test.each do |attrs, expected|
1002 1018 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
1003 1019
1004 1020 assert user.valid?, user.errors.full_messages.to_s
1005 1021 assert_equal attrs.first, user.mail
1006 1022 assert_equal expected[0], user.login
1007 1023 assert_equal expected[1], user.firstname
1008 1024 assert_equal expected[2], user.lastname
1009 1025 assert_equal 'only_my_events', user.mail_notification
1010 1026 end
1011 1027 end
1012 1028
1013 1029 def test_new_user_from_attributes_should_use_default_login_if_invalid
1014 1030 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
1015 1031 assert user.valid?
1016 1032 assert user.login =~ /^user[a-f0-9]+$/
1017 1033 assert_equal 'foo+bar@example.net', user.mail
1018 1034 end
1019 1035
1020 1036 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
1021 1037 assert_difference 'User.count' do
1022 1038 issue = submit_email(
1023 1039 'fullname_of_sender_as_utf8_encoded.eml',
1024 1040 :issue => {:project => 'ecookbook'},
1025 1041 :unknown_user => 'create'
1026 1042 )
1027 1043 end
1028 1044 user = User.order('id DESC').first
1029 1045 assert_equal "foo@example.org", user.mail
1030 1046 str1 = "\xc3\x84\xc3\xa4".force_encoding('UTF-8')
1031 1047 str2 = "\xc3\x96\xc3\xb6".force_encoding('UTF-8')
1032 1048 assert_equal str1, user.firstname
1033 1049 assert_equal str2, user.lastname
1034 1050 end
1035 1051
1036 1052 def test_extract_options_from_env_should_return_options
1037 1053 options = MailHandler.extract_options_from_env({
1038 1054 'tracker' => 'defect',
1039 1055 'project' => 'foo',
1040 1056 'unknown_user' => 'create'
1041 1057 })
1042 1058
1043 1059 assert_equal({
1044 1060 :issue => {:tracker => 'defect', :project => 'foo'},
1045 1061 :unknown_user => 'create'
1046 1062 }, options)
1047 1063 end
1048 1064
1049 1065 def test_safe_receive_should_rescue_exceptions_and_return_false
1050 1066 MailHandler.stubs(:receive).raises(Exception.new "Something went wrong")
1051 1067
1052 1068 assert_equal false, MailHandler.safe_receive
1053 1069 end
1054 1070
1055 1071 private
1056 1072
1057 1073 def submit_email(filename, options={})
1058 1074 raw = IO.read(File.join(FIXTURES_PATH, filename))
1059 1075 yield raw if block_given?
1060 1076 MailHandler.receive(raw, options)
1061 1077 end
1062 1078
1063 1079 def assert_issue_created(issue)
1064 1080 assert issue.is_a?(Issue)
1065 1081 assert !issue.new_record?
1066 1082 issue.reload
1067 1083 end
1068 1084 end
General Comments 0
You need to be logged in to leave comments. Login now