ticket_customer_organization_update_test.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketCustomerOrganizationUpdateTest < 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: '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. 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 = Ticket.find(ticket.id)
  59. assert_equal( nil, ticket.organization_id )
  60. # update customer organization
  61. customer1.organization_id = organization1.id
  62. customer1.save
  63. # verify ticket
  64. ticket = Ticket.find(ticket.id)
  65. assert_equal( organization1.id, ticket.organization_id )
  66. ticket.destroy
  67. end
  68. end