From 485335599ac24c95bd0486137a339342c6b2bb76 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 15 Sep 2010 10:38:07 +0200 Subject: [PATCH] fix attachment_removal --- app/models/issue.rb | 7 +++++++ test/functional/attachments_controller_test.rb | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 151447f3..60737fbb 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -315,6 +315,13 @@ class Issue < ActiveRecord::Base end end + # Callback on attachment deletion + def attachment_removed(obj) + init_journal(User.current) + create_journal + last_journal.update_attribute(:changes, {obj.id => [obj.filename, nil]}.to_yaml) + end + # Return true if the issue is closed, otherwise false def closed? self.status.is_closed? diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 22e5d1ea..4e123462 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -97,10 +97,9 @@ class AttachmentsControllerTest < ActionController::TestCase # no referrer assert_redirected_to 'projects/ecookbook' assert_nil Attachment.find_by_id(1) - j = issue.journals.find(:first, :order => 'created_on DESC') - assert_equal 'attachment', j.details.first.property - assert_equal '1', j.details.first.prop_key - assert_equal 'error281.txt', j.details.first.old_value + j = issue.journals.find(:first, :order => 'created_at DESC') + assert_equal [1], j.details.keys + assert_equal 'error281.txt', j.details[1].first end def test_destroy_wiki_page_attachment