Add tests for base_path (#1540)
This commit is contained in:
+1
-23
@@ -287,29 +287,7 @@ else
|
|||||||
else
|
else
|
||||||
require 'rack'
|
require 'rack'
|
||||||
|
|
||||||
class MapGollum
|
|
||||||
def initialize(base_path)
|
|
||||||
@mg = Rack::Builder.new do
|
|
||||||
|
|
||||||
map "/#{base_path}" do
|
|
||||||
run Precious::App
|
|
||||||
end
|
|
||||||
map '/' do
|
|
||||||
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
|
|
||||||
end
|
|
||||||
map '/*' do
|
|
||||||
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
@mg.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Rack::Handler does not work with Ctrl + C. Use Rack::Server instead.
|
# Rack::Handler does not work with Ctrl + C. Use Rack::Server instead.
|
||||||
Rack::Server.new(:app => MapGollum.new(base_path), :Port => options[:port], :Host => options[:bind]).start
|
Rack::Server.new(:app => Precious::MapGollum.new(base_path), :Port => options[:port], :Host => options[:bind]).start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,6 +40,30 @@ Gollum::set_git_max_filesize(190 * 10**6)
|
|||||||
# See the wiki.rb file for more details on wiki options
|
# See the wiki.rb file for more details on wiki options
|
||||||
|
|
||||||
module Precious
|
module Precious
|
||||||
|
|
||||||
|
# For use with the --base-path option.
|
||||||
|
class MapGollum
|
||||||
|
def initialize(base_path)
|
||||||
|
@mg = Rack::Builder.new do
|
||||||
|
|
||||||
|
map "/#{base_path}" do
|
||||||
|
run Precious::App
|
||||||
|
end
|
||||||
|
map '/' do
|
||||||
|
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
|
||||||
|
end
|
||||||
|
map '/*' do
|
||||||
|
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
@mg.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class App < Sinatra::Base
|
class App < Sinatra::Base
|
||||||
register Mustache::Sinatra
|
register Mustache::Sinatra
|
||||||
register Sinatra::Namespace
|
register Sinatra::Namespace
|
||||||
|
|||||||
@@ -929,3 +929,46 @@ context "Frontend with empty repo" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'Frontend with base path' do
|
||||||
|
include Rack::Test::Methods
|
||||||
|
|
||||||
|
setup do
|
||||||
|
@path = cloned_testpath("examples/lotr.git")
|
||||||
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
|
@base_path = 'wiki'
|
||||||
|
Precious::App.set(:gollum_path, @path)
|
||||||
|
Precious::App.set(:wiki_options, {base_path: @base_path, mathjax: true})
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_rf(@path)
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'page with base path' do
|
||||||
|
get '/wiki/Home'
|
||||||
|
assert last_response.ok?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'base path mathjax assets' do
|
||||||
|
get '/wiki/Home'
|
||||||
|
assert last_response.ok?
|
||||||
|
assert last_response.body.include?('<script defer src="/wiki/gollum/assets/mathjax/MathJax.js')
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'compare view' do
|
||||||
|
post '/wiki/gollum/compare/Bilbo-Baggins.md', :versions => ['f25eccd98e9b667f9e22946f3e2f945378b8a72d', '5bc1aaec6149e854078f1d0f8b71933bbc6c2e43']
|
||||||
|
follow_redirect!
|
||||||
|
assert last_response.ok?
|
||||||
|
assert_equal '/wiki/gollum/compare/Bilbo-Baggins.md/5bc1aaec6149e854078f1d0f8b71933bbc6c2e43...f25eccd98e9b667f9e22946f3e2f945378b8a72d', last_request.fullpath
|
||||||
|
|
||||||
|
post '/wiki/gollum/compare/Bilbo-Baggins.md', :versions => ['f25eccd98e9b667f9e22946f3e2f945378b8a72d']
|
||||||
|
follow_redirect!
|
||||||
|
assert last_response.ok?
|
||||||
|
assert_equal '/wiki/gollum/history/Bilbo-Baggins.md', last_request.fullpath
|
||||||
|
end
|
||||||
|
|
||||||
|
def app
|
||||||
|
Precious::MapGollum.new(@base_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user