Wiki#update_page takes a name parameter for renames

This commit is contained in:
rick
2010-08-02 15:39:04 -07:00
parent 6609b2d636
commit 760d9c1640
4 changed files with 45 additions and 13 deletions
+1 -1
View File
@@ -406,7 +406,7 @@ Update an existing page. If the format is different than the page's current
format, the file name will be changed to reflect the new format. format, the file name will be changed to reflect the new format.
page = wiki.page('Page Name') page = wiki.page('Page Name')
wiki.update_page(page, page.format, 'Page contents', commit) wiki.update_page(page, page.name, page.format, 'Page contents', commit)
To delete a page and commit the change: To delete a page and commit the change:
+1 -1
View File
@@ -56,7 +56,7 @@ module Precious
page = wiki.page(name) page = wiki.page(name)
format = params[:format].intern format = params[:format].intern
wiki.update_page(page, format, params[:content], commit_message) wiki.update_page(page, page.name, format, params[:content], commit_message)
redirect "/#{name}" redirect "/#{name}"
end end
+5 -4
View File
@@ -134,6 +134,7 @@ module Gollum
# changed to reflect the new format. # changed to reflect the new format.
# #
# page - The Gollum::Page to update. # page - The Gollum::Page to update.
# name - The String extension-less name of the page.
# format - The Symbol format of the page. # format - The Symbol format of the page.
# data - The new String contents of the page. # data - The new String contents of the page.
# commit - The commit Hash details: # commit - The commit Hash details:
@@ -142,19 +143,19 @@ module Gollum
# :email - The String email address. # :email - The String email address.
# #
# Returns the String SHA1 of the newly written version. # Returns the String SHA1 of the newly written version.
def update_page(page, format, data, commit = {}) def update_page(page, name, format, data, commit = {})
pcommit = @repo.commit('master') pcommit = @repo.commit('master')
map = tree_map(pcommit.tree) map = tree_map(pcommit.tree)
name ||= page.name
format ||= page.format
index = nil index = nil
if page.format == format if page.name == name && page.format == format
index = tree_map_to_index(map) index = tree_map_to_index(map)
index.add(page.path, normalize(data)) index.add(page.path, normalize(data))
else else
map = delete_from_tree_map(map, page.path) map = delete_from_tree_map(map, page.path)
dir = ::File.dirname(page.path) dir = ::File.dirname(page.path)
name = page.name
map = add_to_tree_map(map, dir, name, format, data) map = add_to_tree_map(map, dir, name, format, data)
index = tree_map_to_index(map) index = tree_map_to_index(map)
end end
+34 -3
View File
@@ -87,7 +87,7 @@ context "Wiki page writing" do
@wiki.write_page("Gollum", :markdown, "# Gollum", commit) @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
page = @wiki.page("Gollum") page = @wiki.page("Gollum")
@wiki.update_page(page, :markdown, "# Gollum2", commit) @wiki.update_page(page, page.name, :markdown, "# Gollum2", commit)
assert_equal 2, @wiki.repo.commits.size assert_equal 2, @wiki.repo.commits.size
assert_equal "# Gollum2", @wiki.page("Gollum").raw_data assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
@@ -105,13 +105,44 @@ context "Wiki page writing" do
assert_equal :markdown, @wiki.page("Gollum").format assert_equal :markdown, @wiki.page("Gollum").format
page = @wiki.page("Gollum") page = @wiki.page("Gollum")
@wiki.update_page(page, :textile, "h1. Gollum", commit) @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit)
assert_equal 2, @wiki.repo.commits.size assert_equal 2, @wiki.repo.commits.size
assert_equal :textile, @wiki.page("Gollum").format assert_equal :textile, @wiki.page("Gollum").format
assert_equal "h1. Gollum", @wiki.page("Gollum").raw_data assert_equal "h1. Gollum", @wiki.page("Gollum").raw_data
end end
test "update page with name change" do
commit = { :message => "Gollum page",
:name => "Tom Preston-Werner",
:email => "tom@github.com" }
@wiki.write_page("Gollum", :markdown, "# Gollum", commit)
assert_equal :markdown, @wiki.page("Gollum").format
page = @wiki.page("Gollum")
@wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit)
assert_equal 2, @wiki.repo.commits.size
assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
end
test "update page with name and format change" do
commit = { :message => "Gollum page",
:name => "Tom Preston-Werner",
:email => "tom@github.com" }
@wiki.write_page("Gollum", :markdown, "# Gollum", commit)
assert_equal :markdown, @wiki.page("Gollum").format
page = @wiki.page("Gollum")
@wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit)
assert_equal 2, @wiki.repo.commits.size
assert_equal :textile, @wiki.page("Smeagol").format
assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
end
test "update nested page with format change" do test "update nested page with format change" do
commit = { :message => "Gollum page", commit = { :message => "Gollum page",
:name => "Tom Preston-Werner", :name => "Tom Preston-Werner",
@@ -123,7 +154,7 @@ context "Wiki page writing" do
page = @wiki.page("Gollum") page = @wiki.page("Gollum")
assert_equal :markdown, @wiki.page("Gollum").format assert_equal :markdown, @wiki.page("Gollum").format
@wiki.update_page(page, :textile, "h1. Gollum", commit) @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit)
page = @wiki.page("Gollum") page = @wiki.page("Gollum")
assert_equal "lotr/Gollum.textile", page.path assert_equal "lotr/Gollum.textile", page.path