subject_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require 'rails_helper'
  2. RSpec.describe Ticket::Subject do
  3. let(:ticket) { create(:ticket) }
  4. describe '.subject_build' do
  5. it 'build subject based on new title' do
  6. expect(ticket.subject_build('other title')).to eq("other title [Ticket##{ticket.number}]")
  7. end
  8. it 'build subject based on new title with ticket_hook_position left' do
  9. Setting.set('ticket_hook_position', 'left')
  10. expect(ticket.subject_build('other title')).to eq("[Ticket##{ticket.number}] other title")
  11. end
  12. it 'build subject based on new title without ticket_hook_position' do
  13. Setting.set('ticket_hook_position', '')
  14. expect(ticket.subject_build('other title')).to eq('other title')
  15. end
  16. it 'build subject based with forward argument' do
  17. expect(ticket.subject_build('other title', 'forward')).to eq("FWD: other title [Ticket##{ticket.number}]")
  18. end
  19. it 'build subject based with reply argument' do
  20. expect(ticket.subject_build('other title', 'reply')).to eq("RE: other title [Ticket##{ticket.number}]")
  21. end
  22. end
  23. describe '.subject_clean' do
  24. it 'cleanup subject with undefined string' do
  25. expect(ticket.subject_clean(nil)).to eq('')
  26. end
  27. it 'cleanup subject with empty string' do
  28. expect(ticket.subject_clean('')).to eq('')
  29. end
  30. it 'cleanup subject with long string which need to be truncated by [...]' do
  31. expect(ticket.subject_clean('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890')).to eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[...]')
  32. end
  33. it 'cleanup subject with regular ticket#' do
  34. expect(ticket.subject_clean("something [Ticket##{ticket.number}]")).to eq('something')
  35. end
  36. it 'cleanup subject with regular ticket# multiple time' do
  37. expect(ticket.subject_clean("[Ticket##{ticket.number}] [Ticket##{ticket.number}] something [Ticket##{ticket.number}]")).to eq('something')
  38. end
  39. it 'cleanup subject with foreign ticket#' do
  40. expect(ticket.subject_clean('something [Ticket#123456]')).to eq('something [Ticket#123456]')
  41. end
  42. it 'cleanup subject with some reply signs' do
  43. expect(ticket.subject_clean('RE: RE: Re[5]: something [Ticket#123456]')).to eq('something [Ticket#123456]')
  44. end
  45. end
  46. end