From 7ca5df08360e8defc30fabc272f44e8c5215fc14 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 26 Dec 2014 10:46:29 +0000 Subject: [PATCH] Merged r13787 (#18667). git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@13803 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 9 +++++---- test/integration/attachments_test.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f36f7cccf..d09ccb86a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -51,7 +51,7 @@ class Attachment < ActiveRecord::Base cattr_accessor :thumbnails_storage_path @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") - before_save :files_to_final_location + before_create :files_to_final_location after_destroy :delete_from_disk # Returns an unsaved copy of the attachment @@ -79,9 +79,6 @@ class Attachment < ActiveRecord::Base if @temp_file.respond_to?(:content_type) self.content_type = @temp_file.content_type.to_s.chomp end - if content_type.blank? && filename.present? - self.content_type = Redmine::MimeType.of(filename) - end self.filesize = @temp_file.size end end @@ -123,6 +120,10 @@ class Attachment < ActiveRecord::Base self.digest = md5.hexdigest end @temp_file = nil + + if content_type.blank? && filename.present? + self.content_type = Redmine::MimeType.of(filename) + end # Don't save the content type if it's longer than the authorized length if self.content_type && self.content_type.length > 255 self.content_type = nil diff --git a/test/integration/attachments_test.rb b/test/integration/attachments_test.rb index 1a2b92da7..b9fde370a 100644 --- a/test/integration/attachments_test.rb +++ b/test/integration/attachments_test.rb @@ -23,6 +23,16 @@ class AttachmentsTest < ActionController::IntegrationTest :trackers, :projects_trackers, :issue_statuses, :enumerations + def test_upload_should_set_default_content_type + log_user('jsmith', 'jsmith') + assert_difference 'Attachment.count' do + post "/uploads.js?attachment_id=1&filename=foo.txt", "File content", {"CONTENT_TYPE" => 'application/octet-stream'} + assert_response :success + end + attachment = Attachment.order(:id => :desc).first + assert_equal 'text/plain', attachment.content_type + end + def test_upload_as_js_and_attach_to_an_issue log_user('jsmith', 'jsmith') -- 2.39.5