Added reset of pending_time on non pending states.

This commit is contained in:
Martin Edenhofer 2015-02-11 23:05:31 +01:00
parent 6fa1d6d2bd
commit a72b777520
2 changed files with 36 additions and 2 deletions

View file

@ -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

View file

@ -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