@@ -52,7 +52,7 class Attachment < ActiveRecord::Base | |||||
52 | cattr_accessor :thumbnails_storage_path |
|
52 | cattr_accessor :thumbnails_storage_path | |
53 | @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") |
|
53 | @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") | |
54 |
|
54 | |||
55 |
before_ |
|
55 | before_create :files_to_final_location | |
56 | after_destroy :delete_from_disk |
|
56 | after_destroy :delete_from_disk | |
57 |
|
57 | |||
58 | # Returns an unsaved copy of the attachment |
|
58 | # Returns an unsaved copy of the attachment | |
@@ -80,9 +80,6 class Attachment < ActiveRecord::Base | |||||
80 | if @temp_file.respond_to?(:content_type) |
|
80 | if @temp_file.respond_to?(:content_type) | |
81 | self.content_type = @temp_file.content_type.to_s.chomp |
|
81 | self.content_type = @temp_file.content_type.to_s.chomp | |
82 | end |
|
82 | end | |
83 | if content_type.blank? && filename.present? |
|
|||
84 | self.content_type = Redmine::MimeType.of(filename) |
|
|||
85 | end |
|
|||
86 | self.filesize = @temp_file.size |
|
83 | self.filesize = @temp_file.size | |
87 | end |
|
84 | end | |
88 | end |
|
85 | end | |
@@ -124,6 +121,10 class Attachment < ActiveRecord::Base | |||||
124 | self.digest = md5.hexdigest |
|
121 | self.digest = md5.hexdigest | |
125 | end |
|
122 | end | |
126 | @temp_file = nil |
|
123 | @temp_file = nil | |
|
124 | ||||
|
125 | if content_type.blank? && filename.present? | |||
|
126 | self.content_type = Redmine::MimeType.of(filename) | |||
|
127 | end | |||
127 | # Don't save the content type if it's longer than the authorized length |
|
128 | # Don't save the content type if it's longer than the authorized length | |
128 | if self.content_type && self.content_type.length > 255 |
|
129 | if self.content_type && self.content_type.length > 255 | |
129 | self.content_type = nil |
|
130 | self.content_type = nil |
@@ -23,6 +23,16 class AttachmentsTest < Redmine::IntegrationTest | |||||
23 | :trackers, :projects_trackers, |
|
23 | :trackers, :projects_trackers, | |
24 | :issue_statuses, :enumerations |
|
24 | :issue_statuses, :enumerations | |
25 |
|
25 | |||
|
26 | def test_upload_should_set_default_content_type | |||
|
27 | log_user('jsmith', 'jsmith') | |||
|
28 | assert_difference 'Attachment.count' do | |||
|
29 | post "/uploads.js?attachment_id=1&filename=foo.txt", "File content", {"CONTENT_TYPE" => 'application/octet-stream'} | |||
|
30 | assert_response :success | |||
|
31 | end | |||
|
32 | attachment = Attachment.order(:id => :desc).first | |||
|
33 | assert_equal 'text/plain', attachment.content_type | |||
|
34 | end | |||
|
35 | ||||
26 | def test_upload_as_js_and_attach_to_an_issue |
|
36 | def test_upload_as_js_and_attach_to_an_issue | |
27 | log_user('jsmith', 'jsmith') |
|
37 | log_user('jsmith', 'jsmith') | |
28 |
|
38 |
General Comments 0
You need to be logged in to leave comments.
Login now