From 2b701ec675b64557b38b6553d2173ada303a5a3d Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Fri, 16 Apr 2010 12:50:10 -0400 Subject: [PATCH] implement Wiki#update_page --- lib/gollum/wiki.rb | 19 +++++++++++++++++++ test/test_wiki.rb | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index bdf3e383..f2ece471 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -51,5 +51,24 @@ module Gollum parent = self.repo.commit('master') index.commit(commit[:message], [parent], actor) 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 \ No newline at end of file diff --git a/test/test_wiki.rb b/test/test_wiki.rb index b8bb81c1..892d0038 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -33,6 +33,22 @@ context "Wiki page writing" do assert_equal "tom@github.com", @wiki.repo.commits.first.author.email 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 FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git])) end