Fixed: file uploads broken by r6312 (#8912).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6320 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ead5475001
commit
6db66f7183
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user