diff options
author | Go MAEDA <maeda@farend.jp> | 2020-03-21 05:59:31 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-03-21 05:59:31 +0000 |
commit | ab47fb8ae0e6685900e3a22de3b9ce265a5b05fa (patch) | |
tree | 22a50ddb755864b883f02833b03db48feb072691 /test/unit/attachment_test.rb | |
parent | 6abf527aa0e3271ebd38c1ac50a4691dab611b2e (diff) | |
download | redmine-ab47fb8ae0e6685900e3a22de3b9ce265a5b05fa.tar.gz redmine-ab47fb8ae0e6685900e3a22de3b9ce265a5b05fa.zip |
Download all attachments at once (#7056).
Patch by Mizuki ISHIKAWA.
git-svn-id: http://svn.redmine.org/redmine/trunk@19601 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/attachment_test.rb')
-rw-r--r-- | test/unit/attachment_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index 7e12483f5..5c32d1e75 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -278,6 +278,32 @@ class AttachmentTest < ActiveSupport::TestCase end end + def test_archive_attachments + attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1) + Tempfile.create('attachments_zip', Rails.root.join('tmp')) do |tempfile| + zip_file = Attachment.archive_attachments(tempfile, [attachment]) + assert_instance_of File, zip_file + end + end + + def test_archive_attachments_without_attachments + Tempfile.create('attachments_zip', Rails.root.join('tmp')) do |tempfile| + zip_file = Attachment.archive_attachments(tempfile, []) + assert_nil zip_file + end + end + + def test_archive_attachments_should_rename_duplicate_file_names + attachment1 = Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1) + attachment2 = Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1) + Tempfile.create('attachments_zip', Rails.root.join('tmp')) do |tempfile| + zip_file = Attachment.archive_attachments(tempfile, [attachment1, attachment2]) + Zip::File.open(zip_file.path) do |z| + assert_equal ['testfile.txt', 'testfile(1).txt'], z.map(&:name) + end + end + end + def test_move_from_root_to_target_directory_should_move_root_files a = Attachment.find(20) assert a.disk_directory.blank? |