##// END OF EJS Templates
Fixed an assertion for ruby1.9....
Jean-Philippe Lang -
r8666:6c27093a8bf4
parent child
Show More
@@ -1,592 +1,592
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2011 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 :issues, :issue_statuses,
26 26 :workflows, :trackers, :projects_trackers,
27 27 :versions, :enumerations, :issue_categories,
28 28 :custom_fields, :custom_fields_trackers, :custom_fields_projects,
29 29 :boards, :messages
30 30
31 31 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
32 32
33 33 def setup
34 34 ActionMailer::Base.deliveries.clear
35 35 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
36 36 end
37 37
38 38 def test_add_issue
39 39 ActionMailer::Base.deliveries.clear
40 40 # This email contains: 'Project: onlinestore'
41 41 issue = submit_email('ticket_on_given_project.eml')
42 42 assert issue.is_a?(Issue)
43 43 assert !issue.new_record?
44 44 issue.reload
45 45 assert_equal Project.find(2), issue.project
46 46 assert_equal issue.project.trackers.first, issue.tracker
47 47 assert_equal 'New ticket on a given project', issue.subject
48 48 assert_equal User.find_by_login('jsmith'), issue.author
49 49 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
50 50 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
51 51 assert_equal '2010-01-01', issue.start_date.to_s
52 52 assert_equal '2010-12-31', issue.due_date.to_s
53 53 assert_equal User.find_by_login('jsmith'), issue.assigned_to
54 54 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
55 55 assert_equal 2.5, issue.estimated_hours
56 56 assert_equal 30, issue.done_ratio
57 57 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
58 58 # keywords should be removed from the email body
59 59 assert !issue.description.match(/^Project:/i)
60 60 assert !issue.description.match(/^Status:/i)
61 61 assert !issue.description.match(/^Start Date:/i)
62 62 # Email notification should be sent
63 63 mail = ActionMailer::Base.deliveries.last
64 64 assert_not_nil mail
65 65 assert mail.subject.include?('New ticket on a given project')
66 66 end
67 67
68 68 def test_add_issue_with_default_tracker
69 69 # This email contains: 'Project: onlinestore'
70 70 issue = submit_email(
71 71 'ticket_on_given_project.eml',
72 72 :issue => {:tracker => 'Support request'}
73 73 )
74 74 assert issue.is_a?(Issue)
75 75 assert !issue.new_record?
76 76 issue.reload
77 77 assert_equal 'Support request', issue.tracker.name
78 78 end
79 79
80 80 def test_add_issue_with_status
81 81 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
82 82 issue = submit_email('ticket_on_given_project.eml')
83 83 assert issue.is_a?(Issue)
84 84 assert !issue.new_record?
85 85 issue.reload
86 86 assert_equal Project.find(2), issue.project
87 87 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
88 88 end
89 89
90 90 def test_add_issue_with_attributes_override
91 91 issue = submit_email(
92 92 'ticket_with_attributes.eml',
93 93 :allow_override => 'tracker,category,priority'
94 94 )
95 95 assert issue.is_a?(Issue)
96 96 assert !issue.new_record?
97 97 issue.reload
98 98 assert_equal 'New ticket on a given project', issue.subject
99 99 assert_equal User.find_by_login('jsmith'), issue.author
100 100 assert_equal Project.find(2), issue.project
101 101 assert_equal 'Feature request', issue.tracker.to_s
102 102 assert_equal 'Stock management', issue.category.to_s
103 103 assert_equal 'Urgent', issue.priority.to_s
104 104 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
105 105 end
106 106
107 107 def test_add_issue_with_group_assignment
108 108 with_settings :issue_group_assignment => '1' do
109 109 issue = submit_email('ticket_on_given_project.eml') do |email|
110 110 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
111 111 end
112 112 assert issue.is_a?(Issue)
113 113 assert !issue.new_record?
114 114 issue.reload
115 115 assert_equal Group.find(11), issue.assigned_to
116 116 end
117 117 end
118 118
119 119 def test_add_issue_with_partial_attributes_override
120 120 issue = submit_email(
121 121 'ticket_with_attributes.eml',
122 122 :issue => {:priority => 'High'},
123 123 :allow_override => ['tracker']
124 124 )
125 125 assert issue.is_a?(Issue)
126 126 assert !issue.new_record?
127 127 issue.reload
128 128 assert_equal 'New ticket on a given project', issue.subject
129 129 assert_equal User.find_by_login('jsmith'), issue.author
130 130 assert_equal Project.find(2), issue.project
131 131 assert_equal 'Feature request', issue.tracker.to_s
132 132 assert_nil issue.category
133 133 assert_equal 'High', issue.priority.to_s
134 134 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
135 135 end
136 136
137 137 def test_add_issue_with_spaces_between_attribute_and_separator
138 138 issue = submit_email(
139 139 'ticket_with_spaces_between_attribute_and_separator.eml',
140 140 :allow_override => 'tracker,category,priority'
141 141 )
142 142 assert issue.is_a?(Issue)
143 143 assert !issue.new_record?
144 144 issue.reload
145 145 assert_equal 'New ticket on a given project', issue.subject
146 146 assert_equal User.find_by_login('jsmith'), issue.author
147 147 assert_equal Project.find(2), issue.project
148 148 assert_equal 'Feature request', issue.tracker.to_s
149 149 assert_equal 'Stock management', issue.category.to_s
150 150 assert_equal 'Urgent', issue.priority.to_s
151 151 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
152 152 end
153 153
154 154 def test_add_issue_with_attachment_to_specific_project
155 155 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
156 156 assert issue.is_a?(Issue)
157 157 assert !issue.new_record?
158 158 issue.reload
159 159 assert_equal 'Ticket created by email with attachment', issue.subject
160 160 assert_equal User.find_by_login('jsmith'), issue.author
161 161 assert_equal Project.find(2), issue.project
162 162 assert_equal 'This is a new ticket with attachments', issue.description
163 163 # Attachment properties
164 164 assert_equal 1, issue.attachments.size
165 165 assert_equal 'Paella.jpg', issue.attachments.first.filename
166 166 assert_equal 'image/jpeg', issue.attachments.first.content_type
167 167 assert_equal 10790, issue.attachments.first.filesize
168 168 end
169 169
170 170 def test_add_issue_with_custom_fields
171 171 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
172 172 assert issue.is_a?(Issue)
173 173 assert !issue.new_record?
174 174 issue.reload
175 175 assert_equal 'New ticket with custom field values', issue.subject
176 176 assert_equal 'Value for a custom field',
177 177 issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
178 178 assert !issue.description.match(/^searchable field:/i)
179 179 end
180 180
181 181 def test_add_issue_with_cc
182 182 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
183 183 assert issue.is_a?(Issue)
184 184 assert !issue.new_record?
185 185 issue.reload
186 186 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
187 187 assert_equal 1, issue.watcher_user_ids.size
188 188 end
189 189
190 190 def test_add_issue_by_unknown_user
191 191 assert_no_difference 'User.count' do
192 192 assert_equal false,
193 193 submit_email(
194 194 'ticket_by_unknown_user.eml',
195 195 :issue => {:project => 'ecookbook'}
196 196 )
197 197 end
198 198 end
199 199
200 200 def test_add_issue_by_anonymous_user
201 201 Role.anonymous.add_permission!(:add_issues)
202 202 assert_no_difference 'User.count' do
203 203 issue = submit_email(
204 204 'ticket_by_unknown_user.eml',
205 205 :issue => {:project => 'ecookbook'},
206 206 :unknown_user => 'accept'
207 207 )
208 208 assert issue.is_a?(Issue)
209 209 assert issue.author.anonymous?
210 210 end
211 211 end
212 212
213 213 def test_add_issue_by_anonymous_user_with_no_from_address
214 214 Role.anonymous.add_permission!(:add_issues)
215 215 assert_no_difference 'User.count' do
216 216 issue = submit_email(
217 217 'ticket_by_empty_user.eml',
218 218 :issue => {:project => 'ecookbook'},
219 219 :unknown_user => 'accept'
220 220 )
221 221 assert issue.is_a?(Issue)
222 222 assert issue.author.anonymous?
223 223 end
224 224 end
225 225
226 226 def test_add_issue_by_anonymous_user_on_private_project
227 227 Role.anonymous.add_permission!(:add_issues)
228 228 assert_no_difference 'User.count' do
229 229 assert_no_difference 'Issue.count' do
230 230 assert_equal false,
231 231 submit_email(
232 232 'ticket_by_unknown_user.eml',
233 233 :issue => {:project => 'onlinestore'},
234 234 :unknown_user => 'accept'
235 235 )
236 236 end
237 237 end
238 238 end
239 239
240 240 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
241 241 assert_no_difference 'User.count' do
242 242 assert_difference 'Issue.count' do
243 243 issue = submit_email(
244 244 'ticket_by_unknown_user.eml',
245 245 :issue => {:project => 'onlinestore'},
246 246 :no_permission_check => '1',
247 247 :unknown_user => 'accept'
248 248 )
249 249 assert issue.is_a?(Issue)
250 250 assert issue.author.anonymous?
251 251 assert !issue.project.is_public?
252 252 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
253 253 end
254 254 end
255 255 end
256 256
257 257 def test_add_issue_by_created_user
258 258 Setting.default_language = 'en'
259 259 assert_difference 'User.count' do
260 260 issue = submit_email(
261 261 'ticket_by_unknown_user.eml',
262 262 :issue => {:project => 'ecookbook'},
263 263 :unknown_user => 'create'
264 264 )
265 265 assert issue.is_a?(Issue)
266 266 assert issue.author.active?
267 267 assert_equal 'john.doe@somenet.foo', issue.author.mail
268 268 assert_equal 'John', issue.author.firstname
269 269 assert_equal 'Doe', issue.author.lastname
270 270
271 271 # account information
272 272 email = ActionMailer::Base.deliveries.first
273 273 assert_not_nil email
274 274 assert email.subject.include?('account activation')
275 275 login = email.body.match(/\* Login: (.*)$/)[1]
276 276 password = email.body.match(/\* Password: (.*)$/)[1]
277 277 assert_equal issue.author, User.try_to_login(login, password)
278 278 end
279 279 end
280 280
281 281 def test_add_issue_without_from_header
282 282 Role.anonymous.add_permission!(:add_issues)
283 283 assert_equal false, submit_email('ticket_without_from_header.eml')
284 284 end
285 285
286 286 def test_add_issue_with_invalid_attributes
287 287 issue = submit_email(
288 288 'ticket_with_invalid_attributes.eml',
289 289 :allow_override => 'tracker,category,priority'
290 290 )
291 291 assert issue.is_a?(Issue)
292 292 assert !issue.new_record?
293 293 issue.reload
294 294 assert_nil issue.assigned_to
295 295 assert_nil issue.start_date
296 296 assert_nil issue.due_date
297 297 assert_equal 0, issue.done_ratio
298 298 assert_equal 'Normal', issue.priority.to_s
299 299 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
300 300 end
301 301
302 302 def test_add_issue_with_localized_attributes
303 303 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
304 304 issue = submit_email(
305 305 'ticket_with_localized_attributes.eml',
306 306 :allow_override => 'tracker,category,priority'
307 307 )
308 308 assert issue.is_a?(Issue)
309 309 assert !issue.new_record?
310 310 issue.reload
311 311 assert_equal 'New ticket on a given project', issue.subject
312 312 assert_equal User.find_by_login('jsmith'), issue.author
313 313 assert_equal Project.find(2), issue.project
314 314 assert_equal 'Feature request', issue.tracker.to_s
315 315 assert_equal 'Stock management', issue.category.to_s
316 316 assert_equal 'Urgent', issue.priority.to_s
317 317 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
318 318 end
319 319
320 320 def test_add_issue_with_japanese_keywords
321 321 ja_dev = "\xe9\x96\x8b\xe7\x99\xba"
322 322 ja_dev.force_encoding('UTF-8') if ja_dev.respond_to?(:force_encoding)
323 323 tracker = Tracker.create!(:name => ja_dev)
324 324 Project.find(1).trackers << tracker
325 325 issue = submit_email(
326 326 'japanese_keywords_iso_2022_jp.eml',
327 327 :issue => {:project => 'ecookbook'},
328 328 :allow_override => 'tracker'
329 329 )
330 330 assert_kind_of Issue, issue
331 331 assert_equal tracker, issue.tracker
332 332 end
333 333
334 334 def test_add_issue_from_apple_mail
335 335 issue = submit_email(
336 336 'apple_mail_with_attachment.eml',
337 337 :issue => {:project => 'ecookbook'}
338 338 )
339 339 assert_kind_of Issue, issue
340 340 assert_equal 1, issue.attachments.size
341 341
342 342 attachment = issue.attachments.first
343 343 assert_equal 'paella.jpg', attachment.filename
344 344 assert_equal 10790, attachment.filesize
345 345 assert File.exist?(attachment.diskfile)
346 346 assert_equal 10790, File.size(attachment.diskfile)
347 347 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
348 348 end
349 349
350 350 def test_should_ignore_emails_from_emission_address
351 351 Role.anonymous.add_permission!(:add_issues)
352 352 assert_no_difference 'User.count' do
353 353 assert_equal false,
354 354 submit_email(
355 355 'ticket_from_emission_address.eml',
356 356 :issue => {:project => 'ecookbook'},
357 357 :unknown_user => 'create'
358 358 )
359 359 end
360 360 end
361 361
362 362 def test_add_issue_should_send_email_notification
363 363 Setting.notified_events = ['issue_added']
364 364 ActionMailer::Base.deliveries.clear
365 365 # This email contains: 'Project: onlinestore'
366 366 issue = submit_email('ticket_on_given_project.eml')
367 367 assert issue.is_a?(Issue)
368 368 assert_equal 1, ActionMailer::Base.deliveries.size
369 369 end
370 370
371 371 def test_update_issue
372 372 journal = submit_email('ticket_reply.eml')
373 373 assert journal.is_a?(Journal)
374 374 assert_equal User.find_by_login('jsmith'), journal.user
375 375 assert_equal Issue.find(2), journal.journalized
376 376 assert_match /This is reply/, journal.notes
377 377 assert_equal 'Feature request', journal.issue.tracker.name
378 378 end
379 379
380 380 def test_update_issue_with_attribute_changes
381 381 # This email contains: 'Status: Resolved'
382 382 journal = submit_email('ticket_reply_with_status.eml')
383 383 assert journal.is_a?(Journal)
384 384 issue = Issue.find(journal.issue.id)
385 385 assert_equal User.find_by_login('jsmith'), journal.user
386 386 assert_equal Issue.find(2), journal.journalized
387 387 assert_match /This is reply/, journal.notes
388 388 assert_equal 'Feature request', journal.issue.tracker.name
389 389 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
390 390 assert_equal '2010-01-01', issue.start_date.to_s
391 391 assert_equal '2010-12-31', issue.due_date.to_s
392 392 assert_equal User.find_by_login('jsmith'), issue.assigned_to
393 393 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
394 394 # keywords should be removed from the email body
395 395 assert !journal.notes.match(/^Status:/i)
396 396 assert !journal.notes.match(/^Start Date:/i)
397 397 end
398 398
399 399 def test_update_issue_with_attachment
400 400 assert_difference 'Journal.count' do
401 401 assert_difference 'JournalDetail.count' do
402 402 assert_difference 'Attachment.count' do
403 403 assert_no_difference 'Issue.count' do
404 404 journal = submit_email('ticket_with_attachment.eml') do |raw|
405 405 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
406 406 end
407 407 end
408 408 end
409 409 end
410 410 end
411 411 journal = Journal.first(:order => 'id DESC')
412 412 assert_equal Issue.find(2), journal.journalized
413 413 assert_equal 1, journal.details.size
414 414
415 415 detail = journal.details.first
416 416 assert_equal 'attachment', detail.property
417 417 assert_equal 'Paella.jpg', detail.value
418 418 end
419 419
420 420 def test_update_issue_should_send_email_notification
421 421 ActionMailer::Base.deliveries.clear
422 422 journal = submit_email('ticket_reply.eml')
423 423 assert journal.is_a?(Journal)
424 424 assert_equal 1, ActionMailer::Base.deliveries.size
425 425 end
426 426
427 427 def test_update_issue_should_not_set_defaults
428 428 journal = submit_email(
429 429 'ticket_reply.eml',
430 430 :issue => {:tracker => 'Support request', :priority => 'High'}
431 431 )
432 432 assert journal.is_a?(Journal)
433 433 assert_match /This is reply/, journal.notes
434 434 assert_equal 'Feature request', journal.issue.tracker.name
435 435 assert_equal 'Normal', journal.issue.priority.name
436 436 end
437 437
438 438 def test_reply_to_a_message
439 439 m = submit_email('message_reply.eml')
440 440 assert m.is_a?(Message)
441 441 assert !m.new_record?
442 442 m.reload
443 443 assert_equal 'Reply via email', m.subject
444 444 # The email replies to message #2 which is part of the thread of message #1
445 445 assert_equal Message.find(1), m.parent
446 446 end
447 447
448 448 def test_reply_to_a_message_by_subject
449 449 m = submit_email('message_reply_by_subject.eml')
450 450 assert m.is_a?(Message)
451 451 assert !m.new_record?
452 452 m.reload
453 453 assert_equal 'Reply to the first post', m.subject
454 454 assert_equal Message.find(1), m.parent
455 455 end
456 456
457 457 def test_should_strip_tags_of_html_only_emails
458 458 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
459 459 assert issue.is_a?(Issue)
460 460 assert !issue.new_record?
461 461 issue.reload
462 462 assert_equal 'HTML email', issue.subject
463 463 assert_equal 'This is a html-only email.', issue.description
464 464 end
465 465
466 466 context "truncate emails based on the Setting" do
467 467 context "with no setting" do
468 468 setup do
469 469 Setting.mail_handler_body_delimiters = ''
470 470 end
471 471
472 472 should "add the entire email into the issue" do
473 473 issue = submit_email('ticket_on_given_project.eml')
474 474 assert_issue_created(issue)
475 475 assert issue.description.include?('---')
476 476 assert issue.description.include?('This paragraph is after the delimiter')
477 477 end
478 478 end
479 479
480 480 context "with a single string" do
481 481 setup do
482 482 Setting.mail_handler_body_delimiters = '---'
483 483 end
484 484 should "truncate the email at the delimiter for the issue" do
485 485 issue = submit_email('ticket_on_given_project.eml')
486 486 assert_issue_created(issue)
487 487 assert issue.description.include?('This paragraph is before delimiters')
488 488 assert issue.description.include?('--- This line starts with a delimiter')
489 489 assert !issue.description.match(/^---$/)
490 490 assert !issue.description.include?('This paragraph is after the delimiter')
491 491 end
492 492 end
493 493
494 494 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
495 495 setup do
496 496 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
497 497 end
498 498 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
499 499 journal = submit_email('issue_update_with_quoted_reply_above.eml')
500 500 assert journal.is_a?(Journal)
501 501 assert journal.notes.include?('An update to the issue by the sender.')
502 502 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
503 503 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
504 504 end
505 505 end
506 506
507 507 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
508 508 setup do
509 509 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
510 510 end
511 511 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
512 512 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
513 513 assert journal.is_a?(Journal)
514 514 assert journal.notes.include?('An update to the issue by the sender.')
515 515 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
516 516 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
517 517 end
518 518 end
519 519
520 520 context "with multiple strings" do
521 521 setup do
522 522 Setting.mail_handler_body_delimiters = "---\nBREAK"
523 523 end
524 524 should "truncate the email at the first delimiter found (BREAK)" do
525 525 issue = submit_email('ticket_on_given_project.eml')
526 526 assert_issue_created(issue)
527 527 assert issue.description.include?('This paragraph is before delimiters')
528 528 assert !issue.description.include?('BREAK')
529 529 assert !issue.description.include?('This paragraph is between delimiters')
530 530 assert !issue.description.match(/^---$/)
531 531 assert !issue.description.include?('This paragraph is after the delimiter')
532 532 end
533 533 end
534 534 end
535 535
536 536 def test_email_with_long_subject_line
537 537 issue = submit_email('ticket_with_long_subject.eml')
538 538 assert issue.is_a?(Issue)
539 539 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]
540 540 end
541 541
542 542 def test_new_user_from_attributes_should_return_valid_user
543 543 to_test = {
544 544 # [address, name] => [login, firstname, lastname]
545 545 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
546 546 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
547 547 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
548 548 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
549 549 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
550 550 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
551 551 }
552 552
553 553 to_test.each do |attrs, expected|
554 554 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
555 555
556 assert user.valid?, user.errors.full_messages
556 assert user.valid?, user.errors.full_messages.to_s
557 557 assert_equal attrs.first, user.mail
558 558 assert_equal expected[0], user.login
559 559 assert_equal expected[1], user.firstname
560 560 assert_equal expected[2], user.lastname
561 561 end
562 562 end
563 563
564 564 def test_new_user_from_attributes_should_respect_minimum_password_length
565 565 with_settings :password_min_length => 15 do
566 566 user = MailHandler.new_user_from_attributes('jsmith@example.net')
567 567 assert user.valid?
568 568 assert user.password.length >= 15
569 569 end
570 570 end
571 571
572 572 def test_new_user_from_attributes_should_use_default_login_if_invalid
573 573 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
574 574 assert user.valid?
575 575 assert user.login =~ /^user[a-f0-9]+$/
576 576 assert_equal 'foo+bar@example.net', user.mail
577 577 end
578 578
579 579 private
580 580
581 581 def submit_email(filename, options={})
582 582 raw = IO.read(File.join(FIXTURES_PATH, filename))
583 583 yield raw if block_given?
584 584 MailHandler.receive(raw, options)
585 585 end
586 586
587 587 def assert_issue_created(issue)
588 588 assert issue.is_a?(Issue)
589 589 assert !issue.new_record?
590 590 issue.reload
591 591 end
592 592 end
General Comments 0
You need to be logged in to leave comments. Login now