ticket_ref_object_touch_test.rb 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketRefObjectTouchTest < ActiveSupport::TestCase
  4. agent1 = nil
  5. organization1 = nil
  6. customer1 = nil
  7. customer2 = nil
  8. test 'aaa - setup' do
  9. # create base
  10. groups = Group.where(name: 'Users')
  11. roles = Role.where(name: 'Agent')
  12. agent1 = User.create_or_update(
  13. login: 'ticket-ref-object-update-agent1@example.com',
  14. firstname: 'Notification',
  15. lastname: 'Agent1',
  16. email: 'ticket-ref-object-update-agent1@example.com',
  17. password: 'agentpw',
  18. active: true,
  19. roles: roles,
  20. groups: groups,
  21. updated_at: '2015-02-05 16:37:00',
  22. updated_by_id: 1,
  23. created_by_id: 1,
  24. )
  25. roles = Role.where(name: 'Customer')
  26. organization1 = Organization.create_if_not_exists(
  27. name: 'Ref Object Update Org',
  28. updated_at: '2015-02-05 16:37:00',
  29. updated_by_id: 1,
  30. created_by_id: 1,
  31. )
  32. customer1 = User.create_or_update(
  33. login: 'ticket-ref-object-update-customer1@example.com',
  34. firstname: 'Notification',
  35. lastname: 'Customer1',
  36. email: 'ticket-ref-object-update-customer1@example.com',
  37. password: 'customerpw',
  38. active: true,
  39. organization_id: organization1.id,
  40. roles: roles,
  41. updated_at: '2015-02-05 16:37:00',
  42. updated_by_id: 1,
  43. created_by_id: 1,
  44. )
  45. customer2 = User.create_or_update(
  46. login: 'ticket-ref-object-update-customer2@example.com',
  47. firstname: 'Notification',
  48. lastname: 'Customer2',
  49. email: 'ticket-ref-object-update-customer2@example.com',
  50. password: 'customerpw',
  51. active: true,
  52. organization_id: nil,
  53. roles: roles,
  54. updated_at: '2015-02-05 16:37:00',
  55. updated_by_id: 1,
  56. created_by_id: 1,
  57. )
  58. end
  59. test 'b - check if customer and organization has been updated' do
  60. ticket = Ticket.create(
  61. title: "some title1\n äöüß",
  62. group: Group.lookup(name: 'Users'),
  63. customer_id: customer1.id,
  64. owner_id: agent1.id,
  65. state: Ticket::State.lookup(name: 'new'),
  66. priority: Ticket::Priority.lookup(name: '2 normal'),
  67. updated_by_id: 1,
  68. created_by_id: 1,
  69. )
  70. assert(ticket, 'ticket created')
  71. assert_equal(ticket.customer.id, customer1.id)
  72. assert_equal(ticket.organization.id, organization1.id)
  73. # check if customer and organization has been touched
  74. customer1 = User.find(customer1.id)
  75. if customer1.updated_at > 3.seconds.ago
  76. assert(true, 'customer1.updated_at has been updated')
  77. else
  78. assert(false, 'customer1.updated_at has not been updated')
  79. end
  80. organization1 = Organization.find(organization1.id)
  81. if organization1.updated_at > 3.seconds.ago
  82. assert(true, 'organization1.updated_at has been updated')
  83. else
  84. assert(false, 'organization1.updated_at has not been updated')
  85. end
  86. travel 4.seconds
  87. delete = ticket.destroy
  88. assert(delete, 'ticket destroy')
  89. # check if customer and organization has been touched
  90. customer1 = User.find(customer1.id)
  91. if customer1.updated_at > 3.seconds.ago
  92. assert(true, 'customer1.updated_at has been updated')
  93. else
  94. assert(false, 'customer1.updated_at has not been updated')
  95. end
  96. organization1 = Organization.find(organization1.id)
  97. if organization1.updated_at > 3.seconds.ago
  98. assert(true, 'organization1.updated_at has been updated')
  99. else
  100. assert(false, 'organization1.updated_at has not been updated')
  101. end
  102. travel_back
  103. end
  104. test 'c - check if customer (not organization) has been updated' do
  105. travel 8.seconds
  106. ticket = Ticket.create(
  107. title: "some title2\n äöüß",
  108. group: Group.lookup(name: 'Users'),
  109. customer_id: customer2.id,
  110. owner_id: agent1.id,
  111. state: Ticket::State.lookup(name: 'new'),
  112. priority: Ticket::Priority.lookup(name: '2 normal'),
  113. updated_by_id: 1,
  114. created_by_id: 1,
  115. )
  116. assert(ticket, 'ticket created')
  117. assert_equal(ticket.customer.id, customer2.id)
  118. assert_equal(ticket.organization, nil)
  119. # check if customer and organization has been touched
  120. customer2 = User.find(customer2.id)
  121. if customer2.updated_at > 3.seconds.ago
  122. assert(true, 'customer2.updated_at has been updated')
  123. else
  124. assert(false, 'customer2.updated_at has not been updated')
  125. end
  126. organization1 = Organization.find(organization1.id)
  127. if organization1.updated_at > 3.seconds.ago
  128. assert(false, 'organization1.updated_at has been updated')
  129. else
  130. assert(true, 'organization1.updated_at has not been updated')
  131. end
  132. travel 4.seconds
  133. delete = ticket.destroy
  134. assert(delete, 'ticket destroy')
  135. # check if customer and organization has been touched
  136. customer2 = User.find(customer2.id)
  137. if customer2.updated_at > 3.seconds.ago
  138. assert(true, 'customer2.updated_at has been updated')
  139. else
  140. assert(false, 'customer2.updated_at has not been updated')
  141. end
  142. organization1 = Organization.find(organization1.id)
  143. if organization1.updated_at > 3.seconds.ago
  144. assert(false, 'organization1.updated_at has been updated')
  145. else
  146. assert(true, 'organization1.updated_at has not been updated')
  147. end
  148. travel_back
  149. end
  150. end