Implemented DmsfFile.copy_to_filename that creates a copy with a new filename.
This commit is contained in:
parent
5d3ac312dc
commit
7533e8948c
@ -274,6 +274,10 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def copy_to(container, folder = nil)
|
||||
copy_to_filename(container, folder, self.name)
|
||||
end
|
||||
|
||||
def copy_to_filename(container, folder=nil, filename)
|
||||
project = container.is_a?(Project) ? container : container.project
|
||||
# If the target project differs from the source project we must physically move the disk files
|
||||
if (self.project != project) && self.last_revision
|
||||
@ -285,7 +289,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
file.dmsf_folder = folder
|
||||
file.container_type = self.container_type
|
||||
file.container_id = container.id
|
||||
file.name = self.name
|
||||
file.name = filename
|
||||
file.notification = Setting.plugin_redmine_dmsf['dmsf_default_notifications'].present?
|
||||
if file.save && self.last_revision
|
||||
new_revision = self.last_revision.clone
|
||||
|
||||
@ -37,6 +37,7 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
|
||||
@file6 = DmsfFile.find_by_id 6
|
||||
@file7 = DmsfFile.find_by_id 7
|
||||
@file8 = DmsfFile.find_by_id 8
|
||||
@folder1 = DmsfFolder.find_by_id 1
|
||||
@issue1 = Issue.find_by_id 1
|
||||
User.current = nil
|
||||
end
|
||||
@ -53,6 +54,7 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
|
||||
assert_kind_of DmsfFile, @file6
|
||||
assert_kind_of DmsfFile, @file7
|
||||
assert_kind_of DmsfFile, @file8
|
||||
assert_kind_of DmsfFolder, @folder1
|
||||
assert_kind_of Issue, @issue1
|
||||
end
|
||||
|
||||
@ -142,6 +144,28 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
|
||||
@file4.dmsf_folder.lock!
|
||||
end
|
||||
|
||||
def test_copy_to_filename
|
||||
assert_no_difference '@file1.dmsf_file_revisions.count' do
|
||||
new_file = @file1.copy_to_filename(@file1.project, nil, "new_file.txt")
|
||||
assert_not_equal new_file.id, @file1.id
|
||||
assert_nil new_file.dmsf_folder_id
|
||||
assert_nil @file1.dmsf_folder_id
|
||||
assert_not_equal new_file.name, @file1.name
|
||||
assert_equal new_file.dmsf_file_revisions.count, 1
|
||||
end
|
||||
end
|
||||
|
||||
def test_copy_to
|
||||
assert_no_difference '@file1.dmsf_file_revisions.count' do
|
||||
new_file = @file1.copy_to(@file1.project, @folder1)
|
||||
assert_not_equal new_file.id, @file1.id
|
||||
assert_not_equal @file1.dmsf_folder_id, @folder1.id
|
||||
assert_equal new_file.dmsf_folder_id, @folder1.id
|
||||
assert_equal new_file.name, @file1.name
|
||||
assert_equal new_file.dmsf_file_revisions.count, 1
|
||||
end
|
||||
end
|
||||
|
||||
def test_save_and_destroy_with_cache
|
||||
RedmineDmsf::Webdav::Cache.init_testcache
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user