diff --git a/app/models/ticket/subject.rb b/app/models/ticket/subject.rb index 53fc18349..3fa3fdd71 100644 --- a/app/models/ticket/subject.rb +++ b/app/models/ticket/subject.rb @@ -22,22 +22,28 @@ returns ticket_hook = Setting.get('ticket_hook') ticket_hook_divider = Setting.get('ticket_hook_divider') ticket_subject_re = Setting.get('ticket_subject_re') - if is_reply && !ticket_subject_re.empty? - subject = "#{ticket_subject_re}: #{subject}" - end # none position if Setting.get('ticket_hook_position') == 'none' + if is_reply && ticket_subject_re.present? + subject = "#{ticket_subject_re}: #{subject}" + end return subject end # right position if Setting.get('ticket_hook_position') == 'right' - return subject + " [#{ticket_hook}#{ticket_hook_divider}#{number}]" + if is_reply && ticket_subject_re.present? + subject = "#{ticket_subject_re}: #{subject}" + end + return "#{subject} [#{ticket_hook}#{ticket_hook_divider}#{number}]" end # left position - "[#{ticket_hook}#{ticket_hook_divider}#{number}] " + subject + if is_reply && ticket_subject_re.present? + return "#{ticket_subject_re}: [#{ticket_hook}#{ticket_hook_divider}#{number}] #{subject}" + end + "[#{ticket_hook}#{ticket_hook_divider}#{number}] #{subject}" end =begin diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb index ec07825d3..dcb2d9f9b 100644 --- a/test/unit/ticket_test.rb +++ b/test/unit/ticket_test.rb @@ -289,7 +289,7 @@ class TicketTest < ActiveSupport::TestCase test 'ticket subject' do - ticket1 = Ticket.create( + ticket = Ticket.create( title: 'subject test 1', group: Group.lookup(name: 'Users'), customer_id: 2, @@ -298,12 +298,48 @@ class TicketTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - assert_equal('subject test 1', ticket1.title) - assert_equal("ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1')) - assert_equal("RE: ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1', true)) - assert_equal("RE: ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build(' ABC subject test 1', true)) - assert_equal("RE: ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1 ', true)) - ticket1.destroy + assert_equal('subject test 1', ticket.title) + assert_equal("ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1')) + assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1', true)) + assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build(' ABC subject test 1', true)) + assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1 ', true)) + ticket.destroy + + Setting.set('ticket_hook_position', 'left') + + ticket = Ticket.create( + title: 'subject test 1', + group: Group.lookup(name: 'Users'), + customer_id: 2, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + updated_by_id: 1, + created_by_id: 1, + ) + assert_equal('subject test 1', ticket.title) + assert_equal("[Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1')) + assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1', true)) + assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build(' ABC subject test 1', true)) + assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1 ', true)) + ticket.destroy + + Setting.set('ticket_hook_position', 'none') + + ticket = Ticket.create( + title: 'subject test 1', + group: Group.lookup(name: 'Users'), + customer_id: 2, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + updated_by_id: 1, + created_by_id: 1, + ) + assert_equal('subject test 1', ticket.title) + assert_equal('ABC subject test 1', ticket.subject_build('ABC subject test 1')) + assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1', true)) + assert_equal('RE: ABC subject test 1', ticket.subject_build(' ABC subject test 1', true)) + assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1 ', true)) + ticket.destroy end