ticket_customer_organization_update_test.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
  4. agent1 = nil
  5. organization1 = nil
  6. customer1 = nil
  7. test 'aaa - setup' do
  8. # create base
  9. groups = Group.where(name: 'Users')
  10. roles = Role.where(name: 'Agent')
  11. agent1 = User.create_or_update(
  12. login: 'ticket-customer-organization-update-agent1@example.com',
  13. firstname: 'Notification',
  14. lastname: 'Agent1',
  15. email: 'ticket-customer-organization-update-agent1@example.com',
  16. password: 'agentpw',
  17. active: true,
  18. roles: roles,
  19. groups: groups,
  20. updated_at: '2015-02-05 16:37:00',
  21. updated_by_id: 1,
  22. created_by_id: 1,
  23. )
  24. roles = Role.where(name: 'Customer')
  25. organization1 = Organization.create_if_not_exists(
  26. name: 'Customer Organization Update',
  27. updated_at: '2015-02-05 16:37:00',
  28. updated_by_id: 1,
  29. created_by_id: 1,
  30. )
  31. customer1 = User.create_or_update(
  32. login: 'ticket-customer-organization-update-customer1@example.com',
  33. firstname: 'Notification',
  34. lastname: 'Customer1',
  35. email: 'ticket-customer-organization-update-customer1@example.com',
  36. password: 'customerpw',
  37. active: true,
  38. organization_id: organization1.id,
  39. roles: roles,
  40. updated_at: '2015-02-05 16:37:00',
  41. updated_by_id: 1,
  42. created_by_id: 1,
  43. )
  44. end
  45. test 'create ticket, update customers organization later' do
  46. ticket = Ticket.create(
  47. title: "some title1\n äöüß",
  48. group: Group.lookup(name: 'Users'),
  49. customer_id: customer1.id,
  50. owner_id: agent1.id,
  51. state: Ticket::State.lookup(name: 'new'),
  52. priority: Ticket::Priority.lookup(name: '2 normal'),
  53. updated_by_id: 1,
  54. created_by_id: 1,
  55. )
  56. assert(ticket, 'ticket created')
  57. assert_equal(customer1.id, ticket.customer.id)
  58. assert_equal(organization1.id, ticket.organization.id)
  59. # update customer organization
  60. customer1.organization_id = nil
  61. customer1.save
  62. # verify ticket
  63. ticket = Ticket.find(ticket.id)
  64. assert_equal(nil, ticket.organization_id)
  65. # update customer organization
  66. customer1.organization_id = organization1.id
  67. customer1.save
  68. # verify ticket
  69. ticket = Ticket.find(ticket.id)
  70. assert_equal(organization1.id, ticket.organization_id)
  71. ticket.destroy
  72. end
  73. end