* Remove all references to page_file_dir. Use new method signature for Wiki#page. Refactor helpers. * Use write_file for uploads * Refactor /pages route
This commit is contained in:
+74
-39
@@ -196,7 +196,7 @@ context "Frontend" do
|
||||
|
||||
|
||||
test "renames page in subdirectory" do
|
||||
page_1 = @wiki.paged("H", "G")
|
||||
page_1 = @wiki.page("G/H")
|
||||
assert_not_equal page_1, nil
|
||||
post "/gollum/rename/G/H", :rename => "/I/C", :message => 'def'
|
||||
|
||||
@@ -205,15 +205,15 @@ context "Frontend" do
|
||||
assert last_response.ok?
|
||||
|
||||
@wiki.clear_cache
|
||||
assert_nil @wiki.paged("H", "G")
|
||||
page_2 = @wiki.paged('C', 'I')
|
||||
assert_nil @wiki.page("G/H")
|
||||
page_2 = @wiki.page('I/C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "renames page relative in subdirectory" do
|
||||
page_1 = @wiki.paged("H", "G")
|
||||
page_1 = @wiki.page("G/H")
|
||||
assert_not_equal page_1, nil
|
||||
post "/gollum/rename/G/H", :rename => "K/C", :message => 'def'
|
||||
|
||||
@@ -222,8 +222,8 @@ context "Frontend" do
|
||||
assert last_response.ok?
|
||||
|
||||
@wiki.clear_cache
|
||||
assert_nil @wiki.paged("H", "G")
|
||||
page_2 = @wiki.paged('C', 'G/K')
|
||||
assert_nil @wiki.page("G/H")
|
||||
page_2 = @wiki.page('G/K/C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
@@ -306,7 +306,6 @@ context "Frontend" do
|
||||
:path => '/', :format => 'markdown', :message => ''
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
#puts last_response
|
||||
@wiki.clear_cache
|
||||
get "/gollum/create/TT"
|
||||
assert last_response.ok?
|
||||
@@ -320,25 +319,14 @@ context "Frontend" do
|
||||
assert last_response.ok?
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
|
||||
test "create sets the correct path for a relative path subdirectory with the page file directory set" do
|
||||
Precious::App.set(:wiki_options, { :page_file_dir => "foo" })
|
||||
dir = "bardir"
|
||||
name = "#{dir}/baz"
|
||||
get "/gollum/create/foo/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
# reset page_file_dir
|
||||
Precious::App.set(:wiki_options, { :page_file_dir => nil })
|
||||
end
|
||||
|
||||
test "edit returns nil for non-existant page" do
|
||||
# post '/edit' fails. post '/edit/' works.
|
||||
page = 'not-real-page'
|
||||
path = '/'
|
||||
post '/gollum/edit/', :content => 'edit_msg',
|
||||
:page => page, :path => path, :message => ''
|
||||
page_e = @wiki.paged(page, path)
|
||||
:page => page, :path => path, :message => ''
|
||||
page_e = @wiki.page(::File.join(path,page))
|
||||
assert_equal nil, page_e
|
||||
end
|
||||
|
||||
@@ -347,8 +335,8 @@ context "Frontend" do
|
||||
path = 'a/b/' # path must end with /
|
||||
|
||||
post '/gollum/create', :content => 'create_msg', :page => page,
|
||||
:path => path, :format => 'markdown', :message => ''
|
||||
page_c = @wiki.paged(page, path)
|
||||
:path => path, :format => 'markdown', :message => ''
|
||||
page_c = @wiki.page(File.join(path, page))
|
||||
assert_equal 'create_msg', page_c.raw_data
|
||||
|
||||
# must clear or create_msg will be returned
|
||||
@@ -356,8 +344,8 @@ context "Frontend" do
|
||||
|
||||
# post '/edit' fails. post '/edit/' works.
|
||||
post '/gollum/edit/', :content => 'edit_msg',
|
||||
:page => page, :path => path, :message => '', :etag => page_c.sha
|
||||
page_e = @wiki.paged(page, path)
|
||||
:page => page, :path => path, :message => '', :etag => page_c.sha
|
||||
page_e = @wiki.page(File.join(path, page))
|
||||
assert_equal 'edit_msg', page_e.raw_data
|
||||
|
||||
@wiki.clear_cache
|
||||
@@ -545,25 +533,12 @@ context "Frontend" do
|
||||
Precious::App.set(:wiki_options, { :js => nil })
|
||||
end
|
||||
|
||||
test "change custom.css path if page-file-dir is set" do
|
||||
Precious::App.set(:wiki_options, { :css => true, :page_file_dir => 'docs'})
|
||||
page = 'docs/yaycustom'
|
||||
text = 'customized!'
|
||||
|
||||
@wiki.write_page(page, :markdown, text,
|
||||
{ :name => 'user1', :email => 'user1' });
|
||||
|
||||
get page
|
||||
assert_match /"\/docs\/custom.css"/, last_response.body
|
||||
Precious::App.set(:wiki_options, { :css => nil, :page_file_dir => nil })
|
||||
end
|
||||
|
||||
test "show edit page with header and footer and sidebar of multibyte" do
|
||||
post "/gollum/create",
|
||||
:content => 'りんご',
|
||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
||||
|
||||
page = @wiki.paged('Multibyte')
|
||||
page = @wiki.page('Multibyte')
|
||||
|
||||
post "/gollum/edit/Multibyte",
|
||||
:content => 'りんご', :header => 'みかん', :footer => 'バナナ', :sidebar => 'スイカ',
|
||||
@@ -716,7 +691,7 @@ context "Frontend with lotr" do
|
||||
|
||||
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||
|
||||
page = @wiki.paged('Orc', 'Mordor')
|
||||
page = @wiki.page('Mordor/Orc')
|
||||
post "/gollum/edit/Mordor/Orc", :content => 'not so big smelly creatures',
|
||||
:page => 'Orc', :path => 'Mordor', :message => 'minor edit', :etag => page.sha
|
||||
assert last_response.ok?
|
||||
@@ -754,3 +729,63 @@ context "Frontend with lotr" do
|
||||
Precious::App
|
||||
end
|
||||
end
|
||||
|
||||
context "Frontend with page-file-dir" do
|
||||
include Rack::Test::Methods
|
||||
|
||||
setup do
|
||||
@path = cloned_testpath("examples/revert.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, {allow_editing: true})
|
||||
Precious::App.set(:wiki_options, { :css => true, :page_file_dir => 'docs'})
|
||||
end
|
||||
|
||||
teardown do
|
||||
Precious::App.set(:wiki_options, { :css => nil, :page_file_dir => nil})
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "create sets the correct path for a relative path subdirectory with the page file directory set" do
|
||||
dir = "bardir"
|
||||
name = "#{dir}/baz"
|
||||
get "/gollum/create/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
end
|
||||
|
||||
test "use custom.css from page-file-dir path if page-file-dir is set" do
|
||||
page = 'docs/yaycustom'
|
||||
text = 'customized!'
|
||||
|
||||
@wiki.write_page(page, :markdown, text,
|
||||
{ :name => 'user1', :email => 'user1' })
|
||||
|
||||
get 'yaycustom'
|
||||
assert_match /"\/custom.css"/, last_response.body
|
||||
end
|
||||
|
||||
test "custom.css with page-file-dir" do
|
||||
custom_content = 'customized for page-file-dir'
|
||||
options = {
|
||||
:message => "Uploaded file",
|
||||
:parent => @wiki.repo.head.commit,
|
||||
:author => "Bilbo Baggins"
|
||||
}
|
||||
|
||||
committer = Gollum::Committer.new(@wiki, options)
|
||||
committer.add_to_index('docs/custom.css', custom_content, {normalize: false})
|
||||
committer.after_commit do |committer, sha|
|
||||
@wiki.clear_cache
|
||||
committer.update_working_dir('docs/custom.css')
|
||||
end
|
||||
committer.commit
|
||||
get 'custom.css'
|
||||
|
||||
assert_equal custom_content, last_response.body
|
||||
end
|
||||
|
||||
def app
|
||||
Precious::App
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user