user_ref_object_touch_test.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class UserRefObjectTouchTest < 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: 'user-ref-object-update-agent1@example.com',
  14. firstname: 'Notification',
  15. lastname: 'Agent1',
  16. email: 'user-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: 'user-ref-object-update-customer1@example.com',
  34. firstname: 'Notification',
  35. lastname: 'Agent1',
  36. email: 'user-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: 'user-ref-object-update-customer2@example.com',
  47. firstname: 'Notification',
  48. lastname: 'Agent2',
  49. email: 'user-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 ticket 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. sleep 4
  74. customer1.firstname = 'firstname customer1'
  75. customer1.save
  76. # check if organization has been touched
  77. organization1 = Organization.find(organization1.id)
  78. if organization1.updated_at > 3.seconds.ago
  79. assert(true, 'organization1.updated_at has been updated')
  80. else
  81. assert(false, 'organization1.updated_at has not been updated')
  82. end
  83. sleep 4
  84. ticket.customer_id = customer2.id
  85. ticket.save
  86. # check if customer1, customer2 and organization has been touched
  87. customer1 = User.find(customer1.id)
  88. if customer1.updated_at > 3.seconds.ago
  89. assert(true, 'customer1.updated_at has been updated')
  90. else
  91. assert(false, 'customer1.updated_at has not been updated')
  92. end
  93. customer2 = User.find(customer2.id)
  94. if customer2.updated_at > 3.seconds.ago
  95. assert(true, 'customer2.updated_at has been updated')
  96. else
  97. assert(false, 'customer2.updated_at has not been updated')
  98. end
  99. organization1 = Organization.find(organization1.id)
  100. if organization1.updated_at > 3.seconds.ago
  101. assert(true, 'organization1.updated_at has been updated')
  102. else
  103. assert(false, 'organization1.updated_at has not been updated')
  104. end
  105. delete = ticket.destroy
  106. assert(delete, 'ticket destroy')
  107. end
  108. end