organization_ref_object_touch_test.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class OrganizationRefObjectTouchTest < 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: 'organization-ref-object-update-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'organization-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 1',
  23. updated_at: '2015-02-05 16:37:00',
  24. updated_by_id: 1,
  25. created_by_id: 1,
  26. )
  27. organization2 = Organization.create_if_not_exists(
  28. name: 'Ref Object Update Org 2',
  29. updated_at: '2015-02-05 16:37:00',
  30. updated_by_id: 1,
  31. created_by_id: 1,
  32. )
  33. customer1 = User.create_or_update(
  34. login: 'organization-ref-object-update-customer1@example.com',
  35. firstname: 'Notification',
  36. lastname: 'Agent1',
  37. email: 'organization-ref-object-update-customer1@example.com',
  38. password: 'customerpw',
  39. active: true,
  40. organization_id: organization1.id,
  41. roles: roles,
  42. updated_at: '2015-02-05 16:37:00',
  43. updated_by_id: 1,
  44. created_by_id: 1,
  45. )
  46. customer2 = User.create_or_update(
  47. login: 'organization-ref-object-update-customer2@example.com',
  48. firstname: 'Notification',
  49. lastname: 'Agent2',
  50. email: 'organization-ref-object-update-customer2@example.com',
  51. password: 'customerpw',
  52. active: true,
  53. organization_id: organization2.id,
  54. roles: roles,
  55. updated_at: '2015-02-05 16:37:00',
  56. updated_by_id: 1,
  57. created_by_id: 1,
  58. )
  59. test 'a - check if ticket and customer 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 5
  74. organization1.name = 'Ref Object Update Org 1/1'
  75. organization1.save
  76. # check if ticket and customer has been touched
  77. ticket = Ticket.find(ticket.id)
  78. if ticket.updated_at > 2.second.ago
  79. assert( true, 'ticket.updated_at has been updated' )
  80. else
  81. assert( false, 'ticket.updated_at has not been updated' )
  82. end
  83. customer1 = User.find(customer1.id)
  84. if customer1.updated_at > 2.second.ago
  85. assert( true, 'customer1.updated_at has been updated' )
  86. else
  87. assert( false, 'customer1.updated_at has not been updated' )
  88. end
  89. sleep 4
  90. customer2.organization_id = organization1.id
  91. customer2.save
  92. # check if customer1 and organization has been touched
  93. customer1 = User.find(customer1.id)
  94. if customer1.updated_at > 2.second.ago
  95. assert( true, 'customer1.updated_at has been updated' )
  96. else
  97. assert( false, 'customer1.updated_at has not been updated' )
  98. end
  99. organization1 = Organization.find(organization1.id)
  100. if organization1.updated_at > 2.second.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