diff --git a/lib/escalation.rb b/lib/escalation.rb index d1cbbd36f..839193daa 100644 --- a/lib/escalation.rb +++ b/lib/escalation.rb @@ -39,7 +39,7 @@ class Escalation end def calculatable? - !escalation_disabled? || preferences.close_at_changed?(ticket) + !escalation_disabled? || preferences.close_at_changed?(ticket) || preferences.last_contact_at_changed?(ticket) end def calculate! diff --git a/lib/escalation/ticket_preferences.rb b/lib/escalation/ticket_preferences.rb index 2a79a14f2..6bca1d8ec 100644 --- a/lib/escalation/ticket_preferences.rb +++ b/lib/escalation/ticket_preferences.rb @@ -3,7 +3,7 @@ class Escalation KEYS = %i[escalation_disabled first_response_at last_update_at close_at escalation_at sla_id sla_updated_at - calendar_id calendar_updated_at].freeze + calendar_id calendar_updated_at last_contact_at].freeze attr_reader :hash @@ -39,6 +39,10 @@ class Escalation @hash[:close_at] != ticket.close_at end + def last_contact_at_changed?(ticket) + @hash[:last_contact_at] != ticket.last_contact_at + end + def property_changes?(ticket) %i[first_response_at last_update_at close_at].any? { |elem| send("#{elem}_changed?", ticket) } end @@ -60,6 +64,7 @@ class Escalation first_response_at: ticket.first_response_at, last_update_at: ticket.last_original_update_at, close_at: ticket.close_at, + last_contact_at: ticket.last_contact_at, sla_id: sla&.id, sla_updated_at: sla&.updated_at, calendar_id: sla&.calendar&.id, diff --git a/spec/lib/escalation_spec.rb b/spec/lib/escalation_spec.rb index 829557bbf..edc181aa0 100644 --- a/spec/lib/escalation_spec.rb +++ b/spec/lib/escalation_spec.rb @@ -67,6 +67,14 @@ RSpec.describe ::Escalation do expect(instance).to be_calculatable end + + it 'true when response to ticket comes while ticket has pending reminder' do + ticket.update(state: Ticket::State.find_by(name: 'pending reminder')) + + without_update_escalation_information_callback { create(:'ticket/article', :outbound_email, ticket: ticket) } + + expect(instance).to be_calculatable + end end describe '#calculate' do diff --git a/spec/models/ticket/escalation_examples.rb b/spec/models/ticket/escalation_examples.rb index f2d7f0eef..0ad9f8a6c 100644 --- a/spec/models/ticket/escalation_examples.rb +++ b/spec/models/ticket/escalation_examples.rb @@ -65,6 +65,17 @@ RSpec.shared_examples 'Ticket::Escalation' do expect(ticket.close_diff_in_min).to be_nil end + context 'with first response time resolved by answer + state pending reminder' do + before do + ticket.update(state: Ticket::State.find_by(name: 'pending reminder')) + create(:'ticket/article', :outbound_email, ticket: ticket, created_at: '2013-03-21 09:45:00 UTC', updated_at: '2013-03-21 09:45:00 UTC') + end + + it 'does set first_response_diff_in_min' do + expect(ticket.reload.first_response_diff_in_min).to eq(45) + end + end + context 'with first response in time' do before do