Page create with a relative path forces an absolute path.

This commit is contained in:
Dustin DeYoung
2013-05-26 10:03:23 -04:00
parent a88314e061
commit 1147186b4c
4 changed files with 62 additions and 23 deletions
+36 -17
View File
@@ -5,14 +5,14 @@ context "Frontend" do
include Rack::Test::Methods
setup do
@path = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
@wikipath = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@wikipath)
Precious::App.set(:gollum_path, @wikipath)
Precious::App.set(:wiki_options, {})
end
teardown do
FileUtils.rm_rf(@path)
FileUtils.rm_rf(@wikipath)
end
test "urls transform unicode" do
@@ -279,7 +279,7 @@ context "Frontend" do
:format => 'markdown', :message => 'foo'
assert_equal "http://example.org/foo/home", last_response.headers['Location']
follow_redirect!
assert last_response.ok?
end
@@ -300,6 +300,25 @@ context "Frontend" do
assert last_response.ok?
end
test "create sets the correct path for a relative path subdirectory" do
dir = "foodir"
name = "#{dir}/bar"
get "/create/#{name}"
assert_match(/\/#{dir}/, last_response.body)
assert_not_match(/(?<!\/)#{dir}/, last_response.body)
end
test "create sets the correct path for a relative path subdirectory with the page file directory set" do
Precious::App.set(:wiki_options, {:page_file_dir => "foo"})
dir = "bardir"
name = "#{dir}/baz"
get "/create/foo/#{name}"
assert_match(/\/#{dir}/, last_response.body)
assert_not_match(/(?<!\/)#{dir}/, last_response.body)
# reset page_file_dir
Precious::App.set(:wiki_options, {:page_file_dir => nil})
end
test "edit returns nil for non-existant page" do
# post '/edit' fails. post '/edit/' works.
page = 'not-real-page'
@@ -372,9 +391,9 @@ context "Frontend" do
end
test "previews content on the first page of an empty wiki" do
@path = cloned_testpath("examples/empty.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
@wikipath = cloned_testpath("examples/empty.git")
@wiki = Gollum::Wiki.new(@wikipath)
Precious::App.set(:gollum_path, @wikipath)
Precious::App.set(:wiki_options, {})
post "/preview", :content => 'abc', :format => 'markdown'
@@ -442,20 +461,20 @@ context "Frontend" do
Precious::App.set(:wiki_options, { :base_path => nil })
end
=end
test "author details in session are used" do
page1 = @wiki.page('A')
gollum_author = { :name => 'ghi', :email => 'jkl' }
session = { 'gollum.author' => gollum_author }
post "/edit/A", { :content => 'abc', :page => 'A', :format => page1.format, :message => 'def' }, { 'rack.session' => session }
follow_redirect!
assert last_response.ok?
@wiki.clear_cache
page2 = @wiki.page(page1.name)
author = page2.version.author
assert_equal 'ghi', author.name
assert_equal 'jkl', author.email
@@ -494,14 +513,14 @@ context "Frontend with lotr" do
include Rack::Test::Methods
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
@wikipath = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@wikipath)
Precious::App.set(:gollum_path, @wikipath)
Precious::App.set(:wiki_options, {})
end
teardown do
FileUtils.rm_rf(@path)
FileUtils.rm_rf(@wikipath)
end
# Here's the dir structure of lotr.git
+12
View File
@@ -9,5 +9,17 @@ context "Precious::Helpers" do
assert_equal 'Mordor', extract_path('Mordor/Sauron')
assert_equal 'Mordor/Sauron', extract_path('Mordor/Sauron/Evil')
end
test "clean path without leading slash" do
assert_equal '/Mordor', clean_path('Mordor')
end
test "clean path with leading slash" do
assert_equal '/Mordor', clean_path('/Mordor')
end
test "clean path with double leading slash" do
assert_equal '/Mordor', clean_path('//Mordor')
end
end