organization_ref_object_touch_test.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class OrganizationRefObjectTouchTest < 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: 'organization-ref-object-update-agent1@example.com',
  14. firstname: 'Notification',
  15. lastname: 'Agent1',
  16. email: 'organization-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 1',
  28. updated_at: '2015-02-05 16:37:00',
  29. updated_by_id: 1,
  30. created_by_id: 1,
  31. )
  32. organization2 = Organization.create_if_not_exists(
  33. name: 'Ref Object Update Org 2',
  34. updated_at: '2015-02-05 16:37:00',
  35. updated_by_id: 1,
  36. created_by_id: 1,
  37. )
  38. customer1 = User.create_or_update(
  39. login: 'organization-ref-object-update-customer1@example.com',
  40. firstname: 'Notification',
  41. lastname: 'Agent1',
  42. email: 'organization-ref-object-update-customer1@example.com',
  43. password: 'customerpw',
  44. active: true,
  45. organization_id: organization1.id,
  46. roles: roles,
  47. updated_at: '2015-02-05 16:37:00',
  48. updated_by_id: 1,
  49. created_by_id: 1,
  50. )
  51. customer2 = User.create_or_update(
  52. login: 'organization-ref-object-update-customer2@example.com',
  53. firstname: 'Notification',
  54. lastname: 'Agent2',
  55. email: 'organization-ref-object-update-customer2@example.com',
  56. password: 'customerpw',
  57. active: true,
  58. organization_id: organization2.id,
  59. roles: roles,
  60. updated_at: '2015-02-05 16:37:00',
  61. updated_by_id: 1,
  62. created_by_id: 1,
  63. )
  64. end
  65. test 'b - check if ticket and customer has been updated' do
  66. ticket = Ticket.create(
  67. title: "some title1\n äöüß",
  68. group: Group.lookup(name: 'Users'),
  69. customer_id: customer1.id,
  70. owner_id: agent1.id,
  71. state: Ticket::State.lookup(name: 'new'),
  72. priority: Ticket::Priority.lookup(name: '2 normal'),
  73. updated_by_id: 1,
  74. created_by_id: 1,
  75. )
  76. assert(ticket, 'ticket created')
  77. assert_equal(ticket.customer.id, customer1.id)
  78. assert_equal(ticket.organization.id, organization1.id)
  79. travel 4.seconds
  80. organization1.name = 'Ref Object Update Org 1/1'
  81. organization1.save
  82. # check if ticket and customer has been touched
  83. ticket = Ticket.find(ticket.id)
  84. if ticket.updated_at > 2.seconds.ago
  85. assert(true, 'ticket.updated_at has been updated')
  86. else
  87. assert(false, 'ticket.updated_at has not been updated')
  88. end
  89. customer1 = User.find(customer1.id)
  90. if customer1.updated_at > 2.seconds.ago
  91. assert(true, 'customer1.updated_at has been updated')
  92. else
  93. assert(false, 'customer1.updated_at has not been updated')
  94. end
  95. travel 4.seconds
  96. customer2.organization_id = organization1.id
  97. customer2.save
  98. # check if customer1 and organization has been touched
  99. customer1 = User.find(customer1.id)
  100. if customer1.updated_at > 2.seconds.ago
  101. assert(true, 'customer1.updated_at has been updated')
  102. else
  103. assert(false, 'customer1.updated_at has not been updated')
  104. end
  105. organization1 = Organization.find(organization1.id)
  106. if organization1.updated_at > 2.seconds.ago
  107. assert(true, 'organization1.updated_at has been updated')
  108. else
  109. assert(false, 'organization1.updated_at has not been updated')
  110. end
  111. delete = ticket.destroy
  112. assert(delete, 'ticket destroy')
  113. travel_back
  114. end
  115. end