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