delete_page

This commit is contained in:
Tom Preston-Werner
2010-04-20 18:19:54 -07:00
parent 6bb9d3408c
commit 63099ec5c0
2 changed files with 60 additions and 0 deletions
+27
View File
@@ -77,6 +77,33 @@ module Gollum
index.commit(commit[:message], [pcommit], actor)
end
# Public: Delete a page.
#
# page - The Gollum::Page to delete.
# commit - The commit Hash details:
# :message - The String commit message.
# :author - The String author full name.
# :email - The String email address.
#
# Returns the String SHA1 of the newly written version.
def delete_page(page, commit)
pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
parts = page.path.split('/')
name = parts.pop
container = nil
parts.each do |part|
container = map[part]
end
(container || map).delete(name)
index = tree_map_to_index(map)
actor = Grit::Actor.new(commit[:name], commit[:email])
index.commit(commit[:message], [pcommit], actor)
end
#########################################################################
#
# Internal Methods
+33
View File
@@ -55,6 +55,39 @@ context "Wiki page writing" do
assert_equal "tom@github.com", @wiki.repo.commits.first.author.email
end
test "delete root page" do
commit = { :message => "Gollum page",
:name => "Tom Preston-Werner",
:email => "tom@github.com" }
@wiki.write_page("Gollum", :markdown, "# Gollum", commit)
page = @wiki.page("Gollum")
@wiki.delete_page(page, commit)
assert_equal 2, @wiki.repo.commits.size
assert_nil @wiki.page("Gollum")
end
test "delete nested page" do
commit = { :message => "Gollum page",
:name => "Tom Preston-Werner",
:email => "tom@github.com" }
index = @wiki.repo.index
index.add("greek/Bilbo-Baggins.md", "hi")
index.add("Gollum.md", "hi")
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo-Baggins")
assert page
@wiki.delete_page(page, commit)
assert_equal 2, @wiki.repo.commits.size
assert_nil @wiki.page("Bilbo-Baggins")
assert @wiki.page("Gollum")
end
teardown do
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
end