##// END OF EJS Templates
add test which ensure received mail text attachment keeps original encoding (#21742)...
Toshi MARUYAMA -
r14801:e28cc10a35a9
parent child
Show More
@@ -0,0 +1,31
1 Date: Thu, 14 Jan 2016 18:32:45 +0100
2 From: John Smith <JSmith@somenet.foo>
3 To: redmine@somenet.foo
4 Message-ID: <7A3.L9Yi.1Ki1}PMZiV5.1Mbzkz@seznam.cz>
5 Subject: issue #21742
6 Mime-Version: 1.0
7 Content-Type: multipart/mixed;
8 boundary="=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=";
9 charset=UTF-8
10 Content-Transfer-Encoding: 7bit
11 X-Mailer: szn-ebox-4.5.88
12
13
14 --=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=
15 Content-Type: text/plain;
16 charset=utf-8
17 Content-Transfer-Encoding: base64
18
19
20 --=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=
21 Content-Type: text/plain;
22 charset=UTF-8;
23 name=latin2.txt
24 Content-Transfer-Encoding: quoted-printable
25 Content-Disposition: attachment;
26 filename=latin2.txt;
27 size=19
28
29 p=F8=EDli=B9 =BEluou=E8k=FD k=F9n=
30
31 --=_08d580646981073f1a667ba3=898e56d9-3d29-5ed2-9c9a-cc3a5d9474b5_=--
@@ -1,1068 +1,1084
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2015 Jean-Philippe Lang
4 # Copyright (C) 2006-2015 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 :email_addresses,
25 :email_addresses,
26 :issues, :issue_statuses,
26 :issues, :issue_statuses,
27 :workflows, :trackers, :projects_trackers,
27 :workflows, :trackers, :projects_trackers,
28 :versions, :enumerations, :issue_categories,
28 :versions, :enumerations, :issue_categories,
29 :custom_fields, :custom_fields_trackers, :custom_fields_projects,
29 :custom_fields, :custom_fields_trackers, :custom_fields_projects,
30 :boards, :messages
30 :boards, :messages
31
31
32 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
32 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
33
33
34 def setup
34 def setup
35 ActionMailer::Base.deliveries.clear
35 ActionMailer::Base.deliveries.clear
36 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
36 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
37 end
37 end
38
38
39 def teardown
39 def teardown
40 Setting.clear_cache
40 Setting.clear_cache
41 end
41 end
42
42
43 def test_add_issue_with_specific_overrides
43 def test_add_issue_with_specific_overrides
44 issue = submit_email('ticket_on_given_project.eml',
44 issue = submit_email('ticket_on_given_project.eml',
45 :allow_override => ['status', 'start_date', 'due_date', 'assigned_to', 'fixed_version', 'estimated_hours', 'done_ratio']
45 :allow_override => ['status', 'start_date', 'due_date', 'assigned_to', 'fixed_version', 'estimated_hours', 'done_ratio']
46 )
46 )
47 assert issue.is_a?(Issue)
47 assert issue.is_a?(Issue)
48 assert !issue.new_record?
48 assert !issue.new_record?
49 issue.reload
49 issue.reload
50 assert_equal Project.find(2), issue.project
50 assert_equal Project.find(2), issue.project
51 assert_equal issue.project.trackers.first, issue.tracker
51 assert_equal issue.project.trackers.first, issue.tracker
52 assert_equal 'New ticket on a given project', issue.subject
52 assert_equal 'New ticket on a given project', issue.subject
53 assert_equal User.find_by_login('jsmith'), issue.author
53 assert_equal User.find_by_login('jsmith'), issue.author
54 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
54 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
55 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
55 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
56 assert_equal '2010-01-01', issue.start_date.to_s
56 assert_equal '2010-01-01', issue.start_date.to_s
57 assert_equal '2010-12-31', issue.due_date.to_s
57 assert_equal '2010-12-31', issue.due_date.to_s
58 assert_equal User.find_by_login('jsmith'), issue.assigned_to
58 assert_equal User.find_by_login('jsmith'), issue.assigned_to
59 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
59 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
60 assert_equal 2.5, issue.estimated_hours
60 assert_equal 2.5, issue.estimated_hours
61 assert_equal 30, issue.done_ratio
61 assert_equal 30, issue.done_ratio
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 end
66 end
67
67
68 def test_add_issue_with_all_overrides
68 def test_add_issue_with_all_overrides
69 issue = submit_email('ticket_on_given_project.eml', :allow_override => 'all')
69 issue = submit_email('ticket_on_given_project.eml', :allow_override => 'all')
70 assert issue.is_a?(Issue)
70 assert issue.is_a?(Issue)
71 assert !issue.new_record?
71 assert !issue.new_record?
72 issue.reload
72 issue.reload
73 assert_equal Project.find(2), issue.project
73 assert_equal Project.find(2), issue.project
74 assert_equal issue.project.trackers.first, issue.tracker
74 assert_equal issue.project.trackers.first, issue.tracker
75 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
75 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
76 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
76 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
77 assert_equal '2010-01-01', issue.start_date.to_s
77 assert_equal '2010-01-01', issue.start_date.to_s
78 assert_equal '2010-12-31', issue.due_date.to_s
78 assert_equal '2010-12-31', issue.due_date.to_s
79 assert_equal User.find_by_login('jsmith'), issue.assigned_to
79 assert_equal User.find_by_login('jsmith'), issue.assigned_to
80 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
80 assert_equal Version.find_by_name('Alpha'), issue.fixed_version
81 assert_equal 2.5, issue.estimated_hours
81 assert_equal 2.5, issue.estimated_hours
82 assert_equal 30, issue.done_ratio
82 assert_equal 30, issue.done_ratio
83 end
83 end
84
84
85 def test_add_issue_without_overrides_should_ignore_attributes
85 def test_add_issue_without_overrides_should_ignore_attributes
86 WorkflowRule.delete_all
86 WorkflowRule.delete_all
87 issue = submit_email('ticket_on_given_project.eml')
87 issue = submit_email('ticket_on_given_project.eml')
88 assert issue.is_a?(Issue)
88 assert issue.is_a?(Issue)
89 assert !issue.new_record?
89 assert !issue.new_record?
90 issue.reload
90 issue.reload
91 assert_equal Project.find(2), issue.project
91 assert_equal Project.find(2), issue.project
92 assert_equal 'New ticket on a given project', issue.subject
92 assert_equal 'New ticket on a given project', issue.subject
93 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
93 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
94 assert_equal User.find_by_login('jsmith'), issue.author
94 assert_equal User.find_by_login('jsmith'), issue.author
95
95
96 assert_equal issue.project.trackers.first, issue.tracker
96 assert_equal issue.project.trackers.first, issue.tracker
97 assert_equal 'New', issue.status.name
97 assert_equal 'New', issue.status.name
98 assert_not_equal '2010-01-01', issue.start_date.to_s
98 assert_not_equal '2010-01-01', issue.start_date.to_s
99 assert_nil issue.due_date
99 assert_nil issue.due_date
100 assert_nil issue.assigned_to
100 assert_nil issue.assigned_to
101 assert_nil issue.fixed_version
101 assert_nil issue.fixed_version
102 assert_nil issue.estimated_hours
102 assert_nil issue.estimated_hours
103 assert_equal 0, issue.done_ratio
103 assert_equal 0, issue.done_ratio
104 end
104 end
105
105
106 def test_add_issue_to_project_specified_by_subaddress
106 def test_add_issue_to_project_specified_by_subaddress
107 # This email has redmine+onlinestore@somenet.foo as 'To' header
107 # This email has redmine+onlinestore@somenet.foo as 'To' header
108 issue = submit_email(
108 issue = submit_email(
109 'ticket_on_project_given_by_to_header.eml',
109 'ticket_on_project_given_by_to_header.eml',
110 :issue => {:tracker => 'Support request'},
110 :issue => {:tracker => 'Support request'},
111 :project_from_subaddress => 'redmine@somenet.foo'
111 :project_from_subaddress => 'redmine@somenet.foo'
112 )
112 )
113 assert issue.is_a?(Issue)
113 assert issue.is_a?(Issue)
114 assert !issue.new_record?
114 assert !issue.new_record?
115 issue.reload
115 issue.reload
116 assert_equal 'onlinestore', issue.project.identifier
116 assert_equal 'onlinestore', issue.project.identifier
117 assert_equal 'Support request', issue.tracker.name
117 assert_equal 'Support request', issue.tracker.name
118 end
118 end
119
119
120 def test_add_issue_with_default_tracker
120 def test_add_issue_with_default_tracker
121 # This email contains: 'Project: onlinestore'
121 # This email contains: 'Project: onlinestore'
122 issue = submit_email(
122 issue = submit_email(
123 'ticket_on_given_project.eml',
123 'ticket_on_given_project.eml',
124 :issue => {:tracker => 'Support request'}
124 :issue => {:tracker => 'Support request'}
125 )
125 )
126 assert issue.is_a?(Issue)
126 assert issue.is_a?(Issue)
127 assert !issue.new_record?
127 assert !issue.new_record?
128 issue.reload
128 issue.reload
129 assert_equal 'Support request', issue.tracker.name
129 assert_equal 'Support request', issue.tracker.name
130 end
130 end
131
131
132 def test_add_issue_with_default_version
132 def test_add_issue_with_default_version
133 # This email contains: 'Project: onlinestore'
133 # This email contains: 'Project: onlinestore'
134 issue = submit_email(
134 issue = submit_email(
135 'ticket_on_given_project.eml',
135 'ticket_on_given_project.eml',
136 :issue => {:fixed_version => 'Alpha'}
136 :issue => {:fixed_version => 'Alpha'}
137 )
137 )
138 assert issue.is_a?(Issue)
138 assert issue.is_a?(Issue)
139 assert !issue.new_record?
139 assert !issue.new_record?
140 assert_equal 'Alpha', issue.reload.fixed_version.name
140 assert_equal 'Alpha', issue.reload.fixed_version.name
141 end
141 end
142
142
143 def test_add_issue_with_status_override
143 def test_add_issue_with_status_override
144 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
144 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
145 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['status'])
145 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['status'])
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 Project.find(2), issue.project
149 assert_equal Project.find(2), issue.project
150 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
150 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
151 end
151 end
152
152
153 def test_add_issue_should_accept_is_private_attribute
153 def test_add_issue_should_accept_is_private_attribute
154 issue = submit_email('ticket_on_given_project.eml', :issue => {:is_private => '1'})
154 issue = submit_email('ticket_on_given_project.eml', :issue => {:is_private => '1'})
155 assert issue.is_a?(Issue)
155 assert issue.is_a?(Issue)
156 assert !issue.new_record?
156 assert !issue.new_record?
157 assert_equal true, issue.reload.is_private
157 assert_equal true, issue.reload.is_private
158 end
158 end
159
159
160 def test_add_issue_with_group_assignment
160 def test_add_issue_with_group_assignment
161 with_settings :issue_group_assignment => '1' do
161 with_settings :issue_group_assignment => '1' do
162 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
162 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
163 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
163 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
164 end
164 end
165 assert issue.is_a?(Issue)
165 assert issue.is_a?(Issue)
166 assert !issue.new_record?
166 assert !issue.new_record?
167 issue.reload
167 issue.reload
168 assert_equal Group.find(11), issue.assigned_to
168 assert_equal Group.find(11), issue.assigned_to
169 end
169 end
170 end
170 end
171
171
172 def test_add_issue_with_partial_attributes_override
172 def test_add_issue_with_partial_attributes_override
173 issue = submit_email(
173 issue = submit_email(
174 'ticket_with_attributes.eml',
174 'ticket_with_attributes.eml',
175 :issue => {:priority => 'High'},
175 :issue => {:priority => 'High'},
176 :allow_override => ['tracker']
176 :allow_override => ['tracker']
177 )
177 )
178 assert issue.is_a?(Issue)
178 assert issue.is_a?(Issue)
179 assert !issue.new_record?
179 assert !issue.new_record?
180 issue.reload
180 issue.reload
181 assert_equal 'New ticket on a given project', issue.subject
181 assert_equal 'New ticket on a given project', issue.subject
182 assert_equal User.find_by_login('jsmith'), issue.author
182 assert_equal User.find_by_login('jsmith'), issue.author
183 assert_equal Project.find(2), issue.project
183 assert_equal Project.find(2), issue.project
184 assert_equal 'Feature request', issue.tracker.to_s
184 assert_equal 'Feature request', issue.tracker.to_s
185 assert_nil issue.category
185 assert_nil issue.category
186 assert_equal 'High', issue.priority.to_s
186 assert_equal 'High', issue.priority.to_s
187 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
187 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
188 end
188 end
189
189
190 def test_add_issue_with_spaces_between_attribute_and_separator
190 def test_add_issue_with_spaces_between_attribute_and_separator
191 issue = submit_email(
191 issue = submit_email(
192 'ticket_with_spaces_between_attribute_and_separator.eml',
192 'ticket_with_spaces_between_attribute_and_separator.eml',
193 :allow_override => 'tracker,category,priority'
193 :allow_override => 'tracker,category,priority'
194 )
194 )
195 assert issue.is_a?(Issue)
195 assert issue.is_a?(Issue)
196 assert !issue.new_record?
196 assert !issue.new_record?
197 issue.reload
197 issue.reload
198 assert_equal 'New ticket on a given project', issue.subject
198 assert_equal 'New ticket on a given project', issue.subject
199 assert_equal User.find_by_login('jsmith'), issue.author
199 assert_equal User.find_by_login('jsmith'), issue.author
200 assert_equal Project.find(2), issue.project
200 assert_equal Project.find(2), issue.project
201 assert_equal 'Feature request', issue.tracker.to_s
201 assert_equal 'Feature request', issue.tracker.to_s
202 assert_equal 'Stock management', issue.category.to_s
202 assert_equal 'Stock management', issue.category.to_s
203 assert_equal 'Urgent', issue.priority.to_s
203 assert_equal 'Urgent', issue.priority.to_s
204 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
204 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
205 end
205 end
206
206
207 def test_add_issue_with_attachment_to_specific_project
207 def test_add_issue_with_attachment_to_specific_project
208 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
208 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
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_equal 'Ticket created by email with attachment', issue.subject
212 assert_equal 'Ticket created by email with attachment', issue.subject
213 assert_equal User.find_by_login('jsmith'), issue.author
213 assert_equal User.find_by_login('jsmith'), issue.author
214 assert_equal Project.find(2), issue.project
214 assert_equal Project.find(2), issue.project
215 assert_equal 'This is a new ticket with attachments', issue.description
215 assert_equal 'This is a new ticket with attachments', issue.description
216 # Attachment properties
216 # Attachment properties
217 assert_equal 1, issue.attachments.size
217 assert_equal 1, issue.attachments.size
218 assert_equal 'Paella.jpg', issue.attachments.first.filename
218 assert_equal 'Paella.jpg', issue.attachments.first.filename
219 assert_equal 'image/jpeg', issue.attachments.first.content_type
219 assert_equal 'image/jpeg', issue.attachments.first.content_type
220 assert_equal 10790, issue.attachments.first.filesize
220 assert_equal 10790, issue.attachments.first.filesize
221 end
221 end
222
222
223 def test_add_issue_with_custom_fields
223 def test_add_issue_with_custom_fields
224 issue = submit_email('ticket_with_custom_fields.eml',
224 issue = submit_email('ticket_with_custom_fields.eml',
225 :issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable_field']
225 :issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable_field']
226 )
226 )
227 assert issue.is_a?(Issue)
227 assert issue.is_a?(Issue)
228 assert !issue.new_record?
228 assert !issue.new_record?
229 issue.reload
229 issue.reload
230 assert_equal 'New ticket with custom field values', issue.subject
230 assert_equal 'New ticket with custom field values', issue.subject
231 assert_equal 'PostgreSQL', issue.custom_field_value(1)
231 assert_equal 'PostgreSQL', issue.custom_field_value(1)
232 assert_equal 'Value for a custom field', issue.custom_field_value(2)
232 assert_equal 'Value for a custom field', issue.custom_field_value(2)
233 assert !issue.description.match(/^searchable field:/i)
233 assert !issue.description.match(/^searchable field:/i)
234 end
234 end
235
235
236 def test_add_issue_with_version_custom_fields
236 def test_add_issue_with_version_custom_fields
237 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
237 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
238
238
239 issue = submit_email('ticket_with_custom_fields.eml',
239 issue = submit_email('ticket_with_custom_fields.eml',
240 :issue => {:project => 'ecookbook'}, :allow_override => ['affected version']
240 :issue => {:project => 'ecookbook'}, :allow_override => ['affected version']
241 ) do |email|
241 ) do |email|
242 email << "Affected version: 1.0\n"
242 email << "Affected version: 1.0\n"
243 end
243 end
244 assert issue.is_a?(Issue)
244 assert issue.is_a?(Issue)
245 assert !issue.new_record?
245 assert !issue.new_record?
246 issue.reload
246 issue.reload
247 assert_equal '2', issue.custom_field_value(field)
247 assert_equal '2', issue.custom_field_value(field)
248 end
248 end
249
249
250 def test_add_issue_should_match_assignee_on_display_name
250 def test_add_issue_should_match_assignee_on_display_name
251 user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
251 user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
252 User.add_to_project(user, Project.find(2))
252 User.add_to_project(user, Project.find(2))
253 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
253 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
254 email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
254 email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
255 end
255 end
256 assert issue.is_a?(Issue)
256 assert issue.is_a?(Issue)
257 assert_equal user, issue.assigned_to
257 assert_equal user, issue.assigned_to
258 end
258 end
259
259
260 def test_add_issue_should_set_default_start_date
260 def test_add_issue_should_set_default_start_date
261 with_settings :default_issue_start_date_to_creation_date => '1' do
261 with_settings :default_issue_start_date_to_creation_date => '1' do
262 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
262 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
263 assert issue.is_a?(Issue)
263 assert issue.is_a?(Issue)
264 assert_equal Date.today, issue.start_date
264 assert_equal Date.today, issue.start_date
265 end
265 end
266 end
266 end
267
267
268 def test_add_issue_should_add_cc_as_watchers
268 def test_add_issue_should_add_cc_as_watchers
269 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
269 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
270 assert issue.is_a?(Issue)
270 assert issue.is_a?(Issue)
271 assert !issue.new_record?
271 assert !issue.new_record?
272 issue.reload
272 issue.reload
273 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
273 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
274 assert_equal 1, issue.watcher_user_ids.size
274 assert_equal 1, issue.watcher_user_ids.size
275 end
275 end
276
276
277 def test_add_issue_from_additional_email_address
277 def test_add_issue_from_additional_email_address
278 user = User.find(2)
278 user = User.find(2)
279 user.mail = 'mainaddress@somenet.foo'
279 user.mail = 'mainaddress@somenet.foo'
280 user.save!
280 user.save!
281 EmailAddress.create!(:user => user, :address => 'jsmith@somenet.foo')
281 EmailAddress.create!(:user => user, :address => 'jsmith@somenet.foo')
282
282
283 issue = submit_email('ticket_on_given_project.eml')
283 issue = submit_email('ticket_on_given_project.eml')
284 assert issue
284 assert issue
285 assert_equal user, issue.author
285 assert_equal user, issue.author
286 end
286 end
287
287
288 def test_add_issue_by_unknown_user
288 def test_add_issue_by_unknown_user
289 assert_no_difference 'User.count' do
289 assert_no_difference 'User.count' do
290 assert_equal false,
290 assert_equal false,
291 submit_email(
291 submit_email(
292 'ticket_by_unknown_user.eml',
292 'ticket_by_unknown_user.eml',
293 :issue => {:project => 'ecookbook'}
293 :issue => {:project => 'ecookbook'}
294 )
294 )
295 end
295 end
296 end
296 end
297
297
298 def test_add_issue_by_anonymous_user
298 def test_add_issue_by_anonymous_user
299 Role.anonymous.add_permission!(:add_issues)
299 Role.anonymous.add_permission!(:add_issues)
300 assert_no_difference 'User.count' do
300 assert_no_difference 'User.count' do
301 issue = submit_email(
301 issue = submit_email(
302 'ticket_by_unknown_user.eml',
302 'ticket_by_unknown_user.eml',
303 :issue => {:project => 'ecookbook'},
303 :issue => {:project => 'ecookbook'},
304 :unknown_user => 'accept'
304 :unknown_user => 'accept'
305 )
305 )
306 assert issue.is_a?(Issue)
306 assert issue.is_a?(Issue)
307 assert issue.author.anonymous?
307 assert issue.author.anonymous?
308 end
308 end
309 end
309 end
310
310
311 def test_add_issue_by_anonymous_user_with_no_from_address
311 def test_add_issue_by_anonymous_user_with_no_from_address
312 Role.anonymous.add_permission!(:add_issues)
312 Role.anonymous.add_permission!(:add_issues)
313 assert_no_difference 'User.count' do
313 assert_no_difference 'User.count' do
314 issue = submit_email(
314 issue = submit_email(
315 'ticket_by_empty_user.eml',
315 'ticket_by_empty_user.eml',
316 :issue => {:project => 'ecookbook'},
316 :issue => {:project => 'ecookbook'},
317 :unknown_user => 'accept'
317 :unknown_user => 'accept'
318 )
318 )
319 assert issue.is_a?(Issue)
319 assert issue.is_a?(Issue)
320 assert issue.author.anonymous?
320 assert issue.author.anonymous?
321 end
321 end
322 end
322 end
323
323
324 def test_add_issue_by_anonymous_user_on_private_project
324 def test_add_issue_by_anonymous_user_on_private_project
325 Role.anonymous.add_permission!(:add_issues)
325 Role.anonymous.add_permission!(:add_issues)
326 assert_no_difference 'User.count' do
326 assert_no_difference 'User.count' do
327 assert_no_difference 'Issue.count' do
327 assert_no_difference 'Issue.count' do
328 assert_equal false,
328 assert_equal false,
329 submit_email(
329 submit_email(
330 'ticket_by_unknown_user.eml',
330 'ticket_by_unknown_user.eml',
331 :issue => {:project => 'onlinestore'},
331 :issue => {:project => 'onlinestore'},
332 :unknown_user => 'accept'
332 :unknown_user => 'accept'
333 )
333 )
334 end
334 end
335 end
335 end
336 end
336 end
337
337
338 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
338 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
339 assert_no_difference 'User.count' do
339 assert_no_difference 'User.count' do
340 assert_difference 'Issue.count' do
340 assert_difference 'Issue.count' do
341 issue = submit_email(
341 issue = submit_email(
342 'ticket_by_unknown_user.eml',
342 'ticket_by_unknown_user.eml',
343 :issue => {:project => 'onlinestore'},
343 :issue => {:project => 'onlinestore'},
344 :no_permission_check => '1',
344 :no_permission_check => '1',
345 :unknown_user => 'accept'
345 :unknown_user => 'accept'
346 )
346 )
347 assert issue.is_a?(Issue)
347 assert issue.is_a?(Issue)
348 assert issue.author.anonymous?
348 assert issue.author.anonymous?
349 assert !issue.project.is_public?
349 assert !issue.project.is_public?
350 end
350 end
351 end
351 end
352 end
352 end
353
353
354 def test_add_issue_by_created_user
354 def test_add_issue_by_created_user
355 Setting.default_language = 'en'
355 Setting.default_language = 'en'
356 assert_difference 'User.count' do
356 assert_difference 'User.count' do
357 issue = submit_email(
357 issue = submit_email(
358 'ticket_by_unknown_user.eml',
358 'ticket_by_unknown_user.eml',
359 :issue => {:project => 'ecookbook'},
359 :issue => {:project => 'ecookbook'},
360 :unknown_user => 'create'
360 :unknown_user => 'create'
361 )
361 )
362 assert issue.is_a?(Issue)
362 assert issue.is_a?(Issue)
363 assert issue.author.active?
363 assert issue.author.active?
364 assert_equal 'john.doe@somenet.foo', issue.author.mail
364 assert_equal 'john.doe@somenet.foo', issue.author.mail
365 assert_equal 'John', issue.author.firstname
365 assert_equal 'John', issue.author.firstname
366 assert_equal 'Doe', issue.author.lastname
366 assert_equal 'Doe', issue.author.lastname
367
367
368 # account information
368 # account information
369 email = ActionMailer::Base.deliveries.first
369 email = ActionMailer::Base.deliveries.first
370 assert_not_nil email
370 assert_not_nil email
371 assert email.subject.include?('account activation')
371 assert email.subject.include?('account activation')
372 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
372 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
373 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
373 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
374 assert_equal issue.author, User.try_to_login(login, password)
374 assert_equal issue.author, User.try_to_login(login, password)
375 end
375 end
376 end
376 end
377
377
378 def test_add_issue_should_send_notification
378 def test_add_issue_should_send_notification
379 issue = submit_email('ticket_on_given_project.eml', :allow_override => 'all')
379 issue = submit_email('ticket_on_given_project.eml', :allow_override => 'all')
380 assert issue.is_a?(Issue)
380 assert issue.is_a?(Issue)
381 assert !issue.new_record?
381 assert !issue.new_record?
382
382
383 mail = ActionMailer::Base.deliveries.last
383 mail = ActionMailer::Base.deliveries.last
384 assert_not_nil mail
384 assert_not_nil mail
385 assert mail.subject.include?("##{issue.id}")
385 assert mail.subject.include?("##{issue.id}")
386 assert mail.subject.include?('New ticket on a given project')
386 assert mail.subject.include?('New ticket on a given project')
387 end
387 end
388
388
389 def test_created_user_should_be_added_to_groups
389 def test_created_user_should_be_added_to_groups
390 group1 = Group.generate!
390 group1 = Group.generate!
391 group2 = Group.generate!
391 group2 = Group.generate!
392
392
393 assert_difference 'User.count' do
393 assert_difference 'User.count' do
394 submit_email(
394 submit_email(
395 'ticket_by_unknown_user.eml',
395 'ticket_by_unknown_user.eml',
396 :issue => {:project => 'ecookbook'},
396 :issue => {:project => 'ecookbook'},
397 :unknown_user => 'create',
397 :unknown_user => 'create',
398 :default_group => "#{group1.name},#{group2.name}"
398 :default_group => "#{group1.name},#{group2.name}"
399 )
399 )
400 end
400 end
401 user = User.order('id DESC').first
401 user = User.order('id DESC').first
402 assert_equal [group1, group2].sort, user.groups.sort
402 assert_equal [group1, group2].sort, user.groups.sort
403 end
403 end
404
404
405 def test_created_user_should_not_receive_account_information_with_no_account_info_option
405 def test_created_user_should_not_receive_account_information_with_no_account_info_option
406 assert_difference 'User.count' do
406 assert_difference 'User.count' do
407 submit_email(
407 submit_email(
408 'ticket_by_unknown_user.eml',
408 'ticket_by_unknown_user.eml',
409 :issue => {:project => 'ecookbook'},
409 :issue => {:project => 'ecookbook'},
410 :unknown_user => 'create',
410 :unknown_user => 'create',
411 :no_account_notice => '1'
411 :no_account_notice => '1'
412 )
412 )
413 end
413 end
414
414
415 # only 1 email for the new issue notification
415 # only 1 email for the new issue notification
416 assert_equal 1, ActionMailer::Base.deliveries.size
416 assert_equal 1, ActionMailer::Base.deliveries.size
417 email = ActionMailer::Base.deliveries.first
417 email = ActionMailer::Base.deliveries.first
418 assert_include 'Ticket by unknown user', email.subject
418 assert_include 'Ticket by unknown user', email.subject
419 end
419 end
420
420
421 def test_created_user_should_have_mail_notification_to_none_with_no_notification_option
421 def test_created_user_should_have_mail_notification_to_none_with_no_notification_option
422 assert_difference 'User.count' do
422 assert_difference 'User.count' do
423 submit_email(
423 submit_email(
424 'ticket_by_unknown_user.eml',
424 'ticket_by_unknown_user.eml',
425 :issue => {:project => 'ecookbook'},
425 :issue => {:project => 'ecookbook'},
426 :unknown_user => 'create',
426 :unknown_user => 'create',
427 :no_notification => '1'
427 :no_notification => '1'
428 )
428 )
429 end
429 end
430 user = User.order('id DESC').first
430 user = User.order('id DESC').first
431 assert_equal 'none', user.mail_notification
431 assert_equal 'none', user.mail_notification
432 end
432 end
433
433
434 def test_add_issue_without_from_header
434 def test_add_issue_without_from_header
435 Role.anonymous.add_permission!(:add_issues)
435 Role.anonymous.add_permission!(:add_issues)
436 assert_equal false, submit_email('ticket_without_from_header.eml')
436 assert_equal false, submit_email('ticket_without_from_header.eml')
437 end
437 end
438
438
439 def test_add_issue_with_invalid_attributes
439 def test_add_issue_with_invalid_attributes
440 with_settings :default_issue_start_date_to_creation_date => '0' do
440 with_settings :default_issue_start_date_to_creation_date => '0' do
441 issue = submit_email(
441 issue = submit_email(
442 'ticket_with_invalid_attributes.eml',
442 'ticket_with_invalid_attributes.eml',
443 :allow_override => 'tracker,category,priority'
443 :allow_override => 'tracker,category,priority'
444 )
444 )
445 assert issue.is_a?(Issue)
445 assert issue.is_a?(Issue)
446 assert !issue.new_record?
446 assert !issue.new_record?
447 issue.reload
447 issue.reload
448 assert_nil issue.assigned_to
448 assert_nil issue.assigned_to
449 assert_nil issue.start_date
449 assert_nil issue.start_date
450 assert_nil issue.due_date
450 assert_nil issue.due_date
451 assert_equal 0, issue.done_ratio
451 assert_equal 0, issue.done_ratio
452 assert_equal 'Normal', issue.priority.to_s
452 assert_equal 'Normal', issue.priority.to_s
453 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
453 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
454 end
454 end
455 end
455 end
456
456
457 def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
457 def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
458 issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
458 issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
459 email.gsub!(/^Project:.+$/, 'Project: invalid')
459 email.gsub!(/^Project:.+$/, 'Project: invalid')
460 end
460 end
461 assert issue.is_a?(Issue)
461 assert issue.is_a?(Issue)
462 assert !issue.new_record?
462 assert !issue.new_record?
463 assert_equal 'ecookbook', issue.project.identifier
463 assert_equal 'ecookbook', issue.project.identifier
464 end
464 end
465
465
466 def test_add_issue_with_localized_attributes
466 def test_add_issue_with_localized_attributes
467 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
467 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
468 issue = submit_email(
468 issue = submit_email(
469 'ticket_with_localized_attributes.eml',
469 'ticket_with_localized_attributes.eml',
470 :allow_override => 'tracker,category,priority'
470 :allow_override => 'tracker,category,priority'
471 )
471 )
472 assert issue.is_a?(Issue)
472 assert issue.is_a?(Issue)
473 assert !issue.new_record?
473 assert !issue.new_record?
474 issue.reload
474 issue.reload
475 assert_equal 'New ticket on a given project', issue.subject
475 assert_equal 'New ticket on a given project', issue.subject
476 assert_equal User.find_by_login('jsmith'), issue.author
476 assert_equal User.find_by_login('jsmith'), issue.author
477 assert_equal Project.find(2), issue.project
477 assert_equal Project.find(2), issue.project
478 assert_equal 'Feature request', issue.tracker.to_s
478 assert_equal 'Feature request', issue.tracker.to_s
479 assert_equal 'Stock management', issue.category.to_s
479 assert_equal 'Stock management', issue.category.to_s
480 assert_equal 'Urgent', issue.priority.to_s
480 assert_equal 'Urgent', issue.priority.to_s
481 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
481 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
482 end
482 end
483
483
484 def test_add_issue_with_japanese_keywords
484 def test_add_issue_with_japanese_keywords
485 ja_dev = "\xe9\x96\x8b\xe7\x99\xba".force_encoding('UTF-8')
485 ja_dev = "\xe9\x96\x8b\xe7\x99\xba".force_encoding('UTF-8')
486 tracker = Tracker.generate!(:name => ja_dev)
486 tracker = Tracker.generate!(:name => ja_dev)
487 Project.find(1).trackers << tracker
487 Project.find(1).trackers << tracker
488 issue = submit_email(
488 issue = submit_email(
489 'japanese_keywords_iso_2022_jp.eml',
489 'japanese_keywords_iso_2022_jp.eml',
490 :issue => {:project => 'ecookbook'},
490 :issue => {:project => 'ecookbook'},
491 :allow_override => 'tracker'
491 :allow_override => 'tracker'
492 )
492 )
493 assert_kind_of Issue, issue
493 assert_kind_of Issue, issue
494 assert_equal tracker, issue.tracker
494 assert_equal tracker, issue.tracker
495 end
495 end
496
496
497 def test_add_issue_from_apple_mail
497 def test_add_issue_from_apple_mail
498 issue = submit_email(
498 issue = submit_email(
499 'apple_mail_with_attachment.eml',
499 'apple_mail_with_attachment.eml',
500 :issue => {:project => 'ecookbook'}
500 :issue => {:project => 'ecookbook'}
501 )
501 )
502 assert_kind_of Issue, issue
502 assert_kind_of Issue, issue
503 assert_equal 1, issue.attachments.size
503 assert_equal 1, issue.attachments.size
504
504
505 attachment = issue.attachments.first
505 attachment = issue.attachments.first
506 assert_equal 'paella.jpg', attachment.filename
506 assert_equal 'paella.jpg', attachment.filename
507 assert_equal 10790, attachment.filesize
507 assert_equal 10790, attachment.filesize
508 assert File.exist?(attachment.diskfile)
508 assert File.exist?(attachment.diskfile)
509 assert_equal 10790, File.size(attachment.diskfile)
509 assert_equal 10790, File.size(attachment.diskfile)
510 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
510 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
511 end
511 end
512
512
513 def test_thunderbird_with_attachment_ja
513 def test_thunderbird_with_attachment_ja
514 issue = submit_email(
514 issue = submit_email(
515 'thunderbird_with_attachment_ja.eml',
515 'thunderbird_with_attachment_ja.eml',
516 :issue => {:project => 'ecookbook'}
516 :issue => {:project => 'ecookbook'}
517 )
517 )
518 assert_kind_of Issue, issue
518 assert_kind_of Issue, issue
519 assert_equal 1, issue.attachments.size
519 assert_equal 1, issue.attachments.size
520 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
520 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
521 attachment = issue.attachments.first
521 attachment = issue.attachments.first
522 assert_equal ja, attachment.filename
522 assert_equal ja, attachment.filename
523 assert_equal 5, attachment.filesize
523 assert_equal 5, attachment.filesize
524 assert File.exist?(attachment.diskfile)
524 assert File.exist?(attachment.diskfile)
525 assert_equal 5, File.size(attachment.diskfile)
525 assert_equal 5, File.size(attachment.diskfile)
526 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
526 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
527 end
527 end
528
528
529 def test_gmail_with_attachment_ja
529 def test_gmail_with_attachment_ja
530 issue = submit_email(
530 issue = submit_email(
531 'gmail_with_attachment_ja.eml',
531 'gmail_with_attachment_ja.eml',
532 :issue => {:project => 'ecookbook'}
532 :issue => {:project => 'ecookbook'}
533 )
533 )
534 assert_kind_of Issue, issue
534 assert_kind_of Issue, issue
535 assert_equal 1, issue.attachments.size
535 assert_equal 1, issue.attachments.size
536 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
536 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
537 attachment = issue.attachments.first
537 attachment = issue.attachments.first
538 assert_equal ja, attachment.filename
538 assert_equal ja, attachment.filename
539 assert_equal 5, attachment.filesize
539 assert_equal 5, attachment.filesize
540 assert File.exist?(attachment.diskfile)
540 assert File.exist?(attachment.diskfile)
541 assert_equal 5, File.size(attachment.diskfile)
541 assert_equal 5, File.size(attachment.diskfile)
542 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
542 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
543 end
543 end
544
544
545 def test_thunderbird_with_attachment_latin1
545 def test_thunderbird_with_attachment_latin1
546 issue = submit_email(
546 issue = submit_email(
547 'thunderbird_with_attachment_iso-8859-1.eml',
547 'thunderbird_with_attachment_iso-8859-1.eml',
548 :issue => {:project => 'ecookbook'}
548 :issue => {:project => 'ecookbook'}
549 )
549 )
550 assert_kind_of Issue, issue
550 assert_kind_of Issue, issue
551 assert_equal 1, issue.attachments.size
551 assert_equal 1, issue.attachments.size
552 u = "".force_encoding('UTF-8')
552 u = "".force_encoding('UTF-8')
553 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
553 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
554 11.times { u << u1 }
554 11.times { u << u1 }
555 attachment = issue.attachments.first
555 attachment = issue.attachments.first
556 assert_equal "#{u}.png", attachment.filename
556 assert_equal "#{u}.png", attachment.filename
557 assert_equal 130, attachment.filesize
557 assert_equal 130, attachment.filesize
558 assert File.exist?(attachment.diskfile)
558 assert File.exist?(attachment.diskfile)
559 assert_equal 130, File.size(attachment.diskfile)
559 assert_equal 130, File.size(attachment.diskfile)
560 assert_equal '4d80e667ac37dddfe05502530f152abb', attachment.digest
560 assert_equal '4d80e667ac37dddfe05502530f152abb', attachment.digest
561 end
561 end
562
562
563 def test_gmail_with_attachment_latin1
563 def test_gmail_with_attachment_latin1
564 issue = submit_email(
564 issue = submit_email(
565 'gmail_with_attachment_iso-8859-1.eml',
565 'gmail_with_attachment_iso-8859-1.eml',
566 :issue => {:project => 'ecookbook'}
566 :issue => {:project => 'ecookbook'}
567 )
567 )
568 assert_kind_of Issue, issue
568 assert_kind_of Issue, issue
569 assert_equal 1, issue.attachments.size
569 assert_equal 1, issue.attachments.size
570 u = "".force_encoding('UTF-8')
570 u = "".force_encoding('UTF-8')
571 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
571 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
572 11.times { u << u1 }
572 11.times { u << u1 }
573 attachment = issue.attachments.first
573 attachment = issue.attachments.first
574 assert_equal "#{u}.txt", attachment.filename
574 assert_equal "#{u}.txt", attachment.filename
575 assert_equal 5, attachment.filesize
575 assert_equal 5, attachment.filesize
576 assert File.exist?(attachment.diskfile)
576 assert File.exist?(attachment.diskfile)
577 assert_equal 5, File.size(attachment.diskfile)
577 assert_equal 5, File.size(attachment.diskfile)
578 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
578 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
579 end
579 end
580
580
581 def test_mail_with_attachment_latin2
582 issue = submit_email(
583 'ticket_with_text_attachment_iso-8859-2.eml',
584 :issue => {:project => 'ecookbook'}
585 )
586 assert_kind_of Issue, issue
587 assert_equal 1, issue.attachments.size
588 attachment = issue.attachments.first
589 assert_equal 'latin2.txt', attachment.filename
590 assert_equal 19, attachment.filesize
591 assert File.exist?(attachment.diskfile)
592 assert_equal 19, File.size(attachment.diskfile)
593 content = "p\xF8\xEDli\xB9 \xBEluou\xE8k\xFD k\xF9n".force_encoding('CP852')
594 assert_equal content, File.read(attachment.diskfile).force_encoding('CP852')
595 end
596
581 def test_multiple_inline_text_parts_should_be_appended_to_issue_description
597 def test_multiple_inline_text_parts_should_be_appended_to_issue_description
582 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
598 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
583 assert_include 'first', issue.description
599 assert_include 'first', issue.description
584 assert_include 'second', issue.description
600 assert_include 'second', issue.description
585 assert_include 'third', issue.description
601 assert_include 'third', issue.description
586 end
602 end
587
603
588 def test_attachment_text_part_should_be_added_as_issue_attachment
604 def test_attachment_text_part_should_be_added_as_issue_attachment
589 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
605 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
590 assert_not_include 'Plain text attachment', issue.description
606 assert_not_include 'Plain text attachment', issue.description
591 attachment = issue.attachments.detect {|a| a.filename == 'textfile.txt'}
607 attachment = issue.attachments.detect {|a| a.filename == 'textfile.txt'}
592 assert_not_nil attachment
608 assert_not_nil attachment
593 assert_include 'Plain text attachment', File.read(attachment.diskfile)
609 assert_include 'Plain text attachment', File.read(attachment.diskfile)
594 end
610 end
595
611
596 def test_add_issue_with_iso_8859_1_subject
612 def test_add_issue_with_iso_8859_1_subject
597 issue = submit_email(
613 issue = submit_email(
598 'subject_as_iso-8859-1.eml',
614 'subject_as_iso-8859-1.eml',
599 :issue => {:project => 'ecookbook'}
615 :issue => {:project => 'ecookbook'}
600 )
616 )
601 str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc...".force_encoding('UTF-8')
617 str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc...".force_encoding('UTF-8')
602 assert_kind_of Issue, issue
618 assert_kind_of Issue, issue
603 assert_equal str, issue.subject
619 assert_equal str, issue.subject
604 end
620 end
605
621
606 def test_quoted_printable_utf8
622 def test_quoted_printable_utf8
607 issue = submit_email(
623 issue = submit_email(
608 'quoted_printable_utf8.eml',
624 'quoted_printable_utf8.eml',
609 :issue => {:project => 'ecookbook'}
625 :issue => {:project => 'ecookbook'}
610 )
626 )
611 assert_kind_of Issue, issue
627 assert_kind_of Issue, issue
612 str = "Freundliche Gr\xc3\xbcsse".force_encoding('UTF-8')
628 str = "Freundliche Gr\xc3\xbcsse".force_encoding('UTF-8')
613 assert_equal str, issue.description
629 assert_equal str, issue.description
614 end
630 end
615
631
616 def test_gmail_iso8859_2
632 def test_gmail_iso8859_2
617 issue = submit_email(
633 issue = submit_email(
618 'gmail-iso8859-2.eml',
634 'gmail-iso8859-2.eml',
619 :issue => {:project => 'ecookbook'}
635 :issue => {:project => 'ecookbook'}
620 )
636 )
621 assert_kind_of Issue, issue
637 assert_kind_of Issue, issue
622 str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87.".force_encoding('UTF-8')
638 str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87.".force_encoding('UTF-8')
623 assert issue.description.include?(str)
639 assert issue.description.include?(str)
624 end
640 end
625
641
626 def test_add_issue_with_japanese_subject
642 def test_add_issue_with_japanese_subject
627 issue = submit_email(
643 issue = submit_email(
628 'subject_japanese_1.eml',
644 'subject_japanese_1.eml',
629 :issue => {:project => 'ecookbook'}
645 :issue => {:project => 'ecookbook'}
630 )
646 )
631 assert_kind_of Issue, issue
647 assert_kind_of Issue, issue
632 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
648 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
633 assert_equal ja, issue.subject
649 assert_equal ja, issue.subject
634 end
650 end
635
651
636 def test_add_issue_with_korean_body
652 def test_add_issue_with_korean_body
637 # Make sure mail bodies with a charset unknown to Ruby
653 # Make sure mail bodies with a charset unknown to Ruby
638 # but known to the Mail gem 2.5.4 are handled correctly
654 # but known to the Mail gem 2.5.4 are handled correctly
639 kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4.".force_encoding('UTF-8')
655 kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4.".force_encoding('UTF-8')
640 issue = submit_email(
656 issue = submit_email(
641 'body_ks_c_5601-1987.eml',
657 'body_ks_c_5601-1987.eml',
642 :issue => {:project => 'ecookbook'}
658 :issue => {:project => 'ecookbook'}
643 )
659 )
644 assert_kind_of Issue, issue
660 assert_kind_of Issue, issue
645 assert_equal kr, issue.description
661 assert_equal kr, issue.description
646 end
662 end
647
663
648 def test_add_issue_with_no_subject_header
664 def test_add_issue_with_no_subject_header
649 issue = submit_email(
665 issue = submit_email(
650 'no_subject_header.eml',
666 'no_subject_header.eml',
651 :issue => {:project => 'ecookbook'}
667 :issue => {:project => 'ecookbook'}
652 )
668 )
653 assert_kind_of Issue, issue
669 assert_kind_of Issue, issue
654 assert_equal '(no subject)', issue.subject
670 assert_equal '(no subject)', issue.subject
655 end
671 end
656
672
657 def test_add_issue_with_mixed_japanese_subject
673 def test_add_issue_with_mixed_japanese_subject
658 issue = submit_email(
674 issue = submit_email(
659 'subject_japanese_2.eml',
675 'subject_japanese_2.eml',
660 :issue => {:project => 'ecookbook'}
676 :issue => {:project => 'ecookbook'}
661 )
677 )
662 assert_kind_of Issue, issue
678 assert_kind_of Issue, issue
663 ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
679 ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
664 assert_equal ja, issue.subject
680 assert_equal ja, issue.subject
665 end
681 end
666
682
667 def test_should_ignore_emails_from_locked_users
683 def test_should_ignore_emails_from_locked_users
668 User.find(2).lock!
684 User.find(2).lock!
669
685
670 MailHandler.any_instance.expects(:dispatch).never
686 MailHandler.any_instance.expects(:dispatch).never
671 assert_no_difference 'Issue.count' do
687 assert_no_difference 'Issue.count' do
672 assert_equal false, submit_email('ticket_on_given_project.eml')
688 assert_equal false, submit_email('ticket_on_given_project.eml')
673 end
689 end
674 end
690 end
675
691
676 def test_should_ignore_emails_from_emission_address
692 def test_should_ignore_emails_from_emission_address
677 Role.anonymous.add_permission!(:add_issues)
693 Role.anonymous.add_permission!(:add_issues)
678 assert_no_difference 'User.count' do
694 assert_no_difference 'User.count' do
679 assert_equal false,
695 assert_equal false,
680 submit_email(
696 submit_email(
681 'ticket_from_emission_address.eml',
697 'ticket_from_emission_address.eml',
682 :issue => {:project => 'ecookbook'},
698 :issue => {:project => 'ecookbook'},
683 :unknown_user => 'create'
699 :unknown_user => 'create'
684 )
700 )
685 end
701 end
686 end
702 end
687
703
688 def test_should_ignore_auto_replied_emails
704 def test_should_ignore_auto_replied_emails
689 MailHandler.any_instance.expects(:dispatch).never
705 MailHandler.any_instance.expects(:dispatch).never
690 [
706 [
691 "Auto-Submitted: auto-replied",
707 "Auto-Submitted: auto-replied",
692 "Auto-Submitted: Auto-Replied",
708 "Auto-Submitted: Auto-Replied",
693 "Auto-Submitted: auto-generated",
709 "Auto-Submitted: auto-generated",
694 'X-Autoreply: yes'
710 'X-Autoreply: yes'
695 ].each do |header|
711 ].each do |header|
696 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
712 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
697 raw = header + "\n" + raw
713 raw = header + "\n" + raw
698
714
699 assert_no_difference 'Issue.count' do
715 assert_no_difference 'Issue.count' do
700 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
716 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
701 end
717 end
702 end
718 end
703 end
719 end
704
720
705 test "should not ignore Auto-Submitted headers not defined in RFC3834" do
721 test "should not ignore Auto-Submitted headers not defined in RFC3834" do
706 [
722 [
707 "Auto-Submitted: auto-forwarded"
723 "Auto-Submitted: auto-forwarded"
708 ].each do |header|
724 ].each do |header|
709 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
725 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
710 raw = header + "\n" + raw
726 raw = header + "\n" + raw
711
727
712 assert_difference 'Issue.count', 1 do
728 assert_difference 'Issue.count', 1 do
713 assert_not_nil MailHandler.receive(raw), "email with #{header} header was ignored"
729 assert_not_nil MailHandler.receive(raw), "email with #{header} header was ignored"
714 end
730 end
715 end
731 end
716 end
732 end
717
733
718 def test_add_issue_should_send_email_notification
734 def test_add_issue_should_send_email_notification
719 Setting.notified_events = ['issue_added']
735 Setting.notified_events = ['issue_added']
720 # This email contains: 'Project: onlinestore'
736 # This email contains: 'Project: onlinestore'
721 issue = submit_email('ticket_on_given_project.eml')
737 issue = submit_email('ticket_on_given_project.eml')
722 assert issue.is_a?(Issue)
738 assert issue.is_a?(Issue)
723 assert_equal 1, ActionMailer::Base.deliveries.size
739 assert_equal 1, ActionMailer::Base.deliveries.size
724 end
740 end
725
741
726 def test_update_issue
742 def test_update_issue
727 journal = submit_email('ticket_reply.eml')
743 journal = submit_email('ticket_reply.eml')
728 assert journal.is_a?(Journal)
744 assert journal.is_a?(Journal)
729 assert_equal User.find_by_login('jsmith'), journal.user
745 assert_equal User.find_by_login('jsmith'), journal.user
730 assert_equal Issue.find(2), journal.journalized
746 assert_equal Issue.find(2), journal.journalized
731 assert_match /This is reply/, journal.notes
747 assert_match /This is reply/, journal.notes
732 assert_equal false, journal.private_notes
748 assert_equal false, journal.private_notes
733 assert_equal 'Feature request', journal.issue.tracker.name
749 assert_equal 'Feature request', journal.issue.tracker.name
734 end
750 end
735
751
736 def test_update_issue_should_accept_issue_id_after_space_inside_brackets
752 def test_update_issue_should_accept_issue_id_after_space_inside_brackets
737 journal = submit_email('ticket_reply_with_status.eml') do |email|
753 journal = submit_email('ticket_reply_with_status.eml') do |email|
738 assert email.sub!(/^Subject:.*$/, "Subject: Re: [Feature request #2] Add ingredients categories")
754 assert email.sub!(/^Subject:.*$/, "Subject: Re: [Feature request #2] Add ingredients categories")
739 end
755 end
740 assert journal.is_a?(Journal)
756 assert journal.is_a?(Journal)
741 assert_equal Issue.find(2), journal.journalized
757 assert_equal Issue.find(2), journal.journalized
742 end
758 end
743
759
744 def test_update_issue_should_accept_issue_id_inside_brackets
760 def test_update_issue_should_accept_issue_id_inside_brackets
745 journal = submit_email('ticket_reply_with_status.eml') do |email|
761 journal = submit_email('ticket_reply_with_status.eml') do |email|
746 assert email.sub!(/^Subject:.*$/, "Subject: Re: [#2] Add ingredients categories")
762 assert email.sub!(/^Subject:.*$/, "Subject: Re: [#2] Add ingredients categories")
747 end
763 end
748 assert journal.is_a?(Journal)
764 assert journal.is_a?(Journal)
749 assert_equal Issue.find(2), journal.journalized
765 assert_equal Issue.find(2), journal.journalized
750 end
766 end
751
767
752 def test_update_issue_should_ignore_bogus_issue_ids_in_subject
768 def test_update_issue_should_ignore_bogus_issue_ids_in_subject
753 journal = submit_email('ticket_reply_with_status.eml') do |email|
769 journal = submit_email('ticket_reply_with_status.eml') do |email|
754 assert email.sub!(/^Subject:.*$/, "Subject: Re: [12345#1][bogus#1][Feature request #2] Add ingredients categories")
770 assert email.sub!(/^Subject:.*$/, "Subject: Re: [12345#1][bogus#1][Feature request #2] Add ingredients categories")
755 end
771 end
756 assert journal.is_a?(Journal)
772 assert journal.is_a?(Journal)
757 assert_equal Issue.find(2), journal.journalized
773 assert_equal Issue.find(2), journal.journalized
758 end
774 end
759
775
760 def test_update_issue_with_attribute_changes
776 def test_update_issue_with_attribute_changes
761 journal = submit_email('ticket_reply_with_status.eml', :allow_override => ['status','assigned_to','start_date','due_date', 'float field'])
777 journal = submit_email('ticket_reply_with_status.eml', :allow_override => ['status','assigned_to','start_date','due_date', 'float field'])
762 assert journal.is_a?(Journal)
778 assert journal.is_a?(Journal)
763 issue = Issue.find(journal.issue.id)
779 issue = Issue.find(journal.issue.id)
764 assert_equal User.find_by_login('jsmith'), journal.user
780 assert_equal User.find_by_login('jsmith'), journal.user
765 assert_equal Issue.find(2), journal.journalized
781 assert_equal Issue.find(2), journal.journalized
766 assert_match /This is reply/, journal.notes
782 assert_match /This is reply/, journal.notes
767 assert_equal 'Feature request', journal.issue.tracker.name
783 assert_equal 'Feature request', journal.issue.tracker.name
768 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
784 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
769 assert_equal '2010-01-01', issue.start_date.to_s
785 assert_equal '2010-01-01', issue.start_date.to_s
770 assert_equal '2010-12-31', issue.due_date.to_s
786 assert_equal '2010-12-31', issue.due_date.to_s
771 assert_equal User.find_by_login('jsmith'), issue.assigned_to
787 assert_equal User.find_by_login('jsmith'), issue.assigned_to
772 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
788 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
773 # keywords should be removed from the email body
789 # keywords should be removed from the email body
774 assert !journal.notes.match(/^Status:/i)
790 assert !journal.notes.match(/^Status:/i)
775 assert !journal.notes.match(/^Start Date:/i)
791 assert !journal.notes.match(/^Start Date:/i)
776 end
792 end
777
793
778 def test_update_issue_with_attachment
794 def test_update_issue_with_attachment
779 assert_difference 'Journal.count' do
795 assert_difference 'Journal.count' do
780 assert_difference 'JournalDetail.count' do
796 assert_difference 'JournalDetail.count' do
781 assert_difference 'Attachment.count' do
797 assert_difference 'Attachment.count' do
782 assert_no_difference 'Issue.count' do
798 assert_no_difference 'Issue.count' do
783 journal = submit_email('ticket_with_attachment.eml') do |raw|
799 journal = submit_email('ticket_with_attachment.eml') do |raw|
784 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
800 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
785 end
801 end
786 end
802 end
787 end
803 end
788 end
804 end
789 end
805 end
790 journal = Journal.order('id DESC').first
806 journal = Journal.order('id DESC').first
791 assert_equal Issue.find(2), journal.journalized
807 assert_equal Issue.find(2), journal.journalized
792 assert_equal 1, journal.details.size
808 assert_equal 1, journal.details.size
793
809
794 detail = journal.details.first
810 detail = journal.details.first
795 assert_equal 'attachment', detail.property
811 assert_equal 'attachment', detail.property
796 assert_equal 'Paella.jpg', detail.value
812 assert_equal 'Paella.jpg', detail.value
797 end
813 end
798
814
799 def test_update_issue_should_send_email_notification
815 def test_update_issue_should_send_email_notification
800 journal = submit_email('ticket_reply.eml')
816 journal = submit_email('ticket_reply.eml')
801 assert journal.is_a?(Journal)
817 assert journal.is_a?(Journal)
802 assert_equal 1, ActionMailer::Base.deliveries.size
818 assert_equal 1, ActionMailer::Base.deliveries.size
803 end
819 end
804
820
805 def test_update_issue_should_not_set_defaults
821 def test_update_issue_should_not_set_defaults
806 journal = submit_email(
822 journal = submit_email(
807 'ticket_reply.eml',
823 'ticket_reply.eml',
808 :issue => {:tracker => 'Support request', :priority => 'High'}
824 :issue => {:tracker => 'Support request', :priority => 'High'}
809 )
825 )
810 assert journal.is_a?(Journal)
826 assert journal.is_a?(Journal)
811 assert_match /This is reply/, journal.notes
827 assert_match /This is reply/, journal.notes
812 assert_equal 'Feature request', journal.issue.tracker.name
828 assert_equal 'Feature request', journal.issue.tracker.name
813 assert_equal 'Normal', journal.issue.priority.name
829 assert_equal 'Normal', journal.issue.priority.name
814 end
830 end
815
831
816 def test_update_issue_should_add_cc_as_watchers
832 def test_update_issue_should_add_cc_as_watchers
817 Watcher.delete_all
833 Watcher.delete_all
818 issue = Issue.find(2)
834 issue = Issue.find(2)
819
835
820 assert_difference 'Watcher.count' do
836 assert_difference 'Watcher.count' do
821 assert submit_email('issue_update_with_cc.eml')
837 assert submit_email('issue_update_with_cc.eml')
822 end
838 end
823 issue.reload
839 issue.reload
824 assert_equal 1, issue.watcher_user_ids.size
840 assert_equal 1, issue.watcher_user_ids.size
825 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
841 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
826 end
842 end
827
843
828 def test_update_issue_should_not_add_cc_as_watchers_if_already_watching
844 def test_update_issue_should_not_add_cc_as_watchers_if_already_watching
829 Watcher.delete_all
845 Watcher.delete_all
830 issue = Issue.find(2)
846 issue = Issue.find(2)
831 Watcher.create!(:watchable => issue, :user => User.find_by_mail('dlopper@somenet.foo'))
847 Watcher.create!(:watchable => issue, :user => User.find_by_mail('dlopper@somenet.foo'))
832
848
833 assert_no_difference 'Watcher.count' do
849 assert_no_difference 'Watcher.count' do
834 assert submit_email('issue_update_with_cc.eml')
850 assert submit_email('issue_update_with_cc.eml')
835 end
851 end
836 end
852 end
837
853
838 def test_replying_to_a_private_note_should_add_reply_as_private
854 def test_replying_to_a_private_note_should_add_reply_as_private
839 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
855 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
840
856
841 assert_difference 'Journal.count' do
857 assert_difference 'Journal.count' do
842 journal = submit_email('ticket_reply.eml') do |email|
858 journal = submit_email('ticket_reply.eml') do |email|
843 email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{private_journal.id}.20060719210421@osiris>"
859 email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{private_journal.id}.20060719210421@osiris>"
844 end
860 end
845
861
846 assert_kind_of Journal, journal
862 assert_kind_of Journal, journal
847 assert_match /This is reply/, journal.notes
863 assert_match /This is reply/, journal.notes
848 assert_equal true, journal.private_notes
864 assert_equal true, journal.private_notes
849 end
865 end
850 end
866 end
851
867
852 def test_reply_to_a_message
868 def test_reply_to_a_message
853 m = submit_email('message_reply.eml')
869 m = submit_email('message_reply.eml')
854 assert m.is_a?(Message)
870 assert m.is_a?(Message)
855 assert !m.new_record?
871 assert !m.new_record?
856 m.reload
872 m.reload
857 assert_equal 'Reply via email', m.subject
873 assert_equal 'Reply via email', m.subject
858 # The email replies to message #2 which is part of the thread of message #1
874 # The email replies to message #2 which is part of the thread of message #1
859 assert_equal Message.find(1), m.parent
875 assert_equal Message.find(1), m.parent
860 end
876 end
861
877
862 def test_reply_to_a_message_by_subject
878 def test_reply_to_a_message_by_subject
863 m = submit_email('message_reply_by_subject.eml')
879 m = submit_email('message_reply_by_subject.eml')
864 assert m.is_a?(Message)
880 assert m.is_a?(Message)
865 assert !m.new_record?
881 assert !m.new_record?
866 m.reload
882 m.reload
867 assert_equal 'Reply to the first post', m.subject
883 assert_equal 'Reply to the first post', m.subject
868 assert_equal Message.find(1), m.parent
884 assert_equal Message.find(1), m.parent
869 end
885 end
870
886
871 def test_should_convert_tags_of_html_only_emails
887 def test_should_convert_tags_of_html_only_emails
872 with_settings :text_formatting => 'textile' do
888 with_settings :text_formatting => 'textile' do
873 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
889 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
874 assert issue.is_a?(Issue)
890 assert issue.is_a?(Issue)
875 assert !issue.new_record?
891 assert !issue.new_record?
876 issue.reload
892 issue.reload
877 assert_equal 'HTML email', issue.subject
893 assert_equal 'HTML email', issue.subject
878 assert_equal "This is a *html-only* email.\r\n\r\nh1. With a title\r\n\r\nand a paragraph.", issue.description
894 assert_equal "This is a *html-only* email.\r\n\r\nh1. With a title\r\n\r\nand a paragraph.", issue.description
879 end
895 end
880 end
896 end
881
897
882 def test_should_handle_outlook_web_access_2010_html_only
898 def test_should_handle_outlook_web_access_2010_html_only
883 issue = submit_email('outlook_web_access_2010_html_only.eml', :issue => {:project => 'ecookbook'})
899 issue = submit_email('outlook_web_access_2010_html_only.eml', :issue => {:project => 'ecookbook'})
884 assert issue.is_a?(Issue)
900 assert issue.is_a?(Issue)
885 issue.reload
901 issue.reload
886 assert_equal 'Upgrade Redmine to 3.0.x', issue.subject
902 assert_equal 'Upgrade Redmine to 3.0.x', issue.subject
887 assert_equal "A mess.\r\n\r\n--Geoff Maciolek\r\nMYCOMPANYNAME, LLC", issue.description
903 assert_equal "A mess.\r\n\r\n--Geoff Maciolek\r\nMYCOMPANYNAME, LLC", issue.description
888 end
904 end
889
905
890 def test_should_handle_outlook_2010_html_only
906 def test_should_handle_outlook_2010_html_only
891 issue = submit_email('outlook_2010_html_only.eml', :issue => {:project => 'ecookbook'})
907 issue = submit_email('outlook_2010_html_only.eml', :issue => {:project => 'ecookbook'})
892 assert issue.is_a?(Issue)
908 assert issue.is_a?(Issue)
893 issue.reload
909 issue.reload
894 assert_equal 'Test email', issue.subject
910 assert_equal 'Test email', issue.subject
895 assert_equal "Simple, unadorned test email generated by Outlook 2010. It is in HTML format, but" +
911 assert_equal "Simple, unadorned test email generated by Outlook 2010. It is in HTML format, but" +
896 " no special formatting has been chosen. I’m going to save this as a draft and then manually" +
912 " no special formatting has been chosen. I’m going to save this as a draft and then manually" +
897 " drop it into the Inbox for scraping by Redmine 3.0.2.", issue.description
913 " drop it into the Inbox for scraping by Redmine 3.0.2.", issue.description
898 end
914 end
899
915
900 test "truncate emails with no setting should add the entire email into the issue" do
916 test "truncate emails with no setting should add the entire email into the issue" do
901 with_settings :mail_handler_body_delimiters => '' do
917 with_settings :mail_handler_body_delimiters => '' do
902 issue = submit_email('ticket_on_given_project.eml')
918 issue = submit_email('ticket_on_given_project.eml')
903 assert_issue_created(issue)
919 assert_issue_created(issue)
904 assert issue.description.include?('---')
920 assert issue.description.include?('---')
905 assert issue.description.include?('This paragraph is after the delimiter')
921 assert issue.description.include?('This paragraph is after the delimiter')
906 end
922 end
907 end
923 end
908
924
909 test "truncate emails with a single string should truncate the email at the delimiter for the issue" do
925 test "truncate emails with a single string should truncate the email at the delimiter for the issue" do
910 with_settings :mail_handler_body_delimiters => '---' do
926 with_settings :mail_handler_body_delimiters => '---' do
911 issue = submit_email('ticket_on_given_project.eml')
927 issue = submit_email('ticket_on_given_project.eml')
912 assert_issue_created(issue)
928 assert_issue_created(issue)
913 assert issue.description.include?('This paragraph is before delimiters')
929 assert issue.description.include?('This paragraph is before delimiters')
914 assert issue.description.include?('--- This line starts with a delimiter')
930 assert issue.description.include?('--- This line starts with a delimiter')
915 assert !issue.description.match(/^---$/)
931 assert !issue.description.match(/^---$/)
916 assert !issue.description.include?('This paragraph is after the delimiter')
932 assert !issue.description.include?('This paragraph is after the delimiter')
917 end
933 end
918 end
934 end
919
935
920 test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do
936 test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do
921 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
937 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
922 journal = submit_email('issue_update_with_quoted_reply_above.eml')
938 journal = submit_email('issue_update_with_quoted_reply_above.eml')
923 assert journal.is_a?(Journal)
939 assert journal.is_a?(Journal)
924 assert journal.notes.include?('An update to the issue by the sender.')
940 assert journal.notes.include?('An update to the issue by the sender.')
925 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
941 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
926 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
942 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
927 end
943 end
928 end
944 end
929
945
930 test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do
946 test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do
931 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
947 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
932 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
948 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
933 assert journal.is_a?(Journal)
949 assert journal.is_a?(Journal)
934 assert journal.notes.include?('An update to the issue by the sender.')
950 assert journal.notes.include?('An update to the issue by the sender.')
935 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
951 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
936 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
952 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
937 end
953 end
938 end
954 end
939
955
940 test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do
956 test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do
941 with_settings :mail_handler_body_delimiters => "---\nBREAK" do
957 with_settings :mail_handler_body_delimiters => "---\nBREAK" do
942 issue = submit_email('ticket_on_given_project.eml')
958 issue = submit_email('ticket_on_given_project.eml')
943 assert_issue_created(issue)
959 assert_issue_created(issue)
944 assert issue.description.include?('This paragraph is before delimiters')
960 assert issue.description.include?('This paragraph is before delimiters')
945 assert !issue.description.include?('BREAK')
961 assert !issue.description.include?('BREAK')
946 assert !issue.description.include?('This paragraph is between delimiters')
962 assert !issue.description.include?('This paragraph is between delimiters')
947 assert !issue.description.match(/^---$/)
963 assert !issue.description.match(/^---$/)
948 assert !issue.description.include?('This paragraph is after the delimiter')
964 assert !issue.description.include?('This paragraph is after the delimiter')
949 end
965 end
950 end
966 end
951
967
952 def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
968 def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
953 with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do
969 with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do
954 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
970 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
955 assert issue.is_a?(Issue)
971 assert issue.is_a?(Issue)
956 assert !issue.new_record?
972 assert !issue.new_record?
957 assert_equal 0, issue.reload.attachments.size
973 assert_equal 0, issue.reload.attachments.size
958 end
974 end
959 end
975 end
960
976
961 def test_attachments_that_do_not_match_mail_handler_excluded_filenames_should_be_attached
977 def test_attachments_that_do_not_match_mail_handler_excluded_filenames_should_be_attached
962 with_settings :mail_handler_excluded_filenames => '*.vcf, *.gif' do
978 with_settings :mail_handler_excluded_filenames => '*.vcf, *.gif' do
963 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
979 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
964 assert issue.is_a?(Issue)
980 assert issue.is_a?(Issue)
965 assert !issue.new_record?
981 assert !issue.new_record?
966 assert_equal 1, issue.reload.attachments.size
982 assert_equal 1, issue.reload.attachments.size
967 end
983 end
968 end
984 end
969
985
970 def test_email_with_long_subject_line
986 def test_email_with_long_subject_line
971 issue = submit_email('ticket_with_long_subject.eml')
987 issue = submit_email('ticket_with_long_subject.eml')
972 assert issue.is_a?(Issue)
988 assert issue.is_a?(Issue)
973 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]
989 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]
974 end
990 end
975
991
976 def test_first_keyword_should_be_matched
992 def test_first_keyword_should_be_matched
977 issue = submit_email('ticket_with_duplicate_keyword.eml', :allow_override => 'priority')
993 issue = submit_email('ticket_with_duplicate_keyword.eml', :allow_override => 'priority')
978 assert issue.is_a?(Issue)
994 assert issue.is_a?(Issue)
979 assert_equal 'High', issue.priority.name
995 assert_equal 'High', issue.priority.name
980 end
996 end
981
997
982 def test_keyword_after_delimiter_should_be_ignored
998 def test_keyword_after_delimiter_should_be_ignored
983 with_settings :mail_handler_body_delimiters => "== DELIMITER ==" do
999 with_settings :mail_handler_body_delimiters => "== DELIMITER ==" do
984 issue = submit_email('ticket_with_keyword_after_delimiter.eml', :allow_override => 'priority')
1000 issue = submit_email('ticket_with_keyword_after_delimiter.eml', :allow_override => 'priority')
985 assert issue.is_a?(Issue)
1001 assert issue.is_a?(Issue)
986 assert_equal 'Normal', issue.priority.name
1002 assert_equal 'Normal', issue.priority.name
987 end
1003 end
988 end
1004 end
989
1005
990 def test_new_user_from_attributes_should_return_valid_user
1006 def test_new_user_from_attributes_should_return_valid_user
991 to_test = {
1007 to_test = {
992 # [address, name] => [login, firstname, lastname]
1008 # [address, name] => [login, firstname, lastname]
993 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
1009 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
994 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
1010 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
995 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
1011 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
996 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
1012 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
997 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
1013 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
998 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
1014 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
999 }
1015 }
1000
1016
1001 to_test.each do |attrs, expected|
1017 to_test.each do |attrs, expected|
1002 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
1018 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
1003
1019
1004 assert user.valid?, user.errors.full_messages.to_s
1020 assert user.valid?, user.errors.full_messages.to_s
1005 assert_equal attrs.first, user.mail
1021 assert_equal attrs.first, user.mail
1006 assert_equal expected[0], user.login
1022 assert_equal expected[0], user.login
1007 assert_equal expected[1], user.firstname
1023 assert_equal expected[1], user.firstname
1008 assert_equal expected[2], user.lastname
1024 assert_equal expected[2], user.lastname
1009 assert_equal 'only_my_events', user.mail_notification
1025 assert_equal 'only_my_events', user.mail_notification
1010 end
1026 end
1011 end
1027 end
1012
1028
1013 def test_new_user_from_attributes_should_use_default_login_if_invalid
1029 def test_new_user_from_attributes_should_use_default_login_if_invalid
1014 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
1030 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
1015 assert user.valid?
1031 assert user.valid?
1016 assert user.login =~ /^user[a-f0-9]+$/
1032 assert user.login =~ /^user[a-f0-9]+$/
1017 assert_equal 'foo+bar@example.net', user.mail
1033 assert_equal 'foo+bar@example.net', user.mail
1018 end
1034 end
1019
1035
1020 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
1036 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
1021 assert_difference 'User.count' do
1037 assert_difference 'User.count' do
1022 issue = submit_email(
1038 issue = submit_email(
1023 'fullname_of_sender_as_utf8_encoded.eml',
1039 'fullname_of_sender_as_utf8_encoded.eml',
1024 :issue => {:project => 'ecookbook'},
1040 :issue => {:project => 'ecookbook'},
1025 :unknown_user => 'create'
1041 :unknown_user => 'create'
1026 )
1042 )
1027 end
1043 end
1028 user = User.order('id DESC').first
1044 user = User.order('id DESC').first
1029 assert_equal "foo@example.org", user.mail
1045 assert_equal "foo@example.org", user.mail
1030 str1 = "\xc3\x84\xc3\xa4".force_encoding('UTF-8')
1046 str1 = "\xc3\x84\xc3\xa4".force_encoding('UTF-8')
1031 str2 = "\xc3\x96\xc3\xb6".force_encoding('UTF-8')
1047 str2 = "\xc3\x96\xc3\xb6".force_encoding('UTF-8')
1032 assert_equal str1, user.firstname
1048 assert_equal str1, user.firstname
1033 assert_equal str2, user.lastname
1049 assert_equal str2, user.lastname
1034 end
1050 end
1035
1051
1036 def test_extract_options_from_env_should_return_options
1052 def test_extract_options_from_env_should_return_options
1037 options = MailHandler.extract_options_from_env({
1053 options = MailHandler.extract_options_from_env({
1038 'tracker' => 'defect',
1054 'tracker' => 'defect',
1039 'project' => 'foo',
1055 'project' => 'foo',
1040 'unknown_user' => 'create'
1056 'unknown_user' => 'create'
1041 })
1057 })
1042
1058
1043 assert_equal({
1059 assert_equal({
1044 :issue => {:tracker => 'defect', :project => 'foo'},
1060 :issue => {:tracker => 'defect', :project => 'foo'},
1045 :unknown_user => 'create'
1061 :unknown_user => 'create'
1046 }, options)
1062 }, options)
1047 end
1063 end
1048
1064
1049 def test_safe_receive_should_rescue_exceptions_and_return_false
1065 def test_safe_receive_should_rescue_exceptions_and_return_false
1050 MailHandler.stubs(:receive).raises(Exception.new "Something went wrong")
1066 MailHandler.stubs(:receive).raises(Exception.new "Something went wrong")
1051
1067
1052 assert_equal false, MailHandler.safe_receive
1068 assert_equal false, MailHandler.safe_receive
1053 end
1069 end
1054
1070
1055 private
1071 private
1056
1072
1057 def submit_email(filename, options={})
1073 def submit_email(filename, options={})
1058 raw = IO.read(File.join(FIXTURES_PATH, filename))
1074 raw = IO.read(File.join(FIXTURES_PATH, filename))
1059 yield raw if block_given?
1075 yield raw if block_given?
1060 MailHandler.receive(raw, options)
1076 MailHandler.receive(raw, options)
1061 end
1077 end
1062
1078
1063 def assert_issue_created(issue)
1079 def assert_issue_created(issue)
1064 assert issue.is_a?(Issue)
1080 assert issue.is_a?(Issue)
1065 assert !issue.new_record?
1081 assert !issue.new_record?
1066 issue.reload
1082 issue.reload
1067 end
1083 end
1068 end
1084 end
General Comments 0
You need to be logged in to leave comments. Login now