user_ref_object_touch_test.rb 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. require 'test_helper'
  2. class UserRefObjectTouchTest < ActiveSupport::TestCase
  3. test 'check if ticket and organization has been updated' do
  4. # create base
  5. groups = Group.where(name: 'Users')
  6. roles = Role.where(name: 'Agent')
  7. agent1 = User.create_or_update(
  8. login: 'user-ref-object-update-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'user-ref-object-update-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: groups,
  16. updated_at: '2015-02-05 16:37:00',
  17. updated_by_id: 1,
  18. created_by_id: 1,
  19. )
  20. roles = Role.where(name: 'Customer')
  21. organization1 = Organization.create_if_not_exists(
  22. name: 'Ref Object Update Org',
  23. updated_at: '2015-02-05 16:37:00',
  24. updated_by_id: 1,
  25. created_by_id: 1,
  26. )
  27. customer1 = User.create_or_update(
  28. login: 'user-ref-object-update-customer1@example.com',
  29. firstname: 'Notification',
  30. lastname: 'Agent1',
  31. email: 'user-ref-object-update-customer1@example.com',
  32. password: 'customerpw',
  33. active: true,
  34. organization_id: organization1.id,
  35. roles: roles,
  36. updated_at: '2015-02-05 16:37:00',
  37. updated_by_id: 1,
  38. created_by_id: 1,
  39. )
  40. customer2 = User.create_or_update(
  41. login: 'user-ref-object-update-customer2@example.com',
  42. firstname: 'Notification',
  43. lastname: 'Agent2',
  44. email: 'user-ref-object-update-customer2@example.com',
  45. password: 'customerpw',
  46. active: true,
  47. organization_id: nil,
  48. roles: roles,
  49. updated_at: '2015-02-05 16:37:00',
  50. updated_by_id: 1,
  51. created_by_id: 1,
  52. )
  53. ticket = Ticket.create(
  54. title: "some title1\n äöüß",
  55. group: Group.lookup(name: 'Users'),
  56. customer_id: customer1.id,
  57. owner_id: agent1.id,
  58. state: Ticket::State.lookup(name: 'new'),
  59. priority: Ticket::Priority.lookup(name: '2 normal'),
  60. updated_by_id: 1,
  61. created_by_id: 1,
  62. )
  63. assert(ticket, 'ticket created')
  64. assert_equal(ticket.customer.id, customer1.id)
  65. assert_equal(ticket.organization.id, organization1.id)
  66. travel 4.seconds
  67. customer1.firstname = 'firstname customer1'
  68. customer1.save
  69. # check if organization has been touched
  70. organization1 = Organization.find(organization1.id)
  71. if organization1.updated_at > 3.seconds.ago
  72. assert(true, 'organization1.updated_at has been updated')
  73. else
  74. assert(false, 'organization1.updated_at has not been updated')
  75. end
  76. travel 4.seconds
  77. ticket.customer_id = customer2.id
  78. ticket.save
  79. # check if customer1, customer2 and organization has been touched
  80. customer1 = User.find(customer1.id)
  81. if customer1.updated_at > 3.seconds.ago
  82. assert(true, 'customer1.updated_at has been updated')
  83. else
  84. assert(false, 'customer1.updated_at has not been updated')
  85. end
  86. customer2 = User.find(customer2.id)
  87. if customer2.updated_at > 3.seconds.ago
  88. assert(true, 'customer2.updated_at has been updated')
  89. else
  90. assert(false, 'customer2.updated_at has not been updated')
  91. end
  92. organization1 = Organization.find(organization1.id)
  93. if organization1.updated_at > 3.seconds.ago
  94. assert(true, 'organization1.updated_at has been updated')
  95. else
  96. assert(false, 'organization1.updated_at has not been updated')
  97. end
  98. delete = ticket.destroy
  99. assert(delete, 'ticket destroy')
  100. end
  101. test 'check if ticket and organization has not been updated (different featrue propose)' do
  102. # create base
  103. groups = Group.where(name: 'Users')
  104. roles = Role.where(name: 'Agent')
  105. agent1 = User.create_or_update(
  106. login: 'user-ref-object-update-agent1@example.com',
  107. firstname: 'Notification',
  108. lastname: 'Agent1',
  109. email: 'user-ref-object-update-agent1@example.com',
  110. password: 'agentpw',
  111. active: true,
  112. roles: roles,
  113. groups: groups,
  114. updated_at: '2015-02-05 16:37:00',
  115. updated_by_id: 1,
  116. created_by_id: 1,
  117. )
  118. roles = Role.where(name: 'Customer')
  119. organization1 = Organization.create_if_not_exists(
  120. name: 'Ref Object Update Org (not updated)',
  121. updated_at: '2015-02-05 16:37:00',
  122. updated_by_id: 1,
  123. created_by_id: 1,
  124. )
  125. customer1 = User.create_or_update(
  126. login: 'user-ref-object-update-customer1@example.com',
  127. firstname: 'Notification',
  128. lastname: 'Agent1',
  129. email: 'user-ref-object-update-customer1@example.com',
  130. password: 'customerpw',
  131. active: true,
  132. organization_id: organization1.id,
  133. roles: roles,
  134. updated_at: '2015-02-05 16:37:00',
  135. updated_by_id: 1,
  136. created_by_id: 1,
  137. )
  138. customer2 = User.create_or_update(
  139. login: 'user-ref-object-update-customer2@example.com',
  140. firstname: 'Notification',
  141. lastname: 'Agent2',
  142. email: 'user-ref-object-update-customer2@example.com',
  143. password: 'customerpw',
  144. active: true,
  145. organization_id: nil,
  146. roles: roles,
  147. updated_at: '2015-02-05 16:37:00',
  148. updated_by_id: 1,
  149. created_by_id: 1,
  150. )
  151. (1..100).each do |count|
  152. User.create_or_update(
  153. login: "user-ref-object-update-customer3-#{count}@example.com",
  154. firstname: 'Notification',
  155. lastname: 'Agent2',
  156. email: "user-ref-object-update-customer3-#{count}@example.com",
  157. password: 'customerpw',
  158. active: true,
  159. organization_id: organization1.id,
  160. roles: roles,
  161. updated_at: '2015-02-05 16:37:00',
  162. updated_by_id: 1,
  163. created_by_id: 1,
  164. )
  165. end
  166. ticket = Ticket.create(
  167. title: "some title1\n äöüß",
  168. group: Group.lookup(name: 'Users'),
  169. customer_id: customer1.id,
  170. owner_id: agent1.id,
  171. state: Ticket::State.lookup(name: 'new'),
  172. priority: Ticket::Priority.lookup(name: '2 normal'),
  173. updated_by_id: 1,
  174. created_by_id: 1,
  175. )
  176. assert(ticket, 'ticket created')
  177. assert_equal(ticket.customer.id, customer1.id)
  178. assert_equal(ticket.organization.id, organization1.id)
  179. organization1_updated_at = ticket.organization.updated_at
  180. travel 4.seconds
  181. customer1.firstname = 'firstname customer1'
  182. customer1.save
  183. customer1_updated_at = customer1.updated_at
  184. # check if organization has been touched
  185. organization1 = Organization.find(organization1.id)
  186. assert_equal(organization1_updated_at.to_s, ticket.updated_at.to_s)
  187. travel 4.seconds
  188. ticket.customer_id = customer2.id
  189. ticket.save
  190. # check if customer1, customer2 and organization has been touched
  191. customer1 = User.find(customer1.id)
  192. if customer1.updated_at > 3.seconds.ago
  193. assert(true, 'customer1.updated_at has been updated')
  194. else
  195. assert(false, 'customer1.updated_at has not been updated')
  196. end
  197. customer2 = User.find(customer2.id)
  198. if customer2.updated_at > 3.seconds.ago
  199. assert(true, 'customer2.updated_at has been updated')
  200. else
  201. assert(false, 'customer2.updated_at has not been updated')
  202. end
  203. organization1 = Organization.find(organization1.id)
  204. if organization1.updated_at > 3.seconds.ago
  205. assert(true, 'organization1.updated_at has been updated')
  206. else
  207. assert(false, 'organization1.updated_at has not been updated')
  208. end
  209. delete = ticket.destroy
  210. assert(delete, 'ticket destroy')
  211. end
  212. end