Add tests for base_path (#1540)

This commit is contained in:
Dawa Ometto
2020-04-03 17:12:09 +02:00
committed by GitHub
parent ff1baf0036
commit 676811206d
3 changed files with 68 additions and 23 deletions
+1 -23
View File
@@ -287,29 +287,7 @@ else
else
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::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
+24
View File
@@ -40,6 +40,30 @@ Gollum::set_git_max_filesize(190 * 10**6)
# See the wiki.rb file for more details on wiki options
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
register Mustache::Sinatra
register Sinatra::Namespace
+43
View File
@@ -928,4 +928,47 @@ context "Frontend with empty repo" do
assert last_response.ok?
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