From 2cd749955e48e1f24cf429817a71787440ada057 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 7 Feb 2013 19:24:57 +0000 Subject: [PATCH] Fixed: error raised when copying project wiki with wiki module disabled (#13097). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11332 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 4 +++- test/unit/project_copy_test.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 28cb52ddc..fdb47cfdd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -772,7 +772,7 @@ class Project < ActiveRecord::Base def copy_wiki(project) # Check that the source project has a wiki first unless project.wiki.nil? - self.wiki ||= Wiki.new + wiki = self.wiki || Wiki.new wiki.attributes = project.wiki.attributes.dup.except("id", "project_id") wiki_pages_map = {} project.wiki.pages.each do |page| @@ -784,6 +784,8 @@ class Project < ActiveRecord::Base wiki.pages << new_wiki_page wiki_pages_map[page.id] = new_wiki_page end + + self.wiki = wiki wiki.save # Reproduce page hierarchy project.wiki.pages.each do |page| diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index cc76852c9..6b505b2b2 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -233,6 +233,15 @@ class ProjectCopyTest < ActiveSupport::TestCase assert_equal "Start page", @project.wiki.start_page end + test "#copy should copy wiki without wiki module" do + project = Project.new(:name => 'Copy Test', :identifier => 'copy-test', :enabled_module_names => []) + assert_difference 'Wiki.count' do + assert project.copy(@source_project) + end + + assert project.wiki + end + test "#copy should copy wiki pages and content with hierarchy" do assert_difference 'WikiPage.count', @source_project.wiki.pages.size do assert @project.copy(@source_project)