From d85565ef9e3516f5281654dc3e422fded39e71ad Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 23 May 2013 08:01:30 +0200 Subject: [PATCH] Improved error handling of already deleted objects. --- app/models/observer/ticket/notification.rb | 12 +++++++++++- test/unit/twitter_test.rb | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index b3bc869b8..f07afc9da 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -17,10 +17,20 @@ class Observer::Ticket::Notification < ActiveRecord::Observer # get current state of objects if event[:name] == 'Ticket::Article' article = Ticket::Article.lookup( :id => event[:id] ) + + # next if article is already deleted + next if !article + ticket = article.ticket - else + elsif event[:name] == 'Ticket' ticket = Ticket.lookup( :id => event[:id] ) + + # next if ticket is already deleted + next if !ticket + article = ticket.articles[-1] + else + raise "unknown object for notification #{event[:name]}" end # send new ticket notification to agents diff --git a/test/unit/twitter_test.rb b/test/unit/twitter_test.rb index ee9fee0a9..e14d47807 100644 --- a/test/unit/twitter_test.rb +++ b/test/unit/twitter_test.rb @@ -150,7 +150,7 @@ class TwitterTest < ActiveSupport::TestCase text, ) assert( dm, "dm with ##{hash} created" ) - sleep 20 + sleep 10 # fetch check system account Channel.fetch