Commit c56c0f41 authored by Eric Davis's avatar Eric Davis

Fix a nil error when a Project cannot save attachments.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3772 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 759858d1
......@@ -150,7 +150,13 @@ class Attachment < ActiveRecord::Base
:file => file,
:description => attachment['description'].to_s.strip,
:author => User.current)
a.new_record? ? (obj.unsaved_attachments << a) : (attached << a)
if a.new_record?
obj.unsaved_attachments ||= []
obj.unsaved_attachments << a
else
attached << a
end
end
end
{:files => attached, :unsaved => obj.unsaved_attachments}
......
......@@ -63,4 +63,30 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
end
context "Attachmnet#attach_files" do
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
# Mock out a file
@file = 'a_file.png'
@file.stubs(:size).returns(32)
@file.stubs(:original_filename).returns('a_file.png')
@file.stubs(:content_type).returns('image/png')
@file.stubs(:read).returns(false)
@project = Project.generate!
response = Attachment.attach_files(@project, {
'1' => {'file' => @file, 'description' => 'test'},
'2' => {'file' => @file, 'description' => 'test'}
})
assert response[:unsaved].present?
assert_equal 2, response[:unsaved].length
assert response[:unsaved].first.new_record?
assert response[:unsaved].second.new_record?
assert_equal response[:unsaved], @project.unsaved_attachments
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment