##// END OF EJS Templates
Additional test for MailHandler....
Jean-Philippe Lang -
r9314:62eb536e32f9
parent child
Show More
@@ -1,626 +1,636
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
4 # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
21
21
22 class MailHandlerTest < ActiveSupport::TestCase
22 class MailHandlerTest < ActiveSupport::TestCase
23 fixtures :users, :projects, :enabled_modules, :roles,
23 fixtures :users, :projects, :enabled_modules, :roles,
24 :members, :member_roles, :users,
24 :members, :member_roles, :users,
25 :issues, :issue_statuses,
25 :issues, :issue_statuses,
26 :workflows, :trackers, :projects_trackers,
26 :workflows, :trackers, :projects_trackers,
27 :versions, :enumerations, :issue_categories,
27 :versions, :enumerations, :issue_categories,
28 :custom_fields, :custom_fields_trackers, :custom_fields_projects,
28 :custom_fields, :custom_fields_trackers, :custom_fields_projects,
29 :boards, :messages
29 :boards, :messages
30
30
31 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
31 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
32
32
33 def setup
33 def setup
34 ActionMailer::Base.deliveries.clear
34 ActionMailer::Base.deliveries.clear
35 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
35 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
36 end
36 end
37
37
38 def test_add_issue
38 def test_add_issue
39 ActionMailer::Base.deliveries.clear
39 ActionMailer::Base.deliveries.clear
40 # This email contains: 'Project: onlinestore'
40 # This email contains: 'Project: onlinestore'
41 issue = submit_email('ticket_on_given_project.eml')
41 issue = submit_email('ticket_on_given_project.eml')
42 assert issue.is_a?(Issue)
42 assert issue.is_a?(Issue)
43 assert !issue.new_record?
43 assert !issue.new_record?
44 issue.reload
44 issue.reload
45 assert_equal Project.find(2), issue.project
45 assert_equal Project.find(2), issue.project
46 assert_equal issue.project.trackers.first, issue.tracker
46 assert_equal issue.project.trackers.first, issue.tracker
47 assert_equal 'New ticket on a given project', issue.subject
47 assert_equal 'New ticket on a given project', issue.subject
48 assert_equal User.find_by_login('jsmith'), issue.author
48 assert_equal User.find_by_login('jsmith'), issue.author
49 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
49 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
50 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
50 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
51 assert_equal '2010-01-01', issue.start_date.to_s
51 assert_equal '2010-01-01', issue.start_date.to_s
52 assert_equal '2010-12-31', issue.due_date.to_s
52 assert_equal '2010-12-31', issue.due_date.to_s
53 assert_equal User.find_by_login('jsmith'), issue.assigned_to
53 assert_equal User.find_by_login('jsmith'), issue.assigned_to
54 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
54 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
55 assert_equal 2.5, issue.estimated_hours
55 assert_equal 2.5, issue.estimated_hours
56 assert_equal 30, issue.done_ratio
56 assert_equal 30, issue.done_ratio
57 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
57 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
58 # keywords should be removed from the email body
58 # keywords should be removed from the email body
59 assert !issue.description.match(/^Project:/i)
59 assert !issue.description.match(/^Project:/i)
60 assert !issue.description.match(/^Status:/i)
60 assert !issue.description.match(/^Status:/i)
61 assert !issue.description.match(/^Start Date:/i)
61 assert !issue.description.match(/^Start Date:/i)
62 # Email notification should be sent
62 # Email notification should be sent
63 mail = ActionMailer::Base.deliveries.last
63 mail = ActionMailer::Base.deliveries.last
64 assert_not_nil mail
64 assert_not_nil mail
65 assert mail.subject.include?('New ticket on a given project')
65 assert mail.subject.include?('New ticket on a given project')
66 end
66 end
67
67
68 def test_add_issue_with_default_tracker
68 def test_add_issue_with_default_tracker
69 # This email contains: 'Project: onlinestore'
69 # This email contains: 'Project: onlinestore'
70 issue = submit_email(
70 issue = submit_email(
71 'ticket_on_given_project.eml',
71 'ticket_on_given_project.eml',
72 :issue => {:tracker => 'Support request'}
72 :issue => {:tracker => 'Support request'}
73 )
73 )
74 assert issue.is_a?(Issue)
74 assert issue.is_a?(Issue)
75 assert !issue.new_record?
75 assert !issue.new_record?
76 issue.reload
76 issue.reload
77 assert_equal 'Support request', issue.tracker.name
77 assert_equal 'Support request', issue.tracker.name
78 end
78 end
79
79
80 def test_add_issue_with_status
80 def test_add_issue_with_status
81 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
81 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
82 issue = submit_email('ticket_on_given_project.eml')
82 issue = submit_email('ticket_on_given_project.eml')
83 assert issue.is_a?(Issue)
83 assert issue.is_a?(Issue)
84 assert !issue.new_record?
84 assert !issue.new_record?
85 issue.reload
85 issue.reload
86 assert_equal Project.find(2), issue.project
86 assert_equal Project.find(2), issue.project
87 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
87 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
88 end
88 end
89
89
90 def test_add_issue_with_attributes_override
90 def test_add_issue_with_attributes_override
91 issue = submit_email(
91 issue = submit_email(
92 'ticket_with_attributes.eml',
92 'ticket_with_attributes.eml',
93 :allow_override => 'tracker,category,priority'
93 :allow_override => 'tracker,category,priority'
94 )
94 )
95 assert issue.is_a?(Issue)
95 assert issue.is_a?(Issue)
96 assert !issue.new_record?
96 assert !issue.new_record?
97 issue.reload
97 issue.reload
98 assert_equal 'New ticket on a given project', issue.subject
98 assert_equal 'New ticket on a given project', issue.subject
99 assert_equal User.find_by_login('jsmith'), issue.author
99 assert_equal User.find_by_login('jsmith'), issue.author
100 assert_equal Project.find(2), issue.project
100 assert_equal Project.find(2), issue.project
101 assert_equal 'Feature request', issue.tracker.to_s
101 assert_equal 'Feature request', issue.tracker.to_s
102 assert_equal 'Stock management', issue.category.to_s
102 assert_equal 'Stock management', issue.category.to_s
103 assert_equal 'Urgent', issue.priority.to_s
103 assert_equal 'Urgent', issue.priority.to_s
104 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
104 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
105 end
105 end
106
106
107 def test_add_issue_with_group_assignment
107 def test_add_issue_with_group_assignment
108 with_settings :issue_group_assignment => '1' do
108 with_settings :issue_group_assignment => '1' do
109 issue = submit_email('ticket_on_given_project.eml') do |email|
109 issue = submit_email('ticket_on_given_project.eml') do |email|
110 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
110 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
111 end
111 end
112 assert issue.is_a?(Issue)
112 assert issue.is_a?(Issue)
113 assert !issue.new_record?
113 assert !issue.new_record?
114 issue.reload
114 issue.reload
115 assert_equal Group.find(11), issue.assigned_to
115 assert_equal Group.find(11), issue.assigned_to
116 end
116 end
117 end
117 end
118
118
119 def test_add_issue_with_partial_attributes_override
119 def test_add_issue_with_partial_attributes_override
120 issue = submit_email(
120 issue = submit_email(
121 'ticket_with_attributes.eml',
121 'ticket_with_attributes.eml',
122 :issue => {:priority => 'High'},
122 :issue => {:priority => 'High'},
123 :allow_override => ['tracker']
123 :allow_override => ['tracker']
124 )
124 )
125 assert issue.is_a?(Issue)
125 assert issue.is_a?(Issue)
126 assert !issue.new_record?
126 assert !issue.new_record?
127 issue.reload
127 issue.reload
128 assert_equal 'New ticket on a given project', issue.subject
128 assert_equal 'New ticket on a given project', issue.subject
129 assert_equal User.find_by_login('jsmith'), issue.author
129 assert_equal User.find_by_login('jsmith'), issue.author
130 assert_equal Project.find(2), issue.project
130 assert_equal Project.find(2), issue.project
131 assert_equal 'Feature request', issue.tracker.to_s
131 assert_equal 'Feature request', issue.tracker.to_s
132 assert_nil issue.category
132 assert_nil issue.category
133 assert_equal 'High', issue.priority.to_s
133 assert_equal 'High', issue.priority.to_s
134 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
134 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
135 end
135 end
136
136
137 def test_add_issue_with_spaces_between_attribute_and_separator
137 def test_add_issue_with_spaces_between_attribute_and_separator
138 issue = submit_email(
138 issue = submit_email(
139 'ticket_with_spaces_between_attribute_and_separator.eml',
139 'ticket_with_spaces_between_attribute_and_separator.eml',
140 :allow_override => 'tracker,category,priority'
140 :allow_override => 'tracker,category,priority'
141 )
141 )
142 assert issue.is_a?(Issue)
142 assert issue.is_a?(Issue)
143 assert !issue.new_record?
143 assert !issue.new_record?
144 issue.reload
144 issue.reload
145 assert_equal 'New ticket on a given project', issue.subject
145 assert_equal 'New ticket on a given project', issue.subject
146 assert_equal User.find_by_login('jsmith'), issue.author
146 assert_equal User.find_by_login('jsmith'), issue.author
147 assert_equal Project.find(2), issue.project
147 assert_equal Project.find(2), issue.project
148 assert_equal 'Feature request', issue.tracker.to_s
148 assert_equal 'Feature request', issue.tracker.to_s
149 assert_equal 'Stock management', issue.category.to_s
149 assert_equal 'Stock management', issue.category.to_s
150 assert_equal 'Urgent', issue.priority.to_s
150 assert_equal 'Urgent', issue.priority.to_s
151 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
151 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
152 end
152 end
153
153
154 def test_add_issue_with_attachment_to_specific_project
154 def test_add_issue_with_attachment_to_specific_project
155 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
155 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
156 assert issue.is_a?(Issue)
156 assert issue.is_a?(Issue)
157 assert !issue.new_record?
157 assert !issue.new_record?
158 issue.reload
158 issue.reload
159 assert_equal 'Ticket created by email with attachment', issue.subject
159 assert_equal 'Ticket created by email with attachment', issue.subject
160 assert_equal User.find_by_login('jsmith'), issue.author
160 assert_equal User.find_by_login('jsmith'), issue.author
161 assert_equal Project.find(2), issue.project
161 assert_equal Project.find(2), issue.project
162 assert_equal 'This is a new ticket with attachments', issue.description
162 assert_equal 'This is a new ticket with attachments', issue.description
163 # Attachment properties
163 # Attachment properties
164 assert_equal 1, issue.attachments.size
164 assert_equal 1, issue.attachments.size
165 assert_equal 'Paella.jpg', issue.attachments.first.filename
165 assert_equal 'Paella.jpg', issue.attachments.first.filename
166 assert_equal 'image/jpeg', issue.attachments.first.content_type
166 assert_equal 'image/jpeg', issue.attachments.first.content_type
167 assert_equal 10790, issue.attachments.first.filesize
167 assert_equal 10790, issue.attachments.first.filesize
168 end
168 end
169
169
170 def test_add_issue_with_custom_fields
170 def test_add_issue_with_custom_fields
171 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
171 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
172 assert issue.is_a?(Issue)
172 assert issue.is_a?(Issue)
173 assert !issue.new_record?
173 assert !issue.new_record?
174 issue.reload
174 issue.reload
175 assert_equal 'New ticket with custom field values', issue.subject
175 assert_equal 'New ticket with custom field values', issue.subject
176 assert_equal 'Value for a custom field',
176 assert_equal 'Value for a custom field',
177 issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
177 issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
178 assert !issue.description.match(/^searchable field:/i)
178 assert !issue.description.match(/^searchable field:/i)
179 end
179 end
180
180
181 def test_add_issue_with_cc
181 def test_add_issue_with_cc
182 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
182 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
183 assert issue.is_a?(Issue)
183 assert issue.is_a?(Issue)
184 assert !issue.new_record?
184 assert !issue.new_record?
185 issue.reload
185 issue.reload
186 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
186 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
187 assert_equal 1, issue.watcher_user_ids.size
187 assert_equal 1, issue.watcher_user_ids.size
188 end
188 end
189
189
190 def test_add_issue_by_unknown_user
190 def test_add_issue_by_unknown_user
191 assert_no_difference 'User.count' do
191 assert_no_difference 'User.count' do
192 assert_equal false,
192 assert_equal false,
193 submit_email(
193 submit_email(
194 'ticket_by_unknown_user.eml',
194 'ticket_by_unknown_user.eml',
195 :issue => {:project => 'ecookbook'}
195 :issue => {:project => 'ecookbook'}
196 )
196 )
197 end
197 end
198 end
198 end
199
199
200 def test_add_issue_by_anonymous_user
200 def test_add_issue_by_anonymous_user
201 Role.anonymous.add_permission!(:add_issues)
201 Role.anonymous.add_permission!(:add_issues)
202 assert_no_difference 'User.count' do
202 assert_no_difference 'User.count' do
203 issue = submit_email(
203 issue = submit_email(
204 'ticket_by_unknown_user.eml',
204 'ticket_by_unknown_user.eml',
205 :issue => {:project => 'ecookbook'},
205 :issue => {:project => 'ecookbook'},
206 :unknown_user => 'accept'
206 :unknown_user => 'accept'
207 )
207 )
208 assert issue.is_a?(Issue)
208 assert issue.is_a?(Issue)
209 assert issue.author.anonymous?
209 assert issue.author.anonymous?
210 end
210 end
211 end
211 end
212
212
213 def test_add_issue_by_anonymous_user_with_no_from_address
213 def test_add_issue_by_anonymous_user_with_no_from_address
214 Role.anonymous.add_permission!(:add_issues)
214 Role.anonymous.add_permission!(:add_issues)
215 assert_no_difference 'User.count' do
215 assert_no_difference 'User.count' do
216 issue = submit_email(
216 issue = submit_email(
217 'ticket_by_empty_user.eml',
217 'ticket_by_empty_user.eml',
218 :issue => {:project => 'ecookbook'},
218 :issue => {:project => 'ecookbook'},
219 :unknown_user => 'accept'
219 :unknown_user => 'accept'
220 )
220 )
221 assert issue.is_a?(Issue)
221 assert issue.is_a?(Issue)
222 assert issue.author.anonymous?
222 assert issue.author.anonymous?
223 end
223 end
224 end
224 end
225
225
226 def test_add_issue_by_anonymous_user_on_private_project
226 def test_add_issue_by_anonymous_user_on_private_project
227 Role.anonymous.add_permission!(:add_issues)
227 Role.anonymous.add_permission!(:add_issues)
228 assert_no_difference 'User.count' do
228 assert_no_difference 'User.count' do
229 assert_no_difference 'Issue.count' do
229 assert_no_difference 'Issue.count' do
230 assert_equal false,
230 assert_equal false,
231 submit_email(
231 submit_email(
232 'ticket_by_unknown_user.eml',
232 'ticket_by_unknown_user.eml',
233 :issue => {:project => 'onlinestore'},
233 :issue => {:project => 'onlinestore'},
234 :unknown_user => 'accept'
234 :unknown_user => 'accept'
235 )
235 )
236 end
236 end
237 end
237 end
238 end
238 end
239
239
240 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
240 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
241 assert_no_difference 'User.count' do
241 assert_no_difference 'User.count' do
242 assert_difference 'Issue.count' do
242 assert_difference 'Issue.count' do
243 issue = submit_email(
243 issue = submit_email(
244 'ticket_by_unknown_user.eml',
244 'ticket_by_unknown_user.eml',
245 :issue => {:project => 'onlinestore'},
245 :issue => {:project => 'onlinestore'},
246 :no_permission_check => '1',
246 :no_permission_check => '1',
247 :unknown_user => 'accept'
247 :unknown_user => 'accept'
248 )
248 )
249 assert issue.is_a?(Issue)
249 assert issue.is_a?(Issue)
250 assert issue.author.anonymous?
250 assert issue.author.anonymous?
251 assert !issue.project.is_public?
251 assert !issue.project.is_public?
252 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
252 assert_equal [issue.id, 1, 2], [issue.root_id, issue.lft, issue.rgt]
253 end
253 end
254 end
254 end
255 end
255 end
256
256
257 def test_add_issue_by_created_user
257 def test_add_issue_by_created_user
258 Setting.default_language = 'en'
258 Setting.default_language = 'en'
259 assert_difference 'User.count' do
259 assert_difference 'User.count' do
260 issue = submit_email(
260 issue = submit_email(
261 'ticket_by_unknown_user.eml',
261 'ticket_by_unknown_user.eml',
262 :issue => {:project => 'ecookbook'},
262 :issue => {:project => 'ecookbook'},
263 :unknown_user => 'create'
263 :unknown_user => 'create'
264 )
264 )
265 assert issue.is_a?(Issue)
265 assert issue.is_a?(Issue)
266 assert issue.author.active?
266 assert issue.author.active?
267 assert_equal 'john.doe@somenet.foo', issue.author.mail
267 assert_equal 'john.doe@somenet.foo', issue.author.mail
268 assert_equal 'John', issue.author.firstname
268 assert_equal 'John', issue.author.firstname
269 assert_equal 'Doe', issue.author.lastname
269 assert_equal 'Doe', issue.author.lastname
270
270
271 # account information
271 # account information
272 email = ActionMailer::Base.deliveries.first
272 email = ActionMailer::Base.deliveries.first
273 assert_not_nil email
273 assert_not_nil email
274 assert email.subject.include?('account activation')
274 assert email.subject.include?('account activation')
275 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
275 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
276 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
276 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
277 assert_equal issue.author, User.try_to_login(login, password)
277 assert_equal issue.author, User.try_to_login(login, password)
278 end
278 end
279 end
279 end
280
280
281 def test_add_issue_without_from_header
281 def test_add_issue_without_from_header
282 Role.anonymous.add_permission!(:add_issues)
282 Role.anonymous.add_permission!(:add_issues)
283 assert_equal false, submit_email('ticket_without_from_header.eml')
283 assert_equal false, submit_email('ticket_without_from_header.eml')
284 end
284 end
285
285
286 def test_add_issue_with_invalid_attributes
286 def test_add_issue_with_invalid_attributes
287 issue = submit_email(
287 issue = submit_email(
288 'ticket_with_invalid_attributes.eml',
288 'ticket_with_invalid_attributes.eml',
289 :allow_override => 'tracker,category,priority'
289 :allow_override => 'tracker,category,priority'
290 )
290 )
291 assert issue.is_a?(Issue)
291 assert issue.is_a?(Issue)
292 assert !issue.new_record?
292 assert !issue.new_record?
293 issue.reload
293 issue.reload
294 assert_nil issue.assigned_to
294 assert_nil issue.assigned_to
295 assert_nil issue.start_date
295 assert_nil issue.start_date
296 assert_nil issue.due_date
296 assert_nil issue.due_date
297 assert_equal 0, issue.done_ratio
297 assert_equal 0, issue.done_ratio
298 assert_equal 'Normal', issue.priority.to_s
298 assert_equal 'Normal', issue.priority.to_s
299 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
299 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
300 end
300 end
301
301
302 def test_add_issue_with_localized_attributes
302 def test_add_issue_with_localized_attributes
303 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
303 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
304 issue = submit_email(
304 issue = submit_email(
305 'ticket_with_localized_attributes.eml',
305 'ticket_with_localized_attributes.eml',
306 :allow_override => 'tracker,category,priority'
306 :allow_override => 'tracker,category,priority'
307 )
307 )
308 assert issue.is_a?(Issue)
308 assert issue.is_a?(Issue)
309 assert !issue.new_record?
309 assert !issue.new_record?
310 issue.reload
310 issue.reload
311 assert_equal 'New ticket on a given project', issue.subject
311 assert_equal 'New ticket on a given project', issue.subject
312 assert_equal User.find_by_login('jsmith'), issue.author
312 assert_equal User.find_by_login('jsmith'), issue.author
313 assert_equal Project.find(2), issue.project
313 assert_equal Project.find(2), issue.project
314 assert_equal 'Feature request', issue.tracker.to_s
314 assert_equal 'Feature request', issue.tracker.to_s
315 assert_equal 'Stock management', issue.category.to_s
315 assert_equal 'Stock management', issue.category.to_s
316 assert_equal 'Urgent', issue.priority.to_s
316 assert_equal 'Urgent', issue.priority.to_s
317 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
317 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
318 end
318 end
319
319
320 def test_add_issue_with_japanese_keywords
320 def test_add_issue_with_japanese_keywords
321 ja_dev = "\xe9\x96\x8b\xe7\x99\xba"
321 ja_dev = "\xe9\x96\x8b\xe7\x99\xba"
322 ja_dev.force_encoding('UTF-8') if ja_dev.respond_to?(:force_encoding)
322 ja_dev.force_encoding('UTF-8') if ja_dev.respond_to?(:force_encoding)
323 tracker = Tracker.create!(:name => ja_dev)
323 tracker = Tracker.create!(:name => ja_dev)
324 Project.find(1).trackers << tracker
324 Project.find(1).trackers << tracker
325 issue = submit_email(
325 issue = submit_email(
326 'japanese_keywords_iso_2022_jp.eml',
326 'japanese_keywords_iso_2022_jp.eml',
327 :issue => {:project => 'ecookbook'},
327 :issue => {:project => 'ecookbook'},
328 :allow_override => 'tracker'
328 :allow_override => 'tracker'
329 )
329 )
330 assert_kind_of Issue, issue
330 assert_kind_of Issue, issue
331 assert_equal tracker, issue.tracker
331 assert_equal tracker, issue.tracker
332 end
332 end
333
333
334 def test_add_issue_from_apple_mail
334 def test_add_issue_from_apple_mail
335 issue = submit_email(
335 issue = submit_email(
336 'apple_mail_with_attachment.eml',
336 'apple_mail_with_attachment.eml',
337 :issue => {:project => 'ecookbook'}
337 :issue => {:project => 'ecookbook'}
338 )
338 )
339 assert_kind_of Issue, issue
339 assert_kind_of Issue, issue
340 assert_equal 1, issue.attachments.size
340 assert_equal 1, issue.attachments.size
341
341
342 attachment = issue.attachments.first
342 attachment = issue.attachments.first
343 assert_equal 'paella.jpg', attachment.filename
343 assert_equal 'paella.jpg', attachment.filename
344 assert_equal 10790, attachment.filesize
344 assert_equal 10790, attachment.filesize
345 assert File.exist?(attachment.diskfile)
345 assert File.exist?(attachment.diskfile)
346 assert_equal 10790, File.size(attachment.diskfile)
346 assert_equal 10790, File.size(attachment.diskfile)
347 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
347 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
348 end
348 end
349
349
350 def test_should_ignore_emails_from_locked_users
351 User.find(2).lock!
352
353 MailHandler.any_instance.expects(:dispatch).never
354 assert_no_difference 'Issue.count' do
355 assert_equal false, submit_email('ticket_on_given_project.eml')
356 end
357 end
358
350 def test_should_ignore_emails_from_emission_address
359 def test_should_ignore_emails_from_emission_address
351 Role.anonymous.add_permission!(:add_issues)
360 Role.anonymous.add_permission!(:add_issues)
352 assert_no_difference 'User.count' do
361 assert_no_difference 'User.count' do
353 assert_equal false,
362 assert_equal false,
354 submit_email(
363 submit_email(
355 'ticket_from_emission_address.eml',
364 'ticket_from_emission_address.eml',
356 :issue => {:project => 'ecookbook'},
365 :issue => {:project => 'ecookbook'},
357 :unknown_user => 'create'
366 :unknown_user => 'create'
358 )
367 )
359 end
368 end
360 end
369 end
361
370
362 def test_should_ignore_auto_replied_emails
371 def test_should_ignore_auto_replied_emails
372 MailHandler.any_instance.expects(:dispatch).never
363 [
373 [
364 "X-Auto-Response-Suppress: OOF",
374 "X-Auto-Response-Suppress: OOF",
365 "Auto-Submitted: auto-replied",
375 "Auto-Submitted: auto-replied",
366 "Auto-Submitted: Auto-Replied"
376 "Auto-Submitted: Auto-Replied"
367 ].each do |header|
377 ].each do |header|
368 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
378 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
369 raw = header + "\n" + raw
379 raw = header + "\n" + raw
370
380
371 assert_no_difference 'Issue.count' do
381 assert_no_difference 'Issue.count' do
372 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
382 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
373 end
383 end
374 end
384 end
375 end
385 end
376
386
377 def test_add_issue_should_send_email_notification
387 def test_add_issue_should_send_email_notification
378 Setting.notified_events = ['issue_added']
388 Setting.notified_events = ['issue_added']
379 ActionMailer::Base.deliveries.clear
389 ActionMailer::Base.deliveries.clear
380 # This email contains: 'Project: onlinestore'
390 # This email contains: 'Project: onlinestore'
381 issue = submit_email('ticket_on_given_project.eml')
391 issue = submit_email('ticket_on_given_project.eml')
382 assert issue.is_a?(Issue)
392 assert issue.is_a?(Issue)
383 assert_equal 1, ActionMailer::Base.deliveries.size
393 assert_equal 1, ActionMailer::Base.deliveries.size
384 end
394 end
385
395
386 def test_update_issue
396 def test_update_issue
387 journal = submit_email('ticket_reply.eml')
397 journal = submit_email('ticket_reply.eml')
388 assert journal.is_a?(Journal)
398 assert journal.is_a?(Journal)
389 assert_equal User.find_by_login('jsmith'), journal.user
399 assert_equal User.find_by_login('jsmith'), journal.user
390 assert_equal Issue.find(2), journal.journalized
400 assert_equal Issue.find(2), journal.journalized
391 assert_match /This is reply/, journal.notes
401 assert_match /This is reply/, journal.notes
392 assert_equal 'Feature request', journal.issue.tracker.name
402 assert_equal 'Feature request', journal.issue.tracker.name
393 end
403 end
394
404
395 def test_update_issue_with_attribute_changes
405 def test_update_issue_with_attribute_changes
396 # This email contains: 'Status: Resolved'
406 # This email contains: 'Status: Resolved'
397 journal = submit_email('ticket_reply_with_status.eml')
407 journal = submit_email('ticket_reply_with_status.eml')
398 assert journal.is_a?(Journal)
408 assert journal.is_a?(Journal)
399 issue = Issue.find(journal.issue.id)
409 issue = Issue.find(journal.issue.id)
400 assert_equal User.find_by_login('jsmith'), journal.user
410 assert_equal User.find_by_login('jsmith'), journal.user
401 assert_equal Issue.find(2), journal.journalized
411 assert_equal Issue.find(2), journal.journalized
402 assert_match /This is reply/, journal.notes
412 assert_match /This is reply/, journal.notes
403 assert_equal 'Feature request', journal.issue.tracker.name
413 assert_equal 'Feature request', journal.issue.tracker.name
404 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
414 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
405 assert_equal '2010-01-01', issue.start_date.to_s
415 assert_equal '2010-01-01', issue.start_date.to_s
406 assert_equal '2010-12-31', issue.due_date.to_s
416 assert_equal '2010-12-31', issue.due_date.to_s
407 assert_equal User.find_by_login('jsmith'), issue.assigned_to
417 assert_equal User.find_by_login('jsmith'), issue.assigned_to
408 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
418 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
409 # keywords should be removed from the email body
419 # keywords should be removed from the email body
410 assert !journal.notes.match(/^Status:/i)
420 assert !journal.notes.match(/^Status:/i)
411 assert !journal.notes.match(/^Start Date:/i)
421 assert !journal.notes.match(/^Start Date:/i)
412 end
422 end
413
423
414 def test_update_issue_with_attachment
424 def test_update_issue_with_attachment
415 assert_difference 'Journal.count' do
425 assert_difference 'Journal.count' do
416 assert_difference 'JournalDetail.count' do
426 assert_difference 'JournalDetail.count' do
417 assert_difference 'Attachment.count' do
427 assert_difference 'Attachment.count' do
418 assert_no_difference 'Issue.count' do
428 assert_no_difference 'Issue.count' do
419 journal = submit_email('ticket_with_attachment.eml') do |raw|
429 journal = submit_email('ticket_with_attachment.eml') do |raw|
420 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
430 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
421 end
431 end
422 end
432 end
423 end
433 end
424 end
434 end
425 end
435 end
426 journal = Journal.first(:order => 'id DESC')
436 journal = Journal.first(:order => 'id DESC')
427 assert_equal Issue.find(2), journal.journalized
437 assert_equal Issue.find(2), journal.journalized
428 assert_equal 1, journal.details.size
438 assert_equal 1, journal.details.size
429
439
430 detail = journal.details.first
440 detail = journal.details.first
431 assert_equal 'attachment', detail.property
441 assert_equal 'attachment', detail.property
432 assert_equal 'Paella.jpg', detail.value
442 assert_equal 'Paella.jpg', detail.value
433 end
443 end
434
444
435 def test_update_issue_should_send_email_notification
445 def test_update_issue_should_send_email_notification
436 ActionMailer::Base.deliveries.clear
446 ActionMailer::Base.deliveries.clear
437 journal = submit_email('ticket_reply.eml')
447 journal = submit_email('ticket_reply.eml')
438 assert journal.is_a?(Journal)
448 assert journal.is_a?(Journal)
439 assert_equal 1, ActionMailer::Base.deliveries.size
449 assert_equal 1, ActionMailer::Base.deliveries.size
440 end
450 end
441
451
442 def test_update_issue_should_not_set_defaults
452 def test_update_issue_should_not_set_defaults
443 journal = submit_email(
453 journal = submit_email(
444 'ticket_reply.eml',
454 'ticket_reply.eml',
445 :issue => {:tracker => 'Support request', :priority => 'High'}
455 :issue => {:tracker => 'Support request', :priority => 'High'}
446 )
456 )
447 assert journal.is_a?(Journal)
457 assert journal.is_a?(Journal)
448 assert_match /This is reply/, journal.notes
458 assert_match /This is reply/, journal.notes
449 assert_equal 'Feature request', journal.issue.tracker.name
459 assert_equal 'Feature request', journal.issue.tracker.name
450 assert_equal 'Normal', journal.issue.priority.name
460 assert_equal 'Normal', journal.issue.priority.name
451 end
461 end
452
462
453 def test_reply_to_a_message
463 def test_reply_to_a_message
454 m = submit_email('message_reply.eml')
464 m = submit_email('message_reply.eml')
455 assert m.is_a?(Message)
465 assert m.is_a?(Message)
456 assert !m.new_record?
466 assert !m.new_record?
457 m.reload
467 m.reload
458 assert_equal 'Reply via email', m.subject
468 assert_equal 'Reply via email', m.subject
459 # The email replies to message #2 which is part of the thread of message #1
469 # The email replies to message #2 which is part of the thread of message #1
460 assert_equal Message.find(1), m.parent
470 assert_equal Message.find(1), m.parent
461 end
471 end
462
472
463 def test_reply_to_a_message_by_subject
473 def test_reply_to_a_message_by_subject
464 m = submit_email('message_reply_by_subject.eml')
474 m = submit_email('message_reply_by_subject.eml')
465 assert m.is_a?(Message)
475 assert m.is_a?(Message)
466 assert !m.new_record?
476 assert !m.new_record?
467 m.reload
477 m.reload
468 assert_equal 'Reply to the first post', m.subject
478 assert_equal 'Reply to the first post', m.subject
469 assert_equal Message.find(1), m.parent
479 assert_equal Message.find(1), m.parent
470 end
480 end
471
481
472 def test_should_strip_tags_of_html_only_emails
482 def test_should_strip_tags_of_html_only_emails
473 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
483 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
474 assert issue.is_a?(Issue)
484 assert issue.is_a?(Issue)
475 assert !issue.new_record?
485 assert !issue.new_record?
476 issue.reload
486 issue.reload
477 assert_equal 'HTML email', issue.subject
487 assert_equal 'HTML email', issue.subject
478 assert_equal 'This is a html-only email.', issue.description
488 assert_equal 'This is a html-only email.', issue.description
479 end
489 end
480
490
481 context "truncate emails based on the Setting" do
491 context "truncate emails based on the Setting" do
482 context "with no setting" do
492 context "with no setting" do
483 setup do
493 setup do
484 Setting.mail_handler_body_delimiters = ''
494 Setting.mail_handler_body_delimiters = ''
485 end
495 end
486
496
487 should "add the entire email into the issue" do
497 should "add the entire email into the issue" do
488 issue = submit_email('ticket_on_given_project.eml')
498 issue = submit_email('ticket_on_given_project.eml')
489 assert_issue_created(issue)
499 assert_issue_created(issue)
490 assert issue.description.include?('---')
500 assert issue.description.include?('---')
491 assert issue.description.include?('This paragraph is after the delimiter')
501 assert issue.description.include?('This paragraph is after the delimiter')
492 end
502 end
493 end
503 end
494
504
495 context "with a single string" do
505 context "with a single string" do
496 setup do
506 setup do
497 Setting.mail_handler_body_delimiters = '---'
507 Setting.mail_handler_body_delimiters = '---'
498 end
508 end
499 should "truncate the email at the delimiter for the issue" do
509 should "truncate the email at the delimiter for the issue" do
500 issue = submit_email('ticket_on_given_project.eml')
510 issue = submit_email('ticket_on_given_project.eml')
501 assert_issue_created(issue)
511 assert_issue_created(issue)
502 assert issue.description.include?('This paragraph is before delimiters')
512 assert issue.description.include?('This paragraph is before delimiters')
503 assert issue.description.include?('--- This line starts with a delimiter')
513 assert issue.description.include?('--- This line starts with a delimiter')
504 assert !issue.description.match(/^---$/)
514 assert !issue.description.match(/^---$/)
505 assert !issue.description.include?('This paragraph is after the delimiter')
515 assert !issue.description.include?('This paragraph is after the delimiter')
506 end
516 end
507 end
517 end
508
518
509 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
519 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
510 setup do
520 setup do
511 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
521 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
512 end
522 end
513 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
523 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
514 journal = submit_email('issue_update_with_quoted_reply_above.eml')
524 journal = submit_email('issue_update_with_quoted_reply_above.eml')
515 assert journal.is_a?(Journal)
525 assert journal.is_a?(Journal)
516 assert journal.notes.include?('An update to the issue by the sender.')
526 assert journal.notes.include?('An update to the issue by the sender.')
517 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
527 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
518 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
528 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
519 end
529 end
520 end
530 end
521
531
522 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
532 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
523 setup do
533 setup do
524 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
534 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
525 end
535 end
526 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
536 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
527 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
537 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
528 assert journal.is_a?(Journal)
538 assert journal.is_a?(Journal)
529 assert journal.notes.include?('An update to the issue by the sender.')
539 assert journal.notes.include?('An update to the issue by the sender.')
530 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
540 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
531 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
541 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
532 end
542 end
533 end
543 end
534
544
535 context "with multiple strings" do
545 context "with multiple strings" do
536 setup do
546 setup do
537 Setting.mail_handler_body_delimiters = "---\nBREAK"
547 Setting.mail_handler_body_delimiters = "---\nBREAK"
538 end
548 end
539 should "truncate the email at the first delimiter found (BREAK)" do
549 should "truncate the email at the first delimiter found (BREAK)" do
540 issue = submit_email('ticket_on_given_project.eml')
550 issue = submit_email('ticket_on_given_project.eml')
541 assert_issue_created(issue)
551 assert_issue_created(issue)
542 assert issue.description.include?('This paragraph is before delimiters')
552 assert issue.description.include?('This paragraph is before delimiters')
543 assert !issue.description.include?('BREAK')
553 assert !issue.description.include?('BREAK')
544 assert !issue.description.include?('This paragraph is between delimiters')
554 assert !issue.description.include?('This paragraph is between delimiters')
545 assert !issue.description.match(/^---$/)
555 assert !issue.description.match(/^---$/)
546 assert !issue.description.include?('This paragraph is after the delimiter')
556 assert !issue.description.include?('This paragraph is after the delimiter')
547 end
557 end
548 end
558 end
549 end
559 end
550
560
551 def test_email_with_long_subject_line
561 def test_email_with_long_subject_line
552 issue = submit_email('ticket_with_long_subject.eml')
562 issue = submit_email('ticket_with_long_subject.eml')
553 assert issue.is_a?(Issue)
563 assert issue.is_a?(Issue)
554 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]
564 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]
555 end
565 end
556
566
557 def test_new_user_from_attributes_should_return_valid_user
567 def test_new_user_from_attributes_should_return_valid_user
558 to_test = {
568 to_test = {
559 # [address, name] => [login, firstname, lastname]
569 # [address, name] => [login, firstname, lastname]
560 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
570 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
561 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
571 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
562 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
572 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
563 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
573 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
564 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
574 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
565 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
575 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
566 }
576 }
567
577
568 to_test.each do |attrs, expected|
578 to_test.each do |attrs, expected|
569 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
579 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
570
580
571 assert user.valid?, user.errors.full_messages.to_s
581 assert user.valid?, user.errors.full_messages.to_s
572 assert_equal attrs.first, user.mail
582 assert_equal attrs.first, user.mail
573 assert_equal expected[0], user.login
583 assert_equal expected[0], user.login
574 assert_equal expected[1], user.firstname
584 assert_equal expected[1], user.firstname
575 assert_equal expected[2], user.lastname
585 assert_equal expected[2], user.lastname
576 end
586 end
577 end
587 end
578
588
579 def test_new_user_from_attributes_should_respect_minimum_password_length
589 def test_new_user_from_attributes_should_respect_minimum_password_length
580 with_settings :password_min_length => 15 do
590 with_settings :password_min_length => 15 do
581 user = MailHandler.new_user_from_attributes('jsmith@example.net')
591 user = MailHandler.new_user_from_attributes('jsmith@example.net')
582 assert user.valid?
592 assert user.valid?
583 assert user.password.length >= 15
593 assert user.password.length >= 15
584 end
594 end
585 end
595 end
586
596
587 def test_new_user_from_attributes_should_use_default_login_if_invalid
597 def test_new_user_from_attributes_should_use_default_login_if_invalid
588 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
598 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
589 assert user.valid?
599 assert user.valid?
590 assert user.login =~ /^user[a-f0-9]+$/
600 assert user.login =~ /^user[a-f0-9]+$/
591 assert_equal 'foo+bar@example.net', user.mail
601 assert_equal 'foo+bar@example.net', user.mail
592 end
602 end
593
603
594 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
604 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
595 assert_difference 'User.count' do
605 assert_difference 'User.count' do
596 issue = submit_email(
606 issue = submit_email(
597 'fullname_of_sender_as_utf8_encoded.eml',
607 'fullname_of_sender_as_utf8_encoded.eml',
598 :issue => {:project => 'ecookbook'},
608 :issue => {:project => 'ecookbook'},
599 :unknown_user => 'create'
609 :unknown_user => 'create'
600 )
610 )
601 end
611 end
602
612
603 user = User.first(:order => 'id DESC')
613 user = User.first(:order => 'id DESC')
604 assert_equal "foo@example.org", user.mail
614 assert_equal "foo@example.org", user.mail
605 str1 = "\xc3\x84\xc3\xa4"
615 str1 = "\xc3\x84\xc3\xa4"
606 str2 = "\xc3\x96\xc3\xb6"
616 str2 = "\xc3\x96\xc3\xb6"
607 str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
617 str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
608 str2.force_encoding('UTF-8') if str2.respond_to?(:force_encoding)
618 str2.force_encoding('UTF-8') if str2.respond_to?(:force_encoding)
609 assert_equal str1, user.firstname
619 assert_equal str1, user.firstname
610 assert_equal str2, user.lastname
620 assert_equal str2, user.lastname
611 end
621 end
612
622
613 private
623 private
614
624
615 def submit_email(filename, options={})
625 def submit_email(filename, options={})
616 raw = IO.read(File.join(FIXTURES_PATH, filename))
626 raw = IO.read(File.join(FIXTURES_PATH, filename))
617 yield raw if block_given?
627 yield raw if block_given?
618 MailHandler.receive(raw, options)
628 MailHandler.receive(raw, options)
619 end
629 end
620
630
621 def assert_issue_created(issue)
631 def assert_issue_created(issue)
622 assert issue.is_a?(Issue)
632 assert issue.is_a?(Issue)
623 assert !issue.new_record?
633 assert !issue.new_record?
624 issue.reload
634 issue.reload
625 end
635 end
626 end
636 end
General Comments 0
You need to be logged in to leave comments. Login now