95d35d38da
* 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.
* 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.
* 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.
* 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.
* 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.
* Use `File.exist?` instead of `File.exists?`
In Ruby 3.x, `File.exists?` is deprecated and outputs a warning.
* 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).
* 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.
* 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"
110 lines
2.8 KiB
Ruby
110 lines
2.8 KiB
Ruby
# ~*~ encoding: utf-8 ~*~
|
|
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 pages is not blocked' do
|
|
post '/gollum/create',
|
|
content: 'abc',
|
|
format: 'markdown',
|
|
message: 'def',
|
|
page: 'D'
|
|
|
|
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
|
|
get '/.redirects.gollum'
|
|
assert_match /Accessing this resource is not allowed/, last_response.body
|
|
end
|
|
|
|
test ".redirects.gollum file should not be editable" do
|
|
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
|
|
get '/A'
|
|
|
|
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 last_response.body.include? "New"
|
|
|
|
get '/gollum/history/A'
|
|
|
|
refute last_response.body.include? "Edit"
|
|
|
|
get '/gollum/compare/A/fc665395..b26b791c'
|
|
|
|
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, allow_uploads: false})
|
|
|
|
get '/A'
|
|
|
|
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'
|
|
|
|
refute last_response.body.include? "New"
|
|
|
|
get '/gollum/history/A'
|
|
|
|
refute last_response.body.include? "Edit"
|
|
|
|
get '/gollum/compare/A/fc665395..b26b791c'
|
|
|
|
refute last_response.body.include? "Edit Page"
|
|
refute last_response.body.include? "Revert Changes"
|
|
end
|
|
|
|
def app
|
|
Precious::App
|
|
end
|
|
end
|