]> source.dussan.org Git - redmine.git/commitdiff
Merged r16341 (#25115).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 28 Feb 2017 20:00:17 +0000 (20:00 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 28 Feb 2017 20:00:17 +0000 (20:00 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@16342 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
test/integration/api_test/attachments_test.rb

index 4bc674f8d752dba91a95ebd300b6c45b89baa3ac..2b13118b1610e5ae93bfc320dbc2a9c7446249c2 100644 (file)
@@ -82,7 +82,6 @@ class Attachment < ActiveRecord::Base
   def file=(incoming_file)
     unless incoming_file.nil?
       @temp_file = incoming_file
-      if @temp_file.size > 0
         if @temp_file.respond_to?(:original_filename)
           self.filename = @temp_file.original_filename
           self.filename.force_encoding("UTF-8")
@@ -91,7 +90,6 @@ class Attachment < ActiveRecord::Base
           self.content_type = @temp_file.content_type.to_s.chomp
         end
         self.filesize = @temp_file.size
-      end
     end
   end
 
@@ -107,7 +105,7 @@ class Attachment < ActiveRecord::Base
   # Copies the temporary file to its final location
   # and computes its MD5 hash
   def files_to_final_location
-    if @temp_file && (@temp_file.size > 0)
+    if @temp_file
       self.disk_directory = target_directory
       self.disk_filename = Attachment.disk_filename(filename, disk_directory)
       logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)") if logger
index bc4242564e8ba12d44b1d5d8db71acfbee3f39cf..a6ca091703511eed78e8f16299132d47dabd1acf 100644 (file)
@@ -88,7 +88,6 @@ module Redmine
               next unless attachment.is_a?(Hash)
               a = nil
               if file = attachment['file']
-                next unless file.size > 0
                 a = Attachment.create(:file => file, :author => author)
               elsif token = attachment['token']
                 a = Attachment.find_by_token(token)
index 640a78290df0d6833ea8518098fadbfebc0c7617..8fa45cdbbe29e225edbf71d7e5acd6500fab8d85 100644 (file)
@@ -171,4 +171,23 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
       end
     end
   end
+
+  test "POST /uploads.json should create an empty file and return a valid token" do
+    set_tmp_attachments_directory
+    assert_difference 'Attachment.count' do
+      post '/uploads.json', '', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
+      assert_response :created
+
+    end
+
+    json = ActiveSupport::JSON.decode(response.body)
+    assert_kind_of Hash, json['upload']
+    token = json['upload']['token']
+    assert token.present?
+
+    assert attachment = Attachment.find_by_token(token)
+    assert_equal 0, attachment.filesize
+    assert attachment.digest.present?
+    assert File.exist? attachment.diskfile
+  end
 end