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