Feature #5664 » 0001-Adds-ability-to-copy-documents-when-copying-a-projec.patch
| app/models/project.rb | ||
|---|---|---|
| 717 | 717 |
def copy(project, options={})
|
| 718 | 718 |
project = project.is_a?(Project) ? project : Project.find(project) |
| 719 | 719 | |
| 720 |
to_be_copied = %w(wiki versions issue_categories issues members queries boards) |
|
| 720 |
to_be_copied = %w(wiki versions issue_categories issues members queries boards documents)
|
|
| 721 | 721 |
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil? |
| 722 | 722 | |
| 723 | 723 |
Project.transaction do |
| ... | ... | |
| 967 | 967 |
end |
| 968 | 968 |
end |
| 969 | 969 | |
| 970 |
# Copies documents from +project+ |
|
| 971 |
def copy_documents(project) |
|
| 972 |
project.documents.each do |document| |
|
| 973 |
new_document = Document.new |
|
| 974 |
new_document.attributes = document.attributes.dup.except("id", "project_id")
|
|
| 975 |
new_document.project = self |
|
| 976 |
self.documents << new_document |
|
| 977 |
# Copy attachments to document |
|
| 978 |
new_document.attachments = document.attachments.map do |attachement| |
|
| 979 |
attachement.copy(:container => new_document) |
|
| 980 |
end |
|
| 981 |
end |
|
| 982 |
end |
|
| 983 | ||
| 970 | 984 |
def allowed_permissions |
| 971 | 985 |
@allowed_permissions ||= begin |
| 972 | 986 |
module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name) |
| app/views/projects/copy.html.erb | ||
|---|---|---|
| 10 | 10 |
<label class="block"><%= check_box_tag 'only[]', 'issues', true %> <%= l(:label_issue_plural) %> (<%= @source_project.issues.count %>)</label> |
| 11 | 11 |
<label class="block"><%= check_box_tag 'only[]', 'queries', true %> <%= l(:label_query_plural) %> (<%= @source_project.queries.count %>)</label> |
| 12 | 12 |
<label class="block"><%= check_box_tag 'only[]', 'boards', true %> <%= l(:label_board_plural) %> (<%= @source_project.boards.count %>)</label> |
| 13 |
<label class="block"><%= check_box_tag 'only[]', 'documents', true %> <%= l(:label_document_plural) %> (<%= @source_project.documents.count %>)</label> |
|
| 13 | 14 |
<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> |
| 14 | 15 |
<%= hidden_field_tag 'only[]', '' %> |
| 15 | 16 |
<br /> |
| test/object_helpers.rb | ||
|---|---|---|
| 186 | 186 |
query.save! |
| 187 | 187 |
query |
| 188 | 188 |
end |
| 189 | ||
| 190 |
def Document.generate!(attributes={})
|
|
| 191 |
document = Document.new(attributes) |
|
| 192 |
document.project ||= Project.find(1) |
|
| 193 |
document.category ||= document.project.categories.first |
|
| 194 |
document.title = 'Generated' if document.title.blank? |
|
| 195 |
yield document if block_given? |
|
| 196 |
document |
|
| 197 |
end |
|
| 189 | 198 |
end |
| 190 | 199 | |
| 191 | 200 |
module IssueObjectHelpers |
| test/unit/project_copy_test.rb | ||
|---|---|---|
| 327 | 327 |
assert @project.members.any? |
| 328 | 328 |
assert @project.issue_categories.any? |
| 329 | 329 |
assert @project.issues.empty? |
| 330 |
assert @project.documents.empty? |
|
| 330 | 331 |
end |
| 331 | 332 | |
| 332 | 333 |
test "#copy should copy subtasks" do |
| ... | ... | |
| 345 | 346 |
child_copy = copy.children.detect {|c| c.subject == 'Child1'}
|
| 346 | 347 |
assert child_copy.descendants.any? |
| 347 | 348 |
end |
| 349 | ||
| 350 |
test "#copy should copy documents" do |
|
| 351 |
@source_project.documents << Document.generate!(:title => "copy document title", |
|
| 352 |
:category_id => 1, |
|
| 353 |
:project_id => @source_project.id) |
|
| 354 |
assert @project.valid? |
|
| 355 |
assert @project.documents.empty? |
|
| 356 |
assert @project.copy(@source_project) |
|
| 357 | ||
| 358 |
assert_equal @source_project.documents.size, @project.documents.size |
|
| 359 |
@project.documents.each do |document| |
|
| 360 |
assert document.valid? |
|
| 361 |
assert_equal @project, document.project |
|
| 362 |
end |
|
| 363 | ||
| 364 |
copied_document = @project.documents.where(:title => "copy document title").first |
|
| 365 |
assert copied_document |
|
| 366 |
end |
|
| 367 | ||
| 368 |
test "#copy should copy document attachments" do |
|
| 369 |
document = Document.generate!(:title => "copy document attachment", :category_id => 1, :project_id => @source_project.id) |
|
| 370 |
Attachment.create!(:container => document, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1)
|
|
| 371 |
@source_project.documents << document |
|
| 372 |
assert @project.copy(@source_project) |
|
| 373 | ||
| 374 |
copied_document = @project.documents.where(:title => "copy document attachment").first |
|
| 375 |
assert_not_nil copied_document |
|
| 376 |
assert_equal 1, copied_document.attachments.count, "Attachment not copied" |
|
| 377 |
assert_equal "testfile.txt", copied_document.attachments.first.filename |
|
| 378 |
end |
|
| 348 | 379 |
end |
- « Previous
- 1
- 2
- 3
- Next »