]> source.dussan.org Git - redmine.git/commitdiff
Remove attachment after transaction commit (#20388).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 30 Sep 2015 18:59:51 +0000 (18:59 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 30 Sep 2015 18:59:51 +0000 (18:59 +0000)
Patch by Ivan Zabrovskiy.

git-svn-id: http://svn.redmine.org/redmine/trunk@14630 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
config/application.rb
test/unit/attachment_test.rb

index d1d7c6dd0948427ed1ac4c9a406e1864f3a60bf1..5fa89ee5ae63c748ceeab47f9ac580391b03f99f 100644 (file)
@@ -53,7 +53,7 @@ class Attachment < ActiveRecord::Base
   @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
 
   before_create :files_to_final_location
-  after_destroy :delete_from_disk
+  after_commit :delete_from_disk, :on => :destroy
 
   # Returns an unsaved copy of the attachment
   def copy(attributes=nil)
index 0f75247c1e780ca43fe2179b76d8f69ac6af4eed..90b1adf9aa02322053d00658028e11ce76b021ad 100644 (file)
@@ -47,6 +47,9 @@ module RedmineApp
     # Do not include all helpers
     config.action_controller.include_all_helpers = false
 
+    # Do not supress errors in after_rollback and after_commit callbacks
+    config.active_record.raise_in_transactional_callbacks = true
+
     # XML parameter parser removed from core in Rails 4.0
     # and extracted to actionpack-xml_parser gem
     config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::XmlParamsParser
index 4c3a13151cc4a50f706a7ffa6481e110c6276057..ac09f5658ac787b8a9246da32d21f37e0f99ada3 100644 (file)
@@ -23,6 +23,10 @@ class AttachmentTest < ActiveSupport::TestCase
   fixtures :users, :projects, :roles, :members, :member_roles,
            :enabled_modules, :issues, :trackers, :attachments
 
+  # TODO: remove this with Rails 5 that supports after_commit callbacks
+  # in transactional fixtures (https://github.com/rails/rails/pull/18458)
+  self.use_transactional_fixtures = false
+
   class MockFile
     attr_reader :original_filename, :content_type, :content, :size