ticket_priority_test.rb 1.8 KB

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