read-only-gollum 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. data/Gemfile +4 -0
  2. data/HISTORY.md +102 -0
  3. data/Home.md +3 -0
  4. data/LICENSE +21 -0
  5. data/README.md +477 -0
  6. data/Rakefile +142 -0
  7. data/bin/read-only-gollum +126 -0
  8. data/docs/sanitization.md +32 -0
  9. data/lib/gollum.rb +41 -0
  10. data/lib/gollum/blob_entry.rb +78 -0
  11. data/lib/gollum/committer.rb +218 -0
  12. data/lib/gollum/file.rb +64 -0
  13. data/lib/gollum/frontend/app.rb +225 -0
  14. data/lib/gollum/frontend/public/css/dialog.css +141 -0
  15. data/lib/gollum/frontend/public/css/editor.css +537 -0
  16. data/lib/gollum/frontend/public/css/gollum.css +660 -0
  17. data/lib/gollum/frontend/public/css/ie7.css +69 -0
  18. data/lib/gollum/frontend/public/css/template.css +381 -0
  19. data/lib/gollum/frontend/public/images/icon-sprite.png +0 -0
  20. data/lib/gollum/frontend/public/javascript/editor/gollum.editor.js +1096 -0
  21. data/lib/gollum/frontend/public/javascript/editor/langs/asciidoc.js +167 -0
  22. data/lib/gollum/frontend/public/javascript/editor/langs/creole.js +104 -0
  23. data/lib/gollum/frontend/public/javascript/editor/langs/markdown.js +211 -0
  24. data/lib/gollum/frontend/public/javascript/editor/langs/org.js +173 -0
  25. data/lib/gollum/frontend/public/javascript/editor/langs/pod.js +111 -0
  26. data/lib/gollum/frontend/public/javascript/editor/langs/rdoc.js +74 -0
  27. data/lib/gollum/frontend/public/javascript/editor/langs/textile.js +175 -0
  28. data/lib/gollum/frontend/public/javascript/gollum.dialog.js +263 -0
  29. data/lib/gollum/frontend/public/javascript/gollum.js +161 -0
  30. data/lib/gollum/frontend/public/javascript/gollum.placeholder.js +54 -0
  31. data/lib/gollum/frontend/public/javascript/jquery.color.js +123 -0
  32. data/lib/gollum/frontend/public/javascript/jquery.js +7179 -0
  33. data/lib/gollum/frontend/templates/compare.mustache +38 -0
  34. data/lib/gollum/frontend/templates/create.mustache +17 -0
  35. data/lib/gollum/frontend/templates/edit.mustache +17 -0
  36. data/lib/gollum/frontend/templates/editor.mustache +116 -0
  37. data/lib/gollum/frontend/templates/error.mustache +8 -0
  38. data/lib/gollum/frontend/templates/history.mustache +58 -0
  39. data/lib/gollum/frontend/templates/layout.mustache +28 -0
  40. data/lib/gollum/frontend/templates/page.mustache +37 -0
  41. data/lib/gollum/frontend/templates/pages.mustache +35 -0
  42. data/lib/gollum/frontend/templates/search.mustache +36 -0
  43. data/lib/gollum/frontend/templates/searchbar.mustache +10 -0
  44. data/lib/gollum/frontend/views/compare.rb +94 -0
  45. data/lib/gollum/frontend/views/create.rb +48 -0
  46. data/lib/gollum/frontend/views/edit.rb +52 -0
  47. data/lib/gollum/frontend/views/editable.rb +13 -0
  48. data/lib/gollum/frontend/views/error.rb +7 -0
  49. data/lib/gollum/frontend/views/history.rb +44 -0
  50. data/lib/gollum/frontend/views/layout.rb +20 -0
  51. data/lib/gollum/frontend/views/page.rb +57 -0
  52. data/lib/gollum/frontend/views/pages.rb +19 -0
  53. data/lib/gollum/frontend/views/search.rb +20 -0
  54. data/lib/gollum/git_access.rb +248 -0
  55. data/lib/gollum/markup.rb +489 -0
  56. data/lib/gollum/page.rb +430 -0
  57. data/lib/gollum/pagination.rb +61 -0
  58. data/lib/gollum/sanitization.rb +174 -0
  59. data/lib/gollum/tex.rb +89 -0
  60. data/lib/gollum/web_sequence_diagram.rb +43 -0
  61. data/lib/gollum/wiki.rb +636 -0
  62. data/read-only-gollum.gemspec +224 -0
  63. data/templates/formatting.html +92 -0
  64. data/test/examples/empty.git/HEAD +1 -0
  65. data/test/examples/empty.git/config +5 -0
  66. data/test/examples/empty.git/description +1 -0
  67. data/test/examples/empty.git/hooks/applypatch-msg.sample +15 -0
  68. data/test/examples/empty.git/hooks/commit-msg.sample +24 -0
  69. data/test/examples/empty.git/hooks/post-commit.sample +8 -0
  70. data/test/examples/empty.git/hooks/post-receive.sample +15 -0
  71. data/test/examples/empty.git/hooks/post-update.sample +8 -0
  72. data/test/examples/empty.git/hooks/pre-applypatch.sample +14 -0
  73. data/test/examples/empty.git/hooks/pre-commit.sample +46 -0
  74. data/test/examples/empty.git/hooks/pre-rebase.sample +169 -0
  75. data/test/examples/empty.git/hooks/prepare-commit-msg.sample +36 -0
  76. data/test/examples/empty.git/hooks/update.sample +128 -0
  77. data/test/examples/empty.git/info/exclude +6 -0
  78. data/test/examples/empty.git/objects/info/.gitkeep +0 -0
  79. data/test/examples/empty.git/objects/pack/.gitkeep +0 -0
  80. data/test/examples/empty.git/refs/heads/.gitkeep +0 -0
  81. data/test/examples/lotr.git/COMMIT_EDITMSG +1 -0
  82. data/test/examples/lotr.git/HEAD +1 -0
  83. data/test/examples/lotr.git/ORIG_HEAD +1 -0
  84. data/test/examples/lotr.git/config +12 -0
  85. data/test/examples/lotr.git/description +1 -0
  86. data/test/examples/lotr.git/index +0 -0
  87. data/test/examples/lotr.git/info/exclude +6 -0
  88. data/test/examples/lotr.git/logs/HEAD +3 -0
  89. data/test/examples/lotr.git/logs/refs/heads/master +3 -0
  90. data/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 +0 -0
  91. data/test/examples/lotr.git/objects/0a/de1e2916346d4c1f2fb63b863fd3c16808fe44 +0 -0
  92. data/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef +3 -0
  93. data/test/examples/lotr.git/objects/12/629d666c5e3178f82f533f543d61b53dc78c0b +0 -0
  94. data/test/examples/lotr.git/objects/1d/b89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 +2 -0
  95. data/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 +0 -0
  96. data/test/examples/lotr.git/objects/25/4bdc1ba27d8b8a794538a8522d9a2b56ec2dd9 +0 -0
  97. data/test/examples/lotr.git/objects/2c/b9156ad383914561a8502fc70f5a1d887e48ad +4 -0
  98. data/test/examples/lotr.git/objects/5d/cac289a8603188d2c5caf481dcba2985126aaa +0 -0
  99. data/test/examples/lotr.git/objects/60/f12f4254f58801b9ee7db7bca5fa8aeefaa56b +0 -0
  100. data/test/examples/lotr.git/objects/71/4323c104239440a5c66ab12a67ed07a83c404f +0 -0
  101. data/test/examples/lotr.git/objects/84/0ec5b1ba1320e8ec443f28f99566f615d5af10 +0 -0
  102. data/test/examples/lotr.git/objects/93/6b83ee0dd8837adb82511e40d5e4ebe59bb675 +0 -0
  103. data/test/examples/lotr.git/objects/94/523d7ae48aeba575099dd12926420d8fd0425d +2 -0
  104. data/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 +0 -0
  105. data/test/examples/lotr.git/objects/a3/1ca2a7c352c92531a8b99815d15843b259e814 +0 -0
  106. data/test/examples/lotr.git/objects/a6/59b3763b822dd97544621fd0beef162ea37b14 +4 -0
  107. data/test/examples/lotr.git/objects/a8/ad3c09dd842a3517085bfadd37718856dee813 +0 -0
  108. data/test/examples/lotr.git/objects/aa/b61fe89d56f8614c0a8151da34f939dcedfa68 +0 -0
  109. data/test/examples/lotr.git/objects/bc/4b5fc0ce2c2ba3acef6647e4f67256ee45ab60 +0 -0
  110. data/test/examples/lotr.git/objects/c3/b43e9f08966b088e7a0192e436b7a884542e05 +0 -0
  111. data/test/examples/lotr.git/objects/dc/596d6b2dd89ab05c66f4abd7d5eb706bc17f19 +0 -0
  112. data/test/examples/lotr.git/objects/ec/da3205bee14520aab5a7bb307392064b938e83 +0 -0
  113. data/test/examples/lotr.git/objects/f4/84ebb1f40f8eb20d1bcd8d1d71934d2b8ae961 +0 -0
  114. data/test/examples/lotr.git/objects/fa/e7ef5344202bba4129abdc13060d9297d99465 +3 -0
  115. data/test/examples/lotr.git/objects/info/packs +2 -0
  116. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.idx +0 -0
  117. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.pack +0 -0
  118. data/test/examples/lotr.git/packed-refs +2 -0
  119. data/test/examples/lotr.git/refs/heads/master +1 -0
  120. data/test/examples/lotr.git/refs/remotes/origin/HEAD +1 -0
  121. data/test/examples/page_file_dir.git/COMMIT_EDITMSG +1 -0
  122. data/test/examples/page_file_dir.git/HEAD +1 -0
  123. data/test/examples/page_file_dir.git/config +6 -0
  124. data/test/examples/page_file_dir.git/description +1 -0
  125. data/test/examples/page_file_dir.git/index +0 -0
  126. data/test/examples/page_file_dir.git/info/exclude +6 -0
  127. data/test/examples/page_file_dir.git/logs/HEAD +1 -0
  128. data/test/examples/page_file_dir.git/logs/refs/heads/master +1 -0
  129. data/test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf +0 -0
  130. data/test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e +0 -0
  131. data/test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 +0 -0
  132. data/test/examples/page_file_dir.git/objects/57/16ca5987cbf97d6bb54920bea6adde242d87e6 +0 -0
  133. data/test/examples/page_file_dir.git/objects/5b/43e14e0a15fb6f08feab1773d1c0991e9f71e2 +0 -0
  134. data/test/examples/page_file_dir.git/refs/heads/master +1 -0
  135. data/test/examples/revert.git/COMMIT_EDITMSG +1 -0
  136. data/test/examples/revert.git/HEAD +1 -0
  137. data/test/examples/revert.git/config +12 -0
  138. data/test/examples/revert.git/description +1 -0
  139. data/test/examples/revert.git/index +0 -0
  140. data/test/examples/revert.git/info/exclude +6 -0
  141. data/test/examples/revert.git/logs/HEAD +2 -0
  142. data/test/examples/revert.git/logs/refs/heads/master +2 -0
  143. data/test/examples/revert.git/objects/20/2ced67cea93c7b6bd2928aa1daef8d1d55a20d +0 -0
  144. data/test/examples/revert.git/objects/41/76394bfa11222363c66ce7e84b5f154095b6d9 +0 -0
  145. data/test/examples/revert.git/objects/6a/69f92020f5df77af6e8813ff1232493383b708 +0 -0
  146. data/test/examples/revert.git/objects/b4/785957bc986dc39c629de9fac9df46972c00fc +0 -0
  147. data/test/examples/revert.git/objects/f4/03b791119f8232b7cb0ba455c624ac6435f433 +0 -0
  148. data/test/examples/revert.git/objects/info/packs +2 -0
  149. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.idx +0 -0
  150. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.pack +0 -0
  151. data/test/examples/revert.git/packed-refs +2 -0
  152. data/test/examples/revert.git/refs/heads/master +1 -0
  153. data/test/examples/revert.git/refs/remotes/origin/HEAD +1 -0
  154. data/test/examples/yubiwa.git/HEAD +1 -0
  155. data/test/examples/yubiwa.git/config +5 -0
  156. data/test/examples/yubiwa.git/description +1 -0
  157. data/test/examples/yubiwa.git/info/exclude +6 -0
  158. data/test/examples/yubiwa.git/objects/10/fa2ddc4e3b4009d8a453aace10bd6148c1ad00 +0 -0
  159. data/test/examples/yubiwa.git/objects/52/4b82874327ea7cbf730389964ba7cb3de966de +0 -0
  160. data/test/examples/yubiwa.git/objects/58/3fc201cb457fb3f1480f3e1e5999b119633835 +0 -0
  161. data/test/examples/yubiwa.git/objects/87/bc1dd46ab3d3874d4e898d45dd512cc20a7cc8 +1 -0
  162. data/test/examples/yubiwa.git/objects/89/64ed1b4e21aa90e831763bbce9034bfda81b70 +0 -0
  163. data/test/examples/yubiwa.git/objects/9f/f6dd0660da5fba2d3374adb2b84fa653bb538b +0 -0
  164. data/test/examples/yubiwa.git/objects/ac/e97abf2b177815a1972d7db22f229f58c83309 +0 -0
  165. data/test/examples/yubiwa.git/objects/b1/f443863a4816628807fbf86141ebef055dda34 +0 -0
  166. data/test/examples/yubiwa.git/refs/heads/master +1 -0
  167. data/test/helper.rb +66 -0
  168. data/test/test_app.rb +169 -0
  169. data/test/test_committer.rb +64 -0
  170. data/test/test_file.rb +27 -0
  171. data/test/test_git_access.rb +52 -0
  172. data/test/test_markup.rb +628 -0
  173. data/test/test_page.rb +166 -0
  174. data/test/test_page_revert.rb +45 -0
  175. data/test/test_wiki.rb +462 -0
  176. metadata +470 -0
@@ -0,0 +1,166 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
+
4
+ context "Page" do
5
+ setup do
6
+ @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
7
+ end
8
+
9
+ test "new page" do
10
+ page = Gollum::Page.new(@wiki)
11
+ assert_nil page.raw_data
12
+ assert_nil page.formatted_data
13
+ end
14
+
15
+ test "get existing page" do
16
+ page = @wiki.page('Bilbo Baggins')
17
+ assert_equal Gollum::Page, page.class
18
+ assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
19
+ assert page.formatted_data =~ /<h1>Bilbo Baggins<\/h1>\n\n<p>Bilbo Baggins/
20
+ assert_equal 'Bilbo-Baggins.md', page.path
21
+ assert_equal :markdown, page.format
22
+ assert_equal @wiki.repo.commits.first.id, page.version.id
23
+ end
24
+
25
+ test "get existing page case insensitive" do
26
+ assert_equal @wiki.page('Bilbo Baggins').path, @wiki.page('bilbo baggins').path
27
+ end
28
+
29
+ test "get existing page with hyphen" do
30
+ assert_equal @wiki.page('Bilbo Baggins').path, @wiki.page('Bilbo-Baggins').path
31
+ end
32
+
33
+ test "get existing page with underscore" do
34
+ assert_nil @wiki.page('Bilbo_Baggins')
35
+ end
36
+
37
+ test "get existing page where filename contains whitespace, with hypen" do
38
+ assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path
39
+ end
40
+
41
+ test "get existing page where filename contains whitespace, with underscore" do
42
+ assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise_Gamgee').path
43
+ end
44
+
45
+ test "get existing page where filename contains whitespace, with whitespace" do
46
+ assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise Gamgee').path
47
+ end
48
+
49
+ test "get nested page" do
50
+ page = @wiki.page('Eye Of Sauron')
51
+ assert_equal 'Mordor/Eye-Of-Sauron.md', page.path
52
+ end
53
+
54
+ test "page versions" do
55
+ page = @wiki.page('Bilbo Baggins')
56
+ assert_equal ["f25eccd98e9b667f9e22946f3e2f945378b8a72d", "5bc1aaec6149e854078f1d0f8b71933bbc6c2e43"],
57
+ page.versions.map { |v| v.id }
58
+ end
59
+
60
+ test "page versions across renames" do
61
+ page = @wiki.page 'My-Precious'
62
+ assert_equal ['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b', '94523d7ae48aeba575099dd12926420d8fd0425d'],
63
+ page.versions(:follow => true).map { |v| v.id }
64
+ end
65
+
66
+ test "page versions without renames" do
67
+ page = @wiki.page 'My-Precious'
68
+ assert_equal ['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'],
69
+ page.versions(:follow => false).map { |v| v.id }
70
+ end
71
+
72
+ test "specific page version" do
73
+ page = @wiki.page('Bilbo Baggins', 'fbabba862dfa7ac35b39042dd4ad780c9f67b8cb')
74
+ assert_equal 'fbabba862dfa7ac35b39042dd4ad780c9f67b8cb', page.version.id
75
+ end
76
+
77
+ test "no page match" do
78
+ assert_nil @wiki.page('I do not exist')
79
+ end
80
+
81
+ test "no version match" do
82
+ assert_nil @wiki.page('Bilbo Baggins', 'I do not exist')
83
+ end
84
+
85
+ test "no ext match" do
86
+ assert_nil @wiki.page('Data')
87
+ end
88
+
89
+ test "cname" do
90
+ assert_equal "Foo", Gollum::Page.cname("Foo")
91
+ assert_equal "Foo-Bar", Gollum::Page.cname("Foo Bar")
92
+ assert_equal "Foo---Bar", Gollum::Page.cname("Foo / Bar")
93
+ assert_equal "José", Gollum::Page.cname("José")
94
+ assert_equal "モルドール", Gollum::Page.cname("モルドール")
95
+ end
96
+
97
+ test "title from filename with normal contents" do
98
+ page = @wiki.page('Bilbo Baggins')
99
+ assert_equal 'Bilbo Baggins', page.title
100
+ end
101
+
102
+ test "title from filename with html contents" do
103
+ page = @wiki.page('My <b>Precious', '0ed8cbe0a25235bd867e65193c7d837c66b328ef')
104
+ assert_equal 'My Precious', page.title
105
+ end
106
+
107
+ test "title from h1 with normal contents" do
108
+ page = @wiki.page('Home')
109
+ assert_equal "The LOTR Wiki", page.title
110
+ end
111
+
112
+ test "title from h1 with html contents" do
113
+ page = @wiki.page('Eye Of Sauron')
114
+ assert_equal "Eye Of Sauron", page.title
115
+ end
116
+
117
+ test "top level footer" do
118
+ footer = @wiki.page('Home').footer
119
+ assert_equal 'Lord of the Rings wiki', footer.raw_data
120
+ assert_equal '_Footer.md', footer.path
121
+ end
122
+
123
+ test "nested footer" do
124
+ footer = @wiki.page('Eye Of Sauron').footer
125
+ assert_equal "Ones does not simply **walk** into Mordor!\n", footer.raw_data
126
+ assert_equal "Mordor/_Footer.md", footer.path
127
+ end
128
+
129
+ test "footer itself" do
130
+ footer = @wiki.page("_Footer")
131
+ assert_nil footer.footer
132
+ assert_nil footer.sidebar
133
+ end
134
+
135
+ test "top level sidebar" do
136
+ sidebar = @wiki.page('Home').sidebar
137
+ assert_equal 'Lord of the Rings wiki', sidebar.raw_data
138
+ assert_equal '_Sidebar.md', sidebar.path
139
+ end
140
+
141
+ test "nested sidebar" do
142
+ sidebar = @wiki.page('Eye Of Sauron').sidebar
143
+ assert_equal "Ones does not simply **walk** into Mordor!\n", sidebar.raw_data
144
+ assert_equal "Mordor/_Sidebar.md", sidebar.path
145
+ end
146
+
147
+ test "sidebar itself" do
148
+ sidebar = @wiki.page("_Sidebar")
149
+ assert_nil sidebar.footer
150
+ assert_nil sidebar.sidebar
151
+ end
152
+
153
+ test "cannot convert non string to human readable page title" do
154
+ assert_equal '', Gollum::Page.cname(nil)
155
+ assert_equal '', Gollum::Page.cname(3)
156
+ end
157
+
158
+ test "normalize_dir" do
159
+ assert_equal "", Gollum::BlobEntry.normalize_dir("")
160
+ assert_equal "", Gollum::BlobEntry.normalize_dir(".")
161
+ assert_equal "", Gollum::BlobEntry.normalize_dir("/")
162
+ assert_equal "", Gollum::BlobEntry.normalize_dir("c:/")
163
+ assert_equal "/foo", Gollum::BlobEntry.normalize_dir("foo")
164
+ assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo")
165
+ end
166
+ end
@@ -0,0 +1,45 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
+
4
+ context "Page Reverting" do
5
+ setup do
6
+ @path = cloned_testpath("examples/revert.git")
7
+ @wiki = Gollum::Wiki.new(@path)
8
+ end
9
+
10
+ teardown do
11
+ FileUtils.rm_rf(@path)
12
+ end
13
+
14
+ test "reverts single commit" do
15
+ page1 = @wiki.page("B")
16
+ sha = @wiki.revert_commit('7c45b5f16ff3bae2a0063191ef832701214d4df5')
17
+ page2 = @wiki.page("B")
18
+ assert_equal sha, page2.version.sha
19
+ assert_equal "INITIAL", body=page2.raw_data.strip
20
+ assert_equal body, File.read(File.join(@path, "B.md")).strip
21
+ end
22
+
23
+ test "reverts single commit for a page" do
24
+ page1 = @wiki.page('B')
25
+ sha = @wiki.revert_page(page1, '7c45b5f16ff3bae2a0063191ef832701214d4df5')
26
+ page2 = @wiki.page('B')
27
+ assert_equal sha, page2.version.sha
28
+ assert_equal "INITIAL", body=page2.raw_data.strip
29
+ assert_equal body, File.read(File.join(@path, "B.md")).strip
30
+ end
31
+
32
+ test "reverts multiple commits for a page" do
33
+ page1 = @wiki.page('A')
34
+ sha = @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2^', 'b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f')
35
+ page2 = @wiki.page('A')
36
+ assert_equal sha, page2.version.sha
37
+ assert_equal "INITIAL", body=page2.raw_data.strip
38
+ assert_equal body, File.read(File.join(@path, "A.md")).strip
39
+ end
40
+
41
+ test "cannot revert conflicting commit" do
42
+ page1 = @wiki.page('A')
43
+ assert_equal false, @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2')
44
+ end
45
+ end
@@ -0,0 +1,462 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
+
4
+ context "Wiki" do
5
+ setup do
6
+ @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
7
+ Gollum::Wiki.markup_classes = nil
8
+ end
9
+
10
+ test "#markup_class gets default markup" do
11
+ assert_equal Gollum::Markup, Gollum::Wiki.markup_class
12
+ end
13
+
14
+ test "#default_markup_class= doesn't clobber alternate markups" do
15
+ custom = Class.new(Gollum::Markup)
16
+ custom_md = Class.new(Gollum::Markup)
17
+
18
+ Gollum::Wiki.markup_classes = Hash.new Gollum::Markup
19
+ Gollum::Wiki.markup_classes[:markdown] = custom_md
20
+ Gollum::Wiki.default_markup_class = custom
21
+
22
+ assert_equal custom, Gollum::Wiki.default_markup_class
23
+ assert_equal custom, Gollum::Wiki.markup_classes[:orgmode]
24
+ assert_equal custom_md, Gollum::Wiki.markup_classes[:markdown]
25
+ end
26
+
27
+ test "repo path" do
28
+ assert_equal testpath("examples/lotr.git"), @wiki.path
29
+ end
30
+
31
+ test "git repo" do
32
+ assert_equal Grit::Repo, @wiki.repo.class
33
+ assert @wiki.exist?
34
+ end
35
+
36
+ test "shows paginated log with no page" do
37
+ Gollum::Wiki.per_page = 3
38
+ commits = @wiki.repo.commits[0..2].map { |x| x.id }
39
+ assert_equal commits, @wiki.log.map { |c| c.id }
40
+ end
41
+
42
+ test "shows paginated log with 1st page" do
43
+ Gollum::Wiki.per_page = 3
44
+ commits = @wiki.repo.commits[0..2].map { |x| x.id }
45
+ assert_equal commits, @wiki.log(:page => 1).map { |c| c.id }
46
+ end
47
+
48
+ test "shows paginated log with next page" do
49
+ Gollum::Wiki.per_page = 3
50
+ commits = @wiki.repo.commits[3..5].map { |x| x.id }
51
+ assert_equal commits, @wiki.log(:page => 2).map { |c| c.id }
52
+ end
53
+
54
+ test "list pages" do
55
+ pages = @wiki.pages
56
+ assert_equal \
57
+ ['Bilbo-Baggins.md', 'Eye-Of-Sauron.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'],
58
+ pages.map { |p| p.filename }.sort
59
+ end
60
+
61
+ test "counts pages" do
62
+ assert_equal 5, @wiki.size
63
+ end
64
+
65
+ test "text_data" do
66
+ wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
67
+ if String.instance_methods.include?(:encoding)
68
+ utf8 = wiki.page("strider").text_data
69
+ assert_equal Encoding::UTF_8, utf8.encoding
70
+ sjis = wiki.page("sjis").text_data(Encoding::SHIFT_JIS)
71
+ assert_equal Encoding::SHIFT_JIS, sjis.encoding
72
+ else
73
+ page = wiki.page("strider")
74
+ assert_equal page.raw_data, page.text_data
75
+ end
76
+ end
77
+
78
+ test "gets reverse diff" do
79
+ diff = @wiki.full_reverse_diff('a8ad3c09dd842a3517085bfadd37718856dee813')
80
+ assert_match "b/Mordor/_Sidebar.md", diff
81
+ assert_match "b/_Sidebar.md", diff
82
+ end
83
+
84
+ test "gets reverse diff for a page" do
85
+ diff = @wiki.full_reverse_diff_for('_Sidebar.md', 'a8ad3c09dd842a3517085bfadd37718856dee813')
86
+ regex = /b\/Mordor\/\_Sidebar\.md/
87
+ assert_match "b/_Sidebar.md", diff
88
+ assert_no_match regex, diff
89
+ end
90
+ end
91
+
92
+ context "Wiki page previewing" do
93
+ setup do
94
+ @path = testpath("examples/lotr.git")
95
+ @wiki = Gollum::Wiki.new(@path)
96
+ end
97
+
98
+ test "preview_page" do
99
+ page = @wiki.preview_page("Test", "# Bilbo", :markdown)
100
+ assert_equal "# Bilbo", page.raw_data
101
+ assert_equal "<h1>Bilbo</h1>", page.formatted_data
102
+ assert_equal "Test.md", page.filename
103
+ assert_equal "Test", page.name
104
+ end
105
+ end
106
+
107
+ context "Wiki page writing" do
108
+ setup do
109
+ @path = testpath("examples/test.git")
110
+ FileUtils.rm_rf(@path)
111
+ Grit::Repo.init_bare(@path)
112
+ @wiki = Gollum::Wiki.new(@path)
113
+ end
114
+
115
+ test "write_page" do
116
+ cd = commit_details
117
+ @wiki.write_page("Gollum", :markdown, "# Gollum", cd)
118
+ assert_equal 1, @wiki.repo.commits.size
119
+ assert_equal cd[:message], @wiki.repo.commits.first.message
120
+ assert_equal cd[:name], @wiki.repo.commits.first.author.name
121
+ assert_equal cd[:email], @wiki.repo.commits.first.author.email
122
+ assert @wiki.page("Gollum")
123
+
124
+ @wiki.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
125
+ assert_equal 2, @wiki.repo.commits.size
126
+ assert @wiki.page("Bilbo")
127
+ assert @wiki.page("Gollum")
128
+ end
129
+
130
+ test "is not allowed to overwrite file" do
131
+ @wiki.write_page("Abc-Def", :markdown, "# Gollum", commit_details)
132
+ assert_raises Gollum::DuplicatePageError do
133
+ @wiki.write_page("ABC DEF", :textile, "# Gollum", commit_details)
134
+ end
135
+ end
136
+
137
+ test "update_page" do
138
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
139
+
140
+ page = @wiki.page("Gollum")
141
+ cd = commit_details
142
+ @wiki.update_page(page, page.name, :markdown, "# Gollum2", cd)
143
+
144
+ assert_equal 2, @wiki.repo.commits.size
145
+ assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
146
+ assert_equal cd[:message], @wiki.repo.commits.first.message
147
+ assert_equal cd[:name], @wiki.repo.commits.first.author.name
148
+ assert_equal cd[:email], @wiki.repo.commits.first.author.email
149
+ end
150
+
151
+ test "update page with format change" do
152
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
153
+
154
+ assert_equal :markdown, @wiki.page("Gollum").format
155
+
156
+ page = @wiki.page("Gollum")
157
+ @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
158
+
159
+ assert_equal 2, @wiki.repo.commits.size
160
+ assert_equal :textile, @wiki.page("Gollum").format
161
+ assert_equal "h1. Gollum", @wiki.page("Gollum").raw_data
162
+ end
163
+
164
+ test "update page with name change" do
165
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
166
+
167
+ assert_equal :markdown, @wiki.page("Gollum").format
168
+
169
+ page = @wiki.page("Gollum")
170
+ @wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit_details)
171
+
172
+ assert_equal 2, @wiki.repo.commits.size
173
+ assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
174
+ end
175
+
176
+ test "update page with name and format change" do
177
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
178
+
179
+ assert_equal :markdown, @wiki.page("Gollum").format
180
+
181
+ page = @wiki.page("Gollum")
182
+ @wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit_details)
183
+
184
+ assert_equal 2, @wiki.repo.commits.size
185
+ assert_equal :textile, @wiki.page("Smeagol").format
186
+ assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
187
+ end
188
+
189
+ test "update nested page with format change" do
190
+ index = @wiki.repo.index
191
+ index.add("lotr/Gollum.md", "# Gollum")
192
+ index.commit("Add nested page")
193
+
194
+ page = @wiki.page("Gollum")
195
+ assert_equal :markdown, @wiki.page("Gollum").format
196
+ @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
197
+
198
+ page = @wiki.page("Gollum")
199
+ assert_equal "lotr/Gollum.textile", page.path
200
+ assert_equal :textile, page.format
201
+ assert_equal "h1. Gollum", page.raw_data
202
+ end
203
+
204
+ test "delete root page" do
205
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
206
+
207
+ page = @wiki.page("Gollum")
208
+ @wiki.delete_page(page, commit_details)
209
+
210
+ assert_equal 2, @wiki.repo.commits.size
211
+ assert_nil @wiki.page("Gollum")
212
+ end
213
+
214
+ test "delete nested page" do
215
+ index = @wiki.repo.index
216
+ index.add("greek/Bilbo-Baggins.md", "hi")
217
+ index.add("Gollum.md", "hi")
218
+ index.commit("Add alpha.jpg")
219
+
220
+ page = @wiki.page("Bilbo-Baggins")
221
+ assert page
222
+ @wiki.delete_page(page, commit_details)
223
+
224
+ assert_equal 2, @wiki.repo.commits.size
225
+ assert_nil @wiki.page("Bilbo-Baggins")
226
+
227
+ assert @wiki.page("Gollum")
228
+ end
229
+
230
+ teardown do
231
+ FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
232
+ end
233
+ end
234
+
235
+ context "Wiki page writing with whitespace (filename contains whitespace)" do
236
+ setup do
237
+ @path = cloned_testpath("examples/lotr.git")
238
+ @wiki = Gollum::Wiki.new(@path)
239
+ end
240
+
241
+ test "update_page" do
242
+ assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
243
+ assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
244
+
245
+ page = @wiki.page("Samwise Gamgee")
246
+ @wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee2", commit_details)
247
+
248
+ assert_equal :textile, @wiki.page("Samwise Gamgee").format
249
+ assert_equal "h1. Samwise Gamgee2", @wiki.page("Samwise Gamgee").raw_data
250
+ assert_equal "Samwise Gamgee.textile", @wiki.page("Samwise Gamgee").filename
251
+ end
252
+
253
+ test "update page with format change, verify non-canonicalization of filename, where filename contains Whitespace" do
254
+ assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
255
+ assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
256
+
257
+ page = @wiki.page("Samwise Gamgee")
258
+ @wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee", commit_details)
259
+
260
+ assert_equal :textile, @wiki.page("Samwise Gamgee").format
261
+ assert_equal "h1. Samwise Gamgee", @wiki.page("Samwise Gamgee").raw_data
262
+ assert_equal "Samwise Gamgee.textile", @wiki.page("Samwise Gamgee").filename
263
+ end
264
+
265
+ test "update page with name change, verify canonicalization of filename, where filename contains Whitespace" do
266
+ assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
267
+ assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
268
+
269
+ page = @wiki.page("Samwise Gamgee")
270
+ @wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
271
+
272
+ assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
273
+ assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
274
+ end
275
+
276
+ test "update page with name and format change, verify canonicalization of filename, where filename contains Whitespace" do
277
+ assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
278
+ assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
279
+
280
+ page = @wiki.page("Samwise Gamgee")
281
+ @wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
282
+
283
+ assert_equal :textile, @wiki.page("Sam Gamgee").format
284
+ assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
285
+ assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
286
+ end
287
+
288
+ teardown do
289
+ FileUtils.rm_rf(@path)
290
+ end
291
+ end
292
+
293
+ context "Wiki sync with working directory" do
294
+ setup do
295
+ @path = testpath('examples/wdtest')
296
+ Grit::Repo.init(@path)
297
+ @wiki = Gollum::Wiki.new(@path)
298
+ end
299
+
300
+ test "write a page" do
301
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
302
+ assert_equal "Hi", File.read(File.join(@path, "New-Page.md"))
303
+ end
304
+
305
+ test "update a page with same name and format" do
306
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
307
+ page = @wiki.page("New Page")
308
+ @wiki.update_page(page, page.name, page.format, "Bye", commit_details)
309
+ assert_equal "Bye", File.read(File.join(@path, "New-Page.md"))
310
+ end
311
+
312
+ test "update a page with different name and same format" do
313
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
314
+ page = @wiki.page("New Page")
315
+ @wiki.update_page(page, "New Page 2", page.format, "Bye", commit_details)
316
+ assert_equal "Bye", File.read(File.join(@path, "New-Page-2.md"))
317
+ assert !File.exist?(File.join(@path, "New-Page.md"))
318
+ end
319
+
320
+ test "update a page with same name and different format" do
321
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
322
+ page = @wiki.page("New Page")
323
+ @wiki.update_page(page, page.name, :textile, "Bye", commit_details)
324
+ assert_equal "Bye", File.read(File.join(@path, "New-Page.textile"))
325
+ assert !File.exist?(File.join(@path, "New-Page.md"))
326
+ end
327
+
328
+ test "update a page with different name and different format" do
329
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
330
+ page = @wiki.page("New Page")
331
+ @wiki.update_page(page, "New Page 2", :textile, "Bye", commit_details)
332
+ assert_equal "Bye", File.read(File.join(@path, "New-Page-2.textile"))
333
+ assert !File.exist?(File.join(@path, "New-Page.md"))
334
+ end
335
+
336
+ test "delete a page" do
337
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
338
+ page = @wiki.page("New Page")
339
+ @wiki.delete_page(page, commit_details)
340
+ assert !File.exist?(File.join(@path, "New-Page.md"))
341
+ end
342
+
343
+ teardown do
344
+ FileUtils.rm_r(@path)
345
+ end
346
+ end
347
+
348
+ context "Wiki sync with working directory (filename contains whitespace)" do
349
+ setup do
350
+ @path = cloned_testpath("examples/lotr.git")
351
+ @wiki = Gollum::Wiki.new(@path)
352
+ end
353
+ test "update a page with same name and format" do
354
+ page = @wiki.page("Samwise Gamgee")
355
+ @wiki.update_page(page, page.name, page.format, "What we need is a few good taters.", commit_details)
356
+ assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.mediawiki"))
357
+ end
358
+
359
+ test "update a page with different name and same format" do
360
+ page = @wiki.page("Samwise Gamgee")
361
+ @wiki.update_page(page, "Sam Gamgee", page.format, "What we need is a few good taters.", commit_details)
362
+ assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.mediawiki"))
363
+ assert !File.exist?(File.join(@path, "Samwise Gamgee"))
364
+ end
365
+
366
+ test "update a page with same name and different format" do
367
+ page = @wiki.page("Samwise Gamgee")
368
+ @wiki.update_page(page, page.name, :textile, "What we need is a few good taters.", commit_details)
369
+ assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.textile"))
370
+ assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
371
+ end
372
+
373
+ test "update a page with different name and different format" do
374
+ page = @wiki.page("Samwise Gamgee")
375
+ @wiki.update_page(page, "Sam Gamgee", :textile, "What we need is a few good taters.", commit_details)
376
+ assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.textile"))
377
+ assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
378
+ end
379
+
380
+ test "delete a page" do
381
+ page = @wiki.page("Samwise Gamgee")
382
+ @wiki.delete_page(page, commit_details)
383
+ assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
384
+ end
385
+
386
+ teardown do
387
+ FileUtils.rm_r(@path)
388
+ end
389
+ end
390
+
391
+ context "page_file_dir option" do
392
+ setup do
393
+ @path = cloned_testpath('examples/page_file_dir')
394
+ @repo = Grit::Repo.init(@path)
395
+ @page_file_dir = 'docs'
396
+ @wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_file_dir)
397
+ end
398
+
399
+ test "write a page in sub directory" do
400
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
401
+ assert_equal "Hi", File.read(File.join(@path, @page_file_dir, "New-Page.md"))
402
+ assert !File.exist?(File.join(@path, "New-Page.md"))
403
+ end
404
+
405
+ test "edit a page in a sub directory" do
406
+ page = @wiki.page('foo')
407
+ @wiki.update_page(page, page.name, page.format, 'new contents', commit_details)
408
+ end
409
+
410
+ test "a file in page file dir should be found" do
411
+ assert @wiki.page("foo")
412
+ end
413
+
414
+ test "a file out of page file dir should not be found" do
415
+ assert !@wiki.page("bar")
416
+ end
417
+
418
+ test "search results should be restricted in page filer dir" do
419
+ results = @wiki.search("foo")
420
+ assert_equal 1, results.size
421
+ assert_equal "foo", results[0][:name]
422
+ end
423
+
424
+ teardown do
425
+ FileUtils.rm_r(@path)
426
+ end
427
+ end
428
+
429
+ context "Wiki page writing with different branch" do
430
+ setup do
431
+ @path = testpath("examples/test.git")
432
+ FileUtils.rm_rf(@path)
433
+ @repo = Grit::Repo.init_bare(@path)
434
+ @wiki = Gollum::Wiki.new(@path)
435
+
436
+ # We need an initial commit to create the master branch
437
+ # before we can create new branches
438
+ cd = commit_details
439
+ @wiki.write_page("Gollum", :markdown, "# Gollum", cd)
440
+
441
+ # Create our test branch and check it out
442
+ @repo.update_ref("test", @repo.commits.first.id)
443
+ @branch = Gollum::Wiki.new(@path, :ref => "test")
444
+ end
445
+
446
+ teardown do
447
+ FileUtils.rm_rf(@path)
448
+ end
449
+
450
+ test "write_page" do
451
+ cd = commit_details
452
+
453
+ @branch.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
454
+ assert @branch.page("Bilbo")
455
+ assert @wiki.page("Gollum")
456
+
457
+ assert_equal 1, @wiki.repo.commits.size
458
+ assert_equal 1, @branch.repo.commits.size
459
+
460
+ assert_equal nil, @wiki.page("Bilbo")
461
+ end
462
+ end