]> source.dussan.org Git - redmine.git/commitdiff
Fixed: file uploads broken by r6312 (#8912).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 29 Jul 2011 15:28:59 +0000 (15:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 29 Jul 2011 15:28:59 +0000 (15:28 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6320 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
test/unit/attachment_test.rb

index 7e3a915815830cc2cdf76822e12cb1e32d2fae17..d16d5cddf02f37b7cb9dd3b8088280f39a49ed27 100644 (file)
@@ -74,7 +74,7 @@ class Attachment < ActiveRecord::Base
   # and computes its MD5 hash
   def before_save
     if @temp_file && (@temp_file.size > 0)
-      logger.debug("saving '#{self.diskfile}'")
+      logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)")
       md5 = Digest::MD5.new
       File.open(diskfile, "wb") do |f|
         buffer = ""
@@ -85,6 +85,7 @@ class Attachment < ActiveRecord::Base
       end
       self.digest = md5.hexdigest
     end
+    @temp_file = nil
     # 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
index 4a57669c17bca48f4fd606437ddfb45c07c075a9..d433ae7572ea57ede3feefa531b036402887484e 100644 (file)
@@ -36,6 +36,7 @@ class AttachmentTest < ActiveSupport::TestCase
     assert_equal 0, a.downloads
     assert_equal '1478adae0d4eb06d35897518540e25d6', a.digest
     assert File.exist?(a.diskfile)
+    assert_equal 59, File.size(a.diskfile)
   end
 
   def test_create_should_auto_assign_content_type
@@ -64,7 +65,27 @@ class AttachmentTest < ActiveSupport::TestCase
     assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
   end
 
-  context "Attachmnet#attach_files" do
+  context "Attachmnet.attach_files" do
+    should "attach the file" do
+      issue = Issue.first
+      assert_difference 'Attachment.count' do
+        Attachment.attach_files(issue,
+          '1' => {
+            'file' => uploaded_test_file('testfile.txt', 'text/plain'),
+            'description' => 'test'
+          })
+      end
+      
+      attachment = Attachment.first(:order => 'id DESC')
+      assert_equal issue, attachment.container
+      assert_equal 'testfile.txt', attachment.filename
+      assert_equal 59, attachment.filesize
+      assert_equal 'test', attachment.description
+      assert_equal 'text/plain', attachment.content_type
+      assert File.exists?(attachment.diskfile)
+      assert_equal 59, File.size(attachment.diskfile)
+    end
+    
     should "add unsaved files to the object as unsaved attachments" do
       # Max size of 0 to force Attachment creation failures
       with_settings(:attachment_max_size => 0) do