Merge remote-tracking branch 'origin/master' into websequencediagrams

Conflicts:
	README.md
	lib/gollum.rb
	lib/gollum/markup.rb
This commit is contained in:
Corey Donohoe
2012-04-10 17:37:48 -07:00
544 changed files with 14948 additions and 43418 deletions
+1
View File
@@ -0,0 +1 @@
ref: refs/heads/master
+5
View File
@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
+1
View File
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
@@ -1,7 +1,7 @@
#!/bin/sh
#
# An example hook script to check the commit log message.
# Called by git-commit with one argument, the name of the file
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
@@ -5,4 +5,4 @@
#
# To enable this hook, rename this file to "post-update".
exec git-update-server-info
exec git update-server-info
@@ -1,13 +1,13 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit with no arguments. The hook should
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if git-rev-parse --verify HEAD >/dev/null 2>&1
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
@@ -2,7 +2,7 @@
#
# Copyright (c) 2006, 2008 Junio C Hamano
#
# The "pre-rebase" hook is run just before "git-rebase" starts doing
# The "pre-rebase" hook is run just before "git rebase" starts doing
# its job, and can prevent the command from running by exiting with
# non-zero status.
#
@@ -43,7 +43,7 @@ git show-ref -q "$topic" || {
}
# Is topic fully merged to master?
not_in_master=`git-rev-list --pretty=oneline ^master "$topic"`
not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
if test -z "$not_in_master"
then
echo >&2 "$topic is fully merged to master; better remove it."
@@ -51,11 +51,11 @@ then
fi
# Is topic ever merged to next? If so you should not be rebasing it.
only_next_1=`git-rev-list ^master "^$topic" ${publish} | sort`
only_next_2=`git-rev-list ^master ${publish} | sort`
only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
only_next_2=`git rev-list ^master ${publish} | sort`
if test "$only_next_1" = "$only_next_2"
then
not_in_topic=`git-rev-list "^$topic" master`
not_in_topic=`git rev-list "^$topic" master`
if test -z "$not_in_topic"
then
echo >&2 "$topic is already up-to-date with master"
@@ -64,8 +64,8 @@ then
exit 0
fi
else
not_in_next=`git-rev-list --pretty=oneline ^${publish} "$topic"`
perl -e '
not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
/usr/bin/perl -e '
my $topic = $ARGV[0];
my $msg = "* $topic has commits already merged to public branch:\n";
my (%not_in_next) = map {
@@ -157,13 +157,13 @@ B to be deleted.
To compute (1):
git-rev-list ^master ^topic next
git-rev-list ^master next
git rev-list ^master ^topic next
git rev-list ^master next
if these match, topic has not merged in next at all.
To compute (2):
git-rev-list master..topic
git rev-list master..topic
if this is empty, it is fully merged to "master".
@@ -1,7 +1,7 @@
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by git-commit with the name of the file that has the
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
@@ -22,10 +22,10 @@
case "$2,$3" in
merge,)
perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
/usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
# ,|template,)
# perl -i.bak -pe '
# /usr/bin/perl -i.bak -pe '
# print "\n" . `git diff --cached --name-status -r`
# if /^#/ && $first++ == 0' "$1" ;;
@@ -1,7 +1,7 @@
#!/bin/sh
#
# An example hook script to blocks unannotated tags from entering.
# Called by git-receive-pack with arguments: refname sha1-old sha1-new
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
#
# To enable this hook, rename this file to "update".
#
@@ -64,7 +64,7 @@ zero="0000000000000000000000000000000000000000"
if [ "$newrev" = "$zero" ]; then
newrev_type=delete
else
newrev_type=$(git-cat-file -t $newrev)
newrev_type=$(git cat-file -t $newrev)
fi
case "$refname","$newrev_type" in
+6
View File
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
+1
View File
@@ -0,0 +1 @@
Test out whitespace with Sam
+1
View File
@@ -0,0 +1 @@
a8ad3c09dd842a3517085bfadd37718856dee813
+8 -1
View File
@@ -1,5 +1,12 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = /Users/rick/p/gollum/test/examples/lotr.git
[branch "master"]
remote = origin
merge = refs/heads/master
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
# git-ls-files --others --exclude-from=.git/info/exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
-1
View File
@@ -1 +0,0 @@
d61c3de65957b5997c236393b3ad4d70b5cd8931 refs/heads/master
+3
View File
@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 60f12f4254f58801b9ee7db7bca5fa8aeefaa56b rick <technoweenie@gmail.com> 1291341857 -0800 clone: from /Users/rick/p/gollum/test/examples/lotr.git
60f12f4254f58801b9ee7db7bca5fa8aeefaa56b a8ad3c09dd842a3517085bfadd37718856dee813 rick <technoweenie@gmail.com> 1291341922 -0800 commit: add sidebars
a8ad3c09dd842a3517085bfadd37718856dee813 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 Arran Cudbard-Bell <a.cudbardb@freeradius.org> 1309107565 +0200 commit: Test out whitespace with Sam
@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 60f12f4254f58801b9ee7db7bca5fa8aeefaa56b rick <technoweenie@gmail.com> 1291341857 -0800 clone: from /Users/rick/p/gollum/test/examples/lotr.git
60f12f4254f58801b9ee7db7bca5fa8aeefaa56b a8ad3c09dd842a3517085bfadd37718856dee813 rick <technoweenie@gmail.com> 1291341922 -0800 commit: add sidebars
a8ad3c09dd842a3517085bfadd37718856dee813 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 Arran Cudbard-Bell <a.cudbardb@freeradius.org> 1309107565 +0200 commit: Test out whitespace with Sam
@@ -0,0 +1,2 @@
x╔нKNд0 ─aж9┘В┬Q°GЦH#дЦp'vh╔Иt■╕ К┐Ю,Ъм╞╞nК╨ pS~]Z══╔` ╤▒gK■└ыq┘XС└Фф]╞≤X|╣Y└┌c1Y┼╔╠┬O ┴Б$╙└чП1Ф╜цkО|┘ВC
wyzскн|╙]^з▐║Ё,г~зЗв3═╥m┼S└GК╛5Ув;ТЪ'С╘Ш─Мp÷≈║Ш█╚б}3|Пj╬KФWo
@@ -1,2 +0,0 @@
x∙н[
б0@Q©Ё┼ы─▓╓yDэй$≥╘AшH:БЖМЭ=pА√╬╝MюзИ$┐(Ш≤≤UJ(ег╧tяq╤yv.EvVsUoмфДШ■╢и3Q╛9Ф┌·1!#З░~Дя▄V·p*▐╜┴╤FВeеЖ╨■╬чюьД┌÷ЭdА╛ёжЙпcOХОPa╜╟В!m[@hУrH┐
@@ -0,0 +1,4 @@
xRMK1õ¼¿bè¥
e÷¢ÄTPOµ·%È4;Ý6Yh-ôÇ;[mK¡!‡äÍLÞG²t²„›Ûë‹)¼c·æHð‚]MÓ,ǧ p˜(@ëeí#œ4…ÊSPä>Ð
<v4Õ¸G³‡¾'_ñ7<A[4o*$ÝÏÙ×QG ú
¬tx·9Òìp„²\±M,ØZUe °×ÒB\ËäÇÕJŠ?»íkóÝ:[6&?D  âi/Ì6¬n$qà8^á勜ÚQÖs†Œ2Ó‰uömY±sê`ЉÁ6”6=m÷;¶èÔEGƒë!—²Œ\Q˶ÕÂ_VeÙIX‹ç˜Œ™hÓsëš}T3Y¦He“RWäó5·ÜSŘK¨‹áTœ>¯¹üOóÇï¹Ê³ShÄA
+1 -1
View File
@@ -1,2 +1,2 @@
# pack-refs with: peeled
d61c3de65957b5997c236393b3ad4d70b5cd8931 refs/heads/master
60f12f4254f58801b9ee7db7bca5fa8aeefaa56b refs/remotes/origin/master
+1 -1
View File
@@ -1 +1 @@
308fdf72d89351bf53fa6eeb00884273047e07fa
1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3
@@ -0,0 +1 @@
ref: refs/remotes/origin/master
@@ -0,0 +1 @@
initial commit
+1
View File
@@ -0,0 +1 @@
ref: refs/heads/master
+6
View File
@@ -0,0 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 22b404803c966dd92865614d86ff22ca12e50c1e rick <technoweenie@gmail.com> 1295287591 -0800 commit (initial): initial commit
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 22b404803c966dd92865614d86ff22ca12e50c1e rick <technoweenie@gmail.com> 1295287591 -0800 commit (initial): initial commit
@@ -0,0 +1 @@
22b404803c966dd92865614d86ff22ca12e50c1e
+1
View File
@@ -0,0 +1 @@
add footer and sidebar
+1
View File
@@ -0,0 +1 @@
ref: refs/heads/master
+12
View File
@@ -0,0 +1,12 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = /Users/rick/p/gollum/test/examples/revert.git
[branch "master"]
remote = origin
merge = refs/heads/master
+1
View File
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
+2
View File
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 7c45b5f16ff3bae2a0063191ef832701214d4df5 rick <technoweenie@gmail.com> 1291942707 -0800 clone: from /Users/rick/p/gollum/test/examples/revert.git
7c45b5f16ff3bae2a0063191ef832701214d4df5 f403b791119f8232b7cb0ba455c624ac6435f433 rick <technoweenie@gmail.com> 1291942743 -0800 commit: add footer and sidebar
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 7c45b5f16ff3bae2a0063191ef832701214d4df5 rick <technoweenie@gmail.com> 1291942707 -0800 clone: from /Users/rick/p/gollum/test/examples/revert.git
7c45b5f16ff3bae2a0063191ef832701214d4df5 f403b791119f8232b7cb0ba455c624ac6435f433 rick <technoweenie@gmail.com> 1291942743 -0800 commit: add footer and sidebar
@@ -0,0 +1,2 @@
P pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.pack
+2
View File
@@ -0,0 +1,2 @@
# pack-refs with: peeled
7c45b5f16ff3bae2a0063191ef832701214d4df5 refs/remotes/origin/master
@@ -0,0 +1 @@
f403b791119f8232b7cb0ba455c624ac6435f433
@@ -0,0 +1 @@
ref: refs/remotes/origin/master
+1
View File
@@ -0,0 +1 @@
ref: refs/heads/master
+5
View File
@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
+1
View File
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
+6
View File
@@ -0,0 +1,6 @@
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
@@ -0,0 +1 @@
xAjΓ0E»φ)ώΎ¤Θ’­ΨPJC 4λ΄i${ Φ½A—ο-ή‹Ίm`ϋΤjJsφΜΖ{Γ4ζ@–;ΔΑ†iΘδGΒθ¦ΠΡO[µβSξ«ΰJ―λΊΎ7οΛFr{‰Ί½΅·“νΰΜg3Σ=μcΫΏέ‰91wZ²άΆ–FRv-8]Ο—ΛαΈR¥Ψ΄ξ‚ο―Γ„TΆ²”¥ϋφ[NΥ
@@ -0,0 +1 @@
8964ed1b4e21aa90e831763bbce9034bfda81b70
+25 -3
View File
@@ -1,4 +1,5 @@
require 'rubygems'
require 'rack/test'
require 'test/unit'
require 'shoulda'
require 'mocha'
@@ -8,7 +9,9 @@ dir = File.dirname(File.expand_path(__FILE__))
$LOAD_PATH.unshift(File.join(dir, '..', 'lib'))
$LOAD_PATH.unshift(dir)
ENV['RACK_ENV'] = 'test'
require 'gollum'
require 'gollum/frontend/app'
# Make sure we're in the test dir, the tests expect that to be the current
# directory.
@@ -18,10 +21,27 @@ def testpath(path)
File.join(TEST_DIR, path)
end
def cloned_testpath(path)
repo = File.expand_path(testpath(path))
path = File.dirname(repo)
cloned = File.join(path, self.class.name)
FileUtils.rm_rf(cloned)
Dir.chdir(path) do
%x{git clone #{File.basename(repo)} #{self.class.name} 2>/dev/null}
end
cloned
end
def commit_details
{ :message => "Did something at #{Time.now}",
:name => "Tom Preston-Werner",
:email => "tom@github.com" }
:name => "Tom Preston-Werner",
:email => "tom@github.com" }
end
def normal(text)
text.gsub!(' ', '')
text.gsub!("\n", '')
text
end
# test/spec/mini 3
@@ -40,5 +60,7 @@ def context(*args, &block)
def self.teardown(&block) define_method(:teardown, &block) end
end
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
$contexts << klass
klass.class_eval &block
end
end
$contexts = []
+169
View File
@@ -0,0 +1,169 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Frontend" 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, {})
end
teardown do
FileUtils.rm_rf(@path)
end
test "edits page" do
page_1 = @wiki.page('A')
post "/edit/A", :content => 'abc',
:format => page_1.format, :message => 'def'
follow_redirect!
assert last_response.ok?
@wiki.clear_cache
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
end
test "edits page footer and sidebar" do
commits = @wiki.repo.commits('master').size
page_1 = @wiki.page('A')
foot_1 = page_1.footer
side_1 = page_1.sidebar
post "/edit/A",
:footer => 'footer', :page => "A", :sidebar => 'sidebar', :message => 'def'
follow_redirect!
assert_equal "/A", last_request.fullpath
assert last_response.ok?
@wiki.clear_cache
page_2 = @wiki.page(page_1.name)
foot_2 = page_2.footer
side_2 = page_2.sidebar
assert_equal page_1.raw_data, page_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_equal 'sidebar', side_2.raw_data
assert_equal 'def', side_2.version.message
assert_not_equal side_1.version.sha, side_2.version.sha
assert_equal commits+1, @wiki.repo.commits('master').size
end
test "renames page" do
page_1 = @wiki.page('B')
post "/edit/B", :content => 'abc',
:rename => "C",
:format => page_1.format, :message => 'def'
follow_redirect!
assert_equal "/C", last_request.fullpath
assert last_response.ok?
@wiki.clear_cache
assert_nil @wiki.page("B")
page_2 = @wiki.page('C')
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
end
test "creates page" do
post "/create", :content => 'abc', :page => "D",
:format => 'markdown', :message => 'def'
follow_redirect!
assert last_response.ok?
page = @wiki.page('D')
assert_equal 'abc', page.raw_data
assert_equal 'def', page.version.message
end
test "creates pages with escaped characters in title" do
post "/create", :content => 'abc', :page => 'Title with spaces',
:format => 'markdown', :message => 'foo'
assert_equal 'http://example.org/Title-with-spaces', last_response.headers['Location']
get "/Title-with-spaces"
assert_match /abc/, last_response.body
post "/create", :content => 'ghi', :page => 'Title/with/slashes',
:format => 'markdown', :message => 'bar'
assert_equal 'http://example.org/Title-with-slashes', last_response.headers['Location']
get "/Title-with-slashes"
assert_match /ghi/, last_response.body
end
test "guards against creation of existing page" do
name = "A"
post "/create", :content => 'abc', :page => name,
:format => 'markdown', :message => 'def'
assert last_response.ok?
@wiki.clear_cache
page = @wiki.page(name)
assert_not_equal 'abc', page.raw_data
end
test "previews content" do
post "/preview", :content => 'abc', :format => 'markdown'
assert last_response.ok?
end
test "previews content on the first page of an empty wiki" do
@path = cloned_testpath("examples/empty.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {})
post "/preview", :content => 'abc', :format => 'markdown'
assert last_response.ok?
end
test "reverts single commit" do
page1 = @wiki.page('B')
post "/revert/B/7c45b5f16ff3bae2a0063191ef832701214d4df5"
follow_redirect!
assert last_response.ok?
@wiki.clear_cache
page2 = @wiki.page('B')
assert_not_equal page1.version.sha, page2.version.sha
assert_equal "INITIAL", page2.raw_data.strip
end
test "reverts multiple commits" do
page1 = @wiki.page('A')
post "/revert/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac/b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f"
follow_redirect!
assert last_response.ok?
@wiki.clear_cache
page2 = @wiki.page('A')
assert_not_equal page1.version.sha, page2.version.sha
assert_equal "INITIAL", page2.raw_data.strip
end
test "cannot revert conflicting commit" do
page1 = @wiki.page('A')
post "/revert/A/302a5491a9a5ba12c7652ac831a44961afa312d2"
assert last_response.ok?
@wiki.clear_cache
page2 = @wiki.page('A')
assert_equal page1.version.sha, page2.version.sha
end
def app
Precious::App
end
end
+64
View File
@@ -0,0 +1,64 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Wiki" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
end
test "normalizes commit hash" do
commit = {:message => 'abc'}
name = @wiki.repo.config['user.name']
email = @wiki.repo.config['user.email']
committer = Gollum::Committer.new(@wiki, commit)
assert_equal name, committer.actor.name
assert_equal email, committer.actor.email
commit[:name] = 'bob'
commit[:email] = ''
committer = Gollum::Committer.new(@wiki, commit)
assert_equal 'bob', committer.actor.name
assert_equal email, committer.actor.email
commit[:email] = 'foo@bar.com'
committer = Gollum::Committer.new(@wiki, commit)
assert_equal 'bob', committer.actor.name
assert_equal 'foo@bar.com', committer.actor.email
end
test "yield after_commit callback" do
@path = cloned_testpath('examples/lotr.git')
yielded = nil
begin
wiki = Gollum::Wiki.new(@path)
committer = Gollum::Committer.new(wiki)
committer.after_commit do |index, sha1|
yielded = sha1
assert_equal committer, index
end
res = wiki.write_page("Gollum", :markdown, "# Gollum",
:committer => committer)
assert_equal committer, res
sha1 = committer.commit
assert_equal sha1, yielded
ensure
FileUtils.rm_rf(@path)
end
end
test "parents with default master ref" do
ref = '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'
committer = Gollum::Committer.new(@wiki)
assert_equal ref, committer.parents.first.sha
end
test "parents with custom ref" do
ref = '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), :ref => ref)
committer = Gollum::Committer.new(@wiki)
assert_equal ref, committer.parents.first.sha
end
end
+3 -1
View File
@@ -1,4 +1,6 @@
require File.join(File.dirname(__FILE__), *%w[helper])
# ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "helper")
require File.expand_path(path)
context "File" do
setup do
+52
View File
@@ -0,0 +1,52 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "GitAccess" do
setup do
@access = Gollum::GitAccess.new(testpath("examples/lotr.git"))
end
test "#commit fills commit_map cache" do
assert @access.commit_map.empty?
actual = @access.repo.commits.first
expected = @access.commit(actual.id)
assert_equal actual.message, expected.message
assert_equal actual.message, @access.commit_map[actual.id].message
end
test "#tree_map_for caches ref and tree" do
assert @access.ref_map.empty?
assert @access.tree_map.empty?
@access.tree 'master'
assert_equal({"master"=>"1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3"}, @access.ref_map)
map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3']
assert_equal 'Bilbo-Baggins.md', map[0].path
assert_equal '', map[0].dir
assert_equal map[0].path, map[0].name
assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
assert_equal '/Mordor', map[3].dir
assert_equal 'Eye-Of-Sauron.md', map[3].name
end
test "#tree_map_for only caches tree for commit" do
assert @access.tree_map.empty?
@access.tree '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
assert @access.ref_map.empty?
entry = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
assert_equal 'Bilbo-Baggins.md', entry.path
end
test "cannot access commit from invalid ref" do
assert_nil @access.commit('foo')
end
test "cannot access sha from invalid ref" do
assert_nil @access.ref_to_sha('foo')
end
test "cannot access tree from invalid ref" do
assert_equal [], @access.tree('foo')
end
end
+220 -27
View File
@@ -1,4 +1,5 @@
require File.join(File.dirname(__FILE__), *%w[helper])
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Markup" do
setup do
@@ -17,6 +18,39 @@ context "Markup" do
assert @wiki.pages[0].formatted_data
end
# This test is to assume that Sanitize.clean doesn't raise Encoding::CompatibilityError on ruby 1.9
test "formats non ASCII-7 character page from Wiki#pages" do
wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
assert_nothing_raised(defined?(Encoding) && Encoding::CompatibilityError) do
assert wiki.page("strider").formatted_data
end
end
test "Gollum::Markup#render yields a DocumentFragment" do
yielded = false
@wiki.write_page("Yielded", :markdown, "abc", commit_details)
page = @wiki.page("Yielded")
markup = Gollum::Markup.new(page)
markup.render do |doc|
assert_kind_of Nokogiri::HTML::DocumentFragment, doc
yielded = true
end
assert yielded
end
test "Gollum::Page#formatted_data yields a DocumentFragment" do
yielded = false
@wiki.write_page("Yielded", :markdown, "abc", commit_details)
page = @wiki.page("Yielded")
page.formatted_data do |doc|
assert_kind_of Nokogiri::HTML::DocumentFragment, doc
yielded = true
end
assert yielded
end
#########################################################################
#
# Links
@@ -128,6 +162,20 @@ context "Markup" do
assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
end
test "page link with different text" do
@wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details)
page = @wiki.page("Potato")
output = page.formatted_data
assert_equal "<p>a<aclass=\"internalpresent\"href=\"/Potato\">PotatoHeaad</a></p>", normal(output)
end
test "page link with different text on mediawiki" do
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
page = @wiki.page("Potato")
output = page.formatted_data
assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>"), normal(output)
end
#########################################################################
#
# Images
@@ -141,7 +189,18 @@ context "Markup" do
page = @wiki.page(name)
output = page.formatted_data
assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg" /> b</p>}, output
assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg"> b</p>}, output
end
end
test "image with extension in caps with http url" do
['http', 'https'].each do |scheme|
name = "Bilbo Baggins #{scheme}"
@wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.JPG]] b", commit_details)
page = @wiki.page(name)
output = page.formatted_data
assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.JPG"> b</p>}, output
end
end
@@ -153,7 +212,7 @@ context "Markup" do
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
page = @wiki.page("Bilbo Baggins")
assert_equal %{<p>a <img src="/wiki/alpha.jpg" /><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
end
test "image with relative path on root" do
@@ -164,7 +223,7 @@ context "Markup" do
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
assert_equal %{<p>a <img src="/wiki/alpha.jpg" /><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
end
test "image with relative path" do
@@ -176,12 +235,33 @@ context "Markup" do
page = @wiki.page("Bilbo Baggins")
output = page.formatted_data
assert_equal %{<p>a <img src="/wiki/greek/alpha.jpg" /><a href="/wiki/greek/alpha.jpg">a</a> b</p>}, output
assert_equal %{<p>a <img src="/wiki/greek/alpha.jpg"><a href="/wiki/greek/alpha.jpg">a</a> b</p>}, output
end
test "image with absolute path on a preview" do
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
index = @wiki.repo.index
index.add("alpha.jpg", "hi")
index.commit("Add alpha.jpg")
page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown)
assert_equal %{<p>a <img src="/wiki/alpha.jpg"> b</p>}, page.formatted_data
end
test "image with relative path on a preview" do
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
index = @wiki.repo.index
index.add("alpha.jpg", "hi")
index.add("greek/alpha.jpg", "hi")
index.commit("Add alpha.jpg")
page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown)
assert_equal %{<p>a <img src="/wiki/alpha.jpg"><img src="/wiki/greek/alpha.jpg"> b</p>}, page.formatted_data
end
test "image with alt" do
content = "a [[alpha.jpg|alt=Alpha Dog]] b"
output = %{<p>a <img src="/greek/alpha.jpg" alt="Alpha Dog" /> b</p>}
output = %{<p>a <img src="/greek/alpha.jpg" alt="Alpha Dog"> b</p>}
relative_image(content, output)
end
@@ -189,7 +269,7 @@ context "Markup" do
%w{em px}.each do |unit|
%w{width height}.each do |dim|
content = "a [[alpha.jpg|#{dim}=100#{unit}]] b"
output = "<p>a <img src=\"/greek/alpha.jpg\" #{dim}=\"100#{unit}\" /> b</p>"
output = "<p>a <img src=\"/greek/alpha.jpg\" #{dim}=\"100#{unit}\"> b</p>"
relative_image(content, output)
end
end
@@ -198,7 +278,7 @@ context "Markup" do
test "image with bogus dimension" do
%w{width height}.each do |dim|
content = "a [[alpha.jpg|#{dim}=100]] b"
output = "<p>a <img src=\"/greek/alpha.jpg\" /> b</p>"
output = "<p>a <img src=\"/greek/alpha.jpg\"> b</p>"
relative_image(content, output)
end
end
@@ -206,7 +286,7 @@ context "Markup" do
test "image with vertical align" do
%w{top texttop middle absmiddle bottom absbottom baseline}.each do |align|
content = "a [[alpha.jpg|align=#{align}]] b"
output = "<p>a <img src=\"/greek/alpha.jpg\" align=\"#{align}\" /> b</p>"
output = "<p>a <img src=\"/greek/alpha.jpg\" align=\"#{align}\"> b</p>"
relative_image(content, output)
end
end
@@ -214,40 +294,40 @@ context "Markup" do
test "image with horizontal align" do
%w{left center right}.each do |align|
content = "a [[alpha.jpg|align=#{align}]] b"
output = "<p>a <span class=\"align-#{align}\"><span><img src=\"/greek/alpha.jpg\" /></span></span> b</p>"
output = "<p>a <span class=\"align-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span> b</p>"
relative_image(content, output)
end
end
test "image with float" do
content = "a\n\n[[alpha.jpg|float]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"float-left\"><span><img src=\"/greek/alpha.jpg\" /></span></span></p>\n\n<p>b</p>"
output = "<p>a</p>\n\n<p><span class=\"float-left\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
relative_image(content, output)
end
test "image with float and align" do
%w{left right}.each do |align|
content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"float-#{align}\"><span><img src=\"/greek/alpha.jpg\" /></span></span></p>\n\n<p>b</p>"
output = "<p>a</p>\n\n<p><span class=\"float-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
relative_image(content, output)
end
end
test "image with frame" do
content = "a\n\n[[alpha.jpg|frame]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\" /></span></span></p>\n\n<p>b</p>"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
relative_image(content, output)
end
test "absolute image with frame" do
content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"http://example.com/bilbo.jpg\" /></span></span></p>\n\n<p>b</p>"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"http://example.com/bilbo.jpg\"></span></span></p>\n\n<p>b</p>"
relative_image(content, output)
end
test "image with frame and alt" do
content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\" alt=\"Alpha\" /><span>Alpha</span></span></span></p>\n\n<p>b</p>"
output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\" alt=\"Alpha\"><span>Alpha</span></span></span></p>\n\n<p>b</p>"
relative_image(content, output)
end
@@ -296,9 +376,9 @@ context "Markup" do
test "code blocks" do
content = "a\n\n```ruby\nx = 1\n```\n\nb"
output = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre>" +
"<span class=\"n\">x</span> <span class=\"o\">=</span> " +
"<span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>"
"<span class=\"mi\">1</span>\n</pre>\n</div>\n\n\n<p>b</p>"
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
@@ -311,9 +391,9 @@ context "Markup" do
test "code blocks with carriage returns" do
content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
output = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre>" +
"<span class=\"n\">x</span> <span class=\"o\">=</span> " +
"<span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>"
"<span class=\"mi\">1</span>\n</pre>\n</div>\n\n\n<p>b</p>"
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
@@ -329,7 +409,7 @@ context "Markup" do
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
"x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
"</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n<p>b</p>"
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
compare(content, output)
end
@@ -338,10 +418,57 @@ context "Markup" do
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
"x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
"</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n<p>b</p>"
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
compare(content, output)
end
test "code blocks with multibyte caracters indent" do
content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb"
output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre><span class=\"n\">" +
"s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'" +
"</span>\n</pre>\n</div>\n\n\n<p>b</p>"
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render(false, 'utf-8')
assert_equal output, rendered
end
test "code blocks with ascii characters" do
content = "a\n\n```\n├─foo\n```\n\nb"
output = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
"├─<span class=\"n\">foo</span>" +
"\n</pre>\n</div>\n\n<p>b</p>"
compare(content, output)
end
test "code with wiki links" do
content = <<-END
booya
``` python
np.array([[2,2],[1,3]],np.float)
```
END
# rendered with Gollum::Markup
page, rendered = render_page(content)
assert_markup_highlights_code Gollum::Markup, rendered
if Gollum.const_defined?(:MarkupGFM)
rendered_gfm = Gollum::MarkupGFM.new(page).render
assert_markup_highlights_code Gollum::MarkupGFM, rendered_gfm
end
end
def assert_markup_highlights_code(markup_class, rendered)
assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
end
#########################################################################
#
# Web Sequence Diagrams
@@ -367,6 +494,24 @@ context "Markup" do
#
#########################################################################
test "strips javscript protocol urls" do
content = "[Hack me](javascript:hacked=true)"
output = "<p><a>Hackme</a></p>"
compare(content, output)
end
test "removes style blocks completely" do
content = "<style>body { color: red }</style>foobar"
output = "<p>foobar</p>"
compare(content, output)
end
test "removes script blocks completely" do
content = "<script>alert('hax');</script>foobar"
output = "<p>foobar</p>"
compare(content, output)
end
test "escaped wiki link" do
content = "a '[[Foo]], b"
output = "<p>a [[Foo]], b</p>"
@@ -388,6 +533,48 @@ context "Markup" do
compare(content, output, 'org')
end
test "org mode style double file links" do
content = "a [[file:f.org][Google]] b"
output = "<p class=\"title\">a <a class=\"internal absent\" href=\"/f\">Google</a> b</p>"
compare(content, output, 'org')
end
test "short double links" do
content = "a [[b]] c"
output = %(<p class="title">a <a class="internal absent" href="/b">b</a> c</p>)
compare(content, output, 'org')
end
test "double linked pipe" do
content = "a [[|]] b"
output = %(<p class="title">a <a class="internal absent" href="/"></a> b</p>)
compare(content, output, 'org')
end
# test "id with prefix ok" do
# content = "h2(example#wiki-foo). xxxx"
# output = %(<h2 class="example" id="wiki-foo">xxxx</h2>)
# compare(content, output, :textile)
# end
# test "id prefix added" do
# content = "h2(#foo). xxxx[1]\n\nfn1.footnote"
# output = "<h2 id=\"wiki-foo\">xxxx" +
# "<sup class=\"footnote\" id=\"wiki-fnr1\"><a href=\"#wiki-fn1\">1</a></sup></h2>" +
# "\n<p class=\"footnote\" id=\"wiki-fn1\"><a href=\"#wiki-fnr1\"><sup>1</sup></a> footnote</p>"
# compare(content, output, :textile)
# end
# test "name prefix added" do
# content = "abc\n\n__TOC__\n\n==Header==\n\nblah"
# compare content, '', :mediawiki, [
# /id="wiki-toc"/,
# /href="#wiki-Header"/,
# /id="wiki-Header"/,
# /name="wiki-Header"/
# ]
# end
#########################################################################
#
# TeX
@@ -396,13 +583,13 @@ context "Markup" do
test "TeX block syntax" do
content = 'a \[ a^2 \] b'
output = "<p>a <script type=\"math/tex; mode=display\">a^2</script> b</p>"
output = "<p>a<imgsrc=\"/_tex.png?type=block&data=YV4y\"alt=\"a^2\">b</p>"
compare(content, output, 'md')
end
test "TeX inline syntax" do
content = 'a \( a^2 \) b'
output = "<p>a <script type=\"math/tex\">a^2</script> b</p>"
output = "<p>a<imgsrc=\"/_tex.png?type=inline&data=YV4y\"alt=\"a^2\">b</p>"
compare(content, output, 'md')
end
@@ -412,16 +599,22 @@ context "Markup" do
#
#########################################################################
def compare(content, output, ext = "md", regexes = [])
def render_page(content, ext = "md")
index = @wiki.repo.index
index.add("Bilbo-Baggins.#{ext}", content)
index.commit("Add baggins")
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
[page, Gollum::Markup.new(page).render]
end
def compare(content, output, ext = "md", regexes = [])
page, rendered = render_page(content, ext)
if regexes.empty?
assert_equal output, rendered
assert_equal normal(output), normal(rendered)
else
output = page.formatted_data
regexes.each { |r| assert_match r, output }
end
end
@@ -435,6 +628,6 @@ context "Markup" do
@wiki.clear_cache
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
assert_equal normal(output), normal(rendered)
end
end
+50 -2
View File
@@ -1,5 +1,5 @@
# ~*~ encoding: utf-8 ~*~
require File.join(File.dirname(__FILE__), *%w[helper])
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Page" do
setup do
@@ -25,7 +25,27 @@ context "Page" do
test "get existing page case insensitive" do
assert_equal @wiki.page('Bilbo Baggins').path, @wiki.page('bilbo baggins').path
end
test "get existing page with hyphen" do
assert_equal @wiki.page('Bilbo Baggins').path, @wiki.page('Bilbo-Baggins').path
end
test "get existing page with underscore" do
assert_nil @wiki.page('Bilbo_Baggins')
end
test "get existing page where filename contains whitespace, with hypen" do
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path
end
test "get existing page where filename contains whitespace, with underscore" do
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise_Gamgee').path
end
test "get existing page where filename contains whitespace, with whitespace" do
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise Gamgee').path
end
test "get nested page" do
page = @wiki.page('Eye Of Sauron')
assert_equal 'Mordor/Eye-Of-Sauron.md', page.path
@@ -109,10 +129,38 @@ context "Page" do
test "footer itself" do
footer = @wiki.page("_Footer")
assert_nil footer.footer
assert_nil footer.sidebar
end
test "top level sidebar" do
sidebar = @wiki.page('Home').sidebar
assert_equal 'Lord of the Rings wiki', sidebar.raw_data
assert_equal '_Sidebar.md', sidebar.path
end
test "nested sidebar" do
sidebar = @wiki.page('Eye Of Sauron').sidebar
assert_equal "Ones does not simply **walk** into Mordor!\n", sidebar.raw_data
assert_equal "Mordor/_Sidebar.md", sidebar.path
end
test "sidebar itself" do
sidebar = @wiki.page("_Sidebar")
assert_nil sidebar.footer
assert_nil sidebar.sidebar
end
test "cannot convert non string to human readable page title" do
assert_equal '', Gollum::Page.cname(nil)
assert_equal '', Gollum::Page.cname(3)
end
end
test "normalize_dir" do
assert_equal "", Gollum::BlobEntry.normalize_dir("")
assert_equal "", Gollum::BlobEntry.normalize_dir(".")
assert_equal "", Gollum::BlobEntry.normalize_dir("/")
assert_equal "", Gollum::BlobEntry.normalize_dir("c:/")
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("foo")
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo")
end
end
+45
View File
@@ -0,0 +1,45 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Page Reverting" do
setup do
@path = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@path)
end
teardown do
FileUtils.rm_rf(@path)
end
test "reverts single commit" do
page1 = @wiki.page("B")
sha = @wiki.revert_commit('7c45b5f16ff3bae2a0063191ef832701214d4df5')
page2 = @wiki.page("B")
assert_equal sha, page2.version.sha
assert_equal "INITIAL", body=page2.raw_data.strip
assert_equal body, File.read(File.join(@path, "B.md")).strip
end
test "reverts single commit for a page" do
page1 = @wiki.page('B')
sha = @wiki.revert_page(page1, '7c45b5f16ff3bae2a0063191ef832701214d4df5')
page2 = @wiki.page('B')
assert_equal sha, page2.version.sha
assert_equal "INITIAL", body=page2.raw_data.strip
assert_equal body, File.read(File.join(@path, "B.md")).strip
end
test "reverts multiple commits for a page" do
page1 = @wiki.page('A')
sha = @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2^', 'b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f')
page2 = @wiki.page('A')
assert_equal sha, page2.version.sha
assert_equal "INITIAL", body=page2.raw_data.strip
assert_equal body, File.read(File.join(@path, "A.md")).strip
end
test "cannot revert conflicting commit" do
page1 = @wiki.page('A')
assert_equal false, @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2')
end
end
+217 -39
View File
@@ -1,8 +1,27 @@
require File.join(File.dirname(__FILE__), *%w[helper])
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Wiki" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
Gollum::Wiki.markup_classes = nil
end
test "#markup_class gets default markup" do
assert_equal Gollum::Markup, Gollum::Wiki.markup_class
end
test "#default_markup_class= doesn't clobber alternate markups" do
custom = Class.new(Gollum::Markup)
custom_md = Class.new(Gollum::Markup)
Gollum::Wiki.markup_classes = Hash.new Gollum::Markup
Gollum::Wiki.markup_classes[:markdown] = custom_md
Gollum::Wiki.default_markup_class = custom
assert_equal custom, Gollum::Wiki.default_markup_class
assert_equal custom, Gollum::Wiki.markup_classes[:orgmode]
assert_equal custom_md, Gollum::Wiki.markup_classes[:markdown]
end
test "repo path" do
@@ -32,56 +51,41 @@ context "Wiki" do
assert_equal commits, @wiki.log(:page => 2).map { |c| c.id }
end
test "list pages, sorted by title" do
test "list pages" do
pages = @wiki.pages
assert_equal \
%w(bilbo.md Bilbo-Baggins.md Eye-Of-Sauron.md My-Precious.md Home.textile),
pages.map { |p| p.filename }
['Bilbo-Baggins.md', 'Eye-Of-Sauron.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'],
pages.map { |p| p.filename }.sort
end
test "counts pages" do
assert_equal 5, @wiki.size
end
test "normalizes commit hash" do
commit = {:message => 'abc'}
name = @wiki.repo.config['user.name']
email = @wiki.repo.config['user.email']
assert_equal({:message => 'abc', :name => name, :email => email},
@wiki.normalize_commit(commit.dup))
commit[:name] = 'bob'
commit[:email] = ''
assert_equal({:message => 'abc', :name => 'bob', :email => email},
@wiki.normalize_commit(commit.dup))
commit[:email] = 'foo@bar.com'
assert_equal({:message => 'abc', :name => 'bob', :email => 'foo@bar.com'},
@wiki.normalize_commit(commit.dup))
test "text_data" do
wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
if String.instance_methods.include?(:encoding)
utf8 = wiki.page("strider").text_data
assert_equal Encoding::UTF_8, utf8.encoding
sjis = wiki.page("sjis").text_data(Encoding::SHIFT_JIS)
assert_equal Encoding::SHIFT_JIS, sjis.encoding
else
page = wiki.page("strider")
assert_equal page.raw_data, page.text_data
end
end
test "#tree_map_for caches ref and tree" do
assert @wiki.ref_map.empty?
assert @wiki.tree_map.empty?
@wiki.tree_map_for 'master'
assert_equal({"master"=>"308fdf72d89351bf53fa6eeb00884273047e07fa"}, @wiki.ref_map)
map = @wiki.tree_map['308fdf72d89351bf53fa6eeb00884273047e07fa']
assert_equal 'Bilbo-Baggins.md', map[0].path
assert_equal '', map[0].dir
assert_equal map[0].path, map[0].name
assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
assert_equal '/Mordor', map[3].dir
assert_equal 'Eye-Of-Sauron.md', map[3].name
test "gets reverse diff" do
diff = @wiki.full_reverse_diff('a8ad3c09dd842a3517085bfadd37718856dee813')
assert_match "b/Mordor/_Sidebar.md", diff
assert_match "b/_Sidebar.md", diff
end
test "#tree_map_for only caches tree for commit" do
assert @wiki.tree_map.empty?
@wiki.tree_map_for '308fdf72d89351bf53fa6eeb00884273047e07fa'
assert @wiki.ref_map.empty?
entry = @wiki.tree_map['308fdf72d89351bf53fa6eeb00884273047e07fa'][0]
assert_equal 'Bilbo-Baggins.md', entry.path
test "gets reverse diff for a page" do
diff = @wiki.full_reverse_diff_for('_Sidebar.md', 'a8ad3c09dd842a3517085bfadd37718856dee813')
regex = /b\/Mordor\/\_Sidebar\.md/
assert_match "b/_Sidebar.md", diff
assert_no_match regex, diff
end
end
@@ -228,6 +232,64 @@ context "Wiki page writing" do
end
end
context "Wiki page writing with whitespace (filename contains whitespace)" do
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
end
test "update_page" do
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee2", commit_details)
assert_equal :textile, @wiki.page("Samwise Gamgee").format
assert_equal "h1. Samwise Gamgee2", @wiki.page("Samwise Gamgee").raw_data
assert_equal "Samwise Gamgee.textile", @wiki.page("Samwise Gamgee").filename
end
test "update page with format change, verify non-canonicalization of filename, where filename contains Whitespace" do
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee", commit_details)
assert_equal :textile, @wiki.page("Samwise Gamgee").format
assert_equal "h1. Samwise Gamgee", @wiki.page("Samwise Gamgee").raw_data
assert_equal "Samwise Gamgee.textile", @wiki.page("Samwise Gamgee").filename
end
test "update page with name change, verify canonicalization of filename, where filename contains Whitespace" do
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
end
test "update page with name and format change, verify canonicalization of filename, where filename contains Whitespace" do
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
assert_equal :textile, @wiki.page("Sam Gamgee").format
assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
end
teardown do
FileUtils.rm_rf(@path)
end
end
context "Wiki sync with working directory" do
setup do
@path = testpath('examples/wdtest')
@@ -282,3 +344,119 @@ context "Wiki sync with working directory" do
FileUtils.rm_r(@path)
end
end
context "Wiki sync with working directory (filename contains whitespace)" do
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
end
test "update a page with same name and format" do
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, page.name, page.format, "What we need is a few good taters.", commit_details)
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.mediawiki"))
end
test "update a page with different name and same format" do
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, "Sam Gamgee", page.format, "What we need is a few good taters.", commit_details)
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.mediawiki"))
assert !File.exist?(File.join(@path, "Samwise Gamgee"))
end
test "update a page with same name and different format" do
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, page.name, :textile, "What we need is a few good taters.", commit_details)
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.textile"))
assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
end
test "update a page with different name and different format" do
page = @wiki.page("Samwise Gamgee")
@wiki.update_page(page, "Sam Gamgee", :textile, "What we need is a few good taters.", commit_details)
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.textile"))
assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
end
test "delete a page" do
page = @wiki.page("Samwise Gamgee")
@wiki.delete_page(page, commit_details)
assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
end
teardown do
FileUtils.rm_r(@path)
end
end
context "page_file_dir option" do
setup do
@path = cloned_testpath('examples/page_file_dir')
@repo = Grit::Repo.init(@path)
@page_file_dir = 'docs'
@wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_file_dir)
end
test "write a page in sub directory" do
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
assert_equal "Hi", File.read(File.join(@path, @page_file_dir, "New-Page.md"))
assert !File.exist?(File.join(@path, "New-Page.md"))
end
test "edit a page in a sub directory" do
page = @wiki.page('foo')
@wiki.update_page(page, page.name, page.format, 'new contents', commit_details)
end
test "a file in page file dir should be found" do
assert @wiki.page("foo")
end
test "a file out of page file dir should not be found" do
assert !@wiki.page("bar")
end
test "search results should be restricted in page filer dir" do
results = @wiki.search("foo")
assert_equal 1, results.size
assert_equal "foo", results[0][:name]
end
teardown do
FileUtils.rm_r(@path)
end
end
context "Wiki page writing with different branch" do
setup do
@path = testpath("examples/test.git")
FileUtils.rm_rf(@path)
@repo = Grit::Repo.init_bare(@path)
@wiki = Gollum::Wiki.new(@path)
# We need an initial commit to create the master branch
# before we can create new branches
cd = commit_details
@wiki.write_page("Gollum", :markdown, "# Gollum", cd)
# Create our test branch and check it out
@repo.update_ref("test", @repo.commits.first.id)
@branch = Gollum::Wiki.new(@path, :ref => "test")
end
teardown do
FileUtils.rm_rf(@path)
end
test "write_page" do
cd = commit_details
@branch.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
assert @branch.page("Bilbo")
assert @wiki.page("Gollum")
assert_equal 1, @wiki.repo.commits.size
assert_equal 1, @branch.repo.commits.size
assert_equal nil, @wiki.page("Bilbo")
end
end