Mercurial > hg > soundsoftware-site
comparison test/unit/mail_handler_test.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # | 2 # |
3 # Redmine - project management software | 3 # Redmine - project management software |
4 # Copyright (C) 2006-2012 Jean-Philippe Lang | 4 # Copyright (C) 2006-2013 Jean-Philippe Lang |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; either version 2 | 8 # as published by the Free Software Foundation; either version 2 |
9 # of the License, or (at your option) any later version. | 9 # of the License, or (at your option) any later version. |
302 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip | 302 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip |
303 assert_equal issue.author, User.try_to_login(login, password) | 303 assert_equal issue.author, User.try_to_login(login, password) |
304 end | 304 end |
305 end | 305 end |
306 | 306 |
307 def test_created_user_should_be_added_to_groups | |
308 group1 = Group.generate! | |
309 group2 = Group.generate! | |
310 | |
311 assert_difference 'User.count' do | |
312 submit_email( | |
313 'ticket_by_unknown_user.eml', | |
314 :issue => {:project => 'ecookbook'}, | |
315 :unknown_user => 'create', | |
316 :default_group => "#{group1.name},#{group2.name}" | |
317 ) | |
318 end | |
319 user = User.order('id DESC').first | |
320 assert_same_elements [group1, group2], user.groups | |
321 end | |
322 | |
323 def test_created_user_should_not_receive_account_information_with_no_account_info_option | |
324 assert_difference 'User.count' do | |
325 submit_email( | |
326 'ticket_by_unknown_user.eml', | |
327 :issue => {:project => 'ecookbook'}, | |
328 :unknown_user => 'create', | |
329 :no_account_notice => '1' | |
330 ) | |
331 end | |
332 | |
333 # only 1 email for the new issue notification | |
334 assert_equal 1, ActionMailer::Base.deliveries.size | |
335 email = ActionMailer::Base.deliveries.first | |
336 assert_include 'Ticket by unknown user', email.subject | |
337 end | |
338 | |
339 def test_created_user_should_have_mail_notification_to_none_with_no_notification_option | |
340 assert_difference 'User.count' do | |
341 submit_email( | |
342 'ticket_by_unknown_user.eml', | |
343 :issue => {:project => 'ecookbook'}, | |
344 :unknown_user => 'create', | |
345 :no_notification => '1' | |
346 ) | |
347 end | |
348 user = User.order('id DESC').first | |
349 assert_equal 'none', user.mail_notification | |
350 end | |
351 | |
307 def test_add_issue_without_from_header | 352 def test_add_issue_without_from_header |
308 Role.anonymous.add_permission!(:add_issues) | 353 Role.anonymous.add_permission!(:add_issues) |
309 assert_equal false, submit_email('ticket_without_from_header.eml') | 354 assert_equal false, submit_email('ticket_without_from_header.eml') |
310 end | 355 end |
311 | 356 |
644 issue.reload | 689 issue.reload |
645 assert_equal 'HTML email', issue.subject | 690 assert_equal 'HTML email', issue.subject |
646 assert_equal 'This is a html-only email.', issue.description | 691 assert_equal 'This is a html-only email.', issue.description |
647 end | 692 end |
648 | 693 |
649 context "truncate emails based on the Setting" do | 694 test "truncate emails with no setting should add the entire email into the issue" do |
650 context "with no setting" do | 695 with_settings :mail_handler_body_delimiters => '' do |
651 setup do | 696 issue = submit_email('ticket_on_given_project.eml') |
652 Setting.mail_handler_body_delimiters = '' | 697 assert_issue_created(issue) |
653 end | 698 assert issue.description.include?('---') |
654 | 699 assert issue.description.include?('This paragraph is after the delimiter') |
655 should "add the entire email into the issue" do | 700 end |
656 issue = submit_email('ticket_on_given_project.eml') | 701 end |
657 assert_issue_created(issue) | 702 |
658 assert issue.description.include?('---') | 703 test "truncate emails with a single string should truncate the email at the delimiter for the issue" do |
659 assert issue.description.include?('This paragraph is after the delimiter') | 704 with_settings :mail_handler_body_delimiters => '---' do |
660 end | 705 issue = submit_email('ticket_on_given_project.eml') |
661 end | 706 assert_issue_created(issue) |
662 | 707 assert issue.description.include?('This paragraph is before delimiters') |
663 context "with a single string" do | 708 assert issue.description.include?('--- This line starts with a delimiter') |
664 setup do | 709 assert !issue.description.match(/^---$/) |
665 Setting.mail_handler_body_delimiters = '---' | 710 assert !issue.description.include?('This paragraph is after the delimiter') |
666 end | 711 end |
667 should "truncate the email at the delimiter for the issue" do | 712 end |
668 issue = submit_email('ticket_on_given_project.eml') | 713 |
669 assert_issue_created(issue) | 714 test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do |
670 assert issue.description.include?('This paragraph is before delimiters') | 715 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do |
671 assert issue.description.include?('--- This line starts with a delimiter') | 716 journal = submit_email('issue_update_with_quoted_reply_above.eml') |
672 assert !issue.description.match(/^---$/) | 717 assert journal.is_a?(Journal) |
673 assert !issue.description.include?('This paragraph is after the delimiter') | 718 assert journal.notes.include?('An update to the issue by the sender.') |
674 end | 719 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) |
675 end | 720 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') |
676 | 721 end |
677 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do | 722 end |
678 setup do | 723 |
679 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | 724 test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do |
680 end | 725 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do |
681 should "truncate the email at the delimiter with the quoted reply symbols (>)" do | 726 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') |
682 journal = submit_email('issue_update_with_quoted_reply_above.eml') | 727 assert journal.is_a?(Journal) |
683 assert journal.is_a?(Journal) | 728 assert journal.notes.include?('An update to the issue by the sender.') |
684 assert journal.notes.include?('An update to the issue by the sender.') | 729 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) |
685 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | 730 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') |
686 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | 731 end |
687 end | 732 end |
688 end | 733 |
689 | 734 test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do |
690 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do | 735 with_settings :mail_handler_body_delimiters => "---\nBREAK" do |
691 setup do | 736 issue = submit_email('ticket_on_given_project.eml') |
692 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | 737 assert_issue_created(issue) |
693 end | 738 assert issue.description.include?('This paragraph is before delimiters') |
694 should "truncate the email at the delimiter with the quoted reply symbols (>)" do | 739 assert !issue.description.include?('BREAK') |
695 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') | 740 assert !issue.description.include?('This paragraph is between delimiters') |
696 assert journal.is_a?(Journal) | 741 assert !issue.description.match(/^---$/) |
697 assert journal.notes.include?('An update to the issue by the sender.') | 742 assert !issue.description.include?('This paragraph is after the delimiter') |
698 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
699 assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
700 end | |
701 end | |
702 | |
703 context "with multiple strings" do | |
704 setup do | |
705 Setting.mail_handler_body_delimiters = "---\nBREAK" | |
706 end | |
707 should "truncate the email at the first delimiter found (BREAK)" do | |
708 issue = submit_email('ticket_on_given_project.eml') | |
709 assert_issue_created(issue) | |
710 assert issue.description.include?('This paragraph is before delimiters') | |
711 assert !issue.description.include?('BREAK') | |
712 assert !issue.description.include?('This paragraph is between delimiters') | |
713 assert !issue.description.match(/^---$/) | |
714 assert !issue.description.include?('This paragraph is after the delimiter') | |
715 end | |
716 end | 743 end |
717 end | 744 end |
718 | 745 |
719 def test_email_with_long_subject_line | 746 def test_email_with_long_subject_line |
720 issue = submit_email('ticket_with_long_subject.eml') | 747 issue = submit_email('ticket_with_long_subject.eml') |
739 assert user.valid?, user.errors.full_messages.to_s | 766 assert user.valid?, user.errors.full_messages.to_s |
740 assert_equal attrs.first, user.mail | 767 assert_equal attrs.first, user.mail |
741 assert_equal expected[0], user.login | 768 assert_equal expected[0], user.login |
742 assert_equal expected[1], user.firstname | 769 assert_equal expected[1], user.firstname |
743 assert_equal expected[2], user.lastname | 770 assert_equal expected[2], user.lastname |
771 assert_equal 'only_my_events', user.mail_notification | |
744 end | 772 end |
745 end | 773 end |
746 | 774 |
747 def test_new_user_from_attributes_should_respect_minimum_password_length | 775 def test_new_user_from_attributes_should_respect_minimum_password_length |
748 with_settings :password_min_length => 15 do | 776 with_settings :password_min_length => 15 do |