From 676811206d8d4442ec0c891b3c8be619b1dcae9c Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Fri, 3 Apr 2020 17:12:09 +0200 Subject: [PATCH] Add tests for base_path (#1540) --- bin/gollum | 24 +----------------------- lib/gollum/app.rb | 24 ++++++++++++++++++++++++ test/test_app.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/bin/gollum b/bin/gollum index 9d9544e4..28f8dc18 100755 --- a/bin/gollum +++ b/bin/gollum @@ -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 diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 2a2743d1..641a49d2 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -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 diff --git a/test/test_app.rb b/test/test_app.rb index c18efa9f..077d5021 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -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?('