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