##// END OF EJS Templates
Added a test for the mail handler....
Jean-Philippe Lang -
r521:cff3950e6bda
parent child
Show More
@@ -0,0 +1,14
1 x-sender: <jsmith@somenet.foo>
2 x-receiver: <redmine@somenet.foo>
3 Received: from somenet.foo ([127.0.0.1]) by somenet.foo;
4 Sun, 25 Feb 2007 09:57:56 GMT
5 Date: Sun, 25 Feb 2007 10:57:56 +0100
6 From: jsmith@somenet.foo
7 To: redmine@somenet.foo
8 Message-Id: <45e15df440c00_b90238570a27b@osiris.tmail>
9 In-Reply-To: <45e15df440c29_b90238570a27b@osiris.tmail>
10 Subject: [Cookbook - Feature #2]
11 Mime-Version: 1.0
12 Content-Type: text/plain; charset=utf-8
13
14 Note added by mail
@@ -0,0 +1,57
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19
20 class MailHandlerTest < Test::Unit::TestCase
21 fixtures :users, :projects, :roles, :members, :permissions, :issues, :permissions_roles, :trackers, :enumerations
22
23 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
24 CHARSET = "utf-8"
25
26 include ActionMailer::Quoting
27
28 def setup
29 ActionMailer::Base.delivery_method = :test
30 ActionMailer::Base.perform_deliveries = true
31 ActionMailer::Base.deliveries = []
32
33 @expected = TMail::Mail.new
34 @expected.set_content_type "text", "plain", { "charset" => CHARSET }
35 @expected.mime_version = '1.0'
36 end
37
38 def test_add_note_to_issue
39 raw = read_fixture("add_note_to_issue_2.txt").join
40 MailHandler.receive(raw)
41
42 issue = Issue.find(2)
43 journal = issue.journals.find(:first, :order => "created_on DESC")
44 assert journal
45 assert_equal User.find_by_mail("jsmith@somenet.foo"), journal.user
46 assert_equal "Note added by mail", journal.notes
47 end
48
49 private
50 def read_fixture(action)
51 IO.readlines("#{FIXTURES_PATH}/mail_handler/#{action}")
52 end
53
54 def encode(subject)
55 quoted_printable(subject, CHARSET)
56 end
57 end
@@ -18,7 +18,7
18 class MailHandler < ActionMailer::Base
18 class MailHandler < ActionMailer::Base
19
19
20 # Processes incoming emails
20 # Processes incoming emails
21 # Currently, it only supports adding notes to an existing issue
21 # Currently, it only supports adding a note to an existing issue
22 # by replying to the initial notification message
22 # by replying to the initial notification message
23 def receive(email)
23 def receive(email)
24 # find related issue by parsing the subject
24 # find related issue by parsing the subject
@@ -33,8 +33,8 class MailHandler < ActionMailer::Base
33 # check permission
33 # check permission
34 return unless Permission.allowed_to_role("issues/add_note", user.role_for_project(issue.project))
34 return unless Permission.allowed_to_role("issues/add_note", user.role_for_project(issue.project))
35
35
36 # add the notes
36 # add the note
37 issue.init_journal(user, email.body)
37 issue.init_journal(user, email.body.chomp)
38 issue.save
38 issue.save
39 end
39 end
40 end
40 end
General Comments 0
You need to be logged in to leave comments. Login now