Merge pull request #6839 from opf/core/fix/29053/copy-wiki-attachments

[29053] Fix copying wiki attachments

[ci skip]
pull/6842/head
Oliver Günther 6 years ago committed by GitHub
commit 5f44741f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/models/project/copy.rb
  2. 21
      spec/features/projects/copy_spec.rb

@ -71,8 +71,8 @@ module Project::Copy
unless project.wiki.nil?
self.wiki = build_wiki(project.wiki.attributes.dup.except('id', 'project_id'))
self.wiki.wiki_menu_items.delete_all
copy_wiki_pages(project)
copy_wiki_menu_items(project)
copy_wiki_pages(project, selected_copies)
copy_wiki_menu_items(project, selected_copies)
end
end
@ -87,15 +87,15 @@ module Project::Copy
new_wiki_page.content = new_wiki_content
wiki.pages << new_wiki_page
wiki_pages_map[page.id] = new_wiki_page
wiki_pages_map[page] = new_wiki_page
end
wiki.save
# Reproduce page hierarchy
project.wiki.pages.each do |page|
if page.parent_id && wiki_pages_map[page.id]
wiki_pages_map[page.id].parent = wiki_pages_map[page.parent_id]
wiki_pages_map[page.id].save
if page.parent_id && wiki_pages_map[page]
wiki_pages_map[page].parent = wiki_pages_map[page.parent]
wiki_pages_map[page].save
end
end

@ -45,6 +45,9 @@ describe 'Projects copy',
project.work_package_custom_fields << wp_custom_field
project.types.first.custom_fields << wp_custom_field
# Enable wiki
project.enabled_module_names += ['wiki']
project
end
let!(:parent_project) do
@ -106,6 +109,14 @@ describe 'Projects copy',
custom_field_values: { wp_custom_field.id => 'Some wp cf text' })
end
let!(:wiki) { project.wiki }
let!(:wiki_page) do
FactoryBot.create :wiki_page_with_content,
title: 'Attached',
wiki: wiki,
attachments: [FactoryBot.build(:attachment, container: nil, filename: 'attachment.pdf')]
end
before do
login_as user
@ -121,6 +132,9 @@ describe 'Projects copy',
click_link 'Copy'
fill_in 'Name', with: 'Copied project'
# Check copy wiki page attachments
check 'only_wiki_page_attachments'
# the value of the custom field should be preselected
expect(page)
.to have_field(project_custom_field.name, with: 'some text cf')
@ -164,6 +178,13 @@ describe 'Projects copy',
copied_settings_page.expect_type_inactive(inactive_type)
# Expect wiki was copied
expect(copied_project.wiki.pages.count).to eq(project.wiki.pages.count)
copied_page = copied_project.wiki.find_page 'Attached'
expect(copied_page).not_to be_nil
expect(copied_page.attachments.count).to eq 1
expect(copied_page.attachments.first.filename).to eq 'attachment.pdf'
# custom field is copied over where the author is the current user
# Using the db directly due to performance and clarity
copied_work_packages = copied_project.work_packages

Loading…
Cancel
Save