comparison test/unit/mail_handler_test.rb @ 37:94944d00e43c

* Update to SVN trunk rev 4411
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 19 Nov 2010 13:24:41 +0000
parents 513646585e45
children af80e5618e9b
comparison
equal deleted inserted replaced
22:40f7cfd4df19 37:94944d00e43c
23 fixtures :users, :projects, 23 fixtures :users, :projects,
24 :enabled_modules, 24 :enabled_modules,
25 :roles, 25 :roles,
26 :members, 26 :members,
27 :member_roles, 27 :member_roles,
28 :users,
28 :issues, 29 :issues,
29 :issue_statuses, 30 :issue_statuses,
30 :workflows, 31 :workflows,
31 :trackers, 32 :trackers,
32 :projects_trackers, 33 :projects_trackers,
34 :versions,
33 :enumerations, 35 :enumerations,
34 :issue_categories, 36 :issue_categories,
35 :custom_fields, 37 :custom_fields,
36 :custom_fields_trackers, 38 :custom_fields_trackers,
37 :boards, 39 :boards,
39 41
40 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' 42 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
41 43
42 def setup 44 def setup
43 ActionMailer::Base.deliveries.clear 45 ActionMailer::Base.deliveries.clear
46 Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
44 end 47 end
45 48
46 def test_add_issue 49 def test_add_issue
47 ActionMailer::Base.deliveries.clear 50 ActionMailer::Base.deliveries.clear
48 # This email contains: 'Project: onlinestore' 51 # This email contains: 'Project: onlinestore'
56 assert_equal IssueStatus.find_by_name('Resolved'), issue.status 59 assert_equal IssueStatus.find_by_name('Resolved'), issue.status
57 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') 60 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
58 assert_equal '2010-01-01', issue.start_date.to_s 61 assert_equal '2010-01-01', issue.start_date.to_s
59 assert_equal '2010-12-31', issue.due_date.to_s 62 assert_equal '2010-12-31', issue.due_date.to_s
60 assert_equal User.find_by_login('jsmith'), issue.assigned_to 63 assert_equal User.find_by_login('jsmith'), issue.assigned_to
64 assert_equal Version.find_by_name('alpha'), issue.fixed_version
65 assert_equal 2.5, issue.estimated_hours
66 assert_equal 30, issue.done_ratio
61 # keywords should be removed from the email body 67 # keywords should be removed from the email body
62 assert !issue.description.match(/^Project:/i) 68 assert !issue.description.match(/^Project:/i)
63 assert !issue.description.match(/^Status:/i) 69 assert !issue.description.match(/^Status:/i)
64 # Email notification should be sent 70 # Email notification should be sent
65 mail = ActionMailer::Base.deliveries.last 71 mail = ActionMailer::Base.deliveries.last
150 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) 156 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
151 assert issue.is_a?(Issue) 157 assert issue.is_a?(Issue)
152 assert !issue.new_record? 158 assert !issue.new_record?
153 issue.reload 159 issue.reload
154 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) 160 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
155 assert_equal 1, issue.watchers.size 161 assert_equal 1, issue.watcher_user_ids.size
156 end 162 end
157 163
158 def test_add_issue_by_unknown_user 164 def test_add_issue_by_unknown_user
159 assert_no_difference 'User.count' do 165 assert_no_difference 'User.count' do
160 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'}) 166 assert_equal false, submit_email('ticket_by_unknown_user.eml', :issue => {:project => 'ecookbook'})
221 227
222 def test_add_issue_without_from_header 228 def test_add_issue_without_from_header
223 Role.anonymous.add_permission!(:add_issues) 229 Role.anonymous.add_permission!(:add_issues)
224 assert_equal false, submit_email('ticket_without_from_header.eml') 230 assert_equal false, submit_email('ticket_without_from_header.eml')
225 end 231 end
232
233 def test_add_issue_with_invalid_attributes
234 issue = submit_email('ticket_with_invalid_attributes.eml', :allow_override => 'tracker,category,priority')
235 assert issue.is_a?(Issue)
236 assert !issue.new_record?
237 issue.reload
238 assert_nil issue.assigned_to
239 assert_nil issue.start_date
240 assert_nil issue.due_date
241 assert_equal 0, issue.done_ratio
242 assert_equal 'Normal', issue.priority.to_s
243 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
244 end
245
246 def test_add_issue_with_localized_attributes
247 User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
248 issue = submit_email('ticket_with_localized_attributes.eml', :allow_override => 'tracker,category,priority')
249 assert issue.is_a?(Issue)
250 assert !issue.new_record?
251 issue.reload
252 assert_equal 'New ticket on a given project', issue.subject
253 assert_equal User.find_by_login('jsmith'), issue.author
254 assert_equal Project.find(2), issue.project
255 assert_equal 'Feature request', issue.tracker.to_s
256 assert_equal 'Stock management', issue.category.to_s
257 assert_equal 'Urgent', issue.priority.to_s
258 assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
259 end
226 260
227 def test_add_issue_with_japanese_keywords 261 def test_add_issue_with_japanese_keywords
228 tracker = Tracker.create!(:name => '開発') 262 tracker = Tracker.create!(:name => '開発')
229 Project.find(1).trackers << tracker 263 Project.find(1).trackers << tracker
230 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker') 264 issue = submit_email('japanese_keywords_iso_2022_jp.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'tracker')
238 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') 272 assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
239 end 273 end
240 end 274 end
241 275
242 def test_add_issue_should_send_email_notification 276 def test_add_issue_should_send_email_notification
277 Setting.notified_events = ['issue_added']
243 ActionMailer::Base.deliveries.clear 278 ActionMailer::Base.deliveries.clear
244 # This email contains: 'Project: onlinestore' 279 # This email contains: 'Project: onlinestore'
245 issue = submit_email('ticket_on_given_project.eml') 280 issue = submit_email('ticket_on_given_project.eml')
246 assert issue.is_a?(Issue) 281 assert issue.is_a?(Issue)
247 assert_equal 1, ActionMailer::Base.deliveries.size 282 assert_equal 1, ActionMailer::Base.deliveries.size
265 assert_match /This is reply/, journal.notes 300 assert_match /This is reply/, journal.notes
266 assert_equal IssueStatus.find_by_name("Resolved"), issue.status 301 assert_equal IssueStatus.find_by_name("Resolved"), issue.status
267 assert_equal '2010-01-01', issue.start_date.to_s 302 assert_equal '2010-01-01', issue.start_date.to_s
268 assert_equal '2010-12-31', issue.due_date.to_s 303 assert_equal '2010-12-31', issue.due_date.to_s
269 assert_equal User.find_by_login('jsmith'), issue.assigned_to 304 assert_equal User.find_by_login('jsmith'), issue.assigned_to
305 assert_equal 'Updated custom value', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value
270 end 306 end
271 307
272 def test_add_issue_note_should_send_email_notification 308 def test_add_issue_note_should_send_email_notification
273 ActionMailer::Base.deliveries.clear 309 ActionMailer::Base.deliveries.clear
274 journal = submit_email('ticket_reply.eml') 310 journal = submit_email('ticket_reply.eml')
331 assert !issue.description.match(/^---$/) 367 assert !issue.description.match(/^---$/)
332 assert !issue.description.include?('This paragraph is after the delimiter') 368 assert !issue.description.include?('This paragraph is after the delimiter')
333 end 369 end
334 end 370 end
335 371
372 context "with a single quoted reply (e.g. reply to a Redmine email notification)" do
373 setup do
374 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
375 end
376
377 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
378 journal = submit_email('issue_update_with_quoted_reply_above.eml')
379 assert journal.is_a?(Journal)
380 assert journal.notes.include?('An update to the issue by the sender.')
381 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
382 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
383
384 end
385
386 end
387
388 context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do
389 setup do
390 Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---'
391 end
392
393 should "truncate the email at the delimiter with the quoted reply symbols (>)" do
394 journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
395 assert journal.is_a?(Journal)
396 assert journal.notes.include?('An update to the issue by the sender.')
397 assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
398 assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
399
400 end
401
402 end
403
336 context "with multiple strings" do 404 context "with multiple strings" do
337 setup do 405 setup do
338 Setting.mail_handler_body_delimiters = "---\nBREAK" 406 Setting.mail_handler_body_delimiters = "---\nBREAK"
339 end 407 end
340 408