Compare commits

..

9 Commits

Author SHA1 Message Date
benjamin wil b035e3cd26 Fix another order-dependent test failure
Very occasionally, this test fails due to `Precious::App` settings set
in previous tests. You can reproduce this failure using this seed:

    bundle exec rake TESTOPTS="--seed=42898"
2022-02-21 14:13:17 -08:00
benjamin wil 63edb3e8c4 Do not attempt to modify frozen strings
Using `#gsub!` here now results in an error. I am not entirely sure why
this hasn't happened before, but the error is straightforward:

     FrozenError: can't modify frozen String: "Author %{author} is from %{location}"
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:45:in `gsub!'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:45:in `fill_argument_content'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:37:in `block in autofill'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:33:in `each'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:33:in `map'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:33:in `autofill'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:35:in `block in autofill'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:33:in `each'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:33:in `map'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:33:in `autofill'
        /home/runner/work/gollum/gollum/lib/gollum/views/helpers/locale_helpers.rb:21:in `t'
        /home/runner/work/gollum/gollum/test/gollum/views/test_locale_helper.rb:95:in `block (4 levels) in <top (required)>'

`#gsub!` attempts to modify a string in-place, which does not work when
a string is frozen. It seems that in some Ruby environments, strings
from YAML files are frozen.
2022-02-20 15:39:05 -08:00
benjamin wil e4f549a9b9 Improve "allow editing" tests
While making changes to the test suite, I ran into some issues with
these tests failing on occasion.

I added some setup and teardown to help with this.

But one thing I did notice is that the word "Upload" appears in the
response body whether uploading is enabled or not, so I made these
assertions more specific to the HTML rather than other places the word
"Upload" might appear (which is related to Critic Markup).
2022-02-20 15:39:05 -08:00
benjamin wil 1641fa4e90 Use File.exist? instead of File.exists?
In Ruby 3.x, `File.exists?` is deprecated and outputs a warning.
2022-02-20 15:39:05 -08:00
benjamin wil 0b18f475f0 Update migration script to test run warnings
When running the entire test suite, many warnings would be output:

/Users/bw/Projects/gollum/test/test_migrate.rb:37: warning: already initialized constant HYPHENATE
/Users/bw/Projects/gollum/test/test_migrate.rb:37: warning: previous definition of HYPHENATE was here
/Users/bw/Projects/gollum/test/test_migrate.rb:37: warning: already initialized constant PAGE_FILE_DIR
/Users/bw/Projects/gollum/test/test_migrate.rb:37: warning: previous definition of PAGE_FILE_DIR was here
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:91: warning: already initialized constant REPO
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:91: warning: previous definition of REPO was here
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:236: warning: already initialized constant TREE
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:236: warning: previous definition of TREE was here
/Users/bw/Projects/gollum/test/test_migrate.rb:37: warning: already initialized constant PAGE_FILE_DIR
/Users/bw/Projects/gollum/test/test_migrate.rb:37: warning: previous definition of PAGE_FILE_DIR was here
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:91: warning: already initialized constant REPO
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:91: warning: previous definition of REPO was here
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:236: warning: already initialized constant TREE
/Users/bw/Projects/gollum/bin/gollum-migrate-tags:236: warning: previous definition of TREE was here

While it's unlikely that end users would ever see these warnings, as
they'd only be running the migration script once, they will always be
shown in our local test runs and CI run output.

So instead of using constants in our migration script, I change the
script to use class variables instead. This should not effect the
functionality of the migration script whatsoever.
2022-02-20 15:39:05 -08:00
benjamin wil f5c8af9904 Tweak setting initialization
I could not see a meaningful reason behind calling `forbid` so early in
the settings initialization block. But moving the `forbid` call until
later resolved this issue.

In the real world, I don't see how this would cause issues. But I found
that calling `forbid` when `wiki_options[:allow_editing]` was set to
false caused order-dependent test errors where Sprockets would end up
being badly configured and left without an initialized
`Sprockets::Environment` object, which is required by the
`sprockets-helpers` gem to resolve asset paths.

The test that would cause errors is also in this commit diff. I've
updated it to be a bit more readable.

I also took this opportunity to review and clean up the `@allow_editing`
assignment, which seemed a bit obfuscated.
2022-02-20 15:39:05 -08:00
benjamin wil 7a019567ec Tweak test formatting; fix order-dependent failure
The order-dependent failure has been been commented in code.

After manually bisecting the test suite, I was able to determine that
the template cascade tests were leaving the `@@template_priority_path`
set to an overridden value in tests run afterward.
2022-02-20 15:39:04 -08:00
benjamin wil 675fff02ac Change Minitest output format
- The `DefaultReporter` seems to have cleaner output than what we had
  before.
- `color: true` ensures things are colorized. It's pretty nice.
2022-02-20 11:19:22 -08:00
benjamin wil 0364d6e1be Use Minitest::Test
`Test::Unit` is deprecated, and we can switch to `Minitest::Test` with
almost no side effects.

This commit does all of the work required to make Minitest tests run
with Gollum's existing test helpers.
2022-02-20 11:18:54 -08:00
9 changed files with 71 additions and 94 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
ruby: ['2.6', '2.7', '3.0', '3.1'] ruby: [2.6, 2.7, 3.0]
steps: steps:
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v2 uses: actions/checkout@v2
+13 -1
View File
@@ -1,5 +1,6 @@
require 'rubygems' require 'rubygems'
require 'rake' require 'rake'
require 'date'
############################################################################# #############################################################################
# #
@@ -37,6 +38,14 @@ def bump_version
new_version new_version
end end
def date
Date.today.to_s
end
def rubyforge_project
name
end
def gemspec_file def gemspec_file
"#{name}.gemspec" "#{name}.gemspec"
end end
@@ -134,9 +143,12 @@ task :gemspec => :validate do
spec = File.read(gemspec_file) spec = File.read(gemspec_file)
head, manifest, tail = spec.split(" # = MANIFEST =\n") head, manifest, tail = spec.split(" # = MANIFEST =\n")
# replace name and version # replace name version and date
replace_header(head, :name) replace_header(head, :name)
replace_header(head, :version) 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 # determine file list from git ls-files
files = `git ls-files`. files = `git ls-files`.
+3
View File
@@ -1,9 +1,12 @@
Gem::Specification.new do |s| 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.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.required_ruby_version = '>= 2.6'
s.name = 'gollum' s.name = 'gollum'
s.version = '5.2.3' s.version = '5.2.3'
s.date = '2021-04-18'
s.license = 'MIT' s.license = 'MIT'
s.summary = 'A simple, Git-powered wiki.' s.summary = 'A simple, Git-powered wiki.'
+2 -3
View File
@@ -29,10 +29,9 @@ module Gollum
@@filters[pattern] = replacement @@filters[pattern] = replacement
end end
def self.apply_filters(wiki_page, data) def self.apply_filters(data)
@@filters.each do |pattern, replacement| @@filters.each do |pattern, replacement|
params = replacement.parameters.length == 0 ? nil : wiki_page data.gsub!(pattern, replacement.call)
data.gsub!(pattern, replacement.call(*params))
end end
data data
end end
+3 -3
View File
@@ -368,7 +368,7 @@ module Precious
@name = wikip.name @name = wikip.name
@ext = wikip.ext @ext = wikip.ext
@path = wikip.path @path = wikip.path
@template_page = load_template(wikip, @path) if settings.wiki_options[:template_page] @template_page = load_template(@path) if settings.wiki_options[:template_page]
@allow_uploads = wikip.wiki.allow_uploads @allow_uploads = wikip.wiki.allow_uploads
@upload_dest = find_upload_dest(wikip.fullpath) @upload_dest = find_upload_dest(wikip.fullpath)
@@ -660,9 +660,9 @@ module Precious
end end
end end
def load_template(wiki_page, path) def load_template(path)
template_page = wiki_page(::File.join(path, '_Template')).page || wiki_page('/_Template').page template_page = wiki_page(::File.join(path, '_Template')).page || wiki_page('/_Template').page
template_page ? Gollum::TemplateFilter.apply_filters(wiki_page, template_page.text_data) : nil template_page ? Gollum::TemplateFilter.apply_filters(template_page.text_data) : nil
end end
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil) def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
-39
View File
@@ -344,45 +344,6 @@ EOF
Precious::App.set(:wiki_options, { :template_page => false }) Precious::App.set(:wiki_options, { :template_page => false })
end 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 test "edit returns nil for non-existant page" do
# post '/edit' fails. post '/edit/' works. # post '/edit' fails. post '/edit/' works.
page = 'not-real-page' page = 'not-real-page'
+49 -47
View File
@@ -25,60 +25,62 @@ def load_script(**args)
end end
end end
context '4.x -> 5.x tag migrator' do unless ENV['CI']
include Rack::Test::Methods context '4.x -> 5.x tag migrator' do
include Rack::Test::Methods
setup do setup do
@path = cloned_testpath("examples/lotr_migration.git") @path = cloned_testpath("examples/lotr_migration.git")
end end
test 'repair broken links' do test 'repair broken links' do
# The original contents of Subdir/Foo.md: # The original contents of Subdir/Foo.md:
# #
# waa # waa
# [[Samwi]] # [[Samwi]]
# [[samwise gamgee.mediaWiki]] # [[samwise gamgee.mediaWiki]]
# [[Samwise Gamgee.mediawiki]] # [[Samwise Gamgee.mediawiki]]
# [[Samwise Gamgee]] # [[Samwise Gamgee]]
# [[Test|Samwise Gamgee#Anchor]] # [[Test|Samwise Gamgee#Anchor]]
# [[Waaa|Test]] # [[Waaa|Test]]
# [[Zaa]] # [[Zaa]]
# #
# The contents will be updated after running the migration script. # The contents will be updated after running the migration script.
load_script load_script
file = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r') file = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
assert_equal <<~FILE_CONTENTS, file.read assert_equal <<~FILE_CONTENTS, file.read
waa waa
[[Samwi]] [[Samwi]]
[[/Samwise Gamgee.mediawiki]] [[/Samwise Gamgee.mediawiki]]
[[/Samwise Gamgee.mediawiki]] [[/Samwise Gamgee.mediawiki]]
[[/Samwise Gamgee.md]] [[/Samwise Gamgee.md]]
[[Test|/Samwise Gamgee.md#Anchor]] [[Test|/Samwise Gamgee.md#Anchor]]
[[Waaa|/Bar/Test.md]] [[Waaa|/Bar/Test.md]]
[[Subsub/Zaa.md]] [[Subsub/Zaa.md]]
FILE_CONTENTS FILE_CONTENTS
end end
test 'change spaced filenames to hyphenated filenames' do test 'change spaced filenames to hyphenated filenames' do
load_script(hyphenate: true) load_script(hyphenate: true)
f = ::File.new(::File.join(@path, 'Home.textile'), 'r') f = ::File.new(::File.join(@path, 'Home.textile'), 'r')
output = f.read output = f.read
assert_equal true, output.include?('[[Bilbo-Baggins.md]]') assert_equal true, output.include?('[[Bilbo-Baggins.md]]')
assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]') assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]')
end end
test 'migration with page file dir' do test 'migration with page file dir' do
load_script(page_file_dir: 'Subdir') load_script(page_file_dir: 'Subdir')
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r') f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
output = f.read output = f.read
assert_equal true, output.include?('[[Subsub/Zaa.md]]') assert_equal true, output.include?('[[Subsub/Zaa.md]]')
assert_equal true, output.include?('[[Samwi]]') assert_equal true, output.include?('[[Samwi]]')
end end
teardown do teardown do
FileUtils.rm_rf(@path) FileUtils.rm_rf(@path)
end
end end
end end