implement Wiki#update_page
This commit is contained in:
@@ -51,5 +51,24 @@ module Gollum
|
|||||||
parent = self.repo.commit('master')
|
parent = self.repo.commit('master')
|
||||||
index.commit(commit[:message], [parent], actor)
|
index.commit(commit[:message], [parent], actor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Update an existing page with new content. The location of the page
|
||||||
|
# inside the repository and the page's format will not change.
|
||||||
|
#
|
||||||
|
# page - The Gollum::Page to update.
|
||||||
|
# data - The new String contents of the page.
|
||||||
|
# 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 update_page(page, data, commit = {})
|
||||||
|
index = self.repo.index
|
||||||
|
index.add(page.path, data)
|
||||||
|
actor = Grit::Actor.new(commit[:name], commit[:email])
|
||||||
|
parent = self.repo.commit('master')
|
||||||
|
index.commit(commit[:message], [parent], actor)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -33,6 +33,22 @@ context "Wiki page writing" do
|
|||||||
assert_equal "tom@github.com", @wiki.repo.commits.first.author.email
|
assert_equal "tom@github.com", @wiki.repo.commits.first.author.email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "update_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.update_page(page, "# Gollum2", commit)
|
||||||
|
|
||||||
|
assert_equal 2, @wiki.repo.commits.size
|
||||||
|
assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
|
||||||
|
assert_equal "Gollum page", @wiki.repo.commits.first.message
|
||||||
|
assert_equal "Tom Preston-Werner", @wiki.repo.commits.first.author.name
|
||||||
|
assert_equal "tom@github.com", @wiki.repo.commits.first.author.email
|
||||||
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
|
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user