ticket_priority_test.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. require 'test_helper'
  2. class TicketPriorityTest < ActiveSupport::TestCase
  3. test 'base' do
  4. # check current state
  5. assert_equal(1, Ticket::Priority.where(default_create: true).count)
  6. priority_create = Ticket::Priority.find_by(default_create: true)
  7. # add new state
  8. priority_new2 = Ticket::Priority.create_if_not_exists(
  9. name: 'priority 2',
  10. updated_by_id: 1,
  11. created_by_id: 1,
  12. )
  13. # verify states
  14. assert_equal(1, Ticket::Priority.where(default_create: true).count)
  15. assert_equal(priority_create.id, Ticket::Priority.find_by(default_create: true).id)
  16. # cleanup
  17. priority_new2.destroy
  18. # verify states
  19. assert_equal(1, Ticket::Priority.where(default_create: true).count)
  20. assert_equal(priority_create.id, Ticket::Priority.find_by(default_create: true).id)
  21. # add new state
  22. priority_new3 = Ticket::Priority.create_if_not_exists(
  23. name: 'priority 3',
  24. default_create: true,
  25. updated_by_id: 1,
  26. created_by_id: 1,
  27. )
  28. # verify states
  29. assert_equal(1, Ticket::Priority.where(default_create: true).count)
  30. assert_equal(priority_new3.id, Ticket::Priority.find_by(default_create: true).id)
  31. assert_not_equal(priority_create.id, Ticket::Priority.find_by(default_create: true).id)
  32. # cleanup
  33. priority_new3.destroy
  34. # verify states
  35. assert_equal(1, Ticket::Priority.where(default_create: true).count)
  36. assert_equal(Ticket::Priority.first, Ticket::Priority.find_by(default_create: true))
  37. # cleanup
  38. priority_create.reload
  39. priority_create.default_create = true
  40. priority_create.save!
  41. # verify states
  42. assert_equal(1, Ticket::Priority.where(default_create: true).count)
  43. assert_equal(priority_create.id, Ticket::Priority.find_by(default_create: true).id)
  44. end
  45. end