user_ref_object_touch_test.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class UserRefObjectTouchTest < 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: '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. test 'a - check if ticket 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. sleep 6
  68. customer1.firstname = 'firstname customer1'
  69. customer1.save
  70. # check if organization has been touched
  71. organization1 = Organization.find(organization1.id)
  72. if organization1.updated_at > 4.second.ago
  73. assert( true, 'organization1.updated_at has been updated' )
  74. else
  75. assert( false, 'organization1.updated_at has not been updated' )
  76. end
  77. sleep 6
  78. ticket.customer_id = customer2.id
  79. ticket.save
  80. # check if customer1, customer2 and organization has been touched
  81. customer1 = User.find(customer1.id)
  82. if customer1.updated_at > 4.second.ago
  83. assert( true, 'customer1.updated_at has been updated' )
  84. else
  85. assert( false, 'customer1.updated_at has not been updated' )
  86. end
  87. customer2 = User.find(customer2.id)
  88. if customer2.updated_at > 4.second.ago
  89. assert( true, 'customer2.updated_at has been updated' )
  90. else
  91. assert( false, 'customer2.updated_at has not been updated' )
  92. end
  93. organization1 = Organization.find(organization1.id)
  94. if organization1.updated_at > 4.second.ago
  95. assert( true, 'organization1.updated_at has been updated' )
  96. else
  97. assert( false, 'organization1.updated_at has not been updated' )
  98. end
  99. delete = ticket.destroy
  100. assert( delete, 'ticket destroy' )
  101. end
  102. end