From e3277a3b8ab8a859b9532d772f9dafcc73c3e764 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 23 Sep 2015 01:50:38 +0200 Subject: [PATCH] Fixed first response detection. --- app/models/observer/ticket/article_changes.rb | 12 ++++----- test/unit/ticket_sla_test.rb | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/models/observer/ticket/article_changes.rb b/app/models/observer/ticket/article_changes.rb index d4beac442..a4512a759 100644 --- a/app/models/observer/ticket/article_changes.rb +++ b/app/models/observer/ticket/article_changes.rb @@ -32,9 +32,9 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer return true if record.internal # if sender is not agent - sender = Ticket::Article::Sender.lookup( id: record.sender_id ) - type = Ticket::Article::Type.lookup( id: record.type_id ) - return true if sender.name != 'Agent' && type.name !~ /^phone/ + sender = Ticket::Article::Sender.lookup(id: record.sender_id) + type = Ticket::Article::Type.lookup(id: record.type_id) + return true if sender.name != 'Agent' # if article is a message to customer return true if !type.communication @@ -52,7 +52,7 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer def sender_type_update(record) # ignore if create channel is already set - count = Ticket::Article.where( ticket_id: record.ticket_id ).count + count = Ticket::Article.where(ticket_id: record.ticket_id).count return if count > 1 record.ticket.create_article_type_id = record.type_id @@ -66,10 +66,10 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer return true if record.internal # if article is a message to customer - return true if !Ticket::Article::Type.lookup( id: record.type_id ).communication + return true if !Ticket::Article::Type.lookup(id: record.type_id).communication # if sender is customer - sender = Ticket::Article::Sender.lookup( id: record.sender_id ) + sender = Ticket::Article::Sender.lookup(id: record.sender_id) if sender.name == 'Customer' # check if last communication is done by agent, else do not set last_contact_customer diff --git a/test/unit/ticket_sla_test.rb b/test/unit/ticket_sla_test.rb index 17668f399..1b51e56e1 100644 --- a/test/unit/ticket_sla_test.rb +++ b/test/unit/ticket_sla_test.rb @@ -394,7 +394,30 @@ class TicketSlaTest < ActiveSupport::TestCase assert_equal( ticket.last_contact.to_s, article_inbound.created_at.to_s, 'ticket.last_contact verify - inbound' ) assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' ) assert_equal( ticket.last_contact_agent, nil, 'ticket.last_contact_agent verify - inbound' ) - assert_equal( ticket.first_response.to_s, article_inbound.created_at.to_s, 'ticket.first_response verify - inbound' ) + assert_equal( ticket.first_response, nil, 'ticket.first_response verify - inbound' ) + assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' ) + + # create outbound article + article_outbound = Ticket::Article.create( + ticket_id: ticket.id, + from: 'some_sender@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Agent').first, + type: Ticket::Article::Type.where(name: 'phone').first, + updated_by_id: 1, + created_by_id: 1, + created_at: '2013-03-28 23:55:00 UTC', + updated_at: '2013-03-28 23:55:00 UTC', + ) + ticket = Ticket.find(ticket.id) + assert_equal( ticket.article_count, 2, 'ticket.article_count verify - inbound' ) + assert_equal( ticket.last_contact.to_s, article_outbound.created_at.to_s, 'ticket.last_contact verify - inbound' ) + assert_equal( ticket.last_contact_customer.to_s, article_inbound.created_at.to_s, 'ticket.last_contact_customer verify - inbound' ) + assert_equal( ticket.last_contact_agent.to_s, article_outbound.created_at.to_s, 'ticket.last_contact_agent verify - inbound' ) + assert_equal( ticket.first_response.to_s, article_outbound.created_at.to_s, 'ticket.first_response verify - inbound' ) assert_equal( ticket.close_time, nil, 'ticket.close_time verify - inbound' ) delete = sla.destroy