##// END OF EJS Templates
Fixed: file uploads broken by r6312 (#8912)....
Jean-Philippe Lang -
r6200:6db66f718368
parent child
Show More
@@ -74,7 +74,7 class Attachment < ActiveRecord::Base
74 # and computes its MD5 hash
74 # and computes its MD5 hash
75 def before_save
75 def before_save
76 if @temp_file && (@temp_file.size > 0)
76 if @temp_file && (@temp_file.size > 0)
77 logger.debug("saving '#{self.diskfile}'")
77 logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)")
78 md5 = Digest::MD5.new
78 md5 = Digest::MD5.new
79 File.open(diskfile, "wb") do |f|
79 File.open(diskfile, "wb") do |f|
80 buffer = ""
80 buffer = ""
@@ -85,6 +85,7 class Attachment < ActiveRecord::Base
85 end
85 end
86 self.digest = md5.hexdigest
86 self.digest = md5.hexdigest
87 end
87 end
88 @temp_file = nil
88 # Don't save the content type if it's longer than the authorized length
89 # Don't save the content type if it's longer than the authorized length
89 if self.content_type && self.content_type.length > 255
90 if self.content_type && self.content_type.length > 255
90 self.content_type = nil
91 self.content_type = nil
@@ -36,6 +36,7 class AttachmentTest < ActiveSupport::TestCase
36 assert_equal 0, a.downloads
36 assert_equal 0, a.downloads
37 assert_equal '1478adae0d4eb06d35897518540e25d6', a.digest
37 assert_equal '1478adae0d4eb06d35897518540e25d6', a.digest
38 assert File.exist?(a.diskfile)
38 assert File.exist?(a.diskfile)
39 assert_equal 59, File.size(a.diskfile)
39 end
40 end
40
41
41 def test_create_should_auto_assign_content_type
42 def test_create_should_auto_assign_content_type
@@ -64,7 +65,27 class AttachmentTest < ActiveSupport::TestCase
64 assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
65 assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
65 end
66 end
66
67
67 context "Attachmnet#attach_files" do
68 context "Attachmnet.attach_files" do
69 should "attach the file" do
70 issue = Issue.first
71 assert_difference 'Attachment.count' do
72 Attachment.attach_files(issue,
73 '1' => {
74 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
75 'description' => 'test'
76 })
77 end
78
79 attachment = Attachment.first(:order => 'id DESC')
80 assert_equal issue, attachment.container
81 assert_equal 'testfile.txt', attachment.filename
82 assert_equal 59, attachment.filesize
83 assert_equal 'test', attachment.description
84 assert_equal 'text/plain', attachment.content_type
85 assert File.exists?(attachment.diskfile)
86 assert_equal 59, File.size(attachment.diskfile)
87 end
88
68 should "add unsaved files to the object as unsaved attachments" do
89 should "add unsaved files to the object as unsaved attachments" do
69 # Max size of 0 to force Attachment creation failures
90 # Max size of 0 to force Attachment creation failures
70 with_settings(:attachment_max_size => 0) do
91 with_settings(:attachment_max_size => 0) do
General Comments 0
You need to be logged in to leave comments. Login now