mirror of
https://github.com/redmine/redmine.git
synced 2026-08-31 03:27:33 +02:00
Copy attachments on issue and project copy (#3055).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8676 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -52,6 +52,25 @@ class AttachmentTest < ActiveSupport::TestCase
|
||||
assert_equal 59, File.size(a.diskfile)
|
||||
end
|
||||
|
||||
def test_size_should_be_validated_for_new_file
|
||||
with_settings :attachment_max_size => 0 do
|
||||
a = Attachment.new(:container => Issue.find(1),
|
||||
:file => uploaded_test_file("testfile.txt", "text/plain"),
|
||||
:author => User.find(1))
|
||||
assert !a.save
|
||||
end
|
||||
end
|
||||
|
||||
def test_size_should_not_be_validated_when_copying
|
||||
a = Attachment.create!(:container => Issue.find(1),
|
||||
:file => uploaded_test_file("testfile.txt", "text/plain"),
|
||||
:author => User.find(1))
|
||||
with_settings :attachment_max_size => 0 do
|
||||
copy = a.copy
|
||||
assert copy.save
|
||||
end
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
a = Attachment.new(:container => Issue.find(1),
|
||||
:file => uploaded_test_file("testfile.txt", "text/plain"),
|
||||
@@ -69,6 +88,22 @@ class AttachmentTest < ActiveSupport::TestCase
|
||||
assert !File.exist?(diskfile)
|
||||
end
|
||||
|
||||
def test_destroy_should_not_delete_file_referenced_by_other_attachment
|
||||
a = Attachment.create!(:container => Issue.find(1),
|
||||
:file => uploaded_test_file("testfile.txt", "text/plain"),
|
||||
:author => User.find(1))
|
||||
diskfile = a.diskfile
|
||||
|
||||
copy = a.copy
|
||||
copy.save!
|
||||
|
||||
assert File.exists?(diskfile)
|
||||
a.destroy
|
||||
assert File.exists?(diskfile)
|
||||
copy.destroy
|
||||
assert !File.exists?(diskfile)
|
||||
end
|
||||
|
||||
def test_create_should_auto_assign_content_type
|
||||
a = Attachment.new(:container => Issue.find(1),
|
||||
:file => uploaded_test_file("testfile.txt", ""),
|
||||
|
||||
@@ -870,6 +870,18 @@ class ProjectTest < ActiveSupport::TestCase
|
||||
assert_not_equal source_relation_cross_project.id, copied_relation.id
|
||||
end
|
||||
|
||||
should "copy issue attachments" do
|
||||
issue = Issue.generate!(:subject => "copy with attachment", :tracker_id => 1, :project_id => @source_project.id)
|
||||
Attachment.create!(:container => issue, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1)
|
||||
@source_project.issues << issue
|
||||
assert @project.copy(@source_project)
|
||||
|
||||
copied_issue = @project.issues.first(:conditions => {:subject => "copy with attachment"})
|
||||
assert_not_nil copied_issue
|
||||
assert_equal 1, copied_issue.attachments.count, "Attachment not copied"
|
||||
assert_equal "testfile.txt", copied_issue.attachments.first.filename
|
||||
end
|
||||
|
||||
should "copy memberships" do
|
||||
assert @project.valid?
|
||||
assert @project.members.empty?
|
||||
|
||||
Reference in New Issue
Block a user