ticket_article_store_empty.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. require 'test_helper'
  2. class TicketArticleStoreEmpty < ActiveSupport::TestCase
  3. test 'check if attachments are deleted after ticket is deleted' do
  4. current_count = Store.count
  5. current_file_count = Store::File.count
  6. current_backend_count = Store::Provider::DB.count
  7. email_raw_string = File.read(Rails.root.join('test', 'data', 'mail', 'mail001.box'))
  8. ticket, article, user, mail = Channel::EmailParser.new.process({}, email_raw_string)
  9. next_count = Store.count
  10. next_file_count = Store::File.count
  11. next_backend_count = Store::Provider::DB.count
  12. assert_equal(current_count, next_count - 2)
  13. assert_equal(current_file_count, next_file_count - 2)
  14. assert_equal(current_backend_count, next_backend_count - 2)
  15. ticket.destroy!
  16. after_count = Store.count
  17. after_file_count = Store::File.count
  18. after_backend_count = Store::Provider::DB.count
  19. assert_equal(current_count, after_count)
  20. assert_equal(current_file_count, after_file_count)
  21. assert_equal(current_backend_count, after_backend_count)
  22. end
  23. test 'check if attachments are deleted after ticket same ticket 2 times is deleted' do
  24. current_count = Store.count
  25. current_file_count = Store::File.count
  26. current_backend_count = Store::Provider::DB.count
  27. email_raw_string = File.read(Rails.root.join('test', 'data', 'mail', 'mail001.box'))
  28. ticket1, article1, user1, mail1 = Channel::EmailParser.new.process({}, email_raw_string)
  29. ticket2, article2, user2, mail2 = Channel::EmailParser.new.process({}, email_raw_string)
  30. next_count = Store.count
  31. next_file_count = Store::File.count
  32. next_backend_count = Store::Provider::DB.count
  33. assert_equal(current_count, next_count - 4)
  34. assert_equal(current_file_count, next_file_count - 2)
  35. assert_equal(current_backend_count, next_backend_count - 2)
  36. ticket1.destroy!
  37. next_count = Store.count
  38. next_file_count = Store::File.count
  39. next_backend_count = Store::Provider::DB.count
  40. assert_equal(current_count, next_count - 2)
  41. assert_equal(current_file_count, next_file_count - 2)
  42. assert_equal(current_backend_count, next_backend_count - 2)
  43. ticket2.destroy!
  44. after_count = Store.count
  45. after_file_count = Store::File.count
  46. after_backend_count = Store::Provider::DB.count
  47. assert_equal(current_count, after_count)
  48. assert_equal(current_file_count, after_file_count)
  49. assert_equal(current_backend_count, after_backend_count)
  50. end
  51. end