diff options
-rw-r--r-- | app/models/attachment.rb | 9 | ||||
-rw-r--r-- | 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 42690912a..a008c4a29 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -52,7 +52,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 @@ -80,9 +80,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 @@ -124,6 +121,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 47577cbd0..646382a42 100644 --- a/test/integration/attachments_test.rb +++ b/test/integration/attachments_test.rb @@ -23,6 +23,16 @@ class AttachmentsTest < Redmine::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') |