summaryrefslogtreecommitdiffstats
path: root/test/unit/attachment_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-11-29 13:41:53 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-11-29 13:41:53 +0000
commit288c014aa7aa608751dbafeb2c8b358f2fec5c22 (patch)
tree68a5705092edc501641630fa960cee368d27ca88 /test/unit/attachment_test.rb
parent3c7f638a834d6d9717e3d8babe3bab6af5100994 (diff)
downloadredmine-288c014aa7aa608751dbafeb2c8b358f2fec5c22.tar.gz
redmine-288c014aa7aa608751dbafeb2c8b358f2fec5c22.zip
Edit attachments after upload (#1326).
git-svn-id: http://svn.redmine.org/redmine/trunk@13665 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/attachment_test.rb')
-rw-r--r--test/unit/attachment_test.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index 6a077fcc2..29c433f7b 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -250,6 +250,45 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal 'text/plain', attachment.content_type
end
+ def test_update_attachments
+ attachments = Attachment.where(:id => [2, 3]).to_a
+
+ assert Attachment.update_attachments(attachments, {
+ '2' => {:filename => 'newname.txt', :description => 'New description'},
+ 3 => {:filename => 'othername.txt'}
+ })
+
+ attachment = Attachment.find(2)
+ assert_equal 'newname.txt', attachment.filename
+ assert_equal 'New description', attachment.description
+
+ attachment = Attachment.find(3)
+ assert_equal 'othername.txt', attachment.filename
+ end
+
+ def test_update_attachments_with_failure
+ attachments = Attachment.where(:id => [2, 3]).to_a
+
+ assert !Attachment.update_attachments(attachments, {
+ '2' => {:filename => '', :description => 'New description'},
+ 3 => {:filename => 'othername.txt'}
+ })
+
+ attachment = Attachment.find(3)
+ assert_equal 'logo.gif', attachment.filename
+ end
+
+ def test_update_attachments_should_sanitize_filename
+ attachments = Attachment.where(:id => 2).to_a
+
+ assert Attachment.update_attachments(attachments, {
+ 2 => {:filename => 'newname?.txt'},
+ })
+
+ attachment = Attachment.find(2)
+ assert_equal 'newname_.txt', attachment.filename
+ end
+
def test_latest_attach
set_fixtures_attachments_directory
a1 = Attachment.find(16)