From 4ed6e670966f8519112c4ae6fc49b09654fedaee Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 15 Dec 2016 17:05:54 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20issue=20#169=20-=20Allow=20users=20to?= =?UTF-8?q?=20delete=20"Notes=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/observer/ticket/article_changes.rb | 14 +++++++++++ test/unit/ticket_test.rb | 23 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/models/observer/ticket/article_changes.rb b/app/models/observer/ticket/article_changes.rb index 0a0a15845..2ae9294db 100644 --- a/app/models/observer/ticket/article_changes.rb +++ b/app/models/observer/ticket/article_changes.rb @@ -30,6 +30,20 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer record.ticket.save end + def after_destroy(record) + changed = false + if article_count_update(record) + changed = true + end + + # save ticket + if !changed + record.ticket.touch + return + end + record.ticket.save + end + # get article count def article_count_update(record) current_count = record.ticket.article_count diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb index ce777ef82..caaccf7ca 100644 --- a/test/unit/ticket_test.rb +++ b/test/unit/ticket_test.rb @@ -189,7 +189,28 @@ class TicketTest < ActiveSupport::TestCase ticket = Ticket.find(ticket.id) assert_equal(ticket.state.name, 'closed', 'state verify') - assert_equal(ticket.pending_time, nil ) + assert_equal(ticket.pending_time, nil) + + # delete article + article_note = Ticket::Article.create( + ticket_id: ticket.id, + from: 'some person', + subject: 'some note', + body: 'some message', + internal: true, + sender: Ticket::Article::Sender.find_by(name: 'Agent'), + type: Ticket::Article::Type.find_by(name: 'note'), + updated_by_id: 1, + created_by_id: 1, + ) + + ticket = Ticket.find(ticket.id) + assert_equal(ticket.article_count, 7, 'ticket.article_count verify - note') + + article_note.destroy + + ticket = Ticket.find(ticket.id) + assert_equal(ticket.article_count, 6, 'ticket.article_count verify - note') delete = ticket.destroy assert(delete, 'ticket destroy')