Feature #5664 » feature_5664_copy_docs_w_tests_trunk.diff
| test/unit/project_copy_test.rb (working copy) | ||
|---|---|---|
|
assert @project.members.any?
|
||
|
assert @project.issue_categories.any?
|
||
|
assert @project.issues.empty?
|
||
|
assert @project.documents.empty?
|
||
|
end
|
||
|
test "#copy should copy subtasks" do
|
||
| ... | ... | |
|
child_copy = copy.children.detect {|c| c.subject == 'Child1'}
|
||
|
assert child_copy.descendants.any?
|
||
|
end
|
||
|
test "#copy should copy documents" do
|
||
|
@source_project.documents << Document.generate!(:title => "copy document title",
|
||
|
:category_id => 1,
|
||
|
:project_id => @source_project.id)
|
||
|
assert @project.valid?
|
||
|
assert @project.documents.empty?
|
||
|
assert @project.copy(@source_project)
|
||
|
assert_equal @source_project.documents.size, @project.documents.size
|
||
|
@project.documents.each do |document|
|
||
|
assert document.valid?
|
||
|
assert_equal @project, document.project
|
||
|
end
|
||
|
copied_document = @project.documents.where(:title => "copy document title").first
|
||
|
assert copied_document
|
||
|
end
|
||
|
test "#copy should copy document attachments" do
|
||
|
document = Document.generate!(:title => "copy document attachment", :category_id => 1, :project_id => @source_project.id)
|
||
|
Attachment.create!(:container => document, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1)
|
||
|
@source_project.documents << document
|
||
|
assert @project.copy(@source_project)
|
||
|
copied_document = @project.documents.where(:title => "copy document attachment").first
|
||
|
assert_not_nil copied_document
|
||
|
assert_equal 1, copied_document.attachments.count, "Attachment not copied"
|
||
|
assert_equal "testfile.txt", copied_document.attachments.first.filename
|
||
|
end
|
||
|
end
|
||
| test/object_helpers.rb (working copy) | ||
|---|---|---|
|
changeset.save!
|
||
|
changeset
|
||
|
end
|
||
|
def Document.generate!(attributes={})
|
||
|
document = Document.new(attributes)
|
||
|
document.project ||= Project.find(1)
|
||
|
document.category ||= document.project.categories.first
|
||
|
document.title = 'Generated' if document.title.blank?
|
||
|
yield document if block_given?
|
||
|
document
|
||
|
end
|
||
|
end
|
||
| app/models/project.rb (working copy) | ||
|---|---|---|
|
def copy(project, options={})
|
||
|
project = project.is_a?(Project) ? project : Project.find(project)
|
||
|
to_be_copied = %w(wiki versions issue_categories issues members queries boards)
|
||
|
to_be_copied = %w(wiki versions issue_categories issues members queries boards documents)
|
||
|
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
|
||
|
Project.transaction do
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
# Copies documents from +project+
|
||
|
def copy_documents(project)
|
||
|
project.documents.each do |document|
|
||
|
new_document = Document.new
|
||
|
new_document.attributes = document.attributes.dup.except("id", "project_id")
|
||
|
new_document.project = self
|
||
|
self.documents << new_document
|
||
|
# Copy attachments to document
|
||
|
new_document.attachments = document.attachments.map do |attachement|
|
||
|
attachement.copy(:container => new_document)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def allowed_permissions
|
||
|
@allowed_permissions ||= begin
|
||
|
module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name)
|
||
| app/views/projects/copy.html.erb (working copy) | ||
|---|---|---|
|
<label class="block"><%= check_box_tag 'only[]', 'issues', true %> <%= l(:label_issue_plural) %> (<%= @source_project.issues.count %>)</label>
|
||
|
<label class="block"><%= check_box_tag 'only[]', 'queries', true %> <%= l(:label_query_plural) %> (<%= @source_project.queries.count %>)</label>
|
||
|
<label class="block"><%= check_box_tag 'only[]', 'boards', true %> <%= l(:label_board_plural) %> (<%= @source_project.boards.count %>)</label>
|
||
|
<label class="block"><%= check_box_tag 'only[]', 'documents', true %> <%= l(:label_document_plural) %> (<%= @source_project.documents.count %>)</label>
|
||
|
<label class="block"><%= check_box_tag 'only[]', 'wiki', true %> <%= l(:label_wiki_page_plural) %> (<%= @source_project.wiki.nil? ? 0 : @source_project.wiki.pages.count %>)</label>
|
||
|
<%= hidden_field_tag 'only[]', '' %>
|
||
|
<br />
|
||