Fixed issue #169 - Allow users to delete "Notes”.

This commit is contained in:
Martin Edenhofer 2016-12-15 17:05:54 +01:00
parent ab4a408d3e
commit 4ed6e67096
2 changed files with 36 additions and 1 deletions

View file

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

View file

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