Commit 461abaa843b5c21a5103fde802db770dd583ac92

Authored by Jacob Vosmaer
1 parent 7af1bc3b

Add GollumWiki#empty? method

app/models/gollum_wiki.rb
@@ -45,6 +45,10 @@ class GollumWiki @@ -45,6 +45,10 @@ class GollumWiki
45 end 45 end
46 end 46 end
47 47
  48 + def empty?
  49 + pages.empty?
  50 + end
  51 +
48 # Returns an Array of Gitlab WikiPage instances or an 52 # Returns an Array of Gitlab WikiPage instances or an
49 # empty Array if this Wiki has no pages. 53 # empty Array if this Wiki has no pages.
50 def pages 54 def pages
spec/models/gollum_wiki_spec.rb
@@ -86,6 +86,27 @@ describe GollumWiki do @@ -86,6 +86,27 @@ describe GollumWiki do
86 end 86 end
87 end 87 end
88 88
  89 + describe "#empty?" do
  90 + context "when the wiki repository is empty" do
  91 + before do
  92 + Gitlab::Shell.any_instance.stub(:add_repository) do
  93 + create_temp_repo("#{Rails.root}/tmp/test-git-base-path/non-existant.wiki.git")
  94 + end
  95 + project.stub(:path_with_namespace).and_return("non-existant")
  96 + end
  97 +
  98 + its(:empty?) { should be_true }
  99 + end
  100 +
  101 + context "when the wiki has pages" do
  102 + before do
  103 + create_page("index", "This is an awesome new Gollum Wiki")
  104 + end
  105 +
  106 + its(:empty?) { should be_false }
  107 + end
  108 + end
  109 +
89 describe "#pages" do 110 describe "#pages" do
90 before do 111 before do
91 create_page("index", "This is an awesome new Gollum Wiki") 112 create_page("index", "This is an awesome new Gollum Wiki")