@@ -1,348 +1,350 | |||||
|
1 | # encoding: utf-8 | |||
|
2 | # | |||
1 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
3 | # |
|
5 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
8 | # |
|
10 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
13 | # |
|
15 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
19 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
20 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
21 | |||
20 | class MailHandlerTest < ActiveSupport::TestCase |
|
22 | class MailHandlerTest < ActiveSupport::TestCase | |
21 | fixtures :users, :projects, |
|
23 | fixtures :users, :projects, | |
22 | :enabled_modules, |
|
24 | :enabled_modules, | |
23 | :roles, |
|
25 | :roles, | |
24 | :members, |
|
26 | :members, | |
25 | :member_roles, |
|
27 | :member_roles, | |
26 | :issues, |
|
28 | :issues, | |
27 | :issue_statuses, |
|
29 | :issue_statuses, | |
28 | :workflows, |
|
30 | :workflows, | |
29 | :trackers, |
|
31 | :trackers, | |
30 | :projects_trackers, |
|
32 | :projects_trackers, | |
31 | :enumerations, |
|
33 | :enumerations, | |
32 | :issue_categories, |
|
34 | :issue_categories, | |
33 | :custom_fields, |
|
35 | :custom_fields, | |
34 | :custom_fields_trackers, |
|
36 | :custom_fields_trackers, | |
35 | :boards, |
|
37 | :boards, | |
36 | :messages |
|
38 | :messages | |
37 |
|
39 | |||
38 | FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' |
|
40 | FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' | |
39 |
|
41 | |||
40 | def setup |
|
42 | def setup | |
41 | ActionMailer::Base.deliveries.clear |
|
43 | ActionMailer::Base.deliveries.clear | |
42 | end |
|
44 | end | |
43 |
|
45 | |||
44 | def test_add_issue |
|
46 | def test_add_issue | |
45 | ActionMailer::Base.deliveries.clear |
|
47 | ActionMailer::Base.deliveries.clear | |
46 | # This email contains: 'Project: onlinestore' |
|
48 | # This email contains: 'Project: onlinestore' | |
47 | issue = submit_email('ticket_on_given_project.eml') |
|
49 | issue = submit_email('ticket_on_given_project.eml') | |
48 | assert issue.is_a?(Issue) |
|
50 | assert issue.is_a?(Issue) | |
49 | assert !issue.new_record? |
|
51 | assert !issue.new_record? | |
50 | issue.reload |
|
52 | issue.reload | |
51 | assert_equal 'New ticket on a given project', issue.subject |
|
53 | assert_equal 'New ticket on a given project', issue.subject | |
52 | assert_equal User.find_by_login('jsmith'), issue.author |
|
54 | assert_equal User.find_by_login('jsmith'), issue.author | |
53 | assert_equal Project.find(2), issue.project |
|
55 | assert_equal Project.find(2), issue.project | |
54 | assert_equal IssueStatus.find_by_name('Resolved'), issue.status |
|
56 | assert_equal IssueStatus.find_by_name('Resolved'), issue.status | |
55 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
57 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
56 | # keywords should be removed from the email body |
|
58 | # keywords should be removed from the email body | |
57 | assert !issue.description.match(/^Project:/i) |
|
59 | assert !issue.description.match(/^Project:/i) | |
58 | assert !issue.description.match(/^Status:/i) |
|
60 | assert !issue.description.match(/^Status:/i) | |
59 | # Email notification should be sent |
|
61 | # Email notification should be sent | |
60 | mail = ActionMailer::Base.deliveries.last |
|
62 | mail = ActionMailer::Base.deliveries.last | |
61 | assert_not_nil mail |
|
63 | assert_not_nil mail | |
62 | assert mail.subject.include?('New ticket on a given project') |
|
64 | assert mail.subject.include?('New ticket on a given project') | |
63 | end |
|
65 | end | |
64 |
|
66 | |||
65 | def test_add_issue_with_status |
|
67 | def test_add_issue_with_status | |
66 | # This email contains: 'Project: onlinestore' and 'Status: Resolved' |
|
68 | # This email contains: 'Project: onlinestore' and 'Status: Resolved' | |
67 | issue = submit_email('ticket_on_given_project.eml') |
|
69 | issue = submit_email('ticket_on_given_project.eml') | |
68 | assert issue.is_a?(Issue) |
|
70 | assert issue.is_a?(Issue) | |
69 | assert !issue.new_record? |
|
71 | assert !issue.new_record? | |
70 | issue.reload |
|
72 | issue.reload | |
71 | assert_equal Project.find(2), issue.project |
|
73 | assert_equal Project.find(2), issue.project | |
72 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
|
74 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status | |
73 | end |
|
75 | end | |
74 |
|
76 | |||
75 | def test_add_issue_with_attributes_override |
|
77 | def test_add_issue_with_attributes_override | |
76 | issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority') |
|
78 | issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority') | |
77 | assert issue.is_a?(Issue) |
|
79 | assert issue.is_a?(Issue) | |
78 | assert !issue.new_record? |
|
80 | assert !issue.new_record? | |
79 | issue.reload |
|
81 | issue.reload | |
80 | assert_equal 'New ticket on a given project', issue.subject |
|
82 | assert_equal 'New ticket on a given project', issue.subject | |
81 | assert_equal User.find_by_login('jsmith'), issue.author |
|
83 | assert_equal User.find_by_login('jsmith'), issue.author | |
82 | assert_equal Project.find(2), issue.project |
|
84 | assert_equal Project.find(2), issue.project | |
83 | assert_equal 'Feature request', issue.tracker.to_s |
|
85 | assert_equal 'Feature request', issue.tracker.to_s | |
84 | assert_equal 'Stock management', issue.category.to_s |
|
86 | assert_equal 'Stock management', issue.category.to_s | |
85 | assert_equal 'Urgent', issue.priority.to_s |
|
87 | assert_equal 'Urgent', issue.priority.to_s | |
86 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
88 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
87 | end |
|
89 | end | |
88 |
|
90 | |||
89 | def test_add_issue_with_partial_attributes_override |
|
91 | def test_add_issue_with_partial_attributes_override | |
90 | issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker']) |
|
92 | issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker']) | |
91 | assert issue.is_a?(Issue) |
|
93 | assert issue.is_a?(Issue) | |
92 | assert !issue.new_record? |
|
94 | assert !issue.new_record? | |
93 | issue.reload |
|
95 | issue.reload | |
94 | assert_equal 'New ticket on a given project', issue.subject |
|
96 | assert_equal 'New ticket on a given project', issue.subject | |
95 | assert_equal User.find_by_login('jsmith'), issue.author |
|
97 | assert_equal User.find_by_login('jsmith'), issue.author | |
96 | assert_equal Project.find(2), issue.project |
|
98 | assert_equal Project.find(2), issue.project | |
97 | assert_equal 'Feature request', issue.tracker.to_s |
|
99 | assert_equal 'Feature request', issue.tracker.to_s | |
98 | assert_nil issue.category |
|
100 | assert_nil issue.category | |
99 | assert_equal 'High', issue.priority.to_s |
|
101 | assert_equal 'High', issue.priority.to_s | |
100 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
102 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
101 | end |
|
103 | end | |
102 |
|
104 | |||
103 | def test_add_issue_with_spaces_between_attribute_and_separator |
|
105 | def test_add_issue_with_spaces_between_attribute_and_separator | |
104 | issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority') |
|
106 | issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority') | |
105 | assert issue.is_a?(Issue) |
|
107 | assert issue.is_a?(Issue) | |
106 | assert !issue.new_record? |
|
108 | assert !issue.new_record? | |
107 | issue.reload |
|
109 | issue.reload | |
108 | assert_equal 'New ticket on a given project', issue.subject |
|
110 | assert_equal 'New ticket on a given project', issue.subject | |
109 | assert_equal User.find_by_login('jsmith'), issue.author |
|
111 | assert_equal User.find_by_login('jsmith'), issue.author | |
110 | assert_equal Project.find(2), issue.project |
|
112 | assert_equal Project.find(2), issue.project | |
111 | assert_equal 'Feature request', issue.tracker.to_s |
|
113 | assert_equal 'Feature request', issue.tracker.to_s | |
112 | assert_equal 'Stock management', issue.category.to_s |
|
114 | assert_equal 'Stock management', issue.category.to_s | |
113 | assert_equal 'Urgent', issue.priority.to_s |
|
115 | assert_equal 'Urgent', issue.priority.to_s | |
114 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
116 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
115 | end |
|
117 | end | |
116 |
|
118 | |||
117 |
|
119 | |||
118 | def test_add_issue_with_attachment_to_specific_project |
|
120 | def test_add_issue_with_attachment_to_specific_project | |
119 | issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) |
|
121 | issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) | |
120 | assert issue.is_a?(Issue) |
|
122 | assert issue.is_a?(Issue) | |
121 | assert !issue.new_record? |
|
123 | assert !issue.new_record? | |
122 | issue.reload |
|
124 | issue.reload | |
123 | assert_equal 'Ticket created by email with attachment', issue.subject |
|
125 | assert_equal 'Ticket created by email with attachment', issue.subject | |
124 | assert_equal User.find_by_login('jsmith'), issue.author |
|
126 | assert_equal User.find_by_login('jsmith'), issue.author | |
125 | assert_equal Project.find(2), issue.project |
|
127 | assert_equal Project.find(2), issue.project | |
126 | assert_equal 'This is a new ticket with attachments', issue.description |
|
128 | assert_equal 'This is a new ticket with attachments', issue.description | |
127 | # Attachment properties |
|
129 | # Attachment properties | |
128 | assert_equal 1, issue.attachments.size |
|
130 | assert_equal 1, issue.attachments.size | |
129 | assert_equal 'Paella.jpg', issue.attachments.first.filename |
|
131 | assert_equal 'Paella.jpg', issue.attachments.first.filename | |
130 | assert_equal 'image/jpeg', issue.attachments.first.content_type |
|
132 | assert_equal 'image/jpeg', issue.attachments.first.content_type | |
131 | assert_equal 10790, issue.attachments.first.filesize |
|
133 | assert_equal 10790, issue.attachments.first.filesize | |
132 | end |
|
134 | end | |
133 |
|
135 | |||
134 | def test_add_issue_with_custom_fields |
|
136 | def test_add_issue_with_custom_fields | |
135 | issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) |
|
137 | issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) | |
136 | assert issue.is_a?(Issue) |
|
138 | assert issue.is_a?(Issue) | |
137 | assert !issue.new_record? |
|
139 | assert !issue.new_record? | |
138 | issue.reload |
|
140 | issue.reload | |
139 | assert_equal 'New ticket with custom field values', issue.subject |
|
141 | assert_equal 'New ticket with custom field values', issue.subject | |
140 | assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value |
|
142 | assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value | |
141 | assert !issue.description.match(/^searchable field:/i) |
|
143 | assert !issue.description.match(/^searchable field:/i) | |
142 | end |
|
144 | end | |
143 |
|
145 | |||
144 | def test_add_issue_with_cc |
|
146 | def test_add_issue_with_cc | |
145 | issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) |
|
147 | issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) | |
146 | assert issue.is_a?(Issue) |
|
148 | assert issue.is_a?(Issue) | |
147 | assert !issue.new_record? |
|
149 | assert !issue.new_record? | |
148 | issue.reload |
|
150 | issue.reload | |
149 | assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) |
|
151 | assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) | |
150 | assert_equal 1, issue.watchers.size |
|
152 | assert_equal 1, issue.watchers.size | |
151 | end |
|
153 | end | |
152 |
|
154 | |||
153 | def test_add_issue_by_unknown_user |
|
155 | def test_add_issue_by_unknown_user | |
154 | assert_no_difference 'User.count' do |
|
156 | assert_no_difference 'User.count' do | |
155 | assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) |
|
157 | assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) | |
156 | end |
|
158 | end | |
157 | end |
|
159 | end | |
158 |
|
160 | |||
159 | def test_add_issue_by_anonymous_user |
|
161 | def test_add_issue_by_anonymous_user | |
160 | Role.anonymous.add_permission!(:add_issues) |
|
162 | Role.anonymous.add_permission!(:add_issues) | |
161 | assert_no_difference 'User.count' do |
|
163 | assert_no_difference 'User.count' do | |
162 | issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept') |
|
164 | issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept') | |
163 | assert issue.is_a?(Issue) |
|
165 | assert issue.is_a?(Issue) | |
164 | assert issue.author.anonymous? |
|
166 | assert issue.author.anonymous? | |
165 | end |
|
167 | end | |
166 | end |
|
168 | end | |
167 |
|
169 | |||
168 | def test_add_issue_by_anonymous_user_on_private_project |
|
170 | def test_add_issue_by_anonymous_user_on_private_project | |
169 | Role.anonymous.add_permission!(:add_issues) |
|
171 | Role.anonymous.add_permission!(:add_issues) | |
170 | assert_no_difference 'User.count' do |
|
172 | assert_no_difference 'User.count' do | |
171 | assert_no_difference 'Issue.count' do |
|
173 | assert_no_difference 'Issue.count' do | |
172 | assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept') |
|
174 | assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept') | |
173 | end |
|
175 | end | |
174 | end |
|
176 | end | |
175 | end |
|
177 | end | |
176 |
|
178 | |||
177 | def test_add_issue_by_anonymous_user_on_private_project_without_permission_check |
|
179 | def test_add_issue_by_anonymous_user_on_private_project_without_permission_check | |
178 | assert_no_difference 'User.count' do |
|
180 | assert_no_difference 'User.count' do | |
179 | assert_difference 'Issue.count' do |
|
181 | assert_difference 'Issue.count' do | |
180 | issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept') |
|
182 | issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept') | |
181 | assert issue.is_a?(Issue) |
|
183 | assert issue.is_a?(Issue) | |
182 | assert issue.author.anonymous? |
|
184 | assert issue.author.anonymous? | |
183 | assert !issue.project.is_public? |
|
185 | assert !issue.project.is_public? | |
184 | end |
|
186 | end | |
185 | end |
|
187 | end | |
186 | end |
|
188 | end | |
187 |
|
189 | |||
188 | def test_add_issue_by_created_user |
|
190 | def test_add_issue_by_created_user | |
189 | Setting.default_language = 'en' |
|
191 | Setting.default_language = 'en' | |
190 | assert_difference 'User.count' do |
|
192 | assert_difference 'User.count' do | |
191 | issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') |
|
193 | issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') | |
192 | assert issue.is_a?(Issue) |
|
194 | assert issue.is_a?(Issue) | |
193 | assert issue.author.active? |
|
195 | assert issue.author.active? | |
194 | assert_equal 'john.doe@somenet.foo', issue.author.mail |
|
196 | assert_equal 'john.doe@somenet.foo', issue.author.mail | |
195 | assert_equal 'John', issue.author.firstname |
|
197 | assert_equal 'John', issue.author.firstname | |
196 | assert_equal 'Doe', issue.author.lastname |
|
198 | assert_equal 'Doe', issue.author.lastname | |
197 |
|
199 | |||
198 | # account information |
|
200 | # account information | |
199 | email = ActionMailer::Base.deliveries.first |
|
201 | email = ActionMailer::Base.deliveries.first | |
200 | assert_not_nil email |
|
202 | assert_not_nil email | |
201 | assert email.subject.include?('account activation') |
|
203 | assert email.subject.include?('account activation') | |
202 | login = email.body.match(/\* Login: (.*)$/)[1] |
|
204 | login = email.body.match(/\* Login: (.*)$/)[1] | |
203 | password = email.body.match(/\* Password: (.*)$/)[1] |
|
205 | password = email.body.match(/\* Password: (.*)$/)[1] | |
204 | assert_equal issue.author, User.try_to_login(login, password) |
|
206 | assert_equal issue.author, User.try_to_login(login, password) | |
205 | end |
|
207 | end | |
206 | end |
|
208 | end | |
207 |
|
209 | |||
208 | def test_add_issue_without_from_header |
|
210 | def test_add_issue_without_from_header | |
209 | Role.anonymous.add_permission!(:add_issues) |
|
211 | Role.anonymous.add_permission!(:add_issues) | |
210 | assert_equal false, submit_email('ticket_without_from_header.eml') |
|
212 | assert_equal false, submit_email('ticket_without_from_header.eml') | |
211 | end |
|
213 | end | |
212 |
|
214 | |||
213 | def test_add_issue_with_japanese_keywords |
|
215 | def test_add_issue_with_japanese_keywords | |
214 | tracker = Tracker.create!(:name => 'ιηΊ') |
|
216 | tracker = Tracker.create!(:name => 'ιηΊ') | |
215 | Project.find(1).trackers << tracker |
|
217 | Project.find(1).trackers << tracker | |
216 | issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker') |
|
218 | issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker') | |
217 | assert_kind_of Issue, issue |
|
219 | assert_kind_of Issue, issue | |
218 | assert_equal tracker, issue.tracker |
|
220 | assert_equal tracker, issue.tracker | |
219 | end |
|
221 | end | |
220 |
|
222 | |||
221 | def test_should_ignore_emails_from_emission_address |
|
223 | def test_should_ignore_emails_from_emission_address | |
222 | Role.anonymous.add_permission!(:add_issues) |
|
224 | Role.anonymous.add_permission!(:add_issues) | |
223 | assert_no_difference 'User.count' do |
|
225 | assert_no_difference 'User.count' do | |
224 | assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') |
|
226 | assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') | |
225 | end |
|
227 | end | |
226 | end |
|
228 | end | |
227 |
|
229 | |||
228 | def test_add_issue_should_send_email_notification |
|
230 | def test_add_issue_should_send_email_notification | |
229 | ActionMailer::Base.deliveries.clear |
|
231 | ActionMailer::Base.deliveries.clear | |
230 | # This email contains: 'Project: onlinestore' |
|
232 | # This email contains: 'Project: onlinestore' | |
231 | issue = submit_email('ticket_on_given_project.eml') |
|
233 | issue = submit_email('ticket_on_given_project.eml') | |
232 | assert issue.is_a?(Issue) |
|
234 | assert issue.is_a?(Issue) | |
233 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
235 | assert_equal 1, ActionMailer::Base.deliveries.size | |
234 | end |
|
236 | end | |
235 |
|
237 | |||
236 | def test_add_issue_note |
|
238 | def test_add_issue_note | |
237 | journal = submit_email('ticket_reply.eml') |
|
239 | journal = submit_email('ticket_reply.eml') | |
238 | assert journal.is_a?(Journal) |
|
240 | assert journal.is_a?(Journal) | |
239 | assert_equal User.find_by_login('jsmith'), journal.user |
|
241 | assert_equal User.find_by_login('jsmith'), journal.user | |
240 | assert_equal Issue.find(2), journal.journalized |
|
242 | assert_equal Issue.find(2), journal.journalized | |
241 | assert_match /This is reply/, journal.notes |
|
243 | assert_match /This is reply/, journal.notes | |
242 | end |
|
244 | end | |
243 |
|
245 | |||
244 | def test_add_issue_note_with_status_change |
|
246 | def test_add_issue_note_with_status_change | |
245 | # This email contains: 'Status: Resolved' |
|
247 | # This email contains: 'Status: Resolved' | |
246 | journal = submit_email('ticket_reply_with_status.eml') |
|
248 | journal = submit_email('ticket_reply_with_status.eml') | |
247 | assert journal.is_a?(Journal) |
|
249 | assert journal.is_a?(Journal) | |
248 | issue = Issue.find(journal.issue.id) |
|
250 | issue = Issue.find(journal.issue.id) | |
249 | assert_equal User.find_by_login('jsmith'), journal.user |
|
251 | assert_equal User.find_by_login('jsmith'), journal.user | |
250 | assert_equal Issue.find(2), journal.journalized |
|
252 | assert_equal Issue.find(2), journal.journalized | |
251 | assert_match /This is reply/, journal.notes |
|
253 | assert_match /This is reply/, journal.notes | |
252 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
|
254 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status | |
253 | end |
|
255 | end | |
254 |
|
256 | |||
255 | def test_add_issue_note_should_send_email_notification |
|
257 | def test_add_issue_note_should_send_email_notification | |
256 | ActionMailer::Base.deliveries.clear |
|
258 | ActionMailer::Base.deliveries.clear | |
257 | journal = submit_email('ticket_reply.eml') |
|
259 | journal = submit_email('ticket_reply.eml') | |
258 | assert journal.is_a?(Journal) |
|
260 | assert journal.is_a?(Journal) | |
259 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
261 | assert_equal 1, ActionMailer::Base.deliveries.size | |
260 | end |
|
262 | end | |
261 |
|
263 | |||
262 | def test_reply_to_a_message |
|
264 | def test_reply_to_a_message | |
263 | m = submit_email('message_reply.eml') |
|
265 | m = submit_email('message_reply.eml') | |
264 | assert m.is_a?(Message) |
|
266 | assert m.is_a?(Message) | |
265 | assert !m.new_record? |
|
267 | assert !m.new_record? | |
266 | m.reload |
|
268 | m.reload | |
267 | assert_equal 'Reply via email', m.subject |
|
269 | assert_equal 'Reply via email', m.subject | |
268 | # The email replies to message #2 which is part of the thread of message #1 |
|
270 | # The email replies to message #2 which is part of the thread of message #1 | |
269 | assert_equal Message.find(1), m.parent |
|
271 | assert_equal Message.find(1), m.parent | |
270 | end |
|
272 | end | |
271 |
|
273 | |||
272 | def test_reply_to_a_message_by_subject |
|
274 | def test_reply_to_a_message_by_subject | |
273 | m = submit_email('message_reply_by_subject.eml') |
|
275 | m = submit_email('message_reply_by_subject.eml') | |
274 | assert m.is_a?(Message) |
|
276 | assert m.is_a?(Message) | |
275 | assert !m.new_record? |
|
277 | assert !m.new_record? | |
276 | m.reload |
|
278 | m.reload | |
277 | assert_equal 'Reply to the first post', m.subject |
|
279 | assert_equal 'Reply to the first post', m.subject | |
278 | assert_equal Message.find(1), m.parent |
|
280 | assert_equal Message.find(1), m.parent | |
279 | end |
|
281 | end | |
280 |
|
282 | |||
281 | def test_should_strip_tags_of_html_only_emails |
|
283 | def test_should_strip_tags_of_html_only_emails | |
282 | issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) |
|
284 | issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) | |
283 | assert issue.is_a?(Issue) |
|
285 | assert issue.is_a?(Issue) | |
284 | assert !issue.new_record? |
|
286 | assert !issue.new_record? | |
285 | issue.reload |
|
287 | issue.reload | |
286 | assert_equal 'HTML email', issue.subject |
|
288 | assert_equal 'HTML email', issue.subject | |
287 | assert_equal 'This is a html-only email.', issue.description |
|
289 | assert_equal 'This is a html-only email.', issue.description | |
288 | end |
|
290 | end | |
289 |
|
291 | |||
290 | context "truncate emails based on the Setting" do |
|
292 | context "truncate emails based on the Setting" do | |
291 | context "with no setting" do |
|
293 | context "with no setting" do | |
292 | setup do |
|
294 | setup do | |
293 | Setting.mail_handler_body_delimiters = '' |
|
295 | Setting.mail_handler_body_delimiters = '' | |
294 | end |
|
296 | end | |
295 |
|
297 | |||
296 | should "add the entire email into the issue" do |
|
298 | should "add the entire email into the issue" do | |
297 | issue = submit_email('ticket_on_given_project.eml') |
|
299 | issue = submit_email('ticket_on_given_project.eml') | |
298 | assert_issue_created(issue) |
|
300 | assert_issue_created(issue) | |
299 | assert issue.description.include?('---') |
|
301 | assert issue.description.include?('---') | |
300 | assert issue.description.include?('This paragraph is after the delimiter') |
|
302 | assert issue.description.include?('This paragraph is after the delimiter') | |
301 | end |
|
303 | end | |
302 | end |
|
304 | end | |
303 |
|
305 | |||
304 | context "with a single string" do |
|
306 | context "with a single string" do | |
305 | setup do |
|
307 | setup do | |
306 | Setting.mail_handler_body_delimiters = '---' |
|
308 | Setting.mail_handler_body_delimiters = '---' | |
307 | end |
|
309 | end | |
308 |
|
310 | |||
309 | should "truncate the email at the delimiter for the issue" do |
|
311 | should "truncate the email at the delimiter for the issue" do | |
310 | issue = submit_email('ticket_on_given_project.eml') |
|
312 | issue = submit_email('ticket_on_given_project.eml') | |
311 | assert_issue_created(issue) |
|
313 | assert_issue_created(issue) | |
312 | assert issue.description.include?('This paragraph is before delimiters') |
|
314 | assert issue.description.include?('This paragraph is before delimiters') | |
313 | assert issue.description.include?('--- This line starts with a delimiter') |
|
315 | assert issue.description.include?('--- This line starts with a delimiter') | |
314 | assert !issue.description.match(/^---$/) |
|
316 | assert !issue.description.match(/^---$/) | |
315 | assert !issue.description.include?('This paragraph is after the delimiter') |
|
317 | assert !issue.description.include?('This paragraph is after the delimiter') | |
316 | end |
|
318 | end | |
317 | end |
|
319 | end | |
318 |
|
320 | |||
319 | context "with multiple strings" do |
|
321 | context "with multiple strings" do | |
320 | setup do |
|
322 | setup do | |
321 | Setting.mail_handler_body_delimiters = "---\nBREAK" |
|
323 | Setting.mail_handler_body_delimiters = "---\nBREAK" | |
322 | end |
|
324 | end | |
323 |
|
325 | |||
324 | should "truncate the email at the first delimiter found (BREAK)" do |
|
326 | should "truncate the email at the first delimiter found (BREAK)" do | |
325 | issue = submit_email('ticket_on_given_project.eml') |
|
327 | issue = submit_email('ticket_on_given_project.eml') | |
326 | assert_issue_created(issue) |
|
328 | assert_issue_created(issue) | |
327 | assert issue.description.include?('This paragraph is before delimiters') |
|
329 | assert issue.description.include?('This paragraph is before delimiters') | |
328 | assert !issue.description.include?('BREAK') |
|
330 | assert !issue.description.include?('BREAK') | |
329 | assert !issue.description.include?('This paragraph is between delimiters') |
|
331 | assert !issue.description.include?('This paragraph is between delimiters') | |
330 | assert !issue.description.match(/^---$/) |
|
332 | assert !issue.description.match(/^---$/) | |
331 | assert !issue.description.include?('This paragraph is after the delimiter') |
|
333 | assert !issue.description.include?('This paragraph is after the delimiter') | |
332 | end |
|
334 | end | |
333 | end |
|
335 | end | |
334 | end |
|
336 | end | |
335 |
|
337 | |||
336 | private |
|
338 | private | |
337 |
|
339 | |||
338 | def submit_email(filename, options={}) |
|
340 | def submit_email(filename, options={}) | |
339 | raw = IO.read(File.join(FIXTURES_PATH, filename)) |
|
341 | raw = IO.read(File.join(FIXTURES_PATH, filename)) | |
340 | MailHandler.receive(raw, options) |
|
342 | MailHandler.receive(raw, options) | |
341 | end |
|
343 | end | |
342 |
|
344 | |||
343 | def assert_issue_created(issue) |
|
345 | def assert_issue_created(issue) | |
344 | assert issue.is_a?(Issue) |
|
346 | assert issue.is_a?(Issue) | |
345 | assert !issue.new_record? |
|
347 | assert !issue.new_record? | |
346 | issue.reload |
|
348 | issue.reload | |
347 | end |
|
349 | end | |
348 | end |
|
350 | end |
General Comments 0
You need to be logged in to leave comments.
Login now