Merged r13787 (#18667).

git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@13803 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2014-12-26 10:46:29 +00:00
parent 3c7aa17b5c
commit 7ca5df0836
2 changed files with 15 additions and 4 deletions

View File

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

View File

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