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