@@ -150,7 +150,13 class Attachment < ActiveRecord::Base | |||||
150 | :file => file, |
|
150 | :file => file, | |
151 | :description => attachment['description'].to_s.strip, |
|
151 | :description => attachment['description'].to_s.strip, | |
152 | :author => User.current) |
|
152 | :author => User.current) | |
153 | a.new_record? ? (obj.unsaved_attachments << a) : (attached << a) |
|
153 | ||
|
154 | if a.new_record? | |||
|
155 | obj.unsaved_attachments ||= [] | |||
|
156 | obj.unsaved_attachments << a | |||
|
157 | else | |||
|
158 | attached << a | |||
|
159 | end | |||
154 | end |
|
160 | end | |
155 | end |
|
161 | end | |
156 | {:files => attached, :unsaved => obj.unsaved_attachments} |
|
162 | {:files => attached, :unsaved => obj.unsaved_attachments} |
@@ -63,4 +63,30 class AttachmentTest < ActiveSupport::TestCase | |||||
63 | assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1] |
|
63 | assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1] | |
64 | assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1] |
|
64 | assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1] | |
65 | end |
|
65 | end | |
|
66 | ||||
|
67 | context "Attachmnet#attach_files" do | |||
|
68 | should "add unsaved files to the object as unsaved attachments" do | |||
|
69 | # Max size of 0 to force Attachment creation failures | |||
|
70 | with_settings(:attachment_max_size => 0) do | |||
|
71 | # Mock out a file | |||
|
72 | @file = 'a_file.png' | |||
|
73 | @file.stubs(:size).returns(32) | |||
|
74 | @file.stubs(:original_filename).returns('a_file.png') | |||
|
75 | @file.stubs(:content_type).returns('image/png') | |||
|
76 | @file.stubs(:read).returns(false) | |||
|
77 | ||||
|
78 | @project = Project.generate! | |||
|
79 | response = Attachment.attach_files(@project, { | |||
|
80 | '1' => {'file' => @file, 'description' => 'test'}, | |||
|
81 | '2' => {'file' => @file, 'description' => 'test'} | |||
|
82 | }) | |||
|
83 | ||||
|
84 | assert response[:unsaved].present? | |||
|
85 | assert_equal 2, response[:unsaved].length | |||
|
86 | assert response[:unsaved].first.new_record? | |||
|
87 | assert response[:unsaved].second.new_record? | |||
|
88 | assert_equal response[:unsaved], @project.unsaved_attachments | |||
|
89 | end | |||
|
90 | end | |||
|
91 | end | |||
66 | end |
|
92 | end |
General Comments 0
You need to be logged in to leave comments.
Login now