@@ -512,11 +512,23 class Project < ActiveRecord::Base | |||
|
512 | 512 | unless project.wiki.nil? |
|
513 | 513 | self.wiki ||= Wiki.new |
|
514 | 514 | wiki.attributes = project.wiki.attributes.dup.except("id", "project_id") |
|
515 | wiki_pages_map = {} | |
|
515 | 516 | project.wiki.pages.each do |page| |
|
517 | # Skip pages without content | |
|
518 | next if page.content.nil? | |
|
516 | 519 | new_wiki_content = WikiContent.new(page.content.attributes.dup.except("id", "page_id", "updated_on")) |
|
517 | 520 | new_wiki_page = WikiPage.new(page.attributes.dup.except("id", "wiki_id", "created_on", "parent_id")) |
|
518 | 521 | new_wiki_page.content = new_wiki_content |
|
519 | 522 | wiki.pages << new_wiki_page |
|
523 | wiki_pages_map[page.id] = new_wiki_page | |
|
524 | end | |
|
525 | wiki.save | |
|
526 | # Reproduce page hierarchy | |
|
527 | project.wiki.pages.each do |page| | |
|
528 | if page.parent_id && wiki_pages_map[page.id] | |
|
529 | wiki_pages_map[page.id].parent = wiki_pages_map[page.parent_id] | |
|
530 | wiki_pages_map[page.id].save | |
|
531 | end | |
|
520 | 532 | end |
|
521 | 533 | end |
|
522 | 534 | end |
@@ -71,4 +71,28 wiki_contents_006: | |||
|
71 | 71 | version: 1 |
|
72 | 72 | author_id: 1 |
|
73 | 73 | comments: |
|
74 | wiki_contents_007: | |
|
75 | text: This is a child page | |
|
76 | updated_on: 2007-03-08 00:18:07 +01:00 | |
|
77 | page_id: 7 | |
|
78 | id: 7 | |
|
79 | version: 1 | |
|
80 | author_id: 1 | |
|
81 | comments: | |
|
82 | wiki_contents_008: | |
|
83 | text: This is a parent page | |
|
84 | updated_on: 2007-03-08 00:18:07 +01:00 | |
|
85 | page_id: 8 | |
|
86 | id: 8 | |
|
87 | version: 1 | |
|
88 | author_id: 1 | |
|
89 | comments: | |
|
90 | wiki_contents_009: | |
|
91 | text: This is a child page | |
|
92 | updated_on: 2007-03-08 00:18:07 +01:00 | |
|
93 | page_id: 9 | |
|
94 | id: 9 | |
|
95 | version: 1 | |
|
96 | author_id: 1 | |
|
97 | comments: | |
|
74 | 98 | No newline at end of file |
@@ -41,4 +41,25 wiki_pages_006: | |||
|
41 | 41 | wiki_id: 1 |
|
42 | 42 | protected: false |
|
43 | 43 | parent_id: 2 |
|
44 | wiki_pages_007: | |
|
45 | created_on: 2007-03-08 00:18:07 +01:00 | |
|
46 | title: Child_page_1 | |
|
47 | id: 7 | |
|
48 | wiki_id: 2 | |
|
49 | protected: false | |
|
50 | parent_id: 8 | |
|
51 | wiki_pages_008: | |
|
52 | created_on: 2007-03-08 00:18:07 +01:00 | |
|
53 | title: Parent_page | |
|
54 | id: 8 | |
|
55 | wiki_id: 2 | |
|
56 | protected: false | |
|
57 | parent_id: | |
|
58 | wiki_pages_009: | |
|
59 | created_on: 2007-03-08 00:18:07 +01:00 | |
|
60 | title: Child_page_2 | |
|
61 | id: 9 | |
|
62 | wiki_id: 2 | |
|
63 | protected: false | |
|
64 | parent_id: 8 | |
|
44 | 65 | No newline at end of file |
@@ -723,16 +723,24 class ProjectTest < ActiveSupport::TestCase | |||
|
723 | 723 | assert_equal "Start page", @project.wiki.start_page |
|
724 | 724 | end |
|
725 | 725 | |
|
726 | should "copy wiki pages and content" do | |
|
726 | should "copy wiki pages and content with hierarchy" do | |
|
727 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do | |
|
727 | 728 | assert @project.copy(@source_project) |
|
729 | end | |
|
728 | 730 | |
|
729 | 731 | assert @project.wiki |
|
730 |
assert_equal |
|
|
732 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size | |
|
731 | 733 | |
|
732 | 734 | @project.wiki.pages.each do |wiki_page| |
|
733 | 735 | assert wiki_page.content |
|
734 | 736 | assert !@source_project.wiki.pages.include?(wiki_page) |
|
735 | 737 | end |
|
738 | ||
|
739 | parent = @project.wiki.find_page('Parent_page') | |
|
740 | child1 = @project.wiki.find_page('Child_page_1') | |
|
741 | child2 = @project.wiki.find_page('Child_page_2') | |
|
742 | assert_equal parent, child1.parent | |
|
743 | assert_equal parent, child2.parent | |
|
736 | 744 | end |
|
737 | 745 | |
|
738 | 746 | should "copy issue categories" do |
General Comments 0
You need to be logged in to leave comments.
Login now