ticket_customer_organization_update_test.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
  4. setup do
  5. groups = Group.where(name: 'Users')
  6. roles = Role.where(name: 'Agent')
  7. @agent1 = User.create_or_update(
  8. login: 'ticket-customer-organization-update-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'ticket-customer-organization-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: 'Customer Organization Update',
  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: 'ticket-customer-organization-update-customer1@example.com',
  29. firstname: 'Notification',
  30. lastname: 'Customer1',
  31. email: 'ticket-customer-organization-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. end
  41. test 'create ticket, update customers organization later' do
  42. ticket = Ticket.create(
  43. title: "some title1\n äöüß",
  44. group: Group.lookup(name: 'Users'),
  45. customer_id: @customer1.id,
  46. owner_id: @agent1.id,
  47. state: Ticket::State.lookup(name: 'new'),
  48. priority: Ticket::Priority.lookup(name: '2 normal'),
  49. updated_by_id: 1,
  50. created_by_id: 1,
  51. )
  52. assert(ticket, 'ticket created')
  53. assert_equal(@customer1.id, ticket.customer.id)
  54. assert_equal(@organization1.id, ticket.organization.id)
  55. # update customer organization
  56. @customer1.organization_id = nil
  57. @customer1.save!
  58. # verify ticket
  59. ticket.reload
  60. assert_nil(ticket.organization_id)
  61. # update customer organization
  62. @customer1.organization_id = @organization1.id
  63. @customer1.save!
  64. # verify ticket
  65. ticket.reload
  66. assert_equal(@organization1.id, ticket.organization_id)
  67. ticket.destroy
  68. end
  69. end