##// END OF EJS Templates
Add assertions for #6929 in MailHandler tests....
Jean-Philippe Lang -
r4302:1f237388bddd
parent child
Show More
@@ -1,439 +1,441
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2009 Jean-Philippe Lang
4 # Copyright (C) 2006-2009 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.
10 #
10 #
11 # 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,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # 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
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # 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.
19
19
20 require File.dirname(__FILE__) + '/../test_helper'
20 require File.dirname(__FILE__) + '/../test_helper'
21
21
22 class MailHandlerTest < ActiveSupport::TestCase
22 class MailHandlerTest < ActiveSupport::TestCase
23 fixtures :users, :projects,
23 fixtures :users, :projects,
24 :enabled_modules,
24 :enabled_modules,
25 :roles,
25 :roles,
26 :members,
26 :members,
27 :member_roles,
27 :member_roles,
28 :users,
28 :users,
29 :issues,
29 :issues,
30 :issue_statuses,
30 :issue_statuses,
31 :workflows,
31 :workflows,
32 :trackers,
32 :trackers,
33 :projects_trackers,
33 :projects_trackers,
34 :versions,
34 :versions,
35 :enumerations,
35 :enumerations,
36 :issue_categories,
36 :issue_categories,
37 :custom_fields,
37 :custom_fields,
38 :custom_fields_trackers,
38 :custom_fields_trackers,
39 :boards,
39 :boards,
40 :messages
40 :messages
41
41
42 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
42 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
43
43
44 def setup
44 def setup
45 ActionMailer::Base.deliveries.clear
45 ActionMailer::Base.deliveries.clear
46 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
46 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
47 end
47 end
48
48
49 def test_add_issue
49 def test_add_issue
50 ActionMailer::Base.deliveries.clear
50 ActionMailer::Base.deliveries.clear
51 # This email contains: 'Project: onlinestore'
51 # This email contains: 'Project: onlinestore'
52 issue = submit_email('ticket_on_given_project.eml')
52 issue = submit_email('ticket_on_given_project.eml')
53 assert issue.is_a?(Issue)
53 assert issue.is_a?(Issue)
54 assert !issue.new_record?
54 assert !issue.new_record?
55 issue.reload
55 issue.reload
56 assert_equal 'New ticket on a given project', issue.subject
56 assert_equal 'New ticket on a given project', issue.subject
57 assert_equal User.find_by_login('jsmith'), issue.author
57 assert_equal User.find_by_login('jsmith'), issue.author
58 assert_equal Project.find(2), issue.project
58 assert_equal Project.find(2), issue.project
59 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
59 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
60 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
60 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
61 assert_equal '2010-01-01', issue.start_date.to_s
61 assert_equal '2010-01-01', issue.start_date.to_s
62 assert_equal '2010-12-31', issue.due_date.to_s
62 assert_equal '2010-12-31', issue.due_date.to_s
63 assert_equal User.find_by_login('jsmith'), issue.assigned_to
63 assert_equal User.find_by_login('jsmith'), issue.assigned_to
64 assert_equal Version.find_by_name('alpha'), issue.fixed_version
64 assert_equal Version.find_by_name('alpha'), issue.fixed_version
65 assert_equal 2.5, issue.estimated_hours
65 assert_equal 2.5, issue.estimated_hours
66 assert_equal 30, issue.done_ratio
66 assert_equal 30, issue.done_ratio
67 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
67 # keywords should be removed from the email body
68 # keywords should be removed from the email body
68 assert !issue.description.match(/^Project:/i)
69 assert !issue.description.match(/^Project:/i)
69 assert !issue.description.match(/^Status:/i)
70 assert !issue.description.match(/^Status:/i)
70 # Email notification should be sent
71 # Email notification should be sent
71 mail = ActionMailer::Base.deliveries.last
72 mail = ActionMailer::Base.deliveries.last
72 assert_not_nil mail
73 assert_not_nil mail
73 assert mail.subject.include?('New ticket on a given project')
74 assert mail.subject.include?('New ticket on a given project')
74 end
75 end
75
76
76 def test_add_issue_with_status
77 def test_add_issue_with_status
77 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
78 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
78 issue = submit_email('ticket_on_given_project.eml')
79 issue = submit_email('ticket_on_given_project.eml')
79 assert issue.is_a?(Issue)
80 assert issue.is_a?(Issue)
80 assert !issue.new_record?
81 assert !issue.new_record?
81 issue.reload
82 issue.reload
82 assert_equal Project.find(2), issue.project
83 assert_equal Project.find(2), issue.project
83 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
84 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
84 end
85 end
85
86
86 def test_add_issue_with_attributes_override
87 def test_add_issue_with_attributes_override
87 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
88 issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
88 assert issue.is_a?(Issue)
89 assert issue.is_a?(Issue)
89 assert !issue.new_record?
90 assert !issue.new_record?
90 issue.reload
91 issue.reload
91 assert_equal 'New ticket on a given project', issue.subject
92 assert_equal 'New ticket on a given project', issue.subject
92 assert_equal User.find_by_login('jsmith'), issue.author
93 assert_equal User.find_by_login('jsmith'), issue.author
93 assert_equal Project.find(2), issue.project
94 assert_equal Project.find(2), issue.project
94 assert_equal 'Feature request', issue.tracker.to_s
95 assert_equal 'Feature request', issue.tracker.to_s
95 assert_equal 'Stock management', issue.category.to_s
96 assert_equal 'Stock management', issue.category.to_s
96 assert_equal 'Urgent', issue.priority.to_s
97 assert_equal 'Urgent', issue.priority.to_s
97 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
98 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
98 end
99 end
99
100
100 def test_add_issue_with_partial_attributes_override
101 def test_add_issue_with_partial_attributes_override
101 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker'])
102 issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker'])
102 assert issue.is_a?(Issue)
103 assert issue.is_a?(Issue)
103 assert !issue.new_record?
104 assert !issue.new_record?
104 issue.reload
105 issue.reload
105 assert_equal 'New ticket on a given project', issue.subject
106 assert_equal 'New ticket on a given project', issue.subject
106 assert_equal User.find_by_login('jsmith'), issue.author
107 assert_equal User.find_by_login('jsmith'), issue.author
107 assert_equal Project.find(2), issue.project
108 assert_equal Project.find(2), issue.project
108 assert_equal 'Feature request', issue.tracker.to_s
109 assert_equal 'Feature request', issue.tracker.to_s
109 assert_nil issue.category
110 assert_nil issue.category
110 assert_equal 'High', issue.priority.to_s
111 assert_equal 'High', issue.priority.to_s
111 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
112 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
112 end
113 end
113
114
114 def test_add_issue_with_spaces_between_attribute_and_separator
115 def test_add_issue_with_spaces_between_attribute_and_separator
115 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority')
116 issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority')
116 assert issue.is_a?(Issue)
117 assert issue.is_a?(Issue)
117 assert !issue.new_record?
118 assert !issue.new_record?
118 issue.reload
119 issue.reload
119 assert_equal 'New ticket on a given project', issue.subject
120 assert_equal 'New ticket on a given project', issue.subject
120 assert_equal User.find_by_login('jsmith'), issue.author
121 assert_equal User.find_by_login('jsmith'), issue.author
121 assert_equal Project.find(2), issue.project
122 assert_equal Project.find(2), issue.project
122 assert_equal 'Feature request', issue.tracker.to_s
123 assert_equal 'Feature request', issue.tracker.to_s
123 assert_equal 'Stock management', issue.category.to_s
124 assert_equal 'Stock management', issue.category.to_s
124 assert_equal 'Urgent', issue.priority.to_s
125 assert_equal 'Urgent', issue.priority.to_s
125 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
126 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
126 end
127 end
127
128
128
129
129 def test_add_issue_with_attachment_to_specific_project
130 def test_add_issue_with_attachment_to_specific_project
130 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
131 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
131 assert issue.is_a?(Issue)
132 assert issue.is_a?(Issue)
132 assert !issue.new_record?
133 assert !issue.new_record?
133 issue.reload
134 issue.reload
134 assert_equal 'Ticket created by email with attachment', issue.subject
135 assert_equal 'Ticket created by email with attachment', issue.subject
135 assert_equal User.find_by_login('jsmith'), issue.author
136 assert_equal User.find_by_login('jsmith'), issue.author
136 assert_equal Project.find(2), issue.project
137 assert_equal Project.find(2), issue.project
137 assert_equal 'This is a new ticket with attachments', issue.description
138 assert_equal 'This is a new ticket with attachments', issue.description
138 # Attachment properties
139 # Attachment properties
139 assert_equal 1, issue.attachments.size
140 assert_equal 1, issue.attachments.size
140 assert_equal 'Paella.jpg', issue.attachments.first.filename
141 assert_equal 'Paella.jpg', issue.attachments.first.filename
141 assert_equal 'image/jpeg', issue.attachments.first.content_type
142 assert_equal 'image/jpeg', issue.attachments.first.content_type
142 assert_equal 10790, issue.attachments.first.filesize
143 assert_equal 10790, issue.attachments.first.filesize
143 end
144 end
144
145
145 def test_add_issue_with_custom_fields
146 def test_add_issue_with_custom_fields
146 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
147 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
147 assert issue.is_a?(Issue)
148 assert issue.is_a?(Issue)
148 assert !issue.new_record?
149 assert !issue.new_record?
149 issue.reload
150 issue.reload
150 assert_equal 'New ticket with custom field values', issue.subject
151 assert_equal 'New ticket with custom field values', issue.subject
151 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
152 assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
152 assert !issue.description.match(/^searchable field:/i)
153 assert !issue.description.match(/^searchable field:/i)
153 end
154 end
154
155
155 def test_add_issue_with_cc
156 def test_add_issue_with_cc
156 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
157 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
157 assert issue.is_a?(Issue)
158 assert issue.is_a?(Issue)
158 assert !issue.new_record?
159 assert !issue.new_record?
159 issue.reload
160 issue.reload
160 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
161 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
161 assert_equal 1, issue.watcher_user_ids.size
162 assert_equal 1, issue.watcher_user_ids.size
162 end
163 end
163
164
164 def test_add_issue_by_unknown_user
165 def test_add_issue_by_unknown_user
165 assert_no_difference 'User.count' do
166 assert_no_difference 'User.count' do
166 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
167 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
167 end
168 end
168 end
169 end
169
170
170 def test_add_issue_by_anonymous_user
171 def test_add_issue_by_anonymous_user
171 Role.anonymous.add_permission!(:add_issues)
172 Role.anonymous.add_permission!(:add_issues)
172 assert_no_difference 'User.count' do
173 assert_no_difference 'User.count' do
173 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
174 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
174 assert issue.is_a?(Issue)
175 assert issue.is_a?(Issue)
175 assert issue.author.anonymous?
176 assert issue.author.anonymous?
176 end
177 end
177 end
178 end
178
179
179 def test_add_issue_by_anonymous_user_with_no_from_address
180 def test_add_issue_by_anonymous_user_with_no_from_address
180 Role.anonymous.add_permission!(:add_issues)
181 Role.anonymous.add_permission!(:add_issues)
181 assert_no_difference 'User.count' do
182 assert_no_difference 'User.count' do
182 issue = submit_email('ticket_by_empty_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
183 issue = submit_email('ticket_by_empty_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'accept')
183 assert issue.is_a?(Issue)
184 assert issue.is_a?(Issue)
184 assert issue.author.anonymous?
185 assert issue.author.anonymous?
185 end
186 end
186 end
187 end
187
188
188 def test_add_issue_by_anonymous_user_on_private_project
189 def test_add_issue_by_anonymous_user_on_private_project
189 Role.anonymous.add_permission!(:add_issues)
190 Role.anonymous.add_permission!(:add_issues)
190 assert_no_difference 'User.count' do
191 assert_no_difference 'User.count' do
191 assert_no_difference 'Issue.count' do
192 assert_no_difference 'Issue.count' do
192 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept')
193 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :unknown_user => 'accept')
193 end
194 end
194 end
195 end
195 end
196 end
196
197
197 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
198 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
198 assert_no_difference 'User.count' do
199 assert_no_difference 'User.count' do
199 assert_difference 'Issue.count' do
200 assert_difference 'Issue.count' do
200 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept')
201 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'onlinestore'}, :no_permission_check => '1', :unknown_user => 'accept')
201 assert issue.is_a?(Issue)
202 assert issue.is_a?(Issue)
202 assert issue.author.anonymous?
203 assert issue.author.anonymous?
203 assert !issue.project.is_public?
204 assert !issue.project.is_public?
205 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
204 end
206 end
205 end
207 end
206 end
208 end
207
209
208 def test_add_issue_by_created_user
210 def test_add_issue_by_created_user
209 Setting.default_language = 'en'
211 Setting.default_language = 'en'
210 assert_difference 'User.count' do
212 assert_difference 'User.count' do
211 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
213 issue = submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
212 assert issue.is_a?(Issue)
214 assert issue.is_a?(Issue)
213 assert issue.author.active?
215 assert issue.author.active?
214 assert_equal 'john.doe@somenet.foo', issue.author.mail
216 assert_equal 'john.doe@somenet.foo', issue.author.mail
215 assert_equal 'John', issue.author.firstname
217 assert_equal 'John', issue.author.firstname
216 assert_equal 'Doe', issue.author.lastname
218 assert_equal 'Doe', issue.author.lastname
217
219
218 # account information
220 # account information
219 email = ActionMailer::Base.deliveries.first
221 email = ActionMailer::Base.deliveries.first
220 assert_not_nil email
222 assert_not_nil email
221 assert email.subject.include?('account activation')
223 assert email.subject.include?('account activation')
222 login = email.body.match(/\* Login: (.*)$/)[1]
224 login = email.body.match(/\* Login: (.*)$/)[1]
223 password = email.body.match(/\* Password: (.*)$/)[1]
225 password = email.body.match(/\* Password: (.*)$/)[1]
224 assert_equal issue.author, User.try_to_login(login, password)
226 assert_equal issue.author, User.try_to_login(login, password)
225 end
227 end
226 end
228 end
227
229
228 def test_add_issue_without_from_header
230 def test_add_issue_without_from_header
229 Role.anonymous.add_permission!(:add_issues)
231 Role.anonymous.add_permission!(:add_issues)
230 assert_equal false, submit_email('ticket_without_from_header.eml')
232 assert_equal false, submit_email('ticket_without_from_header.eml')
231 end
233 end
232
234
233 def test_add_issue_with_invalid_attributes
235 def test_add_issue_with_invalid_attributes
234 issue = submit_email('ticket_with_invalid_attributes.eml', :allow_override => 'tracker,category,priority')
236 issue = submit_email('ticket_with_invalid_attributes.eml', :allow_override => 'tracker,category,priority')
235 assert issue.is_a?(Issue)
237 assert issue.is_a?(Issue)
236 assert !issue.new_record?
238 assert !issue.new_record?
237 issue.reload
239 issue.reload
238 assert_nil issue.assigned_to
240 assert_nil issue.assigned_to
239 assert_nil issue.start_date
241 assert_nil issue.start_date
240 assert_nil issue.due_date
242 assert_nil issue.due_date
241 assert_equal 0, issue.done_ratio
243 assert_equal 0, issue.done_ratio
242 assert_equal 'Normal', issue.priority.to_s
244 assert_equal 'Normal', issue.priority.to_s
243 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
245 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
244 end
246 end
245
247
246 def test_add_issue_with_localized_attributes
248 def test_add_issue_with_localized_attributes
247 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
249 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
248 issue = submit_email('ticket_with_localized_attributes.eml', :allow_override => 'tracker,category,priority')
250 issue = submit_email('ticket_with_localized_attributes.eml', :allow_override => 'tracker,category,priority')
249 assert issue.is_a?(Issue)
251 assert issue.is_a?(Issue)
250 assert !issue.new_record?
252 assert !issue.new_record?
251 issue.reload
253 issue.reload
252 assert_equal 'New ticket on a given project', issue.subject
254 assert_equal 'New ticket on a given project', issue.subject
253 assert_equal User.find_by_login('jsmith'), issue.author
255 assert_equal User.find_by_login('jsmith'), issue.author
254 assert_equal Project.find(2), issue.project
256 assert_equal Project.find(2), issue.project
255 assert_equal 'Feature request', issue.tracker.to_s
257 assert_equal 'Feature request', issue.tracker.to_s
256 assert_equal 'Stock management', issue.category.to_s
258 assert_equal 'Stock management', issue.category.to_s
257 assert_equal 'Urgent', issue.priority.to_s
259 assert_equal 'Urgent', issue.priority.to_s
258 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
260 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
259 end
261 end
260
262
261 def test_add_issue_with_japanese_keywords
263 def test_add_issue_with_japanese_keywords
262 tracker = Tracker.create!(:name => 'ι–‹η™Ί')
264 tracker = Tracker.create!(:name => 'ι–‹η™Ί')
263 Project.find(1).trackers << tracker
265 Project.find(1).trackers << tracker
264 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker')
266 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker')
265 assert_kind_of Issue, issue
267 assert_kind_of Issue, issue
266 assert_equal tracker, issue.tracker
268 assert_equal tracker, issue.tracker
267 end
269 end
268
270
269 def test_should_ignore_emails_from_emission_address
271 def test_should_ignore_emails_from_emission_address
270 Role.anonymous.add_permission!(:add_issues)
272 Role.anonymous.add_permission!(:add_issues)
271 assert_no_difference 'User.count' do
273 assert_no_difference 'User.count' do
272 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
274 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
273 end
275 end
274 end
276 end
275
277
276 def test_add_issue_should_send_email_notification
278 def test_add_issue_should_send_email_notification
277 Setting.notified_events = ['issue_added']
279 Setting.notified_events = ['issue_added']
278 ActionMailer::Base.deliveries.clear
280 ActionMailer::Base.deliveries.clear
279 # This email contains: 'Project: onlinestore'
281 # This email contains: 'Project: onlinestore'
280 issue = submit_email('ticket_on_given_project.eml')
282 issue = submit_email('ticket_on_given_project.eml')
281 assert issue.is_a?(Issue)
283 assert issue.is_a?(Issue)
282 assert_equal 1, ActionMailer::Base.deliveries.size
284 assert_equal 1, ActionMailer::Base.deliveries.size
283 end
285 end
284
286
285 def test_add_issue_note
287 def test_add_issue_note
286 journal = submit_email('ticket_reply.eml')
288 journal = submit_email('ticket_reply.eml')
287 assert journal.is_a?(Journal)
289 assert journal.is_a?(Journal)
288 assert_equal User.find_by_login('jsmith'), journal.user
290 assert_equal User.find_by_login('jsmith'), journal.user
289 assert_equal Issue.find(2), journal.journalized
291 assert_equal Issue.find(2), journal.journalized
290 assert_match /This is reply/, journal.notes
292 assert_match /This is reply/, journal.notes
291 end
293 end
292
294
293 def test_add_issue_note_with_attribute_changes
295 def test_add_issue_note_with_attribute_changes
294 # This email contains: 'Status: Resolved'
296 # This email contains: 'Status: Resolved'
295 journal = submit_email('ticket_reply_with_status.eml')
297 journal = submit_email('ticket_reply_with_status.eml')
296 assert journal.is_a?(Journal)
298 assert journal.is_a?(Journal)
297 issue = Issue.find(journal.issue.id)
299 issue = Issue.find(journal.issue.id)
298 assert_equal User.find_by_login('jsmith'), journal.user
300 assert_equal User.find_by_login('jsmith'), journal.user
299 assert_equal Issue.find(2), journal.journalized
301 assert_equal Issue.find(2), journal.journalized
300 assert_match /This is reply/, journal.notes
302 assert_match /This is reply/, journal.notes
301 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
303 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
302 assert_equal '2010-01-01', issue.start_date.to_s
304 assert_equal '2010-01-01', issue.start_date.to_s
303 assert_equal '2010-12-31', issue.due_date.to_s
305 assert_equal '2010-12-31', issue.due_date.to_s
304 assert_equal User.find_by_login('jsmith'), issue.assigned_to
306 assert_equal User.find_by_login('jsmith'), issue.assigned_to
305 assert_equal 'Updated custom value', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
307 assert_equal 'Updated custom value', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
306 end
308 end
307
309
308 def test_add_issue_note_should_send_email_notification
310 def test_add_issue_note_should_send_email_notification
309 ActionMailer::Base.deliveries.clear
311 ActionMailer::Base.deliveries.clear
310 journal = submit_email('ticket_reply.eml')
312 journal = submit_email('ticket_reply.eml')
311 assert journal.is_a?(Journal)
313 assert journal.is_a?(Journal)
312 assert_equal 1, ActionMailer::Base.deliveries.size
314 assert_equal 1, ActionMailer::Base.deliveries.size
313 end
315 end
314
316
315 def test_reply_to_a_message
317 def test_reply_to_a_message
316 m = submit_email('message_reply.eml')
318 m = submit_email('message_reply.eml')
317 assert m.is_a?(Message)
319 assert m.is_a?(Message)
318 assert !m.new_record?
320 assert !m.new_record?
319 m.reload
321 m.reload
320 assert_equal 'Reply via email', m.subject
322 assert_equal 'Reply via email', m.subject
321 # The email replies to message #2 which is part of the thread of message #1
323 # The email replies to message #2 which is part of the thread of message #1
322 assert_equal Message.find(1), m.parent
324 assert_equal Message.find(1), m.parent
323 end
325 end
324
326
325 def test_reply_to_a_message_by_subject
327 def test_reply_to_a_message_by_subject
326 m = submit_email('message_reply_by_subject.eml')
328 m = submit_email('message_reply_by_subject.eml')
327 assert m.is_a?(Message)
329 assert m.is_a?(Message)
328 assert !m.new_record?
330 assert !m.new_record?
329 m.reload
331 m.reload
330 assert_equal 'Reply to the first post', m.subject
332 assert_equal 'Reply to the first post', m.subject
331 assert_equal Message.find(1), m.parent
333 assert_equal Message.find(1), m.parent
332 end
334 end
333
335
334 def test_should_strip_tags_of_html_only_emails
336 def test_should_strip_tags_of_html_only_emails
335 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
337 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
336 assert issue.is_a?(Issue)
338 assert issue.is_a?(Issue)
337 assert !issue.new_record?
339 assert !issue.new_record?
338 issue.reload
340 issue.reload
339 assert_equal 'HTML email', issue.subject
341 assert_equal 'HTML email', issue.subject
340 assert_equal 'This is a html-only email.', issue.description
342 assert_equal 'This is a html-only email.', issue.description
341 end
343 end
342
344
343 context "truncate emails based on the Setting" do
345 context "truncate emails based on the Setting" do
344 context "with no setting" do
346 context "with no setting" do
345 setup do
347 setup do
346 Setting.mail_handler_body_delimiters = ''
348 Setting.mail_handler_body_delimiters = ''
347 end
349 end
348
350
349 should "add the entire email into the issue" do
351 should "add the entire email into the issue" do
350 issue = submit_email('ticket_on_given_project.eml')
352 issue = submit_email('ticket_on_given_project.eml')
351 assert_issue_created(issue)
353 assert_issue_created(issue)
352 assert issue.description.include?('---')
354 assert issue.description.include?('---')
353 assert issue.description.include?('This paragraph is after the delimiter')
355 assert issue.description.include?('This paragraph is after the delimiter')
354 end
356 end
355 end
357 end
356
358
357 context "with a single string" do
359 context "with a single string" do
358 setup do
360 setup do
359 Setting.mail_handler_body_delimiters = '---'
361 Setting.mail_handler_body_delimiters = '---'
360 end
362 end
361
363
362 should "truncate the email at the delimiter for the issue" do
364 should "truncate the email at the delimiter for the issue" do
363 issue = submit_email('ticket_on_given_project.eml')
365 issue = submit_email('ticket_on_given_project.eml')
364 assert_issue_created(issue)
366 assert_issue_created(issue)
365 assert issue.description.include?('This paragraph is before delimiters')
367 assert issue.description.include?('This paragraph is before delimiters')
366 assert issue.description.include?('--- This line starts with a delimiter')
368 assert issue.description.include?('--- This line starts with a delimiter')
367 assert !issue.description.match(/^---$/)
369 assert !issue.description.match(/^---$/)
368 assert !issue.description.include?('This paragraph is after the delimiter')
370 assert !issue.description.include?('This paragraph is after the delimiter')
369 end
371 end
370 end
372 end
371
373
372 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
374 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
373 setup do
375 setup do
374 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
376 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
375 end
377 end
376
378
377 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
379 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
378 journal = submit_email('issue_update_with_quoted_reply_above.eml')
380 journal = submit_email('issue_update_with_quoted_reply_above.eml')
379 assert journal.is_a?(Journal)
381 assert journal.is_a?(Journal)
380 assert journal.notes.include?('An update to the issue by the sender.')
382 assert journal.notes.include?('An update to the issue by the sender.')
381 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
383 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
382 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
384 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
383
385
384 end
386 end
385
387
386 end
388 end
387
389
388 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
390 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
389 setup do
391 setup do
390 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
392 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
391 end
393 end
392
394
393 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
395 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
394 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
396 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
395 assert journal.is_a?(Journal)
397 assert journal.is_a?(Journal)
396 assert journal.notes.include?('An update to the issue by the sender.')
398 assert journal.notes.include?('An update to the issue by the sender.')
397 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
399 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
398 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
400 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
399
401
400 end
402 end
401
403
402 end
404 end
403
405
404 context "with multiple strings" do
406 context "with multiple strings" do
405 setup do
407 setup do
406 Setting.mail_handler_body_delimiters = "---\nBREAK"
408 Setting.mail_handler_body_delimiters = "---\nBREAK"
407 end
409 end
408
410
409 should "truncate the email at the first delimiter found (BREAK)" do
411 should "truncate the email at the first delimiter found (BREAK)" do
410 issue = submit_email('ticket_on_given_project.eml')
412 issue = submit_email('ticket_on_given_project.eml')
411 assert_issue_created(issue)
413 assert_issue_created(issue)
412 assert issue.description.include?('This paragraph is before delimiters')
414 assert issue.description.include?('This paragraph is before delimiters')
413 assert !issue.description.include?('BREAK')
415 assert !issue.description.include?('BREAK')
414 assert !issue.description.include?('This paragraph is between delimiters')
416 assert !issue.description.include?('This paragraph is between delimiters')
415 assert !issue.description.match(/^---$/)
417 assert !issue.description.match(/^---$/)
416 assert !issue.description.include?('This paragraph is after the delimiter')
418 assert !issue.description.include?('This paragraph is after the delimiter')
417 end
419 end
418 end
420 end
419 end
421 end
420
422
421 def test_email_with_long_subject_line
423 def test_email_with_long_subject_line
422 issue = submit_email('ticket_with_long_subject.eml')
424 issue = submit_email('ticket_with_long_subject.eml')
423 assert issue.is_a?(Issue)
425 assert issue.is_a?(Issue)
424 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]
426 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]
425 end
427 end
426
428
427 private
429 private
428
430
429 def submit_email(filename, options={})
431 def submit_email(filename, options={})
430 raw = IO.read(File.join(FIXTURES_PATH, filename))
432 raw = IO.read(File.join(FIXTURES_PATH, filename))
431 MailHandler.receive(raw, options)
433 MailHandler.receive(raw, options)
432 end
434 end
433
435
434 def assert_issue_created(issue)
436 def assert_issue_created(issue)
435 assert issue.is_a?(Issue)
437 assert issue.is_a?(Issue)
436 assert !issue.new_record?
438 assert !issue.new_record?
437 issue.reload
439 issue.reload
438 end
440 end
439 end
441 end
General Comments 0
You need to be logged in to leave comments. Login now