From a72b777520d0fd0c7aa414e3f5114042b0bdf72b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 11 Feb 2015 23:05:31 +0100 Subject: [PATCH] Added reset of pending_time on non pending states. --- app/models/ticket.rb | 19 +++++++++++++++++-- test/unit/ticket_test.rb | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index a0545c609..c5d60dc7a 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -15,7 +15,7 @@ class Ticket < ApplicationModel extend Ticket::Search before_create :check_generate, :check_defaults, :check_title - before_update :check_defaults, :check_title + before_update :check_defaults, :check_title, :reset_pending_time before_destroy :destroy_dependencies notify_clients_support @@ -187,10 +187,25 @@ returns end end + def reset_pending_time + + # ignore if no state has changed + return if !self.changes['state_id'] + + # check if new state isn't pending* + current_state = Ticket::State.lookup( :id => self.state_id ) + current_state_type = Ticket::StateType.lookup( :id => current_state.state_type_id ) + + # in case, set pending_time to nil + if current_state_type.name !~ /^pending/i + self.pending_time = nil + end + end + def destroy_dependencies # delete articles self.articles.destroy_all end -end +end \ No newline at end of file diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb index 4443a0c5b..efb0e5da1 100644 --- a/test/unit/ticket_test.rb +++ b/test/unit/ticket_test.rb @@ -101,6 +101,25 @@ class TicketTest < ActiveSupport::TestCase assert( ticket.close_time, 'ticket.close_time verify - state update' ) + # set pending time + ticket.state_id = Ticket::State.where(:name => 'pending reminder').first.id + ticket.pending_time = Time.parse("1977-10-27 22:00:00 +0000") + ticket.save + + ticket = Ticket.find(ticket.id) + assert_equal( ticket.state.name, 'pending reminder', 'state verify' ) + assert_equal( ticket.pending_time, Time.parse("1977-10-27 22:00:00 +0000"), 'pending_time verify' ) + + + # reset pending state, should also reset pending time + ticket.state_id = Ticket::State.where(:name => 'closed').first.id + ticket.save + + ticket = Ticket.find(ticket.id) + assert_equal( ticket.state.name, 'closed', 'state verify' ) + assert_equal( ticket.pending_time, nil ) + + delete = ticket.destroy assert( delete, "ticket destroy" ) end