subject_spec.rb 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Subject do
  4. let(:ticket) { create(:ticket) }
  5. describe '.subject_build' do
  6. it 'build subject based on new title' do
  7. expect(ticket.subject_build('other title')).to eq("other title [Ticket##{ticket.number}]")
  8. end
  9. it 'build subject based on new title with ticket_hook_position left' do
  10. Setting.set('ticket_hook_position', 'left')
  11. expect(ticket.subject_build('other title')).to eq("[Ticket##{ticket.number}] other title")
  12. end
  13. it 'build subject based on new title without ticket_hook_position' do
  14. Setting.set('ticket_hook_position', '')
  15. expect(ticket.subject_build('other title')).to eq('other title')
  16. end
  17. it 'build subject based with forward argument' do
  18. expect(ticket.subject_build('other title', 'forward')).to eq("FWD: other title [Ticket##{ticket.number}]")
  19. end
  20. it 'build subject based with reply argument' do
  21. expect(ticket.subject_build('other title', 'reply')).to eq("RE: other title [Ticket##{ticket.number}]")
  22. end
  23. end
  24. describe '.subject_clean' do
  25. it 'cleanup subject with undefined string' do
  26. expect(ticket.subject_clean(nil)).to eq('')
  27. end
  28. it 'cleanup subject with empty string' do
  29. expect(ticket.subject_clean('')).to eq('')
  30. end
  31. it 'cleanup subject with long string which needs to be truncated by [...]' do
  32. expect(ticket.subject_clean('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890')).to eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[...]')
  33. end
  34. it 'cleanup subject with regular ticket#' do
  35. expect(ticket.subject_clean("something [Ticket##{ticket.number}]")).to eq('something')
  36. end
  37. it 'cleanup subject with regular ticket# in ()' do
  38. expect(ticket.subject_clean("something (Ticket##{ticket.number})")).to eq('something')
  39. end
  40. it 'cleanup subject with ticket# with a colon' do
  41. expect(ticket.subject_clean("something (Ticket#:#{ticket.number})")).to eq('something')
  42. end
  43. it 'cleanup subject with ticket# with a colon and space' do
  44. expect(ticket.subject_clean("something (Ticket#: #{ticket.number})")).to eq('something')
  45. end
  46. it 'cleanup subject with ticket# with a custom divider' do
  47. Setting.set('ticket_hook_divider', '---')
  48. expect(ticket.subject_clean("something (Ticket#---#{ticket.number})")).to eq('something')
  49. end
  50. it 'cleanup subject with regular ticket# multiple time' do
  51. expect(ticket.subject_clean("[Ticket##{ticket.number}] [Ticket##{ticket.number}] something [Ticket##{ticket.number}]")).to eq('something')
  52. end
  53. it 'cleanup subject with foreign ticket#' do
  54. expect(ticket.subject_clean('something [Ticket#123456]')).to eq('something [Ticket#123456]')
  55. end
  56. it 'cleanup subject with some reply signs' do
  57. expect(ticket.subject_clean('RE: RE: Re[5]: something [Ticket#123456]')).to eq('something [Ticket#123456]')
  58. end
  59. end
  60. end