diff test/unit/mail_handler_test.rb @ 37:94944d00e43c

* Update to SVN trunk rev 4411
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 19 Nov 2010 13:24:41 +0000
parents 513646585e45
children af80e5618e9b
line wrap: on
line diff
--- a/test/unit/mail_handler_test.rb	Fri Sep 24 14:06:04 2010 +0100
+++ b/test/unit/mail_handler_test.rb	Fri Nov 19 13:24:41 2010 +0000
@@ -25,11 +25,13 @@
                    :roles,
                    :members,
                    :member_roles,
+                   :users,
                    :issues,
                    :issue_statuses,
                    :workflows,
                    :trackers,
                    :projects_trackers,
+                   :versions,
                    :enumerations,
                    :issue_categories,
                    :custom_fields,
@@ -41,6 +43,7 @@
   
   def setup
     ActionMailer::Base.deliveries.clear
+    Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
   end
   
   def test_add_issue
@@ -58,6 +61,9 @@
     assert_equal '2010-01-01', issue.start_date.to_s
     assert_equal '2010-12-31', issue.due_date.to_s
     assert_equal User.find_by_login('jsmith'), issue.assigned_to
+    assert_equal Version.find_by_name('alpha'), issue.fixed_version
+    assert_equal 2.5, issue.estimated_hours
+    assert_equal 30, issue.done_ratio
     # keywords should be removed from the email body
     assert !issue.description.match(/^Project:/i)
     assert !issue.description.match(/^Status:/i)
@@ -152,7 +158,7 @@
     assert !issue.new_record?
     issue.reload
     assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
-    assert_equal 1, issue.watchers.size
+    assert_equal 1, issue.watcher_user_ids.size
   end
   
   def test_add_issue_by_unknown_user
@@ -223,6 +229,34 @@
     Role.anonymous.add_permission!(:add_issues)
     assert_equal false, submit_email('ticket_without_from_header.eml')
   end
+
+  def test_add_issue_with_invalid_attributes
+    issue = submit_email('ticket_with_invalid_attributes.eml', :allow_override => 'tracker,category,priority')
+    assert issue.is_a?(Issue)
+    assert !issue.new_record?
+    issue.reload
+    assert_nil issue.assigned_to
+    assert_nil issue.start_date
+    assert_nil issue.due_date
+    assert_equal 0, issue.done_ratio
+    assert_equal 'Normal', issue.priority.to_s
+    assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
+  end
+
+  def test_add_issue_with_localized_attributes
+    User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
+    issue = submit_email('ticket_with_localized_attributes.eml', :allow_override => 'tracker,category,priority')
+    assert issue.is_a?(Issue)
+    assert !issue.new_record?
+    issue.reload
+    assert_equal 'New ticket on a given project', issue.subject
+    assert_equal User.find_by_login('jsmith'), issue.author
+    assert_equal Project.find(2), issue.project
+    assert_equal 'Feature request', issue.tracker.to_s
+    assert_equal 'Stock management', issue.category.to_s
+    assert_equal 'Urgent', issue.priority.to_s
+    assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
+  end
   
   def test_add_issue_with_japanese_keywords
     tracker = Tracker.create!(:name => '開発')
@@ -240,6 +274,7 @@
   end
 
   def test_add_issue_should_send_email_notification
+    Setting.notified_events = ['issue_added']
     ActionMailer::Base.deliveries.clear
     # This email contains: 'Project: onlinestore'
     issue = submit_email('ticket_on_given_project.eml')
@@ -267,6 +302,7 @@
     assert_equal '2010-01-01', issue.start_date.to_s
     assert_equal '2010-12-31', issue.due_date.to_s
     assert_equal User.find_by_login('jsmith'), issue.assigned_to
+    assert_equal 'Updated custom value', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
   end
 
   def test_add_issue_note_should_send_email_notification
@@ -333,6 +369,38 @@
       end
     end
 
+    context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
+      setup do
+        Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
+      end
+
+      should "truncate the email at the delimiter with the quoted reply symbols (>)" do
+        journal = submit_email('issue_update_with_quoted_reply_above.eml')
+        assert journal.is_a?(Journal)
+        assert journal.notes.include?('An update to the issue by the sender.')
+        assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
+        assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
+
+      end
+
+    end
+    
+    context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
+      setup do
+        Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
+      end
+
+      should "truncate the email at the delimiter with the quoted reply symbols (>)" do
+        journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
+        assert journal.is_a?(Journal)
+        assert journal.notes.include?('An update to the issue by the sender.')
+        assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
+        assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
+
+      end
+
+    end
+
     context "with multiple strings" do
       setup do
         Setting.mail_handler_body_delimiters = "---\nBREAK"