@@ -20,7 +20,7 | |||||
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, |
|
23 | fixtures :users, :projects, | |
24 | :enabled_modules, |
|
24 | :enabled_modules, | |
25 | :roles, |
|
25 | :roles, | |
26 | :members, |
|
26 | :members, | |
@@ -39,14 +39,14 class MailHandlerTest < ActiveSupport::TestCase | |||||
39 | :custom_fields_projects, |
|
39 | :custom_fields_projects, | |
40 | :boards, |
|
40 | :boards, | |
41 | :messages |
|
41 | :messages | |
42 |
|
42 | |||
43 | FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' |
|
43 | FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' | |
44 |
|
44 | |||
45 | def setup |
|
45 | def setup | |
46 | ActionMailer::Base.deliveries.clear |
|
46 | ActionMailer::Base.deliveries.clear | |
47 | Setting.notified_events = Redmine::Notifiable.all.collect(&:name) |
|
47 | Setting.notified_events = Redmine::Notifiable.all.collect(&:name) | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_add_issue |
|
50 | def test_add_issue | |
51 | ActionMailer::Base.deliveries.clear |
|
51 | ActionMailer::Base.deliveries.clear | |
52 | # This email contains: 'Project: onlinestore' |
|
52 | # This email contains: 'Project: onlinestore' | |
@@ -76,7 +76,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
76 | assert_not_nil mail |
|
76 | assert_not_nil mail | |
77 | assert mail.subject.include?('New ticket on a given project') |
|
77 | assert mail.subject.include?('New ticket on a given project') | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_add_issue_with_default_tracker |
|
80 | def test_add_issue_with_default_tracker | |
81 | # This email contains: 'Project: onlinestore' |
|
81 | # This email contains: 'Project: onlinestore' | |
82 | issue = submit_email('ticket_on_given_project.eml', :issue => {:tracker => 'Support request'}) |
|
82 | issue = submit_email('ticket_on_given_project.eml', :issue => {:tracker => 'Support request'}) | |
@@ -95,7 +95,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
95 | assert_equal Project.find(2), issue.project |
|
95 | assert_equal Project.find(2), issue.project | |
96 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
|
96 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_add_issue_with_attributes_override |
|
99 | def test_add_issue_with_attributes_override | |
100 | issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority') |
|
100 | issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority') | |
101 | assert issue.is_a?(Issue) |
|
101 | assert issue.is_a?(Issue) | |
@@ -109,7 +109,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
109 | assert_equal 'Urgent', issue.priority.to_s |
|
109 | assert_equal 'Urgent', issue.priority.to_s | |
110 | 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.') | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_add_issue_with_partial_attributes_override |
|
113 | def test_add_issue_with_partial_attributes_override | |
114 | issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker']) |
|
114 | issue = submit_email('ticket_with_attributes.eml', :issue => {:priority => 'High'}, :allow_override => ['tracker']) | |
115 | assert issue.is_a?(Issue) |
|
115 | assert issue.is_a?(Issue) | |
@@ -123,7 +123,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
123 | assert_equal 'High', issue.priority.to_s |
|
123 | assert_equal 'High', issue.priority.to_s | |
124 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
124 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_add_issue_with_spaces_between_attribute_and_separator |
|
127 | def test_add_issue_with_spaces_between_attribute_and_separator | |
128 | issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority') |
|
128 | issue = submit_email('ticket_with_spaces_between_attribute_and_separator.eml', :allow_override => 'tracker,category,priority') | |
129 | assert issue.is_a?(Issue) |
|
129 | assert issue.is_a?(Issue) | |
@@ -138,7 +138,6 class MailHandlerTest < ActiveSupport::TestCase | |||||
138 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
138 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 |
|
||||
142 | def test_add_issue_with_attachment_to_specific_project |
|
141 | def test_add_issue_with_attachment_to_specific_project | |
143 | issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) |
|
142 | issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) | |
144 | assert issue.is_a?(Issue) |
|
143 | assert issue.is_a?(Issue) | |
@@ -154,7 +153,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
154 | assert_equal 'image/jpeg', issue.attachments.first.content_type |
|
153 | assert_equal 'image/jpeg', issue.attachments.first.content_type | |
155 | assert_equal 10790, issue.attachments.first.filesize |
|
154 | assert_equal 10790, issue.attachments.first.filesize | |
156 | end |
|
155 | end | |
157 |
|
156 | |||
158 | def test_add_issue_with_custom_fields |
|
157 | def test_add_issue_with_custom_fields | |
159 | issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) |
|
158 | issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'}) | |
160 | assert issue.is_a?(Issue) |
|
159 | assert issue.is_a?(Issue) | |
@@ -164,7 +163,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
164 | assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value |
|
163 | assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value | |
165 | assert !issue.description.match(/^searchable field:/i) |
|
164 | assert !issue.description.match(/^searchable field:/i) | |
166 | end |
|
165 | end | |
167 |
|
166 | |||
168 | def test_add_issue_with_cc |
|
167 | def test_add_issue_with_cc | |
169 | issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) |
|
168 | issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) | |
170 | assert issue.is_a?(Issue) |
|
169 | assert issue.is_a?(Issue) | |
@@ -173,13 +172,13 class MailHandlerTest < ActiveSupport::TestCase | |||||
173 | assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) |
|
172 | assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) | |
174 | assert_equal 1, issue.watcher_user_ids.size |
|
173 | assert_equal 1, issue.watcher_user_ids.size | |
175 | end |
|
174 | end | |
176 |
|
175 | |||
177 | def test_add_issue_by_unknown_user |
|
176 | def test_add_issue_by_unknown_user | |
178 | assert_no_difference 'User.count' do |
|
177 | assert_no_difference 'User.count' do | |
179 | assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) |
|
178 | assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) | |
180 | end |
|
179 | end | |
181 | end |
|
180 | end | |
182 |
|
181 | |||
183 | def test_add_issue_by_anonymous_user |
|
182 | def test_add_issue_by_anonymous_user | |
184 | Role.anonymous.add_permission!(:add_issues) |
|
183 | Role.anonymous.add_permission!(:add_issues) | |
185 | assert_no_difference 'User.count' do |
|
184 | assert_no_difference 'User.count' do | |
@@ -197,7 +196,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
197 | assert issue.author.anonymous? |
|
196 | assert issue.author.anonymous? | |
198 | end |
|
197 | end | |
199 | end |
|
198 | end | |
200 |
|
199 | |||
201 | def test_add_issue_by_anonymous_user_on_private_project |
|
200 | def test_add_issue_by_anonymous_user_on_private_project | |
202 | Role.anonymous.add_permission!(:add_issues) |
|
201 | Role.anonymous.add_permission!(:add_issues) | |
203 | assert_no_difference 'User.count' do |
|
202 | assert_no_difference 'User.count' do | |
@@ -206,7 +205,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
206 | end |
|
205 | end | |
207 | end |
|
206 | end | |
208 | end |
|
207 | end | |
209 |
|
208 | |||
210 | def test_add_issue_by_anonymous_user_on_private_project_without_permission_check |
|
209 | def test_add_issue_by_anonymous_user_on_private_project_without_permission_check | |
211 | assert_no_difference 'User.count' do |
|
210 | assert_no_difference 'User.count' do | |
212 | assert_difference 'Issue.count' do |
|
211 | assert_difference 'Issue.count' do | |
@@ -218,7 +217,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
218 | end |
|
217 | end | |
219 | end |
|
218 | end | |
220 | end |
|
219 | end | |
221 |
|
220 | |||
222 | def test_add_issue_by_created_user |
|
221 | def test_add_issue_by_created_user | |
223 | Setting.default_language = 'en' |
|
222 | Setting.default_language = 'en' | |
224 | assert_difference 'User.count' do |
|
223 | assert_difference 'User.count' do | |
@@ -228,7 +227,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
228 | assert_equal 'john.doe@somenet.foo', issue.author.mail |
|
227 | assert_equal 'john.doe@somenet.foo', issue.author.mail | |
229 | assert_equal 'John', issue.author.firstname |
|
228 | assert_equal 'John', issue.author.firstname | |
230 | assert_equal 'Doe', issue.author.lastname |
|
229 | assert_equal 'Doe', issue.author.lastname | |
231 |
|
230 | |||
232 | # account information |
|
231 | # account information | |
233 | email = ActionMailer::Base.deliveries.first |
|
232 | email = ActionMailer::Base.deliveries.first | |
234 | assert_not_nil email |
|
233 | assert_not_nil email | |
@@ -238,7 +237,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
238 | assert_equal issue.author, User.try_to_login(login, password) |
|
237 | assert_equal issue.author, User.try_to_login(login, password) | |
239 | end |
|
238 | end | |
240 | end |
|
239 | end | |
241 |
|
240 | |||
242 | def test_add_issue_without_from_header |
|
241 | def test_add_issue_without_from_header | |
243 | Role.anonymous.add_permission!(:add_issues) |
|
242 | Role.anonymous.add_permission!(:add_issues) | |
244 | assert_equal false, submit_email('ticket_without_from_header.eml') |
|
243 | assert_equal false, submit_email('ticket_without_from_header.eml') | |
@@ -271,7 +270,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
271 | assert_equal 'Urgent', issue.priority.to_s |
|
270 | assert_equal 'Urgent', issue.priority.to_s | |
272 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') |
|
271 | assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') | |
273 | end |
|
272 | end | |
274 |
|
273 | |||
275 | def test_add_issue_with_japanese_keywords |
|
274 | def test_add_issue_with_japanese_keywords | |
276 | tracker = Tracker.create!(:name => 'ιηΊ') |
|
275 | tracker = Tracker.create!(:name => 'ιηΊ') | |
277 | Project.find(1).trackers << tracker |
|
276 | Project.find(1).trackers << tracker | |
@@ -295,7 +294,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
295 | assert issue.is_a?(Issue) |
|
294 | assert issue.is_a?(Issue) | |
296 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
295 | assert_equal 1, ActionMailer::Base.deliveries.size | |
297 | end |
|
296 | end | |
298 |
|
297 | |||
299 | def test_add_issue_note |
|
298 | def test_add_issue_note | |
300 | journal = submit_email('ticket_reply.eml') |
|
299 | journal = submit_email('ticket_reply.eml') | |
301 | assert journal.is_a?(Journal) |
|
300 | assert journal.is_a?(Journal) | |
@@ -330,7 +329,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
330 | assert journal.is_a?(Journal) |
|
329 | assert journal.is_a?(Journal) | |
331 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
330 | assert_equal 1, ActionMailer::Base.deliveries.size | |
332 | end |
|
331 | end | |
333 |
|
332 | |||
334 | def test_add_issue_note_should_not_set_defaults |
|
333 | def test_add_issue_note_should_not_set_defaults | |
335 | journal = submit_email('ticket_reply.eml', :issue => {:tracker => 'Support request', :priority => 'High'}) |
|
334 | journal = submit_email('ticket_reply.eml', :issue => {:tracker => 'Support request', :priority => 'High'}) | |
336 | assert journal.is_a?(Journal) |
|
335 | assert journal.is_a?(Journal) | |
@@ -338,7 +337,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
338 | assert_equal 'Feature request', journal.issue.tracker.name |
|
337 | assert_equal 'Feature request', journal.issue.tracker.name | |
339 | assert_equal 'Normal', journal.issue.priority.name |
|
338 | assert_equal 'Normal', journal.issue.priority.name | |
340 | end |
|
339 | end | |
341 |
|
340 | |||
342 | def test_reply_to_a_message |
|
341 | def test_reply_to_a_message | |
343 | m = submit_email('message_reply.eml') |
|
342 | m = submit_email('message_reply.eml') | |
344 | assert m.is_a?(Message) |
|
343 | assert m.is_a?(Message) | |
@@ -348,7 +347,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
348 | # The email replies to message #2 which is part of the thread of message #1 |
|
347 | # The email replies to message #2 which is part of the thread of message #1 | |
349 | assert_equal Message.find(1), m.parent |
|
348 | assert_equal Message.find(1), m.parent | |
350 | end |
|
349 | end | |
351 |
|
350 | |||
352 | def test_reply_to_a_message_by_subject |
|
351 | def test_reply_to_a_message_by_subject | |
353 | m = submit_email('message_reply_by_subject.eml') |
|
352 | m = submit_email('message_reply_by_subject.eml') | |
354 | assert m.is_a?(Message) |
|
353 | assert m.is_a?(Message) | |
@@ -357,7 +356,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
357 | assert_equal 'Reply to the first post', m.subject |
|
356 | assert_equal 'Reply to the first post', m.subject | |
358 | assert_equal Message.find(1), m.parent |
|
357 | assert_equal Message.find(1), m.parent | |
359 | end |
|
358 | end | |
360 |
|
359 | |||
361 | def test_should_strip_tags_of_html_only_emails |
|
360 | def test_should_strip_tags_of_html_only_emails | |
362 | issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) |
|
361 | issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'}) | |
363 | assert issue.is_a?(Issue) |
|
362 | assert issue.is_a?(Issue) | |
@@ -385,7 +384,6 class MailHandlerTest < ActiveSupport::TestCase | |||||
385 | setup do |
|
384 | setup do | |
386 | Setting.mail_handler_body_delimiters = '---' |
|
385 | Setting.mail_handler_body_delimiters = '---' | |
387 | end |
|
386 | end | |
388 |
|
||||
389 | should "truncate the email at the delimiter for the issue" do |
|
387 | should "truncate the email at the delimiter for the issue" do | |
390 | issue = submit_email('ticket_on_given_project.eml') |
|
388 | issue = submit_email('ticket_on_given_project.eml') | |
391 | assert_issue_created(issue) |
|
389 | assert_issue_created(issue) | |
@@ -400,39 +398,32 class MailHandlerTest < ActiveSupport::TestCase | |||||
400 | setup do |
|
398 | setup do | |
401 | Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' |
|
399 | Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | |
402 | end |
|
400 | end | |
403 |
|
||||
404 | should "truncate the email at the delimiter with the quoted reply symbols (>)" do |
|
401 | should "truncate the email at the delimiter with the quoted reply symbols (>)" do | |
405 | journal = submit_email('issue_update_with_quoted_reply_above.eml') |
|
402 | journal = submit_email('issue_update_with_quoted_reply_above.eml') | |
406 | assert journal.is_a?(Journal) |
|
403 | assert journal.is_a?(Journal) | |
407 | assert journal.notes.include?('An update to the issue by the sender.') |
|
404 | assert journal.notes.include?('An update to the issue by the sender.') | |
408 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) |
|
405 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
409 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') |
|
406 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
410 |
|
||||
411 | end |
|
407 | end | |
412 |
|
||||
413 | end |
|
408 | end | |
414 |
|
409 | |||
415 | context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do |
|
410 | context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do | |
416 | setup do |
|
411 | setup do | |
417 | Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' |
|
412 | Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | |
418 | end |
|
413 | end | |
419 |
|
||||
420 | should "truncate the email at the delimiter with the quoted reply symbols (>)" do |
|
414 | should "truncate the email at the delimiter with the quoted reply symbols (>)" do | |
421 | journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') |
|
415 | journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') | |
422 | assert journal.is_a?(Journal) |
|
416 | assert journal.is_a?(Journal) | |
423 | assert journal.notes.include?('An update to the issue by the sender.') |
|
417 | assert journal.notes.include?('An update to the issue by the sender.') | |
424 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) |
|
418 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
425 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') |
|
419 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
426 |
|
||||
427 | end |
|
420 | end | |
428 |
|
||||
429 | end |
|
421 | end | |
430 |
|
422 | |||
431 | context "with multiple strings" do |
|
423 | context "with multiple strings" do | |
432 | setup do |
|
424 | setup do | |
433 | Setting.mail_handler_body_delimiters = "---\nBREAK" |
|
425 | Setting.mail_handler_body_delimiters = "---\nBREAK" | |
434 | end |
|
426 | end | |
435 |
|
||||
436 | should "truncate the email at the first delimiter found (BREAK)" do |
|
427 | should "truncate the email at the first delimiter found (BREAK)" do | |
437 | issue = submit_email('ticket_on_given_project.eml') |
|
428 | issue = submit_email('ticket_on_given_project.eml') | |
438 | assert_issue_created(issue) |
|
429 | assert_issue_created(issue) | |
@@ -444,7 +435,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
444 | end |
|
435 | end | |
445 | end |
|
436 | end | |
446 | end |
|
437 | end | |
447 |
|
438 | |||
448 | def test_email_with_long_subject_line |
|
439 | def test_email_with_long_subject_line | |
449 | issue = submit_email('ticket_with_long_subject.eml') |
|
440 | issue = submit_email('ticket_with_long_subject.eml') | |
450 | assert issue.is_a?(Issue) |
|
441 | assert issue.is_a?(Issue) | |
@@ -452,7 +443,7 class MailHandlerTest < ActiveSupport::TestCase | |||||
452 | end |
|
443 | end | |
453 |
|
444 | |||
454 | private |
|
445 | private | |
455 |
|
446 | |||
456 | def submit_email(filename, options={}) |
|
447 | def submit_email(filename, options={}) | |
457 | raw = IO.read(File.join(FIXTURES_PATH, filename)) |
|
448 | raw = IO.read(File.join(FIXTURES_PATH, filename)) | |
458 | MailHandler.receive(raw, options) |
|
449 | MailHandler.receive(raw, options) |
General Comments 0
You need to be logged in to leave comments.
Login now