ticket_ref_object_touch_test.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketRefObjectTouchTest < ActiveSupport::TestCase
  4. setup do
  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. end
  54. test 'b - check if customer and organization has been updated' do
  55. ticket = Ticket.create(
  56. title: "some title1\n äöüß",
  57. group: Group.lookup(name: 'Users'),
  58. customer_id: @customer1.id,
  59. owner_id: @agent1.id,
  60. state: Ticket::State.lookup(name: 'new'),
  61. priority: Ticket::Priority.lookup(name: '2 normal'),
  62. updated_by_id: 1,
  63. created_by_id: 1,
  64. )
  65. assert(ticket, 'ticket created')
  66. assert_equal(ticket.customer.id, @customer1.id)
  67. assert_equal(ticket.organization.id, @organization1.id)
  68. # check if customer and organization has been touched
  69. @customer1 = User.find(@customer1.id)
  70. if @customer1.updated_at > 3.seconds.ago
  71. assert(true, 'customer1.updated_at has been updated')
  72. else
  73. assert(false, 'customer1.updated_at has not been updated')
  74. end
  75. @organization1 = Organization.find(@organization1.id)
  76. if @organization1.updated_at > 3.seconds.ago
  77. assert(true, 'organization1.updated_at has been updated')
  78. else
  79. assert(false, 'organization1.updated_at has not been updated')
  80. end
  81. travel 4.seconds
  82. delete = ticket.destroy
  83. assert(delete, 'ticket destroy')
  84. # check if customer and organization has been touched
  85. @customer1.reload
  86. if @customer1.updated_at > 3.seconds.ago
  87. assert(true, 'customer1.updated_at has been updated')
  88. else
  89. assert(false, 'customer1.updated_at has not been updated')
  90. end
  91. @organization1.reload
  92. if @organization1.updated_at > 3.seconds.ago
  93. assert(true, 'organization1.updated_at has been updated')
  94. else
  95. assert(false, 'organization1.updated_at has not been updated')
  96. end
  97. travel_back
  98. end
  99. test 'c - check if customer (not organization) has been updated' do
  100. travel 8.seconds
  101. ticket = Ticket.create(
  102. title: "some title2\n äöüß",
  103. group: Group.lookup(name: 'Users'),
  104. customer_id: @customer2.id,
  105. owner_id: @agent1.id,
  106. state: Ticket::State.lookup(name: 'new'),
  107. priority: Ticket::Priority.lookup(name: '2 normal'),
  108. updated_by_id: 1,
  109. created_by_id: 1,
  110. )
  111. assert(ticket, 'ticket created')
  112. assert_equal(ticket.customer.id, @customer2.id)
  113. assert_nil(ticket.organization)
  114. # check if customer and organization has been touched
  115. @customer2.reload
  116. if @customer2.updated_at > 3.seconds.ago
  117. assert(true, 'customer2.updated_at has been updated')
  118. else
  119. assert(false, 'customer2.updated_at has not been updated')
  120. end
  121. @organization1.reload
  122. if @organization1.updated_at > 3.seconds.ago
  123. assert(false, 'organization1.updated_at has been updated')
  124. else
  125. assert(true, 'organization1.updated_at has not been updated')
  126. end
  127. travel 4.seconds
  128. delete = ticket.destroy
  129. assert(delete, 'ticket destroy')
  130. # check if customer and organization has been touched
  131. @customer2.reload
  132. if @customer2.updated_at > 3.seconds.ago
  133. assert(true, 'customer2.updated_at has been updated')
  134. else
  135. assert(false, 'customer2.updated_at has not been updated')
  136. end
  137. @organization1.reload
  138. if @organization1.updated_at > 3.seconds.ago
  139. assert(false, 'organization1.updated_at has been updated')
  140. else
  141. assert(true, 'organization1.updated_at has not been updated')
  142. end
  143. travel_back
  144. end
  145. end