Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-15 18:55:07 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-15 18:55:07 +0400
commit71ab011a1711db9a1a9ced2c2c92c8427ae6f624 (patch)
tree95e38662d7f022061c2c809f4b6c53067a5df468 /spec/lib
parent4f23c30ace844cdcd2c59da1a758c8a6788ca6f3 (diff)
parentd69a37e0b7163f5a03fcc58fdb6ec0ed1eb20862 (diff)
Merge branch 'use_gollum_wikis' of https://github.com/DanKnox/gitlabhq into DanKnox-use_gollum_wikis
Conflicts: app/views/layouts/project_resource.html.haml app/views/wikis/edit.html.haml app/views/wikis/pages.html.haml app/views/wikis/show.html.haml spec/features/gitlab_flavored_markdown_spec.rb
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/wiki_to_gollum_migrator_spec.rb114
1 files changed, 114 insertions, 0 deletions
diff --git a/spec/lib/wiki_to_gollum_migrator_spec.rb b/spec/lib/wiki_to_gollum_migrator_spec.rb
new file mode 100644
index 00000000000..a784d836d62
--- /dev/null
+++ b/spec/lib/wiki_to_gollum_migrator_spec.rb
@@ -0,0 +1,114 @@
+require "spec_helper"
+
+describe WikiToGollumMigrator do
+
+ def create_wiki_for(project)
+ 3.times { @pages[project.id] << create_page(project) }
+ end
+
+ def create_revisions_for(project)
+ @pages[project.id].each do |page|
+ create_revision(page)
+ end
+ end
+
+ def create_page(project)
+ page = project.wikis.new(title: "Page #{rand(1000)}", content: "Content")
+ page.user = project.owner
+ page.slug = page.title.parameterize
+ page.save!
+ page
+ end
+
+ def create_revision(page)
+ revision = page.dup
+ revision.content = "Updated Content"
+ revision.save!
+ end
+
+ def create_temp_repo(path)
+ FileUtils.mkdir_p path
+ command = "git init --quiet --bare #{path};"
+ system(command)
+ end
+
+ before do
+ @repo_path = "#{Rails.root}/tmp/test-git-base-path"
+ @projects = []
+ @pages = Hash.new {|h,k| h[k] = Array.new }
+
+ @projects << create(:project)
+ @projects << create(:project)
+
+ @projects.each do |project|
+ create_wiki_for project
+ create_revisions_for project
+ end
+
+ @project_without_wiki = create(:project)
+ end
+
+ context "Before the migration" do
+ it "has two projects with valid wikis" do
+ @projects.each do |project|
+ pages = project.wikis.group(:slug).all
+ pages.count.should == 3
+ end
+ end
+
+ it "has two revision for each page" do
+ @projects.each do |project|
+ @pages[project.id].each do |page|
+ revisions = project.wikis.where(slug: page.slug)
+ revisions.count.should == 2
+ end
+ end
+ end
+ end
+
+ describe "#initialize" do
+ it "finds all projects that have existing wiki pages" do
+ Project.count.should == 3
+ subject.projects.count.should == 2
+ end
+ end
+
+ context "#migrate!" do
+ before do
+ Gitlab::Shell.any_instance.stub(:add_repository) do |path|
+ create_temp_repo("#{@repo_path}/#{path}.git")
+ end
+
+ subject.stub(:log).as_null_object
+
+ subject.migrate!
+ end
+
+ it "creates a new Gollum Wiki for each project" 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_true
+ File.directory?(full_path).should be_true
+ end
+ end
+
+ it "creates a gollum page for each unique Wiki page" do
+ @projects.each do |project|
+ wiki = GollumWiki.new(project, nil)
+ wiki.pages.count.should == 3
+ end
+ 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
+
+
+end