Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fda5bcf3f6 | |||
| 01005fdccf | |||
| 95d35d38da | |||
| 81c90e55a7 | |||
| 3f0b61081b | |||
| ecc317886a |
@@ -30,7 +30,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
ruby: [2.6, 2.7, 3.0]
|
||||
ruby: ['2.6', '2.7', '3.0', '3.1']
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
require 'rubygems'
|
||||
require 'rake'
|
||||
require 'date'
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
@@ -38,14 +37,6 @@ def bump_version
|
||||
new_version
|
||||
end
|
||||
|
||||
def date
|
||||
Date.today.to_s
|
||||
end
|
||||
|
||||
def rubyforge_project
|
||||
name
|
||||
end
|
||||
|
||||
def gemspec_file
|
||||
"#{name}.gemspec"
|
||||
end
|
||||
@@ -143,12 +134,9 @@ task :gemspec => :validate do
|
||||
spec = File.read(gemspec_file)
|
||||
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
||||
|
||||
# replace name version and date
|
||||
# replace name and version
|
||||
replace_header(head, :name)
|
||||
replace_header(head, :version)
|
||||
replace_header(head, :date)
|
||||
#comment this out if your rubyforge_project has a different name
|
||||
replace_header(head, :rubyforge_project)
|
||||
|
||||
# determine file list from git ls-files
|
||||
files = `git ls-files`.
|
||||
|
||||
+20
-8
@@ -11,8 +11,11 @@ migrate_options = {
|
||||
:hyphenate => true
|
||||
}
|
||||
|
||||
def setting(const)
|
||||
Object.const_defined?(const.upcase) && Object.const_get(const.upcase)
|
||||
def setting(variable_name)
|
||||
class_variable_name = :"@@#{variable_name.to_s}"
|
||||
|
||||
Object.class_variable_defined?(class_variable_name) &&
|
||||
Object.class_variable_get(class_variable_name)
|
||||
end
|
||||
|
||||
opts = OptionParser.new do |opts|
|
||||
@@ -78,8 +81,11 @@ end
|
||||
begin
|
||||
opts.parse!
|
||||
migrate_options.each do |setting, value|
|
||||
const = setting.to_s.upcase
|
||||
Object.const_set(const, value) unless Object.const_defined?(const)
|
||||
variable_name = :"@@#{setting.to_s}"
|
||||
|
||||
unless Object.class_variable_defined?(variable_name)
|
||||
Object.class_variable_set(variable_name, value)
|
||||
end
|
||||
end
|
||||
wiki_options[:page_file_dir] = setting(:page_file_dir) ? setting(:page_file_dir) : wiki_options[:page_file_dir] # Allow settings :page_file_dir through PAGE_FILE_DIR constant.
|
||||
rescue OptionParser::InvalidOption
|
||||
@@ -88,7 +94,7 @@ rescue OptionParser::InvalidOption
|
||||
exit
|
||||
end
|
||||
|
||||
REPO = ARGV[0] || Dir.pwd
|
||||
wiki_directory = ARGV[0] || Dir.pwd
|
||||
|
||||
require 'gollum-lib'
|
||||
|
||||
@@ -232,8 +238,12 @@ end
|
||||
|
||||
filter_chain = [:PlainTextMigrator, :CodeMigrator, :TagMigrator]
|
||||
|
||||
wiki = ::Gollum::Wiki.new(REPO, wiki_options.merge({:filter_chain => filter_chain}))
|
||||
TREE = wiki.tree_list(wiki.ref, true, true).map {|file| ::File.join('/', file.path)}
|
||||
wiki = ::Gollum::Wiki.new(wiki_directory, wiki_options.merge({:filter_chain => filter_chain}))
|
||||
|
||||
Object.class_variable_set(
|
||||
:"@@wiki_tree",
|
||||
wiki.tree_list(wiki.ref, true, true).map {|file| ::File.join('/', file.path)}
|
||||
)
|
||||
|
||||
def find_linked(link)
|
||||
link.gsub!(' ', '-') if setting(:hyphenate) # Match paths containing dashes instead of spaces
|
||||
@@ -243,7 +253,9 @@ def find_linked(link)
|
||||
test_path = ::File.extname(link).empty? ? /#{link}\..+/ : link
|
||||
# Select pages from the wiki whose path =~ 'Foo/Bar/Samwi.*'
|
||||
# Match case-insenstively to mimic 4.x behavior!
|
||||
TREE.select {|path| path =~ /^\/(.*\/)?#{test_path}/i}
|
||||
Object.class_variable_get(:"@@wiki_tree").select { |path|
|
||||
path =~ /^\/(.*\/)?#{test_path}/i
|
||||
}
|
||||
end
|
||||
|
||||
def log(kind, msg = nil)
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.specification_version = 2 if s.respond_to? :specification_version=
|
||||
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
||||
s.rubygems_version = '1.3.5'
|
||||
s.required_ruby_version = '>= 2.6'
|
||||
|
||||
s.name = 'gollum'
|
||||
s.version = '5.2.3'
|
||||
s.date = '2021-04-18'
|
||||
s.license = 'MIT'
|
||||
|
||||
s.summary = 'A simple, Git-powered wiki.'
|
||||
|
||||
+3
-2
@@ -29,9 +29,10 @@ module Gollum
|
||||
@@filters[pattern] = replacement
|
||||
end
|
||||
|
||||
def self.apply_filters(data)
|
||||
def self.apply_filters(wiki_page, data)
|
||||
@@filters.each do |pattern, replacement|
|
||||
data.gsub!(pattern, replacement.call)
|
||||
params = replacement.parameters.length == 0 ? nil : wiki_page
|
||||
data.gsub!(pattern, replacement.call(*params))
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
+6
-7
@@ -103,8 +103,7 @@ module Precious
|
||||
end
|
||||
|
||||
before do
|
||||
settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true)
|
||||
@allow_editing = settings.wiki_options[:allow_editing]
|
||||
@allow_editing = settings.wiki_options.fetch(:allow_editing, true)
|
||||
@critic_markup = settings.wiki_options[:critic_markup]
|
||||
@redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true)
|
||||
@per_page_uploads = settings.wiki_options[:per_page_uploads]
|
||||
@@ -112,8 +111,6 @@ module Precious
|
||||
|
||||
@wiki_title = settings.wiki_options.fetch(:title, 'Gollum Wiki')
|
||||
|
||||
forbid unless @allow_editing || request.request_method == 'GET'
|
||||
|
||||
if settings.wiki_options[:template_dir]
|
||||
Precious::Views::Layout.extend Precious::Views::TemplateCascade
|
||||
Precious::Views::Layout.template_priority_path = settings.wiki_options[:template_dir]
|
||||
@@ -143,6 +140,8 @@ module Precious
|
||||
config.manifest = Sprockets::Manifest.new(settings.sprockets, @static_assets_path)
|
||||
end
|
||||
end
|
||||
|
||||
forbid unless @allow_editing || request.request_method == 'GET'
|
||||
end
|
||||
|
||||
get '/' do
|
||||
@@ -369,7 +368,7 @@ module Precious
|
||||
@name = wikip.name
|
||||
@ext = wikip.ext
|
||||
@path = wikip.path
|
||||
@template_page = load_template(@path) if settings.wiki_options[:template_page]
|
||||
@template_page = load_template(wikip, @path) if settings.wiki_options[:template_page]
|
||||
@allow_uploads = wikip.wiki.allow_uploads
|
||||
@upload_dest = find_upload_dest(wikip.fullpath)
|
||||
|
||||
@@ -661,9 +660,9 @@ module Precious
|
||||
end
|
||||
end
|
||||
|
||||
def load_template(path)
|
||||
def load_template(wiki_page, path)
|
||||
template_page = wiki_page(::File.join(path, '_Template')).page || wiki_page('/_Template').page
|
||||
template_page ? Gollum::TemplateFilter.apply_filters(template_page.text_data) : nil
|
||||
template_page ? Gollum::TemplateFilter.apply_filters(wiki_page, template_page.text_data) : nil
|
||||
end
|
||||
|
||||
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
|
||||
|
||||
@@ -42,7 +42,7 @@ module Precious
|
||||
end
|
||||
|
||||
def fill_argument_content(i18n_key, i18n_value)
|
||||
i18n_value.gsub!(YAML_VARIABLE_REGEXP) do |argument|
|
||||
i18n_value = i18n_value.gsub(YAML_VARIABLE_REGEXP) do |argument|
|
||||
method_name = argument.gsub(/[^\w]/, '')
|
||||
|
||||
next if method_name.nil?
|
||||
|
||||
@@ -11,9 +11,13 @@ module Precious
|
||||
end
|
||||
|
||||
def first_path_available(name)
|
||||
priority = File.join(template_priority_path, "#{name}.#{template_extension}")
|
||||
default = File.join(template_path, "#{name}.#{template_extension}")
|
||||
File.exists?(priority) ? priority : default
|
||||
priority =
|
||||
if template_priority_path
|
||||
File.join(template_priority_path, "#{name}.#{template_extension}")
|
||||
end
|
||||
|
||||
priority && File.exist?(priority) ? priority : default
|
||||
end
|
||||
|
||||
# Method should track lib/mustache/settings.rb from Mustache project.
|
||||
|
||||
+30
-10
@@ -1,18 +1,20 @@
|
||||
require 'rubygems'
|
||||
require 'rack/test'
|
||||
require 'test/unit'
|
||||
require 'shoulda'
|
||||
require 'mocha/setup'
|
||||
require 'fileutils'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/reporters'
|
||||
require 'minitest/spec'
|
||||
require 'mocha/setup'
|
||||
require 'fileutils'
|
||||
require 'tmpdir'
|
||||
|
||||
# Silence locale validation warning
|
||||
require 'i18n'
|
||||
I18n.enforce_available_locales = false
|
||||
|
||||
MiniTest::Reporters.use!
|
||||
Minitest::Reporters.use! [
|
||||
Minitest::Reporters::DefaultReporter.new({color: true})
|
||||
]
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
$LOAD_PATH.unshift(File.join(dir, '..', 'lib'))
|
||||
@@ -62,14 +64,29 @@ def normal(text)
|
||||
text
|
||||
end
|
||||
|
||||
# test/spec/mini 3
|
||||
# The following configuration originates from this gist:
|
||||
|
||||
# http://gist.github.com/25455
|
||||
# chris@ozmm.org
|
||||
# file:lib/test/spec/mini.rb
|
||||
#
|
||||
# But it has been modified since it was first committed. It allows you to
|
||||
# write tests with an RSpec-like DSL:
|
||||
#
|
||||
# context "my test context" do
|
||||
# setup do
|
||||
# # My test setup
|
||||
# end
|
||||
#
|
||||
# teardown do
|
||||
# # My test teardown
|
||||
# end
|
||||
#
|
||||
# test "some functionality" do
|
||||
# assert true
|
||||
# end
|
||||
# end
|
||||
def context(*args, &block)
|
||||
return super unless (name = args.first) && block
|
||||
require 'test/unit'
|
||||
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
|
||||
klass = Class.new(Minitest::Test) do
|
||||
def self.test(name, &block)
|
||||
define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
|
||||
end
|
||||
@@ -85,10 +102,13 @@ def context(*args, &block)
|
||||
define_method(:teardown, &block)
|
||||
end
|
||||
end
|
||||
|
||||
(
|
||||
class << klass;
|
||||
self
|
||||
end).send(:define_method, :name) { name.gsub(/\W/, '_') }
|
||||
end
|
||||
).send(:define_method, :name) { name.gsub(/\W/, '_') }
|
||||
|
||||
$contexts << klass
|
||||
klass.class_eval &block
|
||||
end
|
||||
|
||||
+51
-31
@@ -3,84 +3,104 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
|
||||
context "Precious::Views::Editing" do
|
||||
include Rack::Test::Methods
|
||||
|
||||
setup do
|
||||
@path = cloned_testpath('examples/revert.git')
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, {allow_editing: true, allow_uploads: true})
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
teardown do
|
||||
Precious::App.set(:wiki_options, {allow_editing: true, allow_uploads: true})
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "creating page is blocked" do
|
||||
Precious::App.set(:wiki_options, { allow_editing: false})
|
||||
post "/gollum/create", :content => 'abc', :page => "D",
|
||||
:format => 'markdown', :message => 'def'
|
||||
assert !last_response.ok?
|
||||
test 'creating pages is not blocked' do
|
||||
post '/gollum/create',
|
||||
content: 'abc',
|
||||
format: 'markdown',
|
||||
message: 'def',
|
||||
page: 'D'
|
||||
|
||||
page = @wiki.page('D')
|
||||
assert page.nil?
|
||||
assert_equal last_response.status, 302
|
||||
|
||||
refute_nil @wiki.page('D')
|
||||
end
|
||||
|
||||
test 'creating pages is blocked' do
|
||||
Precious::App.set(:wiki_options, {allow_editing: false, allow_uploads: false})
|
||||
|
||||
post '/gollum/create',
|
||||
content: 'abc',
|
||||
format: 'markdown',
|
||||
message: 'def',
|
||||
page: 'D'
|
||||
|
||||
assert last_response.body.include? 'Forbidden. This wiki is set to no-edit mode.'
|
||||
|
||||
refute last_response.ok?
|
||||
|
||||
assert_nil @wiki.page('D')
|
||||
end
|
||||
|
||||
test ".redirects.gollum file should not be accessible" do
|
||||
Precious::App.set(:wiki_options, { allow_editing: true, allow_uploads: true })
|
||||
get '/.redirects.gollum'
|
||||
assert_match /Accessing this resource is not allowed/, last_response.body
|
||||
end
|
||||
|
||||
test ".redirects.gollum file should not be editable" do
|
||||
Precious::App.set(:wiki_options, { allow_editing: true, allow_uploads: true })
|
||||
get '/gollum/edit/.redirects.gollum'
|
||||
assert_match /Changing this resource is not allowed/, last_response.body
|
||||
end
|
||||
|
||||
test "frontend links for editing are not blocked" do
|
||||
Precious::App.set(:wiki_options, { allow_editing: true, allow_uploads: true })
|
||||
get '/A'
|
||||
|
||||
assert_match /Delete this Page/, last_response.body, "'Delete this Page' link is blocked in page template"
|
||||
assert_match /New/, last_response.body, "'New' button is blocked in page template"
|
||||
assert_match /Upload\b/, last_response.body, "'Upload' link is blocked in page template"
|
||||
assert_match /Rename/, last_response.body, "'Rename' link is blocked in page template"
|
||||
assert_match /Edit/, last_response.body, "'Edit' link is blocked in page template"
|
||||
assert last_response.body.include? "Delete this Page"
|
||||
assert last_response.body.include? "New"
|
||||
assert last_response.body.include? "<span>Upload</span>"
|
||||
assert last_response.body.include? "Rename"
|
||||
assert last_response.body.include? "Edit"
|
||||
|
||||
get '/gollum/overview'
|
||||
|
||||
assert_match /New/, last_response.body, "'New' link is blocked in pages template"
|
||||
assert last_response.body.include? "New"
|
||||
|
||||
get '/gollum/history/A'
|
||||
|
||||
assert_no_match /Edit/, last_response.body, "'Edit' link is not blocked in history template"
|
||||
refute last_response.body.include? "Edit"
|
||||
|
||||
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
||||
get '/gollum/compare/A/fc665395..b26b791c'
|
||||
|
||||
assert_no_match /Edit Page/, last_response.body, "'Edit Page' link is not blocked in compare template"
|
||||
assert_match /Revert Changes/, last_response.body, "'Revert Changes' link is blocked in compare template"
|
||||
refute last_response.body.include? "Edit Page"
|
||||
|
||||
assert last_response.body.include? "Revert Changes"
|
||||
end
|
||||
|
||||
test "frontend links for editing blocked" do
|
||||
Precious::App.set(:wiki_options, { allow_editing: false })
|
||||
Precious::App.set(:wiki_options, {allow_editing: false, allow_uploads: false})
|
||||
|
||||
get '/A'
|
||||
|
||||
assert_no_match /Delete this Page/, last_response.body, "'Delete this Page' link not blocked in page template"
|
||||
assert_no_match /New/, last_response.body, "'New' button not blocked in page template"
|
||||
assert_no_match /Upload\b/, last_response.body, "'Upload' link not blocked in page template"
|
||||
assert_no_match /Rename/, last_response.body, "'Rename' link not blocked in page template"
|
||||
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in page template"
|
||||
refute last_response.body.include? "Delete this Page"
|
||||
refute last_response.body.include? "<span>Upload</span>"
|
||||
refute last_response.body.include? "Rename"
|
||||
refute last_response.body.include? "Edit"
|
||||
refute last_response.body.include? "New"
|
||||
|
||||
get '/gollum/overview'
|
||||
|
||||
assert_no_match /New/, last_response.body, "'New' link not blocked in pages template"
|
||||
refute last_response.body.include? "New"
|
||||
|
||||
get '/gollum/history/A'
|
||||
|
||||
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in history template"
|
||||
refute last_response.body.include? "Edit"
|
||||
|
||||
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
||||
get '/gollum/compare/A/fc665395..b26b791c'
|
||||
|
||||
assert_no_match /Edit Page/, last_response.body, "'Edit Page' link not blocked in compare template"
|
||||
assert_no_match /Revert Changes/, last_response.body, "'Revert Changes' link not blocked in compare template"
|
||||
refute last_response.body.include? "Edit Page"
|
||||
refute last_response.body.include? "Revert Changes"
|
||||
end
|
||||
|
||||
def app
|
||||
|
||||
+69
-22
@@ -104,7 +104,7 @@ EOF
|
||||
page_2 = @wiki.page(page_1.name)
|
||||
assert_equal 'abc', page_2.raw_data
|
||||
assert_equal 'def', page_2.version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "edit page fails when page is outdated (edit collision)" do
|
||||
@@ -117,7 +117,7 @@ EOF
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page('A')
|
||||
new_sha = page.sha
|
||||
assert_not_equal old_sha, new_sha
|
||||
refute_equal old_sha, new_sha
|
||||
|
||||
post "/gollum/edit/A", :content => 'def', :page => 'A',
|
||||
:format => page.format, :message => 'def', :etag => old_sha
|
||||
@@ -134,7 +134,7 @@ EOF
|
||||
page_2 = @wiki.page(page_1.name)
|
||||
assert_equal 'abc', page_2.raw_data
|
||||
assert_equal '[no message]', page_2.version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "edit page with slash" do
|
||||
@@ -165,12 +165,12 @@ EOF
|
||||
assert_equal 'header', header_2.raw_data
|
||||
assert_equal 'footer', foot_2.raw_data
|
||||
assert_equal 'def', foot_2.version.message
|
||||
assert_not_equal foot_1.version.sha, foot_2.version.sha
|
||||
assert_not_equal header_1.version.sha, header_2.version.sha
|
||||
refute_equal foot_1.version.sha, foot_2.version.sha
|
||||
refute_equal header_1.version.sha, header_2.version.sha
|
||||
|
||||
assert_equal 'sidebar', side_2.raw_data
|
||||
assert_equal 'def', side_2.version.message
|
||||
assert_not_equal side_1.version.sha, side_2.version.sha
|
||||
refute_equal side_1.version.sha, side_2.version.sha
|
||||
assert_equal commits, @wiki.repo.commits('master').size
|
||||
end
|
||||
|
||||
@@ -187,7 +187,7 @@ EOF
|
||||
page_2 = @wiki.page('C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.last_version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "rename preserves format" do
|
||||
@@ -222,7 +222,7 @@ EOF
|
||||
|
||||
test "renames page in subdirectory" do
|
||||
page_1 = @wiki.page("G/H")
|
||||
assert_not_equal page_1, nil
|
||||
refute_equal page_1, nil
|
||||
post "/gollum/rename/G/H", :rename => "/I/C", :message => 'def'
|
||||
|
||||
follow_redirect!
|
||||
@@ -234,12 +234,12 @@ EOF
|
||||
page_2 = @wiki.page('I/C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.last_version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "renames page relative in subdirectory" do
|
||||
page_1 = @wiki.page("G/H")
|
||||
assert_not_equal page_1, nil
|
||||
refute_equal page_1, nil
|
||||
post "/gollum/rename/G/H", :rename => "K/C", :message => 'def'
|
||||
|
||||
follow_redirect!
|
||||
@@ -251,7 +251,7 @@ EOF
|
||||
page_2 = @wiki.page('G/K/C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.last_version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "creates page" do
|
||||
@@ -320,7 +320,7 @@ EOF
|
||||
name = "#{dir}/bar"
|
||||
get "/gollum/create/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
refute_match(/[^\/]#{dir}/, last_response.body)
|
||||
end
|
||||
|
||||
test "create with template succeed if template exists" do
|
||||
@@ -344,6 +344,45 @@ EOF
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
|
||||
test "create with template filter without parameter" do
|
||||
Precious::App.set(:wiki_options, { :template_page => true })
|
||||
|
||||
# arrange
|
||||
now = Time.parse('2022-04-16')
|
||||
Gollum::TemplateFilter.add_filter("{{today}}", & -> () { now.strftime("%Y-%m-%d") })
|
||||
template_content = "# Daily Log, {{today}}"
|
||||
|
||||
@wiki.write_page("daily-logs/_Template",
|
||||
:markdown,
|
||||
template_content)
|
||||
# act
|
||||
get "/gollum/create/daily-logs/test"
|
||||
# assert
|
||||
assert last_response.ok?
|
||||
assert_match("# Daily Log, 2022-04-16", last_response.body)
|
||||
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
|
||||
test "create with template filter with parameter" do
|
||||
Precious::App.set(:wiki_options, { :template_page => true })
|
||||
|
||||
# arrange
|
||||
Gollum::TemplateFilter.add_filter("{{page_name}}", & -> (page) { page.name })
|
||||
template_content = "# Daily Log, {{page_name}}"
|
||||
|
||||
@wiki.write_page("daily-logs/_Template",
|
||||
:markdown,
|
||||
template_content)
|
||||
# act
|
||||
get "/gollum/create/daily-logs/2022-04-16"
|
||||
# assert
|
||||
assert last_response.ok?
|
||||
assert_match("# Daily Log, 2022-04-16", last_response.body)
|
||||
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
|
||||
test "edit returns nil for non-existant page" do
|
||||
# post '/edit' fails. post '/edit/' works.
|
||||
page = 'not-real-page'
|
||||
@@ -351,7 +390,7 @@ EOF
|
||||
post '/gollum/edit/', :content => 'edit_msg',
|
||||
:page => page, :path => path, :message => ''
|
||||
page_e = @wiki.page(::File.join(path,page))
|
||||
assert_equal nil, page_e
|
||||
assert_nil page_e
|
||||
end
|
||||
|
||||
test "edit allows changing format" do
|
||||
@@ -407,13 +446,21 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page(name)
|
||||
assert_not_equal 'abc', page.raw_data
|
||||
refute_equal 'abc', page.raw_data
|
||||
end
|
||||
|
||||
test "uploading is not allowed unless explicitly enabled" do
|
||||
temp_upload_file = Tempfile.new(['upload', '.file']) << 'abc'
|
||||
temp_upload_file.close
|
||||
post "/gollum/upload_file", :file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))
|
||||
|
||||
Precious::App.set(
|
||||
:wiki_options,
|
||||
{allow_uploads: false, per_page_uploads: false}
|
||||
)
|
||||
|
||||
post '/gollum/upload_file',
|
||||
file: Rack::Test::UploadedFile.new(File.open(temp_upload_file))
|
||||
|
||||
assert_equal 405, last_response.status
|
||||
end
|
||||
|
||||
@@ -483,7 +530,7 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page(name)
|
||||
assert_equal nil, page
|
||||
assert_nil page
|
||||
end
|
||||
|
||||
test "previews content" do
|
||||
@@ -507,7 +554,7 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page2 = @wiki.page('B')
|
||||
assert_not_equal page1.version.sha, page2.version.sha
|
||||
refute_equal page1.version.sha, page2.version.sha
|
||||
assert_equal "INITIAL", page2.raw_data.strip
|
||||
assert_equal "Revert commit 7c45b5f", page2.version.message
|
||||
end
|
||||
@@ -521,7 +568,7 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page2 = @wiki.page('A')
|
||||
assert_not_equal page1.version.sha, page2.version.sha
|
||||
refute_equal page1.version.sha, page2.version.sha
|
||||
assert_equal "INITIAL", page2.raw_data.strip
|
||||
end
|
||||
|
||||
@@ -583,7 +630,7 @@ EOF
|
||||
{ :name => 'user1', :email => 'user1' });
|
||||
|
||||
get page
|
||||
assert_no_match /custom.js/, last_response.body
|
||||
refute_match /custom.js/, last_response.body
|
||||
end
|
||||
|
||||
test "add custom.js if setting" do
|
||||
@@ -652,7 +699,7 @@ EOF
|
||||
get "A"
|
||||
|
||||
assert last_response.ok?
|
||||
assert_no_match /meta name="robots" content="noindex, nofollow"/, last_response.body
|
||||
refute_match /meta name="robots" content="noindex, nofollow"/, last_response.body
|
||||
|
||||
get "A/fc66539528eb96f21b2bbdbf557788fe8a1196ac"
|
||||
|
||||
@@ -834,7 +881,7 @@ context "Frontend with lotr" do
|
||||
|
||||
get "Data.csv/#{old_sha}"
|
||||
assert last_response.ok?
|
||||
assert_no_match /Samwise,Gamgee/, last_response.body
|
||||
refute_match /Samwise,Gamgee/, last_response.body
|
||||
|
||||
get "Data.csv/#{update_sha}"
|
||||
assert last_response.ok?
|
||||
@@ -879,7 +926,7 @@ context "Frontend with page-file-dir" do
|
||||
name = "#{dir}/baz"
|
||||
get "/gollum/create/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
refute_match(/[^\/]#{dir}/, last_response.body)
|
||||
end
|
||||
|
||||
test "use custom.css from page-file-dir path if page-file-dir is set" do
|
||||
|
||||
+29
-31
@@ -1,28 +1,6 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
|
||||
# Original contents of Subdir/Foo.md:
|
||||
# waa
|
||||
# [[Samwi]]
|
||||
# [[samwise gamgee.mediaWiki]]
|
||||
# [[Samwise Gamgee.mediawiki]]
|
||||
# [[Samwise Gamgee]]
|
||||
# [[Test|Samwise Gamgee#Anchor]]
|
||||
# [[Waaa|Test]]
|
||||
# [[Zaa]]
|
||||
|
||||
# Contents of Subdir/Foo.md after successful tag migration
|
||||
result = <<EOF
|
||||
waa
|
||||
[[Samwi]]
|
||||
[[/Samwise Gamgee.mediawiki]]
|
||||
[[/Samwise Gamgee.mediawiki]]
|
||||
[[/Samwise Gamgee.md]]
|
||||
[[Test|/Samwise Gamgee.md#Anchor]]
|
||||
[[Waaa|/Bar/Test.md]]
|
||||
[[Subsub/Zaa.md]]
|
||||
EOF
|
||||
|
||||
def load_script(**args)
|
||||
settings = {
|
||||
:run_silent => true,
|
||||
@@ -32,9 +10,12 @@ def load_script(**args)
|
||||
:page_file_dir => nil,
|
||||
}.merge(args)
|
||||
|
||||
settings.each do |const, val|
|
||||
const_name = const.to_s.upcase
|
||||
Object.const_set(const_name, val) unless Object.const_defined?(const_name) && Object.const_get(const_name) == val
|
||||
settings.each do |setting, val|
|
||||
variable_name = :"@@#{setting.to_s}"
|
||||
|
||||
unless Object.class_variable_defined?(variable_name) && Object.class_variable_get(variable_name) == val
|
||||
Object.class_variable_set(variable_name, val)
|
||||
end
|
||||
end
|
||||
|
||||
script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags'))
|
||||
@@ -44,8 +25,6 @@ def load_script(**args)
|
||||
end
|
||||
end
|
||||
|
||||
unless ENV['CI']
|
||||
|
||||
context '4.x -> 5.x tag migrator' do
|
||||
include Rack::Test::Methods
|
||||
|
||||
@@ -54,10 +33,31 @@ unless ENV['CI']
|
||||
end
|
||||
|
||||
test 'repair broken links' do
|
||||
# The original contents of Subdir/Foo.md:
|
||||
#
|
||||
# waa
|
||||
# [[Samwi]]
|
||||
# [[samwise gamgee.mediaWiki]]
|
||||
# [[Samwise Gamgee.mediawiki]]
|
||||
# [[Samwise Gamgee]]
|
||||
# [[Test|Samwise Gamgee#Anchor]]
|
||||
# [[Waaa|Test]]
|
||||
# [[Zaa]]
|
||||
#
|
||||
# The contents will be updated after running the migration script.
|
||||
load_script
|
||||
|
||||
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
|
||||
assert_equal result, f.read
|
||||
file = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
|
||||
assert_equal <<~FILE_CONTENTS, file.read
|
||||
waa
|
||||
[[Samwi]]
|
||||
[[/Samwise Gamgee.mediawiki]]
|
||||
[[/Samwise Gamgee.mediawiki]]
|
||||
[[/Samwise Gamgee.md]]
|
||||
[[Test|/Samwise Gamgee.md#Anchor]]
|
||||
[[Waaa|/Bar/Test.md]]
|
||||
[[Subsub/Zaa.md]]
|
||||
FILE_CONTENTS
|
||||
end
|
||||
|
||||
test 'change spaced filenames to hyphenated filenames' do
|
||||
@@ -82,5 +82,3 @@ unless ENV['CI']
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -35,7 +35,7 @@ context "Precious::Views::Page" do
|
||||
@view.instance_variable_set :@content, page.formatted_data
|
||||
@view.instance_variable_set :@h1_title, false
|
||||
|
||||
assert_include @view.breadcrumb, "数学 📘"
|
||||
assert_includes @view.breadcrumb, "数学 📘"
|
||||
end
|
||||
|
||||
test 'page <title> is the page header from content, if present' do
|
||||
|
||||
@@ -1,43 +1,59 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
|
||||
class TestTemplateCascade < Minitest::Unit::TestCase
|
||||
context "Precious::Views::TemplateCascade" do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def setup
|
||||
setup do
|
||||
@path = cloned_testpath('examples/lotr.git')
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, {template_dir: testpath('examples/template_cascade')})
|
||||
Precious::App.set(
|
||||
:wiki_options,
|
||||
{template_dir: testpath('examples/template_cascade')}
|
||||
)
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
|
||||
Precious::App.set(:wiki_options, {template_dir: nil})
|
||||
|
||||
# The following line has been added to avoid order-dependent test failures.
|
||||
# We saw issues where the class variable `@@template_priority_path` was not
|
||||
# being reset between test cases.
|
||||
Precious::Views::TemplateCascade.class_variable_set(
|
||||
:@@template_priority_path,
|
||||
nil
|
||||
)
|
||||
end
|
||||
|
||||
def app
|
||||
Precious::App
|
||||
Precious::App.new
|
||||
end
|
||||
|
||||
def test_overridden_page_template_is_used
|
||||
test "overridden_page_template_is_used" do
|
||||
get '/Home'
|
||||
|
||||
assert last_response.body.include?('PAGE_OVERRIDE')
|
||||
end
|
||||
|
||||
def test_overridden_navbar_partial_is_used
|
||||
test "test_overridden_navbar_partial_is_used" do
|
||||
get '/Home'
|
||||
|
||||
assert last_response.body.include?('NAVBAR_OVERRIDE')
|
||||
end
|
||||
|
||||
def test_overridden_templates_are_ignore_without_template_dir_set
|
||||
test "test_overridden_templates_are_ignore_without_template_dir_set" do
|
||||
Precious::App.set(:wiki_options, {template_dir: nil})
|
||||
|
||||
get '/Home'
|
||||
|
||||
assert_equal '/Home', last_request.fullpath
|
||||
|
||||
assert last_response.ok?
|
||||
assert_no_match /PAGE_OVERRIDE/, last_response.body
|
||||
assert_no_match /NAVBAR_OVERRIDE/, last_response.body
|
||||
|
||||
refute_match /PAGE_OVERRIDE/, last_response.body
|
||||
refute_match /NAVBAR_OVERRIDE/, last_response.body
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user