##// END OF EJS Templates
add test of issue id in sending mail when issue is created by mail (#17078)...
Toshi MARUYAMA -
r12920:95482a4fff16
parent child
Show More
@@ -1,919 +1,920
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
4 # Copyright (C) 2006-2014 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 lft1 = new_issue_lft
44 lft1 = new_issue_lft
45 # This email contains: 'Project: onlinestore'
45 # This email contains: 'Project: onlinestore'
46 issue = submit_email('ticket_on_given_project.eml')
46 issue = submit_email('ticket_on_given_project.eml')
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 assert_equal [issue.id, lft1, lft1 + 1], [issue.root_id, issue.lft, issue.rgt]
62 assert_equal [issue.id, lft1, lft1 + 1], [issue.root_id, issue.lft, issue.rgt]
63 # keywords should be removed from the email body
63 # keywords should be removed from the email body
64 assert !issue.description.match(/^Project:/i)
64 assert !issue.description.match(/^Project:/i)
65 assert !issue.description.match(/^Status:/i)
65 assert !issue.description.match(/^Status:/i)
66 assert !issue.description.match(/^Start Date:/i)
66 assert !issue.description.match(/^Start Date:/i)
67 # Email notification should be sent
67 # Email notification should be sent
68 mail = ActionMailer::Base.deliveries.last
68 mail = ActionMailer::Base.deliveries.last
69 assert_not_nil mail
69 assert_not_nil mail
70 assert mail.subject.include?("##{issue.id}")
70 assert mail.subject.include?('New ticket on a given project')
71 assert mail.subject.include?('New ticket on a given project')
71 end
72 end
72
73
73 def test_add_issue_with_default_tracker
74 def test_add_issue_with_default_tracker
74 # This email contains: 'Project: onlinestore'
75 # This email contains: 'Project: onlinestore'
75 issue = submit_email(
76 issue = submit_email(
76 'ticket_on_given_project.eml',
77 'ticket_on_given_project.eml',
77 :issue => {:tracker => 'Support request'}
78 :issue => {:tracker => 'Support request'}
78 )
79 )
79 assert issue.is_a?(Issue)
80 assert issue.is_a?(Issue)
80 assert !issue.new_record?
81 assert !issue.new_record?
81 issue.reload
82 issue.reload
82 assert_equal 'Support request', issue.tracker.name
83 assert_equal 'Support request', issue.tracker.name
83 end
84 end
84
85
85 def test_add_issue_with_status
86 def test_add_issue_with_status
86 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
87 # This email contains: 'Project: onlinestore' and 'Status: Resolved'
87 issue = submit_email('ticket_on_given_project.eml')
88 issue = submit_email('ticket_on_given_project.eml')
88 assert issue.is_a?(Issue)
89 assert issue.is_a?(Issue)
89 assert !issue.new_record?
90 assert !issue.new_record?
90 issue.reload
91 issue.reload
91 assert_equal Project.find(2), issue.project
92 assert_equal Project.find(2), issue.project
92 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
93 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
93 end
94 end
94
95
95 def test_add_issue_with_attributes_override
96 def test_add_issue_with_attributes_override
96 issue = submit_email(
97 issue = submit_email(
97 'ticket_with_attributes.eml',
98 'ticket_with_attributes.eml',
98 :allow_override => 'tracker,category,priority'
99 :allow_override => 'tracker,category,priority'
99 )
100 )
100 assert issue.is_a?(Issue)
101 assert issue.is_a?(Issue)
101 assert !issue.new_record?
102 assert !issue.new_record?
102 issue.reload
103 issue.reload
103 assert_equal 'New ticket on a given project', issue.subject
104 assert_equal 'New ticket on a given project', issue.subject
104 assert_equal User.find_by_login('jsmith'), issue.author
105 assert_equal User.find_by_login('jsmith'), issue.author
105 assert_equal Project.find(2), issue.project
106 assert_equal Project.find(2), issue.project
106 assert_equal 'Feature request', issue.tracker.to_s
107 assert_equal 'Feature request', issue.tracker.to_s
107 assert_equal 'Stock management', issue.category.to_s
108 assert_equal 'Stock management', issue.category.to_s
108 assert_equal 'Urgent', issue.priority.to_s
109 assert_equal 'Urgent', issue.priority.to_s
109 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
110 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
110 end
111 end
111
112
112 def test_add_issue_with_group_assignment
113 def test_add_issue_with_group_assignment
113 with_settings :issue_group_assignment => '1' do
114 with_settings :issue_group_assignment => '1' do
114 issue = submit_email('ticket_on_given_project.eml') do |email|
115 issue = submit_email('ticket_on_given_project.eml') do |email|
115 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
116 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
116 end
117 end
117 assert issue.is_a?(Issue)
118 assert issue.is_a?(Issue)
118 assert !issue.new_record?
119 assert !issue.new_record?
119 issue.reload
120 issue.reload
120 assert_equal Group.find(11), issue.assigned_to
121 assert_equal Group.find(11), issue.assigned_to
121 end
122 end
122 end
123 end
123
124
124 def test_add_issue_with_partial_attributes_override
125 def test_add_issue_with_partial_attributes_override
125 issue = submit_email(
126 issue = submit_email(
126 'ticket_with_attributes.eml',
127 'ticket_with_attributes.eml',
127 :issue => {:priority => 'High'},
128 :issue => {:priority => 'High'},
128 :allow_override => ['tracker']
129 :allow_override => ['tracker']
129 )
130 )
130 assert issue.is_a?(Issue)
131 assert issue.is_a?(Issue)
131 assert !issue.new_record?
132 assert !issue.new_record?
132 issue.reload
133 issue.reload
133 assert_equal 'New ticket on a given project', issue.subject
134 assert_equal 'New ticket on a given project', issue.subject
134 assert_equal User.find_by_login('jsmith'), issue.author
135 assert_equal User.find_by_login('jsmith'), issue.author
135 assert_equal Project.find(2), issue.project
136 assert_equal Project.find(2), issue.project
136 assert_equal 'Feature request', issue.tracker.to_s
137 assert_equal 'Feature request', issue.tracker.to_s
137 assert_nil issue.category
138 assert_nil issue.category
138 assert_equal 'High', issue.priority.to_s
139 assert_equal 'High', issue.priority.to_s
139 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
140 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
140 end
141 end
141
142
142 def test_add_issue_with_spaces_between_attribute_and_separator
143 def test_add_issue_with_spaces_between_attribute_and_separator
143 issue = submit_email(
144 issue = submit_email(
144 'ticket_with_spaces_between_attribute_and_separator.eml',
145 'ticket_with_spaces_between_attribute_and_separator.eml',
145 :allow_override => 'tracker,category,priority'
146 :allow_override => 'tracker,category,priority'
146 )
147 )
147 assert issue.is_a?(Issue)
148 assert issue.is_a?(Issue)
148 assert !issue.new_record?
149 assert !issue.new_record?
149 issue.reload
150 issue.reload
150 assert_equal 'New ticket on a given project', issue.subject
151 assert_equal 'New ticket on a given project', issue.subject
151 assert_equal User.find_by_login('jsmith'), issue.author
152 assert_equal User.find_by_login('jsmith'), issue.author
152 assert_equal Project.find(2), issue.project
153 assert_equal Project.find(2), issue.project
153 assert_equal 'Feature request', issue.tracker.to_s
154 assert_equal 'Feature request', issue.tracker.to_s
154 assert_equal 'Stock management', issue.category.to_s
155 assert_equal 'Stock management', issue.category.to_s
155 assert_equal 'Urgent', issue.priority.to_s
156 assert_equal 'Urgent', issue.priority.to_s
156 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
157 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
157 end
158 end
158
159
159 def test_add_issue_with_attachment_to_specific_project
160 def test_add_issue_with_attachment_to_specific_project
160 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
161 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
161 assert issue.is_a?(Issue)
162 assert issue.is_a?(Issue)
162 assert !issue.new_record?
163 assert !issue.new_record?
163 issue.reload
164 issue.reload
164 assert_equal 'Ticket created by email with attachment', issue.subject
165 assert_equal 'Ticket created by email with attachment', issue.subject
165 assert_equal User.find_by_login('jsmith'), issue.author
166 assert_equal User.find_by_login('jsmith'), issue.author
166 assert_equal Project.find(2), issue.project
167 assert_equal Project.find(2), issue.project
167 assert_equal 'This is a new ticket with attachments', issue.description
168 assert_equal 'This is a new ticket with attachments', issue.description
168 # Attachment properties
169 # Attachment properties
169 assert_equal 1, issue.attachments.size
170 assert_equal 1, issue.attachments.size
170 assert_equal 'Paella.jpg', issue.attachments.first.filename
171 assert_equal 'Paella.jpg', issue.attachments.first.filename
171 assert_equal 'image/jpeg', issue.attachments.first.content_type
172 assert_equal 'image/jpeg', issue.attachments.first.content_type
172 assert_equal 10790, issue.attachments.first.filesize
173 assert_equal 10790, issue.attachments.first.filesize
173 end
174 end
174
175
175 def test_add_issue_with_custom_fields
176 def test_add_issue_with_custom_fields
176 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
177 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
177 assert issue.is_a?(Issue)
178 assert issue.is_a?(Issue)
178 assert !issue.new_record?
179 assert !issue.new_record?
179 issue.reload
180 issue.reload
180 assert_equal 'New ticket with custom field values', issue.subject
181 assert_equal 'New ticket with custom field values', issue.subject
181 assert_equal 'PostgreSQL', issue.custom_field_value(1)
182 assert_equal 'PostgreSQL', issue.custom_field_value(1)
182 assert_equal 'Value for a custom field', issue.custom_field_value(2)
183 assert_equal 'Value for a custom field', issue.custom_field_value(2)
183 assert !issue.description.match(/^searchable field:/i)
184 assert !issue.description.match(/^searchable field:/i)
184 end
185 end
185
186
186 def test_add_issue_with_version_custom_fields
187 def test_add_issue_with_version_custom_fields
187 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
188 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
188
189
189 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'ecookbook'}) do |email|
190 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'ecookbook'}) do |email|
190 email << "Affected version: 1.0\n"
191 email << "Affected version: 1.0\n"
191 end
192 end
192 assert issue.is_a?(Issue)
193 assert issue.is_a?(Issue)
193 assert !issue.new_record?
194 assert !issue.new_record?
194 issue.reload
195 issue.reload
195 assert_equal '2', issue.custom_field_value(field)
196 assert_equal '2', issue.custom_field_value(field)
196 end
197 end
197
198
198 def test_add_issue_should_match_assignee_on_display_name
199 def test_add_issue_should_match_assignee_on_display_name
199 user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
200 user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
200 User.add_to_project(user, Project.find(2))
201 User.add_to_project(user, Project.find(2))
201 issue = submit_email('ticket_on_given_project.eml') do |email|
202 issue = submit_email('ticket_on_given_project.eml') do |email|
202 email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
203 email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
203 end
204 end
204 assert issue.is_a?(Issue)
205 assert issue.is_a?(Issue)
205 assert_equal user, issue.assigned_to
206 assert_equal user, issue.assigned_to
206 end
207 end
207
208
208 def test_add_issue_should_set_default_start_date
209 def test_add_issue_should_set_default_start_date
209 with_settings :default_issue_start_date_to_creation_date => '1' do
210 with_settings :default_issue_start_date_to_creation_date => '1' do
210 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
211 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
211 assert issue.is_a?(Issue)
212 assert issue.is_a?(Issue)
212 assert_equal Date.today, issue.start_date
213 assert_equal Date.today, issue.start_date
213 end
214 end
214 end
215 end
215
216
216 def test_add_issue_with_cc
217 def test_add_issue_with_cc
217 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
218 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
218 assert issue.is_a?(Issue)
219 assert issue.is_a?(Issue)
219 assert !issue.new_record?
220 assert !issue.new_record?
220 issue.reload
221 issue.reload
221 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
222 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
222 assert_equal 1, issue.watcher_user_ids.size
223 assert_equal 1, issue.watcher_user_ids.size
223 end
224 end
224
225
225 def test_add_issue_by_unknown_user
226 def test_add_issue_by_unknown_user
226 assert_no_difference 'User.count' do
227 assert_no_difference 'User.count' do
227 assert_equal false,
228 assert_equal false,
228 submit_email(
229 submit_email(
229 'ticket_by_unknown_user.eml',
230 'ticket_by_unknown_user.eml',
230 :issue => {:project => 'ecookbook'}
231 :issue => {:project => 'ecookbook'}
231 )
232 )
232 end
233 end
233 end
234 end
234
235
235 def test_add_issue_by_anonymous_user
236 def test_add_issue_by_anonymous_user
236 Role.anonymous.add_permission!(:add_issues)
237 Role.anonymous.add_permission!(:add_issues)
237 assert_no_difference 'User.count' do
238 assert_no_difference 'User.count' do
238 issue = submit_email(
239 issue = submit_email(
239 'ticket_by_unknown_user.eml',
240 'ticket_by_unknown_user.eml',
240 :issue => {:project => 'ecookbook'},
241 :issue => {:project => 'ecookbook'},
241 :unknown_user => 'accept'
242 :unknown_user => 'accept'
242 )
243 )
243 assert issue.is_a?(Issue)
244 assert issue.is_a?(Issue)
244 assert issue.author.anonymous?
245 assert issue.author.anonymous?
245 end
246 end
246 end
247 end
247
248
248 def test_add_issue_by_anonymous_user_with_no_from_address
249 def test_add_issue_by_anonymous_user_with_no_from_address
249 Role.anonymous.add_permission!(:add_issues)
250 Role.anonymous.add_permission!(:add_issues)
250 assert_no_difference 'User.count' do
251 assert_no_difference 'User.count' do
251 issue = submit_email(
252 issue = submit_email(
252 'ticket_by_empty_user.eml',
253 'ticket_by_empty_user.eml',
253 :issue => {:project => 'ecookbook'},
254 :issue => {:project => 'ecookbook'},
254 :unknown_user => 'accept'
255 :unknown_user => 'accept'
255 )
256 )
256 assert issue.is_a?(Issue)
257 assert issue.is_a?(Issue)
257 assert issue.author.anonymous?
258 assert issue.author.anonymous?
258 end
259 end
259 end
260 end
260
261
261 def test_add_issue_by_anonymous_user_on_private_project
262 def test_add_issue_by_anonymous_user_on_private_project
262 Role.anonymous.add_permission!(:add_issues)
263 Role.anonymous.add_permission!(:add_issues)
263 assert_no_difference 'User.count' do
264 assert_no_difference 'User.count' do
264 assert_no_difference 'Issue.count' do
265 assert_no_difference 'Issue.count' do
265 assert_equal false,
266 assert_equal false,
266 submit_email(
267 submit_email(
267 'ticket_by_unknown_user.eml',
268 'ticket_by_unknown_user.eml',
268 :issue => {:project => 'onlinestore'},
269 :issue => {:project => 'onlinestore'},
269 :unknown_user => 'accept'
270 :unknown_user => 'accept'
270 )
271 )
271 end
272 end
272 end
273 end
273 end
274 end
274
275
275 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
276 def test_add_issue_by_anonymous_user_on_private_project_without_permission_check
276 lft1 = new_issue_lft
277 lft1 = new_issue_lft
277 assert_no_difference 'User.count' do
278 assert_no_difference 'User.count' do
278 assert_difference 'Issue.count' do
279 assert_difference 'Issue.count' do
279 issue = submit_email(
280 issue = submit_email(
280 'ticket_by_unknown_user.eml',
281 'ticket_by_unknown_user.eml',
281 :issue => {:project => 'onlinestore'},
282 :issue => {:project => 'onlinestore'},
282 :no_permission_check => '1',
283 :no_permission_check => '1',
283 :unknown_user => 'accept'
284 :unknown_user => 'accept'
284 )
285 )
285 assert issue.is_a?(Issue)
286 assert issue.is_a?(Issue)
286 assert issue.author.anonymous?
287 assert issue.author.anonymous?
287 assert !issue.project.is_public?
288 assert !issue.project.is_public?
288 assert_equal [issue.id, lft1, lft1 + 1], [issue.root_id, issue.lft, issue.rgt]
289 assert_equal [issue.id, lft1, lft1 + 1], [issue.root_id, issue.lft, issue.rgt]
289 end
290 end
290 end
291 end
291 end
292 end
292
293
293 def test_add_issue_by_created_user
294 def test_add_issue_by_created_user
294 Setting.default_language = 'en'
295 Setting.default_language = 'en'
295 assert_difference 'User.count' do
296 assert_difference 'User.count' do
296 issue = submit_email(
297 issue = submit_email(
297 'ticket_by_unknown_user.eml',
298 'ticket_by_unknown_user.eml',
298 :issue => {:project => 'ecookbook'},
299 :issue => {:project => 'ecookbook'},
299 :unknown_user => 'create'
300 :unknown_user => 'create'
300 )
301 )
301 assert issue.is_a?(Issue)
302 assert issue.is_a?(Issue)
302 assert issue.author.active?
303 assert issue.author.active?
303 assert_equal 'john.doe@somenet.foo', issue.author.mail
304 assert_equal 'john.doe@somenet.foo', issue.author.mail
304 assert_equal 'John', issue.author.firstname
305 assert_equal 'John', issue.author.firstname
305 assert_equal 'Doe', issue.author.lastname
306 assert_equal 'Doe', issue.author.lastname
306
307
307 # account information
308 # account information
308 email = ActionMailer::Base.deliveries.first
309 email = ActionMailer::Base.deliveries.first
309 assert_not_nil email
310 assert_not_nil email
310 assert email.subject.include?('account activation')
311 assert email.subject.include?('account activation')
311 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
312 login = mail_body(email).match(/\* Login: (.*)$/)[1].strip
312 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
313 password = mail_body(email).match(/\* Password: (.*)$/)[1].strip
313 assert_equal issue.author, User.try_to_login(login, password)
314 assert_equal issue.author, User.try_to_login(login, password)
314 end
315 end
315 end
316 end
316
317
317 def test_created_user_should_be_added_to_groups
318 def test_created_user_should_be_added_to_groups
318 group1 = Group.generate!
319 group1 = Group.generate!
319 group2 = Group.generate!
320 group2 = Group.generate!
320
321
321 assert_difference 'User.count' do
322 assert_difference 'User.count' do
322 submit_email(
323 submit_email(
323 'ticket_by_unknown_user.eml',
324 'ticket_by_unknown_user.eml',
324 :issue => {:project => 'ecookbook'},
325 :issue => {:project => 'ecookbook'},
325 :unknown_user => 'create',
326 :unknown_user => 'create',
326 :default_group => "#{group1.name},#{group2.name}"
327 :default_group => "#{group1.name},#{group2.name}"
327 )
328 )
328 end
329 end
329 user = User.order('id DESC').first
330 user = User.order('id DESC').first
330 assert_same_elements [group1, group2], user.groups
331 assert_same_elements [group1, group2], user.groups
331 end
332 end
332
333
333 def test_created_user_should_not_receive_account_information_with_no_account_info_option
334 def test_created_user_should_not_receive_account_information_with_no_account_info_option
334 assert_difference 'User.count' do
335 assert_difference 'User.count' do
335 submit_email(
336 submit_email(
336 'ticket_by_unknown_user.eml',
337 'ticket_by_unknown_user.eml',
337 :issue => {:project => 'ecookbook'},
338 :issue => {:project => 'ecookbook'},
338 :unknown_user => 'create',
339 :unknown_user => 'create',
339 :no_account_notice => '1'
340 :no_account_notice => '1'
340 )
341 )
341 end
342 end
342
343
343 # only 1 email for the new issue notification
344 # only 1 email for the new issue notification
344 assert_equal 1, ActionMailer::Base.deliveries.size
345 assert_equal 1, ActionMailer::Base.deliveries.size
345 email = ActionMailer::Base.deliveries.first
346 email = ActionMailer::Base.deliveries.first
346 assert_include 'Ticket by unknown user', email.subject
347 assert_include 'Ticket by unknown user', email.subject
347 end
348 end
348
349
349 def test_created_user_should_have_mail_notification_to_none_with_no_notification_option
350 def test_created_user_should_have_mail_notification_to_none_with_no_notification_option
350 assert_difference 'User.count' do
351 assert_difference 'User.count' do
351 submit_email(
352 submit_email(
352 'ticket_by_unknown_user.eml',
353 'ticket_by_unknown_user.eml',
353 :issue => {:project => 'ecookbook'},
354 :issue => {:project => 'ecookbook'},
354 :unknown_user => 'create',
355 :unknown_user => 'create',
355 :no_notification => '1'
356 :no_notification => '1'
356 )
357 )
357 end
358 end
358 user = User.order('id DESC').first
359 user = User.order('id DESC').first
359 assert_equal 'none', user.mail_notification
360 assert_equal 'none', user.mail_notification
360 end
361 end
361
362
362 def test_add_issue_without_from_header
363 def test_add_issue_without_from_header
363 Role.anonymous.add_permission!(:add_issues)
364 Role.anonymous.add_permission!(:add_issues)
364 assert_equal false, submit_email('ticket_without_from_header.eml')
365 assert_equal false, submit_email('ticket_without_from_header.eml')
365 end
366 end
366
367
367 def test_add_issue_with_invalid_attributes
368 def test_add_issue_with_invalid_attributes
368 with_settings :default_issue_start_date_to_creation_date => '0' do
369 with_settings :default_issue_start_date_to_creation_date => '0' do
369 issue = submit_email(
370 issue = submit_email(
370 'ticket_with_invalid_attributes.eml',
371 'ticket_with_invalid_attributes.eml',
371 :allow_override => 'tracker,category,priority'
372 :allow_override => 'tracker,category,priority'
372 )
373 )
373 assert issue.is_a?(Issue)
374 assert issue.is_a?(Issue)
374 assert !issue.new_record?
375 assert !issue.new_record?
375 issue.reload
376 issue.reload
376 assert_nil issue.assigned_to
377 assert_nil issue.assigned_to
377 assert_nil issue.start_date
378 assert_nil issue.start_date
378 assert_nil issue.due_date
379 assert_nil issue.due_date
379 assert_equal 0, issue.done_ratio
380 assert_equal 0, issue.done_ratio
380 assert_equal 'Normal', issue.priority.to_s
381 assert_equal 'Normal', issue.priority.to_s
381 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
382 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
382 end
383 end
383 end
384 end
384
385
385 def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
386 def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
386 issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
387 issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
387 email.gsub!(/^Project:.+$/, 'Project: invalid')
388 email.gsub!(/^Project:.+$/, 'Project: invalid')
388 end
389 end
389 assert issue.is_a?(Issue)
390 assert issue.is_a?(Issue)
390 assert !issue.new_record?
391 assert !issue.new_record?
391 assert_equal 'ecookbook', issue.project.identifier
392 assert_equal 'ecookbook', issue.project.identifier
392 end
393 end
393
394
394 def test_add_issue_with_localized_attributes
395 def test_add_issue_with_localized_attributes
395 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
396 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
396 issue = submit_email(
397 issue = submit_email(
397 'ticket_with_localized_attributes.eml',
398 'ticket_with_localized_attributes.eml',
398 :allow_override => 'tracker,category,priority'
399 :allow_override => 'tracker,category,priority'
399 )
400 )
400 assert issue.is_a?(Issue)
401 assert issue.is_a?(Issue)
401 assert !issue.new_record?
402 assert !issue.new_record?
402 issue.reload
403 issue.reload
403 assert_equal 'New ticket on a given project', issue.subject
404 assert_equal 'New ticket on a given project', issue.subject
404 assert_equal User.find_by_login('jsmith'), issue.author
405 assert_equal User.find_by_login('jsmith'), issue.author
405 assert_equal Project.find(2), issue.project
406 assert_equal Project.find(2), issue.project
406 assert_equal 'Feature request', issue.tracker.to_s
407 assert_equal 'Feature request', issue.tracker.to_s
407 assert_equal 'Stock management', issue.category.to_s
408 assert_equal 'Stock management', issue.category.to_s
408 assert_equal 'Urgent', issue.priority.to_s
409 assert_equal 'Urgent', issue.priority.to_s
409 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
410 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
410 end
411 end
411
412
412 def test_add_issue_with_japanese_keywords
413 def test_add_issue_with_japanese_keywords
413 ja_dev = "\xe9\x96\x8b\xe7\x99\xba"
414 ja_dev = "\xe9\x96\x8b\xe7\x99\xba"
414 ja_dev.force_encoding('UTF-8') if ja_dev.respond_to?(:force_encoding)
415 ja_dev.force_encoding('UTF-8') if ja_dev.respond_to?(:force_encoding)
415 tracker = Tracker.create!(:name => ja_dev)
416 tracker = Tracker.create!(:name => ja_dev)
416 Project.find(1).trackers << tracker
417 Project.find(1).trackers << tracker
417 issue = submit_email(
418 issue = submit_email(
418 'japanese_keywords_iso_2022_jp.eml',
419 'japanese_keywords_iso_2022_jp.eml',
419 :issue => {:project => 'ecookbook'},
420 :issue => {:project => 'ecookbook'},
420 :allow_override => 'tracker'
421 :allow_override => 'tracker'
421 )
422 )
422 assert_kind_of Issue, issue
423 assert_kind_of Issue, issue
423 assert_equal tracker, issue.tracker
424 assert_equal tracker, issue.tracker
424 end
425 end
425
426
426 def test_add_issue_from_apple_mail
427 def test_add_issue_from_apple_mail
427 issue = submit_email(
428 issue = submit_email(
428 'apple_mail_with_attachment.eml',
429 'apple_mail_with_attachment.eml',
429 :issue => {:project => 'ecookbook'}
430 :issue => {:project => 'ecookbook'}
430 )
431 )
431 assert_kind_of Issue, issue
432 assert_kind_of Issue, issue
432 assert_equal 1, issue.attachments.size
433 assert_equal 1, issue.attachments.size
433
434
434 attachment = issue.attachments.first
435 attachment = issue.attachments.first
435 assert_equal 'paella.jpg', attachment.filename
436 assert_equal 'paella.jpg', attachment.filename
436 assert_equal 10790, attachment.filesize
437 assert_equal 10790, attachment.filesize
437 assert File.exist?(attachment.diskfile)
438 assert File.exist?(attachment.diskfile)
438 assert_equal 10790, File.size(attachment.diskfile)
439 assert_equal 10790, File.size(attachment.diskfile)
439 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
440 assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
440 end
441 end
441
442
442 def test_thunderbird_with_attachment_ja
443 def test_thunderbird_with_attachment_ja
443 issue = submit_email(
444 issue = submit_email(
444 'thunderbird_with_attachment_ja.eml',
445 'thunderbird_with_attachment_ja.eml',
445 :issue => {:project => 'ecookbook'}
446 :issue => {:project => 'ecookbook'}
446 )
447 )
447 assert_kind_of Issue, issue
448 assert_kind_of Issue, issue
448 assert_equal 1, issue.attachments.size
449 assert_equal 1, issue.attachments.size
449 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt"
450 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt"
450 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
451 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
451 attachment = issue.attachments.first
452 attachment = issue.attachments.first
452 assert_equal ja, attachment.filename
453 assert_equal ja, attachment.filename
453 assert_equal 5, attachment.filesize
454 assert_equal 5, attachment.filesize
454 assert File.exist?(attachment.diskfile)
455 assert File.exist?(attachment.diskfile)
455 assert_equal 5, File.size(attachment.diskfile)
456 assert_equal 5, File.size(attachment.diskfile)
456 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
457 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
457 end
458 end
458
459
459 def test_gmail_with_attachment_ja
460 def test_gmail_with_attachment_ja
460 issue = submit_email(
461 issue = submit_email(
461 'gmail_with_attachment_ja.eml',
462 'gmail_with_attachment_ja.eml',
462 :issue => {:project => 'ecookbook'}
463 :issue => {:project => 'ecookbook'}
463 )
464 )
464 assert_kind_of Issue, issue
465 assert_kind_of Issue, issue
465 assert_equal 1, issue.attachments.size
466 assert_equal 1, issue.attachments.size
466 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt"
467 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt"
467 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
468 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
468 attachment = issue.attachments.first
469 attachment = issue.attachments.first
469 assert_equal ja, attachment.filename
470 assert_equal ja, attachment.filename
470 assert_equal 5, attachment.filesize
471 assert_equal 5, attachment.filesize
471 assert File.exist?(attachment.diskfile)
472 assert File.exist?(attachment.diskfile)
472 assert_equal 5, File.size(attachment.diskfile)
473 assert_equal 5, File.size(attachment.diskfile)
473 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
474 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
474 end
475 end
475
476
476 def test_thunderbird_with_attachment_latin1
477 def test_thunderbird_with_attachment_latin1
477 issue = submit_email(
478 issue = submit_email(
478 'thunderbird_with_attachment_iso-8859-1.eml',
479 'thunderbird_with_attachment_iso-8859-1.eml',
479 :issue => {:project => 'ecookbook'}
480 :issue => {:project => 'ecookbook'}
480 )
481 )
481 assert_kind_of Issue, issue
482 assert_kind_of Issue, issue
482 assert_equal 1, issue.attachments.size
483 assert_equal 1, issue.attachments.size
483 u = ""
484 u = ""
484 u.force_encoding('UTF-8') if u.respond_to?(:force_encoding)
485 u.force_encoding('UTF-8') if u.respond_to?(:force_encoding)
485 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc"
486 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc"
486 u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding)
487 u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding)
487 11.times { u << u1 }
488 11.times { u << u1 }
488 attachment = issue.attachments.first
489 attachment = issue.attachments.first
489 assert_equal "#{u}.png", attachment.filename
490 assert_equal "#{u}.png", attachment.filename
490 assert_equal 130, attachment.filesize
491 assert_equal 130, attachment.filesize
491 assert File.exist?(attachment.diskfile)
492 assert File.exist?(attachment.diskfile)
492 assert_equal 130, File.size(attachment.diskfile)
493 assert_equal 130, File.size(attachment.diskfile)
493 assert_equal '4d80e667ac37dddfe05502530f152abb', attachment.digest
494 assert_equal '4d80e667ac37dddfe05502530f152abb', attachment.digest
494 end
495 end
495
496
496 def test_gmail_with_attachment_latin1
497 def test_gmail_with_attachment_latin1
497 issue = submit_email(
498 issue = submit_email(
498 'gmail_with_attachment_iso-8859-1.eml',
499 'gmail_with_attachment_iso-8859-1.eml',
499 :issue => {:project => 'ecookbook'}
500 :issue => {:project => 'ecookbook'}
500 )
501 )
501 assert_kind_of Issue, issue
502 assert_kind_of Issue, issue
502 assert_equal 1, issue.attachments.size
503 assert_equal 1, issue.attachments.size
503 u = ""
504 u = ""
504 u.force_encoding('UTF-8') if u.respond_to?(:force_encoding)
505 u.force_encoding('UTF-8') if u.respond_to?(:force_encoding)
505 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc"
506 u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc"
506 u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding)
507 u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding)
507 11.times { u << u1 }
508 11.times { u << u1 }
508 attachment = issue.attachments.first
509 attachment = issue.attachments.first
509 assert_equal "#{u}.txt", attachment.filename
510 assert_equal "#{u}.txt", attachment.filename
510 assert_equal 5, attachment.filesize
511 assert_equal 5, attachment.filesize
511 assert File.exist?(attachment.diskfile)
512 assert File.exist?(attachment.diskfile)
512 assert_equal 5, File.size(attachment.diskfile)
513 assert_equal 5, File.size(attachment.diskfile)
513 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
514 assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
514 end
515 end
515
516
516 def test_multiple_inline_text_parts_should_be_appended_to_issue_description
517 def test_multiple_inline_text_parts_should_be_appended_to_issue_description
517 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
518 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
518 assert_include 'first', issue.description
519 assert_include 'first', issue.description
519 assert_include 'second', issue.description
520 assert_include 'second', issue.description
520 assert_include 'third', issue.description
521 assert_include 'third', issue.description
521 end
522 end
522
523
523 def test_attachment_text_part_should_be_added_as_issue_attachment
524 def test_attachment_text_part_should_be_added_as_issue_attachment
524 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
525 issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
525 assert_not_include 'Plain text attachment', issue.description
526 assert_not_include 'Plain text attachment', issue.description
526 attachment = issue.attachments.detect {|a| a.filename == 'textfile.txt'}
527 attachment = issue.attachments.detect {|a| a.filename == 'textfile.txt'}
527 assert_not_nil attachment
528 assert_not_nil attachment
528 assert_include 'Plain text attachment', File.read(attachment.diskfile)
529 assert_include 'Plain text attachment', File.read(attachment.diskfile)
529 end
530 end
530
531
531 def test_add_issue_with_iso_8859_1_subject
532 def test_add_issue_with_iso_8859_1_subject
532 issue = submit_email(
533 issue = submit_email(
533 'subject_as_iso-8859-1.eml',
534 'subject_as_iso-8859-1.eml',
534 :issue => {:project => 'ecookbook'}
535 :issue => {:project => 'ecookbook'}
535 )
536 )
536 str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc..."
537 str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc..."
537 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
538 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
538 assert_kind_of Issue, issue
539 assert_kind_of Issue, issue
539 assert_equal str, issue.subject
540 assert_equal str, issue.subject
540 end
541 end
541
542
542 def test_quoted_printable_utf8
543 def test_quoted_printable_utf8
543 issue = submit_email(
544 issue = submit_email(
544 'quoted_printable_utf8.eml',
545 'quoted_printable_utf8.eml',
545 :issue => {:project => 'ecookbook'}
546 :issue => {:project => 'ecookbook'}
546 )
547 )
547 assert_kind_of Issue, issue
548 assert_kind_of Issue, issue
548 str = "Freundliche Gr\xc3\xbcsse"
549 str = "Freundliche Gr\xc3\xbcsse"
549 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
550 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
550 assert_equal str, issue.description
551 assert_equal str, issue.description
551 end
552 end
552
553
553 def test_gmail_iso8859_2
554 def test_gmail_iso8859_2
554 issue = submit_email(
555 issue = submit_email(
555 'gmail-iso8859-2.eml',
556 'gmail-iso8859-2.eml',
556 :issue => {:project => 'ecookbook'}
557 :issue => {:project => 'ecookbook'}
557 )
558 )
558 assert_kind_of Issue, issue
559 assert_kind_of Issue, issue
559 str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87."
560 str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87."
560 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
561 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
561 assert issue.description.include?(str)
562 assert issue.description.include?(str)
562 end
563 end
563
564
564 def test_add_issue_with_japanese_subject
565 def test_add_issue_with_japanese_subject
565 issue = submit_email(
566 issue = submit_email(
566 'subject_japanese_1.eml',
567 'subject_japanese_1.eml',
567 :issue => {:project => 'ecookbook'}
568 :issue => {:project => 'ecookbook'}
568 )
569 )
569 assert_kind_of Issue, issue
570 assert_kind_of Issue, issue
570 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
571 ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
571 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
572 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
572 assert_equal ja, issue.subject
573 assert_equal ja, issue.subject
573 end
574 end
574
575
575 def test_add_issue_with_korean_body
576 def test_add_issue_with_korean_body
576 # Make sure mail bodies with a charset unknown to Ruby
577 # Make sure mail bodies with a charset unknown to Ruby
577 # but known to the Mail gem 2.5.4 are handled correctly
578 # but known to the Mail gem 2.5.4 are handled correctly
578 kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4."
579 kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4."
579 if !kr.respond_to?(:force_encoding)
580 if !kr.respond_to?(:force_encoding)
580 puts "\nOn Ruby 1.8, skip Korean encoding mail body test"
581 puts "\nOn Ruby 1.8, skip Korean encoding mail body test"
581 else
582 else
582 kr.force_encoding('UTF-8')
583 kr.force_encoding('UTF-8')
583 issue = submit_email(
584 issue = submit_email(
584 'body_ks_c_5601-1987.eml',
585 'body_ks_c_5601-1987.eml',
585 :issue => {:project => 'ecookbook'}
586 :issue => {:project => 'ecookbook'}
586 )
587 )
587 assert_kind_of Issue, issue
588 assert_kind_of Issue, issue
588 assert_equal kr, issue.description
589 assert_equal kr, issue.description
589 end
590 end
590 end
591 end
591
592
592 def test_add_issue_with_no_subject_header
593 def test_add_issue_with_no_subject_header
593 issue = submit_email(
594 issue = submit_email(
594 'no_subject_header.eml',
595 'no_subject_header.eml',
595 :issue => {:project => 'ecookbook'}
596 :issue => {:project => 'ecookbook'}
596 )
597 )
597 assert_kind_of Issue, issue
598 assert_kind_of Issue, issue
598 assert_equal '(no subject)', issue.subject
599 assert_equal '(no subject)', issue.subject
599 end
600 end
600
601
601 def test_add_issue_with_mixed_japanese_subject
602 def test_add_issue_with_mixed_japanese_subject
602 issue = submit_email(
603 issue = submit_email(
603 'subject_japanese_2.eml',
604 'subject_japanese_2.eml',
604 :issue => {:project => 'ecookbook'}
605 :issue => {:project => 'ecookbook'}
605 )
606 )
606 assert_kind_of Issue, issue
607 assert_kind_of Issue, issue
607 ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
608 ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
608 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
609 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
609 assert_equal ja, issue.subject
610 assert_equal ja, issue.subject
610 end
611 end
611
612
612 def test_should_ignore_emails_from_locked_users
613 def test_should_ignore_emails_from_locked_users
613 User.find(2).lock!
614 User.find(2).lock!
614
615
615 MailHandler.any_instance.expects(:dispatch).never
616 MailHandler.any_instance.expects(:dispatch).never
616 assert_no_difference 'Issue.count' do
617 assert_no_difference 'Issue.count' do
617 assert_equal false, submit_email('ticket_on_given_project.eml')
618 assert_equal false, submit_email('ticket_on_given_project.eml')
618 end
619 end
619 end
620 end
620
621
621 def test_should_ignore_emails_from_emission_address
622 def test_should_ignore_emails_from_emission_address
622 Role.anonymous.add_permission!(:add_issues)
623 Role.anonymous.add_permission!(:add_issues)
623 assert_no_difference 'User.count' do
624 assert_no_difference 'User.count' do
624 assert_equal false,
625 assert_equal false,
625 submit_email(
626 submit_email(
626 'ticket_from_emission_address.eml',
627 'ticket_from_emission_address.eml',
627 :issue => {:project => 'ecookbook'},
628 :issue => {:project => 'ecookbook'},
628 :unknown_user => 'create'
629 :unknown_user => 'create'
629 )
630 )
630 end
631 end
631 end
632 end
632
633
633 def test_should_ignore_auto_replied_emails
634 def test_should_ignore_auto_replied_emails
634 MailHandler.any_instance.expects(:dispatch).never
635 MailHandler.any_instance.expects(:dispatch).never
635 [
636 [
636 "X-Auto-Response-Suppress: OOF",
637 "X-Auto-Response-Suppress: OOF",
637 "Auto-Submitted: auto-replied",
638 "Auto-Submitted: auto-replied",
638 "Auto-Submitted: Auto-Replied",
639 "Auto-Submitted: Auto-Replied",
639 "Auto-Submitted: auto-generated"
640 "Auto-Submitted: auto-generated"
640 ].each do |header|
641 ].each do |header|
641 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
642 raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
642 raw = header + "\n" + raw
643 raw = header + "\n" + raw
643
644
644 assert_no_difference 'Issue.count' do
645 assert_no_difference 'Issue.count' do
645 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
646 assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
646 end
647 end
647 end
648 end
648 end
649 end
649
650
650 def test_add_issue_should_send_email_notification
651 def test_add_issue_should_send_email_notification
651 Setting.notified_events = ['issue_added']
652 Setting.notified_events = ['issue_added']
652 ActionMailer::Base.deliveries.clear
653 ActionMailer::Base.deliveries.clear
653 # This email contains: 'Project: onlinestore'
654 # This email contains: 'Project: onlinestore'
654 issue = submit_email('ticket_on_given_project.eml')
655 issue = submit_email('ticket_on_given_project.eml')
655 assert issue.is_a?(Issue)
656 assert issue.is_a?(Issue)
656 assert_equal 1, ActionMailer::Base.deliveries.size
657 assert_equal 1, ActionMailer::Base.deliveries.size
657 end
658 end
658
659
659 def test_update_issue
660 def test_update_issue
660 journal = submit_email('ticket_reply.eml')
661 journal = submit_email('ticket_reply.eml')
661 assert journal.is_a?(Journal)
662 assert journal.is_a?(Journal)
662 assert_equal User.find_by_login('jsmith'), journal.user
663 assert_equal User.find_by_login('jsmith'), journal.user
663 assert_equal Issue.find(2), journal.journalized
664 assert_equal Issue.find(2), journal.journalized
664 assert_match /This is reply/, journal.notes
665 assert_match /This is reply/, journal.notes
665 assert_equal false, journal.private_notes
666 assert_equal false, journal.private_notes
666 assert_equal 'Feature request', journal.issue.tracker.name
667 assert_equal 'Feature request', journal.issue.tracker.name
667 end
668 end
668
669
669 def test_update_issue_with_attribute_changes
670 def test_update_issue_with_attribute_changes
670 # This email contains: 'Status: Resolved'
671 # This email contains: 'Status: Resolved'
671 journal = submit_email('ticket_reply_with_status.eml')
672 journal = submit_email('ticket_reply_with_status.eml')
672 assert journal.is_a?(Journal)
673 assert journal.is_a?(Journal)
673 issue = Issue.find(journal.issue.id)
674 issue = Issue.find(journal.issue.id)
674 assert_equal User.find_by_login('jsmith'), journal.user
675 assert_equal User.find_by_login('jsmith'), journal.user
675 assert_equal Issue.find(2), journal.journalized
676 assert_equal Issue.find(2), journal.journalized
676 assert_match /This is reply/, journal.notes
677 assert_match /This is reply/, journal.notes
677 assert_equal 'Feature request', journal.issue.tracker.name
678 assert_equal 'Feature request', journal.issue.tracker.name
678 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
679 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
679 assert_equal '2010-01-01', issue.start_date.to_s
680 assert_equal '2010-01-01', issue.start_date.to_s
680 assert_equal '2010-12-31', issue.due_date.to_s
681 assert_equal '2010-12-31', issue.due_date.to_s
681 assert_equal User.find_by_login('jsmith'), issue.assigned_to
682 assert_equal User.find_by_login('jsmith'), issue.assigned_to
682 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
683 assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value
683 # keywords should be removed from the email body
684 # keywords should be removed from the email body
684 assert !journal.notes.match(/^Status:/i)
685 assert !journal.notes.match(/^Status:/i)
685 assert !journal.notes.match(/^Start Date:/i)
686 assert !journal.notes.match(/^Start Date:/i)
686 end
687 end
687
688
688 def test_update_issue_with_attachment
689 def test_update_issue_with_attachment
689 assert_difference 'Journal.count' do
690 assert_difference 'Journal.count' do
690 assert_difference 'JournalDetail.count' do
691 assert_difference 'JournalDetail.count' do
691 assert_difference 'Attachment.count' do
692 assert_difference 'Attachment.count' do
692 assert_no_difference 'Issue.count' do
693 assert_no_difference 'Issue.count' do
693 journal = submit_email('ticket_with_attachment.eml') do |raw|
694 journal = submit_email('ticket_with_attachment.eml') do |raw|
694 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
695 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
695 end
696 end
696 end
697 end
697 end
698 end
698 end
699 end
699 end
700 end
700 journal = Journal.order('id DESC').first
701 journal = Journal.order('id DESC').first
701 assert_equal Issue.find(2), journal.journalized
702 assert_equal Issue.find(2), journal.journalized
702 assert_equal 1, journal.details.size
703 assert_equal 1, journal.details.size
703
704
704 detail = journal.details.first
705 detail = journal.details.first
705 assert_equal 'attachment', detail.property
706 assert_equal 'attachment', detail.property
706 assert_equal 'Paella.jpg', detail.value
707 assert_equal 'Paella.jpg', detail.value
707 end
708 end
708
709
709 def test_update_issue_should_send_email_notification
710 def test_update_issue_should_send_email_notification
710 ActionMailer::Base.deliveries.clear
711 ActionMailer::Base.deliveries.clear
711 journal = submit_email('ticket_reply.eml')
712 journal = submit_email('ticket_reply.eml')
712 assert journal.is_a?(Journal)
713 assert journal.is_a?(Journal)
713 assert_equal 1, ActionMailer::Base.deliveries.size
714 assert_equal 1, ActionMailer::Base.deliveries.size
714 end
715 end
715
716
716 def test_update_issue_should_not_set_defaults
717 def test_update_issue_should_not_set_defaults
717 journal = submit_email(
718 journal = submit_email(
718 'ticket_reply.eml',
719 'ticket_reply.eml',
719 :issue => {:tracker => 'Support request', :priority => 'High'}
720 :issue => {:tracker => 'Support request', :priority => 'High'}
720 )
721 )
721 assert journal.is_a?(Journal)
722 assert journal.is_a?(Journal)
722 assert_match /This is reply/, journal.notes
723 assert_match /This is reply/, journal.notes
723 assert_equal 'Feature request', journal.issue.tracker.name
724 assert_equal 'Feature request', journal.issue.tracker.name
724 assert_equal 'Normal', journal.issue.priority.name
725 assert_equal 'Normal', journal.issue.priority.name
725 end
726 end
726
727
727 def test_replying_to_a_private_note_should_add_reply_as_private
728 def test_replying_to_a_private_note_should_add_reply_as_private
728 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
729 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
729
730
730 assert_difference 'Journal.count' do
731 assert_difference 'Journal.count' do
731 journal = submit_email('ticket_reply.eml') do |email|
732 journal = submit_email('ticket_reply.eml') do |email|
732 email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{private_journal.id}.20060719210421@osiris>"
733 email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{private_journal.id}.20060719210421@osiris>"
733 end
734 end
734
735
735 assert_kind_of Journal, journal
736 assert_kind_of Journal, journal
736 assert_match /This is reply/, journal.notes
737 assert_match /This is reply/, journal.notes
737 assert_equal true, journal.private_notes
738 assert_equal true, journal.private_notes
738 end
739 end
739 end
740 end
740
741
741 def test_reply_to_a_message
742 def test_reply_to_a_message
742 m = submit_email('message_reply.eml')
743 m = submit_email('message_reply.eml')
743 assert m.is_a?(Message)
744 assert m.is_a?(Message)
744 assert !m.new_record?
745 assert !m.new_record?
745 m.reload
746 m.reload
746 assert_equal 'Reply via email', m.subject
747 assert_equal 'Reply via email', m.subject
747 # The email replies to message #2 which is part of the thread of message #1
748 # The email replies to message #2 which is part of the thread of message #1
748 assert_equal Message.find(1), m.parent
749 assert_equal Message.find(1), m.parent
749 end
750 end
750
751
751 def test_reply_to_a_message_by_subject
752 def test_reply_to_a_message_by_subject
752 m = submit_email('message_reply_by_subject.eml')
753 m = submit_email('message_reply_by_subject.eml')
753 assert m.is_a?(Message)
754 assert m.is_a?(Message)
754 assert !m.new_record?
755 assert !m.new_record?
755 m.reload
756 m.reload
756 assert_equal 'Reply to the first post', m.subject
757 assert_equal 'Reply to the first post', m.subject
757 assert_equal Message.find(1), m.parent
758 assert_equal Message.find(1), m.parent
758 end
759 end
759
760
760 def test_should_strip_tags_of_html_only_emails
761 def test_should_strip_tags_of_html_only_emails
761 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
762 issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
762 assert issue.is_a?(Issue)
763 assert issue.is_a?(Issue)
763 assert !issue.new_record?
764 assert !issue.new_record?
764 issue.reload
765 issue.reload
765 assert_equal 'HTML email', issue.subject
766 assert_equal 'HTML email', issue.subject
766 assert_equal 'This is a html-only email.', issue.description
767 assert_equal 'This is a html-only email.', issue.description
767 end
768 end
768
769
769 test "truncate emails with no setting should add the entire email into the issue" do
770 test "truncate emails with no setting should add the entire email into the issue" do
770 with_settings :mail_handler_body_delimiters => '' do
771 with_settings :mail_handler_body_delimiters => '' do
771 issue = submit_email('ticket_on_given_project.eml')
772 issue = submit_email('ticket_on_given_project.eml')
772 assert_issue_created(issue)
773 assert_issue_created(issue)
773 assert issue.description.include?('---')
774 assert issue.description.include?('---')
774 assert issue.description.include?('This paragraph is after the delimiter')
775 assert issue.description.include?('This paragraph is after the delimiter')
775 end
776 end
776 end
777 end
777
778
778 test "truncate emails with a single string should truncate the email at the delimiter for the issue" do
779 test "truncate emails with a single string should truncate the email at the delimiter for the issue" do
779 with_settings :mail_handler_body_delimiters => '---' do
780 with_settings :mail_handler_body_delimiters => '---' do
780 issue = submit_email('ticket_on_given_project.eml')
781 issue = submit_email('ticket_on_given_project.eml')
781 assert_issue_created(issue)
782 assert_issue_created(issue)
782 assert issue.description.include?('This paragraph is before delimiters')
783 assert issue.description.include?('This paragraph is before delimiters')
783 assert issue.description.include?('--- This line starts with a delimiter')
784 assert issue.description.include?('--- This line starts with a delimiter')
784 assert !issue.description.match(/^---$/)
785 assert !issue.description.match(/^---$/)
785 assert !issue.description.include?('This paragraph is after the delimiter')
786 assert !issue.description.include?('This paragraph is after the delimiter')
786 end
787 end
787 end
788 end
788
789
789 test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do
790 test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do
790 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
791 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
791 journal = submit_email('issue_update_with_quoted_reply_above.eml')
792 journal = submit_email('issue_update_with_quoted_reply_above.eml')
792 assert journal.is_a?(Journal)
793 assert journal.is_a?(Journal)
793 assert journal.notes.include?('An update to the issue by the sender.')
794 assert journal.notes.include?('An update to the issue by the sender.')
794 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
795 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
795 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
796 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
796 end
797 end
797 end
798 end
798
799
799 test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do
800 test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do
800 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
801 with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
801 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
802 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
802 assert journal.is_a?(Journal)
803 assert journal.is_a?(Journal)
803 assert journal.notes.include?('An update to the issue by the sender.')
804 assert journal.notes.include?('An update to the issue by the sender.')
804 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
805 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
805 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
806 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
806 end
807 end
807 end
808 end
808
809
809 test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do
810 test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do
810 with_settings :mail_handler_body_delimiters => "---\nBREAK" do
811 with_settings :mail_handler_body_delimiters => "---\nBREAK" do
811 issue = submit_email('ticket_on_given_project.eml')
812 issue = submit_email('ticket_on_given_project.eml')
812 assert_issue_created(issue)
813 assert_issue_created(issue)
813 assert issue.description.include?('This paragraph is before delimiters')
814 assert issue.description.include?('This paragraph is before delimiters')
814 assert !issue.description.include?('BREAK')
815 assert !issue.description.include?('BREAK')
815 assert !issue.description.include?('This paragraph is between delimiters')
816 assert !issue.description.include?('This paragraph is between delimiters')
816 assert !issue.description.match(/^---$/)
817 assert !issue.description.match(/^---$/)
817 assert !issue.description.include?('This paragraph is after the delimiter')
818 assert !issue.description.include?('This paragraph is after the delimiter')
818 end
819 end
819 end
820 end
820
821
821 def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
822 def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
822 with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do
823 with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do
823 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
824 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
824 assert issue.is_a?(Issue)
825 assert issue.is_a?(Issue)
825 assert !issue.new_record?
826 assert !issue.new_record?
826 assert_equal 0, issue.reload.attachments.size
827 assert_equal 0, issue.reload.attachments.size
827 end
828 end
828 end
829 end
829
830
830 def test_attachments_that_do_not_match_mail_handler_excluded_filenames_should_be_attached
831 def test_attachments_that_do_not_match_mail_handler_excluded_filenames_should_be_attached
831 with_settings :mail_handler_excluded_filenames => '*.vcf, *.gif' do
832 with_settings :mail_handler_excluded_filenames => '*.vcf, *.gif' do
832 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
833 issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
833 assert issue.is_a?(Issue)
834 assert issue.is_a?(Issue)
834 assert !issue.new_record?
835 assert !issue.new_record?
835 assert_equal 1, issue.reload.attachments.size
836 assert_equal 1, issue.reload.attachments.size
836 end
837 end
837 end
838 end
838
839
839 def test_email_with_long_subject_line
840 def test_email_with_long_subject_line
840 issue = submit_email('ticket_with_long_subject.eml')
841 issue = submit_email('ticket_with_long_subject.eml')
841 assert issue.is_a?(Issue)
842 assert issue.is_a?(Issue)
842 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]
843 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]
843 end
844 end
844
845
845 def test_new_user_from_attributes_should_return_valid_user
846 def test_new_user_from_attributes_should_return_valid_user
846 to_test = {
847 to_test = {
847 # [address, name] => [login, firstname, lastname]
848 # [address, name] => [login, firstname, lastname]
848 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
849 ['jsmith@example.net', nil] => ['jsmith@example.net', 'jsmith', '-'],
849 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
850 ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'],
850 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
851 ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'],
851 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
852 ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'],
852 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
853 ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatExceedsT', 'Smith'],
853 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
854 ['jsmith@example.net', 'John AVeryLongLastnameThatExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatExceedsTh']
854 }
855 }
855
856
856 to_test.each do |attrs, expected|
857 to_test.each do |attrs, expected|
857 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
858 user = MailHandler.new_user_from_attributes(attrs.first, attrs.last)
858
859
859 assert user.valid?, user.errors.full_messages.to_s
860 assert user.valid?, user.errors.full_messages.to_s
860 assert_equal attrs.first, user.mail
861 assert_equal attrs.first, user.mail
861 assert_equal expected[0], user.login
862 assert_equal expected[0], user.login
862 assert_equal expected[1], user.firstname
863 assert_equal expected[1], user.firstname
863 assert_equal expected[2], user.lastname
864 assert_equal expected[2], user.lastname
864 assert_equal 'only_my_events', user.mail_notification
865 assert_equal 'only_my_events', user.mail_notification
865 end
866 end
866 end
867 end
867
868
868 def test_new_user_from_attributes_should_use_default_login_if_invalid
869 def test_new_user_from_attributes_should_use_default_login_if_invalid
869 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
870 user = MailHandler.new_user_from_attributes('foo+bar@example.net')
870 assert user.valid?
871 assert user.valid?
871 assert user.login =~ /^user[a-f0-9]+$/
872 assert user.login =~ /^user[a-f0-9]+$/
872 assert_equal 'foo+bar@example.net', user.mail
873 assert_equal 'foo+bar@example.net', user.mail
873 end
874 end
874
875
875 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
876 def test_new_user_with_utf8_encoded_fullname_should_be_decoded
876 assert_difference 'User.count' do
877 assert_difference 'User.count' do
877 issue = submit_email(
878 issue = submit_email(
878 'fullname_of_sender_as_utf8_encoded.eml',
879 'fullname_of_sender_as_utf8_encoded.eml',
879 :issue => {:project => 'ecookbook'},
880 :issue => {:project => 'ecookbook'},
880 :unknown_user => 'create'
881 :unknown_user => 'create'
881 )
882 )
882 end
883 end
883 user = User.order('id DESC').first
884 user = User.order('id DESC').first
884 assert_equal "foo@example.org", user.mail
885 assert_equal "foo@example.org", user.mail
885 str1 = "\xc3\x84\xc3\xa4"
886 str1 = "\xc3\x84\xc3\xa4"
886 str2 = "\xc3\x96\xc3\xb6"
887 str2 = "\xc3\x96\xc3\xb6"
887 str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
888 str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
888 str2.force_encoding('UTF-8') if str2.respond_to?(:force_encoding)
889 str2.force_encoding('UTF-8') if str2.respond_to?(:force_encoding)
889 assert_equal str1, user.firstname
890 assert_equal str1, user.firstname
890 assert_equal str2, user.lastname
891 assert_equal str2, user.lastname
891 end
892 end
892
893
893 def test_extract_options_from_env_should_return_options
894 def test_extract_options_from_env_should_return_options
894 options = MailHandler.extract_options_from_env({
895 options = MailHandler.extract_options_from_env({
895 'tracker' => 'defect',
896 'tracker' => 'defect',
896 'project' => 'foo',
897 'project' => 'foo',
897 'unknown_user' => 'create'
898 'unknown_user' => 'create'
898 })
899 })
899
900
900 assert_equal({
901 assert_equal({
901 :issue => {:tracker => 'defect', :project => 'foo'},
902 :issue => {:tracker => 'defect', :project => 'foo'},
902 :unknown_user => 'create'
903 :unknown_user => 'create'
903 }, options)
904 }, options)
904 end
905 end
905
906
906 private
907 private
907
908
908 def submit_email(filename, options={})
909 def submit_email(filename, options={})
909 raw = IO.read(File.join(FIXTURES_PATH, filename))
910 raw = IO.read(File.join(FIXTURES_PATH, filename))
910 yield raw if block_given?
911 yield raw if block_given?
911 MailHandler.receive(raw, options)
912 MailHandler.receive(raw, options)
912 end
913 end
913
914
914 def assert_issue_created(issue)
915 def assert_issue_created(issue)
915 assert issue.is_a?(Issue)
916 assert issue.is_a?(Issue)
916 assert !issue.new_record?
917 assert !issue.new_record?
917 issue.reload
918 issue.reload
918 end
919 end
919 end
920 end
General Comments 0
You need to be logged in to leave comments. Login now