diff options
author | Dan Knox <dknox@threedotloft.com> | 2013-03-16 18:01:48 -0700 |
---|---|---|
committer | Dan Knox <dknox@threedotloft.com> | 2013-03-16 18:01:48 -0700 |
commit | 330fe4162eea06dbcf2cd498fe35436163093e40 (patch) | |
tree | 6cf64c471f4573c1b181f528e3c98fc3866103ab /spec | |
parent | c367cc5ca66c0d59c0e5228ed1724023ea6ad06e (diff) | |
download | gitlab-ce-330fe4162eea06dbcf2cd498fe35436163093e40.tar.gz |
Fix Wiki migration task and add more test coverage.
There was an error in the #extract_attributes_from_page method that
caused an exception when checking to see if a page named "Home"
already exists.
The check occurs to handle the renaming of the main index page to
"Home" to match the Gollum standard. If there is already a page
called "Home" then the migrator will leave that page and create
the Index page as usual. Users will need to manually rename their
old "Home" page to something else then rename their "Index" page
to "Home". Fortunately, I would be highly surprised if this case
ever comes up.
I also added more verbosity to the logging so if an error does
occur, it will be easier to track down which Wiki page is causing
the problem.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/wiki_to_gollum_migrator_spec.rb | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/spec/lib/wiki_to_gollum_migrator_spec.rb b/spec/lib/wiki_to_gollum_migrator_spec.rb index a784d836d62..f9b9c78ea01 100644 --- a/spec/lib/wiki_to_gollum_migrator_spec.rb +++ b/spec/lib/wiki_to_gollum_migrator_spec.rb @@ -108,6 +108,111 @@ describe WikiToGollumMigrator do end end end + + context "wikis with pages that have titles that do not match the slugs" do + before do + project = @projects.last + @page = project.wikis.new(title: "test page", content: "Invalid Page") + @page.slug = "totally-incorrect-slug" + @page.user = project.owner + @page.save! + + create_revision(@page) + + subject.rollback! + subject.migrate! + end + + it "has a page with a title differing the slug" do + @page.slug.should_not == @page.title.parameterize + end + + it "creates a new revision for each old revision of the page" do + @projects.each do |project| + wiki = GollumWiki.new(project, nil) + wiki.pages.each do |page| + page.versions.count.should == 2 + end + end + end + end + + context "changing wiki title from index to home" do + before do + @project = @projects.last + @page = @project.wikis.new(title: "Index", content: "Home Page") + @page.slug = "index" + @page.user = @project.owner + @page.save! + + create_revision(@page) + + subject.rollback! + end + + it "creates a page called Home" do + subject.migrate! + wiki = GollumWiki.new(@project, nil) + page = wiki.find_page("home") + page.should be_present + end + + context "when a page called Home already exists" do + before do + @index_page = @project.wikis.new(title: "Index", content: "Index Page") + @index_page.slug = "index" + @index_page.user = @project.owner + @index_page.save! + + create_revision(@index_page) + + @home_page = @project.wikis.new(title: "Home", content: "Home Page") + @home_page.slug = "home" + @home_page.user = @project.owner + @home_page.save! + + create_revision(@home_page) + subject.migrate! + end + + it "creates the index page" do + wiki = GollumWiki.new(@project, nil) + page = wiki.find_page("index") + page.should be_present + end + + it "creates the home page" do + wiki = GollumWiki.new(@project, nil) + page = wiki.find_page("home") + page.should be_present + end + end + end + end + + context "#rollback!" do + before do + Gitlab::Shell.any_instance.stub(:add_repository) do |path| + create_temp_repo("#{@repo_path}/#{path}.git") + end + + Gitlab::Shell.any_instance.stub(:remove_repository) do |path| + FileUtils.rm_rf "#{@repo_path}/#{path}.git" + end + + subject.stub(:log).as_null_object + + subject.migrate! + subject.rollback! + end + + it "destroys all of the wiki repositories that were created during migrate!" do + @projects.each do |project| + wiki_path = project.path_with_namespace + ".wiki.git" + full_path = @repo_path + "/" + wiki_path + File.exist?(full_path).should be_false + end + end end |