summaryrefslogtreecommitdiffstats
path: root/test/unit/attachment_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-13 12:07:19 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-13 12:07:19 +0000
commitc99b638d61cc5dd6b9ffcf4212dfaca1973f7500 (patch)
tree13f809bad3d9ce0c8583b857d5030b55c54bb1f1 /test/unit/attachment_test.rb
parentd0bbaef308ae6183445a8697b08f8eae5ed9ccf8 (diff)
downloadredmine-c99b638d61cc5dd6b9ffcf4212dfaca1973f7500.tar.gz
redmine-c99b638d61cc5dd6b9ffcf4212dfaca1973f7500.zip
Store attachments in subdirectories (#5298).
Existing files can be moved to their target subdirectories using rake redmine:attachments:move_to_subdirectories. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10990 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/attachment_test.rb')
-rw-r--r--test/unit/attachment_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index 61ff048a7..ad759152f 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -52,10 +52,25 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal 'text/plain', a.content_type
assert_equal 0, a.downloads
assert_equal '1478adae0d4eb06d35897518540e25d6', a.digest
+
+ assert a.disk_directory
+ assert_match %r{\A\d{4}/\d{2}\z}, a.disk_directory
+
assert File.exist?(a.diskfile)
assert_equal 59, File.size(a.diskfile)
end
+ def test_copy_should_preserve_attributes
+ a = Attachment.find(1)
+ copy = a.copy
+
+ assert_save copy
+ copy = Attachment.order('id DESC').first
+ %w(filename filesize content_type author_id created_on description digest disk_filename disk_directory diskfile).each do |attribute|
+ assert_equal a.send(attribute), copy.send(attribute), "#{attribute} was different"
+ end
+ end
+
def test_size_should_be_validated_for_new_file
with_settings :attachment_max_size => 0 do
a = Attachment.new(:container => Issue.find(1),
@@ -123,6 +138,9 @@ class AttachmentTest < ActiveSupport::TestCase
end
def test_identical_attachments_at_the_same_time_should_not_overwrite
+ time = DateTime.now
+ DateTime.stubs(:now).returns(time)
+
a1 = Attachment.create!(:container => Issue.find(1),
:file => uploaded_test_file("testfile.txt", ""),
:author => User.find(1))
@@ -168,6 +186,21 @@ class AttachmentTest < ActiveSupport::TestCase
end
end
+ def test_move_from_root_to_target_directory_should_move_root_files
+ a = Attachment.find(20)
+ assert a.disk_directory.blank?
+ # Create a real file for this fixture
+ File.open(a.diskfile, "w") do |f|
+ f.write "test file at the root of files directory"
+ end
+ assert a.readable?
+ Attachment.move_from_root_to_target_directory
+
+ a.reload
+ assert_equal '2012/05', a.disk_directory
+ assert a.readable?
+ end
+
context "Attachmnet.attach_files" do
should "attach the file" do
issue = Issue.first