@@ -51,7 +51,7 class Attachment < ActiveRecord::Base | |||||
51 | cattr_accessor :thumbnails_storage_path |
|
51 | cattr_accessor :thumbnails_storage_path | |
52 | @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") |
|
52 | @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") | |
53 |
|
53 | |||
54 |
before_ |
|
54 | before_create :files_to_final_location | |
55 | after_destroy :delete_from_disk |
|
55 | after_destroy :delete_from_disk | |
56 |
|
56 | |||
57 | # Returns an unsaved copy of the attachment |
|
57 | # Returns an unsaved copy of the attachment | |
@@ -79,9 +79,6 class Attachment < ActiveRecord::Base | |||||
79 | if @temp_file.respond_to?(:content_type) |
|
79 | if @temp_file.respond_to?(:content_type) | |
80 | self.content_type = @temp_file.content_type.to_s.chomp |
|
80 | self.content_type = @temp_file.content_type.to_s.chomp | |
81 | end |
|
81 | end | |
82 | if content_type.blank? && filename.present? |
|
|||
83 | self.content_type = Redmine::MimeType.of(filename) |
|
|||
84 | end |
|
|||
85 | self.filesize = @temp_file.size |
|
82 | self.filesize = @temp_file.size | |
86 | end |
|
83 | end | |
87 | end |
|
84 | end | |
@@ -123,6 +120,10 class Attachment < ActiveRecord::Base | |||||
123 | self.digest = md5.hexdigest |
|
120 | self.digest = md5.hexdigest | |
124 | end |
|
121 | end | |
125 | @temp_file = nil |
|
122 | @temp_file = nil | |
|
123 | ||||
|
124 | if content_type.blank? && filename.present? | |||
|
125 | self.content_type = Redmine::MimeType.of(filename) | |||
|
126 | end | |||
126 | # Don't save the content type if it's longer than the authorized length |
|
127 | # Don't save the content type if it's longer than the authorized length | |
127 | if self.content_type && self.content_type.length > 255 |
|
128 | if self.content_type && self.content_type.length > 255 | |
128 | self.content_type = nil |
|
129 | self.content_type = nil |
@@ -23,6 +23,16 class AttachmentsTest < ActionController::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