ticket_ref_object_touch_test.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketRefObjectTouchTest < ActiveSupport::TestCase
  4. # create base
  5. groups = Group.where( name: 'Users' )
  6. roles = Role.where( name: 'Agent' )
  7. agent1 = User.create_or_update(
  8. login: 'ticket-ref-object-update-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'ticket-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: 'ticket-ref-object-update-customer1@example.com',
  29. firstname: 'Notification',
  30. lastname: 'Customer1',
  31. email: 'ticket-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: 'ticket-ref-object-update-customer2@example.com',
  42. firstname: 'Notification',
  43. lastname: 'Customer2',
  44. email: 'ticket-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. test 'a - check if customer and organization has been updated' do
  54. ticket = Ticket.create(
  55. title: "some title1\n äöüß",
  56. group: Group.lookup( name: 'Users'),
  57. customer_id: customer1.id,
  58. owner_id: agent1.id,
  59. state: Ticket::State.lookup( name: 'new' ),
  60. priority: Ticket::Priority.lookup( name: '2 normal' ),
  61. updated_by_id: 1,
  62. created_by_id: 1,
  63. )
  64. assert( ticket, 'ticket created' )
  65. assert_equal( ticket.customer.id, customer1.id )
  66. assert_equal( ticket.organization.id, organization1.id )
  67. # check if customer and organization has been touched
  68. customer1 = User.find(customer1.id)
  69. if customer1.updated_at > 2.second.ago
  70. assert( true, 'customer1.updated_at has been updated' )
  71. else
  72. assert( false, 'customer1.updated_at has not been updated' )
  73. end
  74. organization1 = Organization.find(organization1.id)
  75. if organization1.updated_at > 2.second.ago
  76. assert( true, 'organization1.updated_at has been updated' )
  77. else
  78. assert( false, 'organization1.updated_at has not been updated' )
  79. end
  80. sleep 4
  81. delete = ticket.destroy
  82. assert( delete, 'ticket destroy' )
  83. # check if customer and organization has been touched
  84. customer1 = User.find(customer1.id)
  85. if customer1.updated_at > 2.second.ago
  86. assert( true, 'customer1.updated_at has been updated' )
  87. else
  88. assert( false, 'customer1.updated_at has not been updated' )
  89. end
  90. organization1 = Organization.find(organization1.id)
  91. if organization1.updated_at > 2.second.ago
  92. assert( true, 'organization1.updated_at has been updated' )
  93. else
  94. assert( false, 'organization1.updated_at has not been updated' )
  95. end
  96. end
  97. test 'b - check if customer (not organization) has been updated' do
  98. sleep 3
  99. ticket = Ticket.create(
  100. title: "some title2\n äöüß",
  101. group: Group.lookup( name: 'Users'),
  102. customer_id: customer2.id,
  103. owner_id: agent1.id,
  104. state: Ticket::State.lookup( name: 'new' ),
  105. priority: Ticket::Priority.lookup( name: '2 normal' ),
  106. updated_by_id: 1,
  107. created_by_id: 1,
  108. )
  109. assert( ticket, 'ticket created' )
  110. assert_equal( ticket.customer.id, customer2.id )
  111. assert_equal( ticket.organization, nil )
  112. # check if customer and organization has been touched
  113. customer2 = User.find(customer2.id)
  114. if customer2.updated_at > 2.second.ago
  115. assert( true, 'customer2.updated_at has been updated' )
  116. else
  117. assert( false, 'customer2.updated_at has not been updated' )
  118. end
  119. organization1 = Organization.find(organization1.id)
  120. if organization1.updated_at > 2.second.ago
  121. assert( false, 'organization1.updated_at has been updated' )
  122. else
  123. assert( true, 'organization1.updated_at has not been updated' )
  124. end
  125. sleep 3
  126. delete = ticket.destroy
  127. assert( delete, 'ticket destroy' )
  128. # check if customer and organization has been touched
  129. customer2 = User.find(customer2.id)
  130. if customer2.updated_at > 2.second.ago
  131. assert( true, 'customer2.updated_at has been updated' )
  132. else
  133. assert( false, 'customer2.updated_at has not been updated' )
  134. end
  135. organization1 = Organization.find(organization1.id)
  136. if organization1.updated_at > 2.second.ago
  137. assert( false, 'organization1.updated_at has been updated' )
  138. else
  139. assert( true, 'organization1.updated_at has not been updated' )
  140. end
  141. end
  142. end