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