ticket_article_store_empty.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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