ticket_customer_organization_update_test.rb 2.2 KB

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