gollum 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gollum might be problematic. Click here for more details.

Files changed (166) hide show
  1. data/Gemfile +1 -1
  2. data/README.md +24 -1
  3. data/Rakefile +2 -2
  4. data/bin/gollum +1 -1
  5. data/gollum.gemspec +24 -169
  6. data/lib/gollum.rb +1 -1
  7. data/lib/gollum/frontend/app.rb +12 -7
  8. data/lib/gollum/frontend/helpers.rb +6 -0
  9. data/lib/gollum/frontend/public/gollum/livepreview/images/lr_24.png +0 -0
  10. data/lib/gollum/frontend/public/gollum/livepreview/index.html +0 -6
  11. data/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +0 -2
  12. data/lib/gollum/frontend/public/gollum/livepreview/licenses/licenses.txt +7 -0
  13. data/lib/gollum/frontend/public/gollum/livepreview/licenses/templarian_windowsicons/license.txt +40 -0
  14. data/lib/gollum/gitcode.rb +47 -0
  15. data/lib/gollum/markup.rb +58 -8
  16. data/lib/gollum/wiki.rb +7 -2
  17. data/templates/helper_wiki.rb +9 -0
  18. metadata +261 -429
  19. data/test/examples/empty.git/HEAD +0 -1
  20. data/test/examples/empty.git/config +0 -5
  21. data/test/examples/empty.git/description +0 -1
  22. data/test/examples/empty.git/hooks/applypatch-msg.sample +0 -15
  23. data/test/examples/empty.git/hooks/commit-msg.sample +0 -24
  24. data/test/examples/empty.git/hooks/post-commit.sample +0 -8
  25. data/test/examples/empty.git/hooks/post-receive.sample +0 -15
  26. data/test/examples/empty.git/hooks/post-update.sample +0 -8
  27. data/test/examples/empty.git/hooks/pre-applypatch.sample +0 -14
  28. data/test/examples/empty.git/hooks/pre-commit.sample +0 -46
  29. data/test/examples/empty.git/hooks/pre-rebase.sample +0 -169
  30. data/test/examples/empty.git/hooks/prepare-commit-msg.sample +0 -36
  31. data/test/examples/empty.git/hooks/update.sample +0 -128
  32. data/test/examples/empty.git/info/exclude +0 -6
  33. data/test/examples/empty.git/objects/info/.gitkeep +0 -0
  34. data/test/examples/empty.git/objects/pack/.gitkeep +0 -0
  35. data/test/examples/empty.git/refs/heads/.gitkeep +0 -0
  36. data/test/examples/lotr.git/COMMIT_EDITMSG +0 -1
  37. data/test/examples/lotr.git/HEAD +0 -1
  38. data/test/examples/lotr.git/ORIG_HEAD +0 -1
  39. data/test/examples/lotr.git/config +0 -12
  40. data/test/examples/lotr.git/description +0 -1
  41. data/test/examples/lotr.git/index +0 -0
  42. data/test/examples/lotr.git/info/exclude +0 -6
  43. data/test/examples/lotr.git/logs/HEAD +0 -7
  44. data/test/examples/lotr.git/logs/refs/heads/master +0 -7
  45. data/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 +0 -0
  46. data/test/examples/lotr.git/objects/0a/de1e2916346d4c1f2fb63b863fd3c16808fe44 +0 -0
  47. data/test/examples/lotr.git/objects/0d/c9016ca928c78d5421a99a53b379b53929221e +0 -0
  48. data/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef +0 -3
  49. data/test/examples/lotr.git/objects/12/629d666c5e3178f82f533f543d61b53dc78c0b +0 -0
  50. data/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 +0 -0
  51. data/test/examples/lotr.git/objects/1d/b89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 +0 -2
  52. data/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 +0 -0
  53. data/test/examples/lotr.git/objects/25/4bdc1ba27d8b8a794538a8522d9a2b56ec2dd9 +0 -0
  54. data/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 +0 -0
  55. data/test/examples/lotr.git/objects/2c/b9156ad383914561a8502fc70f5a1d887e48ad +0 -4
  56. data/test/examples/lotr.git/objects/45/3b250f979c7bd6dfb62640c944c982ae6721ee +0 -0
  57. data/test/examples/lotr.git/objects/45/f319ee12f2b551b901b22e72602963c366fff1 +0 -0
  58. data/test/examples/lotr.git/objects/46/a697caf435815bb07bbce947fc2d58be15f087 +0 -0
  59. data/test/examples/lotr.git/objects/4c/45c2b4e297a726c3d3f66886f35373e48fe1c5 +0 -2
  60. data/test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 +0 -0
  61. data/test/examples/lotr.git/objects/5d/cac289a8603188d2c5caf481dcba2985126aaa +0 -0
  62. data/test/examples/lotr.git/objects/60/f12f4254f58801b9ee7db7bca5fa8aeefaa56b +0 -0
  63. data/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 +0 -1
  64. data/test/examples/lotr.git/objects/6e/48abfc56565574859e081ee58eae655d48cf71 +0 -0
  65. data/test/examples/lotr.git/objects/71/4323c104239440a5c66ab12a67ed07a83c404f +0 -0
  66. data/test/examples/lotr.git/objects/7b/60c5a20a501a70f2317fa0ef763e1e2ce22d6b +0 -0
  67. data/test/examples/lotr.git/objects/7d/981cd984ad589e3cf00d8122170c6f7d685979 +0 -0
  68. data/test/examples/lotr.git/objects/84/0ec5b1ba1320e8ec443f28f99566f615d5af10 +0 -0
  69. data/test/examples/lotr.git/objects/93/6b83ee0dd8837adb82511e40d5e4ebe59bb675 +0 -0
  70. data/test/examples/lotr.git/objects/94/523d7ae48aeba575099dd12926420d8fd0425d +0 -2
  71. data/test/examples/lotr.git/objects/94/9a9cc3119b9c98817f375e976d2bb5e2a42809 +0 -0
  72. data/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 +0 -0
  73. data/test/examples/lotr.git/objects/9b/e95b960ac388d4e7db55f610f828e9c31344e6 +0 -0
  74. data/test/examples/lotr.git/objects/a3/1ca2a7c352c92531a8b99815d15843b259e814 +0 -0
  75. data/test/examples/lotr.git/objects/a6/59b3763b822dd97544621fd0beef162ea37b14 +0 -4
  76. data/test/examples/lotr.git/objects/a8/ad3c09dd842a3517085bfadd37718856dee813 +0 -0
  77. data/test/examples/lotr.git/objects/aa/b61fe89d56f8614c0a8151da34f939dcedfa68 +0 -0
  78. data/test/examples/lotr.git/objects/b0/de6e794dfdc7ef3400e894225bfe23308aae5c +0 -0
  79. data/test/examples/lotr.git/objects/b1/6b3d9fad9d78e5a669e7f33d94c96da374eccd +0 -0
  80. data/test/examples/lotr.git/objects/bc/4b5fc0ce2c2ba3acef6647e4f67256ee45ab60 +0 -0
  81. data/test/examples/lotr.git/objects/c3/b43e9f08966b088e7a0192e436b7a884542e05 +0 -0
  82. data/test/examples/lotr.git/objects/c9/6a7645db5d4c76389e77cd103ef3ed77d81e4c +0 -0
  83. data/test/examples/lotr.git/objects/ca/7355dc497e9729fbaf0c0e3f424b86afef5614 +0 -0
  84. data/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd +0 -2
  85. data/test/examples/lotr.git/objects/d5/29304506d37f544675244c335d85cab5d29966 +0 -0
  86. data/test/examples/lotr.git/objects/dc/596d6b2dd89ab05c66f4abd7d5eb706bc17f19 +0 -0
  87. data/test/examples/lotr.git/objects/ec/da3205bee14520aab5a7bb307392064b938e83 +0 -0
  88. data/test/examples/lotr.git/objects/f4/84ebb1f40f8eb20d1bcd8d1d71934d2b8ae961 +0 -0
  89. data/test/examples/lotr.git/objects/fa/e7ef5344202bba4129abdc13060d9297d99465 +0 -3
  90. data/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df +0 -1
  91. data/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 +0 -0
  92. data/test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 +0 -0
  93. data/test/examples/lotr.git/objects/info/packs +0 -2
  94. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.idx +0 -0
  95. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.pack +0 -0
  96. data/test/examples/lotr.git/packed-refs +0 -2
  97. data/test/examples/lotr.git/refs/heads/master +0 -1
  98. data/test/examples/lotr.git/refs/remotes/origin/HEAD +0 -1
  99. data/test/examples/page_file_dir.git/COMMIT_EDITMSG +0 -1
  100. data/test/examples/page_file_dir.git/HEAD +0 -1
  101. data/test/examples/page_file_dir.git/config +0 -6
  102. data/test/examples/page_file_dir.git/description +0 -1
  103. data/test/examples/page_file_dir.git/index +0 -0
  104. data/test/examples/page_file_dir.git/info/exclude +0 -6
  105. data/test/examples/page_file_dir.git/logs/HEAD +0 -1
  106. data/test/examples/page_file_dir.git/logs/refs/heads/master +0 -1
  107. data/test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf +0 -0
  108. data/test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e +0 -0
  109. data/test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 +0 -0
  110. data/test/examples/page_file_dir.git/objects/57/16ca5987cbf97d6bb54920bea6adde242d87e6 +0 -0
  111. data/test/examples/page_file_dir.git/objects/5b/43e14e0a15fb6f08feab1773d1c0991e9f71e2 +0 -0
  112. data/test/examples/page_file_dir.git/refs/heads/master +0 -1
  113. data/test/examples/revert.git/COMMIT_EDITMSG +0 -1
  114. data/test/examples/revert.git/HEAD +0 -1
  115. data/test/examples/revert.git/config +0 -12
  116. data/test/examples/revert.git/description +0 -1
  117. data/test/examples/revert.git/index +0 -0
  118. data/test/examples/revert.git/info/exclude +0 -6
  119. data/test/examples/revert.git/logs/HEAD +0 -3
  120. data/test/examples/revert.git/logs/refs/heads/master +0 -3
  121. data/test/examples/revert.git/objects/10/2685c42018f802557f05db171f44443e8dacab +0 -0
  122. data/test/examples/revert.git/objects/20/2ced67cea93c7b6bd2928aa1daef8d1d55a20d +0 -0
  123. data/test/examples/revert.git/objects/41/76394bfa11222363c66ce7e84b5f154095b6d9 +0 -0
  124. data/test/examples/revert.git/objects/6a/69f92020f5df77af6e8813ff1232493383b708 +0 -0
  125. data/test/examples/revert.git/objects/8e/83f898e5e16ae400db59dda1017acad540f3aa +0 -0
  126. data/test/examples/revert.git/objects/b4/785957bc986dc39c629de9fac9df46972c00fc +0 -0
  127. data/test/examples/revert.git/objects/ed/6c9f63b98acf73c25b5ffbb38da557d3682023 +0 -3
  128. data/test/examples/revert.git/objects/f4/03b791119f8232b7cb0ba455c624ac6435f433 +0 -0
  129. data/test/examples/revert.git/objects/info/packs +0 -2
  130. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.idx +0 -0
  131. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.pack +0 -0
  132. data/test/examples/revert.git/packed-refs +0 -2
  133. data/test/examples/revert.git/refs/heads/master +0 -1
  134. data/test/examples/revert.git/refs/remotes/origin/HEAD +0 -1
  135. data/test/examples/yubiwa.git/HEAD +0 -1
  136. data/test/examples/yubiwa.git/config +0 -5
  137. data/test/examples/yubiwa.git/description +0 -1
  138. data/test/examples/yubiwa.git/info/exclude +0 -6
  139. data/test/examples/yubiwa.git/objects/10/fa2ddc4e3b4009d8a453aace10bd6148c1ad00 +0 -0
  140. data/test/examples/yubiwa.git/objects/52/4b82874327ea7cbf730389964ba7cb3de966de +0 -0
  141. data/test/examples/yubiwa.git/objects/58/3fc201cb457fb3f1480f3e1e5999b119633835 +0 -0
  142. data/test/examples/yubiwa.git/objects/87/bc1dd46ab3d3874d4e898d45dd512cc20a7cc8 +0 -1
  143. data/test/examples/yubiwa.git/objects/89/64ed1b4e21aa90e831763bbce9034bfda81b70 +0 -0
  144. data/test/examples/yubiwa.git/objects/9f/f6dd0660da5fba2d3374adb2b84fa653bb538b +0 -0
  145. data/test/examples/yubiwa.git/objects/ac/e97abf2b177815a1972d7db22f229f58c83309 +0 -0
  146. data/test/examples/yubiwa.git/objects/b1/f443863a4816628807fbf86141ebef055dda34 +0 -0
  147. data/test/examples/yubiwa.git/refs/heads/master +0 -1
  148. data/test/file_view/1_file.txt +0 -3
  149. data/test/file_view/1_file_1_folder.txt +0 -8
  150. data/test/file_view/1_folder.txt +0 -8
  151. data/test/file_view/2_files_2_folders.txt +0 -12
  152. data/test/file_view/2_files_2_folders_1_root.txt +0 -13
  153. data/test/file_view/nested_folders.txt +0 -28
  154. data/test/helper.rb +0 -66
  155. data/test/test_app.rb +0 -375
  156. data/test/test_app_helpers.rb +0 -13
  157. data/test/test_committer.rb +0 -64
  158. data/test/test_file.rb +0 -27
  159. data/test/test_file_view.rb +0 -102
  160. data/test/test_git_access.rb +0 -53
  161. data/test/test_markup.rb +0 -732
  162. data/test/test_page.rb +0 -231
  163. data/test/test_page_revert.rb +0 -57
  164. data/test/test_pages_view.rb +0 -46
  165. data/test/test_unicode.rb +0 -131
  166. data/test/test_wiki.rb +0 -509
data/test/test_wiki.rb DELETED
@@ -1,509 +0,0 @@
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', 'Boromir.md', 'Elrond.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 "list files" do
62
- files = @wiki.files
63
- assert_equal \
64
- ['Data.csv', 'eye.jpg', 'todo.txt'],
65
- files.map { |p| p.filename }.sort
66
- end
67
-
68
- test "counts pages" do
69
- assert_equal 7, @wiki.size
70
- end
71
-
72
- test "text_data" do
73
- wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
74
- if String.instance_methods.include?(:encoding)
75
- utf8 = wiki.page("strider").text_data
76
- assert_equal Encoding::UTF_8, utf8.encoding
77
- sjis = wiki.page("sjis").text_data(Encoding::SHIFT_JIS)
78
- assert_equal Encoding::SHIFT_JIS, sjis.encoding
79
- else
80
- page = wiki.page("strider")
81
- assert_equal page.raw_data, page.text_data
82
- end
83
- end
84
-
85
- test "gets reverse diff" do
86
- diff = @wiki.full_reverse_diff('a8ad3c09dd842a3517085bfadd37718856dee813')
87
- assert_match "b/Mordor/_Sidebar.md", diff
88
- assert_match "b/_Sidebar.md", diff
89
- end
90
-
91
- test "gets reverse diff for a page" do
92
- diff = @wiki.full_reverse_diff_for('_Sidebar.md', 'a8ad3c09dd842a3517085bfadd37718856dee813')
93
- regex = /b\/Mordor\/\_Sidebar\.md/
94
- assert_match "b/_Sidebar.md", diff
95
- assert_no_match regex, diff
96
- end
97
-
98
- test "gets scoped page from specified directory" do
99
- @path = cloned_testpath('examples/lotr.git')
100
- begin
101
- wiki = Gollum::Wiki.new(@path)
102
- index = wiki.repo.index
103
- index.read_tree 'master'
104
- index.add('Foobar/Elrond.md', 'Baz')
105
- index.commit 'Add Foobar/Elrond.', [wiki.repo.commits.last], Grit::Actor.new('Tom Preston-Werner', 'tom@github.com')
106
-
107
- assert_equal 'Rivendell/Elrond.md', wiki.page('Elrond', nil, 'Rivendell').path
108
- # test paged as well.
109
- assert_equal 'Foobar/Elrond.md', wiki.paged('Elrond', 'Foobar').path
110
- ensure
111
- FileUtils.rm_rf(@path)
112
- end
113
- end
114
- end
115
-
116
- context "Wiki page previewing" do
117
- setup do
118
- @path = testpath("examples/lotr.git")
119
- Gollum::Wiki.default_options = {:universal_toc => false}
120
- @wiki = Gollum::Wiki.new(@path)
121
- end
122
-
123
- test "preview_page" do
124
- page = @wiki.preview_page("Test", "# Bilbo", :markdown)
125
- assert_equal "# Bilbo", page.raw_data
126
- assert_equal %Q{<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a>\n</h1>}, page.formatted_data
127
- assert_equal "Test.md", page.filename
128
- assert_equal "Test", page.name
129
- end
130
- end
131
-
132
- context "Wiki TOC" do
133
- setup do
134
- @path = testpath("examples/lotr.git")
135
- options = {:universal_toc => true}
136
- @wiki = Gollum::Wiki.new(@path, options)
137
- end
138
-
139
- test "toc_generation" do
140
- page = @wiki.preview_page("Test", "# Bilbo", :markdown)
141
- assert_equal "# Bilbo", page.raw_data
142
- assert_equal '<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a></h1>', page.formatted_data.gsub(/\n/,"")
143
- assert_equal %{<div class="toc"><div class="toc-title">Table of Contents</div><ul><li><a href="#Bilbo">Bilbo</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
144
- end
145
- end
146
-
147
- context "Wiki page writing" do
148
- setup do
149
- @path = testpath("examples/test.git")
150
- FileUtils.rm_rf(@path)
151
- Grit::Repo.init_bare(@path)
152
- @wiki = Gollum::Wiki.new(@path)
153
- end
154
-
155
- test "write_page" do
156
- cd = commit_details
157
- @wiki.write_page("Gollum", :markdown, "# Gollum", cd)
158
- assert_equal 1, @wiki.repo.commits.size
159
- assert_equal cd[:message], @wiki.repo.commits.first.message
160
- assert_equal cd[:name], @wiki.repo.commits.first.author.name
161
- assert_equal cd[:email], @wiki.repo.commits.first.author.email
162
- assert @wiki.page("Gollum")
163
-
164
- @wiki.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
165
- assert_equal 2, @wiki.repo.commits.size
166
- assert @wiki.page("Bilbo")
167
- assert @wiki.page("Gollum")
168
- end
169
-
170
- test "is not allowed to overwrite file" do
171
- @wiki.write_page("Abc-Def", :markdown, "# Gollum", commit_details)
172
- assert_raises Gollum::DuplicatePageError do
173
- @wiki.write_page("ABC DEF", :textile, "# Gollum", commit_details)
174
- end
175
- end
176
-
177
- test "update_page" do
178
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
179
-
180
- page = @wiki.page("Gollum")
181
- cd = commit_details
182
- @wiki.update_page(page, page.name, :markdown, "# Gollum2", cd)
183
-
184
- assert_equal 2, @wiki.repo.commits.size
185
- assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
186
- assert_equal cd[:message], @wiki.repo.commits.first.message
187
- assert_equal cd[:name], @wiki.repo.commits.first.author.name
188
- assert_equal cd[:email], @wiki.repo.commits.first.author.email
189
- end
190
-
191
- test "update page with format change" do
192
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
193
-
194
- assert_equal :markdown, @wiki.page("Gollum").format
195
-
196
- page = @wiki.page("Gollum")
197
- @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
198
-
199
- assert_equal 2, @wiki.repo.commits.size
200
- assert_equal :textile, @wiki.page("Gollum").format
201
- assert_equal "h1. Gollum", @wiki.page("Gollum").raw_data
202
- end
203
-
204
- test "update page with name change" do
205
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
206
-
207
- assert_equal :markdown, @wiki.page("Gollum").format
208
-
209
- page = @wiki.page("Gollum")
210
- @wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit_details)
211
-
212
- assert_equal 2, @wiki.repo.commits.size
213
- assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
214
- end
215
-
216
- test "update page with name and format change" do
217
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
218
-
219
- assert_equal :markdown, @wiki.page("Gollum").format
220
-
221
- page = @wiki.page("Gollum")
222
- @wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit_details)
223
-
224
- assert_equal 2, @wiki.repo.commits.size
225
- assert_equal :textile, @wiki.page("Smeagol").format
226
- assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
227
- end
228
-
229
- test "update nested page with format change" do
230
- index = @wiki.repo.index
231
- index.add("lotr/Gollum.md", "# Gollum")
232
- index.commit("Add nested page")
233
-
234
- page = @wiki.page("Gollum")
235
- assert_equal :markdown, @wiki.page("Gollum").format
236
- @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
237
-
238
- page = @wiki.page("Gollum")
239
- assert_equal "lotr/Gollum.textile", page.path
240
- assert_equal :textile, page.format
241
- assert_equal "h1. Gollum", page.raw_data
242
- end
243
-
244
- test "delete root page" do
245
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
246
-
247
- page = @wiki.page("Gollum")
248
- @wiki.delete_page(page, commit_details)
249
-
250
- assert_equal 2, @wiki.repo.commits.size
251
- assert_nil @wiki.page("Gollum")
252
- end
253
-
254
- test "delete nested page" do
255
- index = @wiki.repo.index
256
- index.add("greek/Bilbo-Baggins.md", "hi")
257
- index.add("Gollum.md", "hi")
258
- index.commit("Add alpha.jpg")
259
-
260
- page = @wiki.page("Bilbo-Baggins")
261
- assert page
262
- @wiki.delete_page(page, commit_details)
263
-
264
- assert_equal 2, @wiki.repo.commits.size
265
- assert_nil @wiki.page("Bilbo-Baggins")
266
-
267
- assert @wiki.page("Gollum")
268
- end
269
-
270
- teardown do
271
- FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
272
- end
273
- end
274
-
275
- context "Wiki page writing with whitespace (filename contains whitespace)" do
276
- setup do
277
- @path = cloned_testpath("examples/lotr.git")
278
- @wiki = Gollum::Wiki.new(@path)
279
- end
280
-
281
- test "update_page" do
282
- assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
283
- assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
284
-
285
- page = @wiki.page("Samwise Gamgee")
286
- @wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee2", commit_details)
287
-
288
- assert_equal :textile, @wiki.page("Samwise Gamgee").format
289
- assert_equal "h1. Samwise Gamgee2", @wiki.page("Samwise Gamgee").raw_data
290
- assert_equal "Samwise Gamgee.textile", @wiki.page("Samwise Gamgee").filename
291
- end
292
-
293
- test "update page with format change, verify non-canonicalization of filename, where filename contains Whitespace" do
294
- assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
295
- assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
296
-
297
- page = @wiki.page("Samwise Gamgee")
298
- @wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee", commit_details)
299
-
300
- assert_equal :textile, @wiki.page("Samwise Gamgee").format
301
- assert_equal "h1. Samwise Gamgee", @wiki.page("Samwise Gamgee").raw_data
302
- assert_equal "Samwise Gamgee.textile", @wiki.page("Samwise Gamgee").filename
303
- end
304
-
305
- test "update page with name change, verify canonicalization of filename, where filename contains Whitespace" do
306
- assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
307
- assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
308
-
309
- page = @wiki.page("Samwise Gamgee")
310
- @wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
311
-
312
- assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
313
- assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
314
- end
315
-
316
- test "update page with name and format change, verify canonicalization of filename, where filename contains Whitespace" do
317
- assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
318
- assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
319
-
320
- page = @wiki.page("Samwise Gamgee")
321
- @wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
322
-
323
- assert_equal :textile, @wiki.page("Sam Gamgee").format
324
- assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
325
- assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
326
- end
327
-
328
- teardown do
329
- FileUtils.rm_rf(@path)
330
- end
331
- end
332
-
333
- context "Wiki sync with working directory" do
334
- setup do
335
- @path = testpath('examples/wdtest')
336
- Grit::Repo.init(@path)
337
- @wiki = Gollum::Wiki.new(@path)
338
- end
339
-
340
- test "write a page" do
341
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
342
- assert_equal "Hi", File.read(File.join(@path, "New-Page.md"))
343
- end
344
-
345
- test "update a page with same name and format" do
346
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
347
- page = @wiki.page("New Page")
348
- @wiki.update_page(page, page.name, page.format, "Bye", commit_details)
349
- assert_equal "Bye", File.read(File.join(@path, "New-Page.md"))
350
- end
351
-
352
- test "update a page with different name and same format" do
353
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
354
- page = @wiki.page("New Page")
355
- @wiki.update_page(page, "New Page 2", page.format, "Bye", commit_details)
356
- assert_equal "Bye", File.read(File.join(@path, "New-Page-2.md"))
357
- assert !File.exist?(File.join(@path, "New-Page.md"))
358
- end
359
-
360
- test "update a page with same name and different format" do
361
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
362
- page = @wiki.page("New Page")
363
- @wiki.update_page(page, page.name, :textile, "Bye", commit_details)
364
- assert_equal "Bye", File.read(File.join(@path, "New-Page.textile"))
365
- assert !File.exist?(File.join(@path, "New-Page.md"))
366
- end
367
-
368
- test "update a page with different name and different format" do
369
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
370
- page = @wiki.page("New Page")
371
- @wiki.update_page(page, "New Page 2", :textile, "Bye", commit_details)
372
- assert_equal "Bye", File.read(File.join(@path, "New-Page-2.textile"))
373
- assert !File.exist?(File.join(@path, "New-Page.md"))
374
- end
375
-
376
- test "delete a page" do
377
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
378
- page = @wiki.page("New Page")
379
- @wiki.delete_page(page, commit_details)
380
- assert !File.exist?(File.join(@path, "New-Page.md"))
381
- end
382
-
383
- teardown do
384
- FileUtils.rm_r(@path)
385
- end
386
- end
387
-
388
- context "Wiki sync with working directory (filename contains whitespace)" do
389
- setup do
390
- @path = cloned_testpath("examples/lotr.git")
391
- @wiki = Gollum::Wiki.new(@path)
392
- end
393
- test "update a page with same name and format" do
394
- page = @wiki.page("Samwise Gamgee")
395
- @wiki.update_page(page, page.name, page.format, "What we need is a few good taters.", commit_details)
396
- assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.mediawiki"))
397
- end
398
-
399
- test "update a page with different name and same format" do
400
- page = @wiki.page("Samwise Gamgee")
401
- @wiki.update_page(page, "Sam Gamgee", page.format, "What we need is a few good taters.", commit_details)
402
- assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.mediawiki"))
403
- assert !File.exist?(File.join(@path, "Samwise Gamgee"))
404
- end
405
-
406
- test "update a page with same name and different format" do
407
- page = @wiki.page("Samwise Gamgee")
408
- @wiki.update_page(page, page.name, :textile, "What we need is a few good taters.", commit_details)
409
- assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.textile"))
410
- assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
411
- end
412
-
413
- test "update a page with different name and different format" do
414
- page = @wiki.page("Samwise Gamgee")
415
- @wiki.update_page(page, "Sam Gamgee", :textile, "What we need is a few good taters.", commit_details)
416
- assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.textile"))
417
- assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
418
- end
419
-
420
- test "delete a page" do
421
- page = @wiki.page("Samwise Gamgee")
422
- @wiki.delete_page(page, commit_details)
423
- assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
424
- end
425
-
426
- teardown do
427
- FileUtils.rm_r(@path)
428
- end
429
- end
430
-
431
- context "page_file_dir option" do
432
- setup do
433
- @path = cloned_testpath('examples/page_file_dir')
434
- @repo = Grit::Repo.init(@path)
435
- @page_file_dir = 'docs'
436
- @wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_file_dir)
437
- end
438
-
439
- test "write a page in sub directory" do
440
- @wiki.write_page("New Page", :markdown, "Hi", commit_details)
441
- assert_equal "Hi", File.read(File.join(@path, @page_file_dir, "New-Page.md"))
442
- assert !File.exist?(File.join(@path, "New-Page.md"))
443
- end
444
-
445
- test "edit a page in a sub directory" do
446
- page = @wiki.page('foo')
447
- @wiki.update_page(page, page.name, page.format, 'new contents', commit_details)
448
- end
449
-
450
- test "a file in page file dir should be found" do
451
- assert @wiki.page("foo")
452
- end
453
-
454
- test "a file out of page file dir should not be found" do
455
- assert !@wiki.page("bar")
456
- end
457
-
458
- test "search results should be restricted in page filer dir" do
459
- results = @wiki.search("foo")
460
- assert_equal 1, results.size
461
- assert_equal "docs/foo", results[0][:name]
462
- end
463
-
464
- test "search results should make the content/filename search additive" do
465
- # This file contains the word 'foo' and is called 'foo', so it should
466
- # have a count of 2, not 1...
467
- results = @wiki.search("foo")
468
- assert_equal 2, results[0][:count]
469
- end
470
-
471
- teardown do
472
- FileUtils.rm_r(@path)
473
- end
474
- end
475
-
476
- context "Wiki page writing with different branch" do
477
- setup do
478
- @path = testpath("examples/test.git")
479
- FileUtils.rm_rf(@path)
480
- @repo = Grit::Repo.init_bare(@path)
481
- @wiki = Gollum::Wiki.new(@path)
482
-
483
- # We need an initial commit to create the master branch
484
- # before we can create new branches
485
- cd = commit_details
486
- @wiki.write_page("Gollum", :markdown, "# Gollum", cd)
487
-
488
- # Create our test branch and check it out
489
- @repo.update_ref("test", @repo.commits.first.id)
490
- @branch = Gollum::Wiki.new(@path, :ref => "test")
491
- end
492
-
493
- teardown do
494
- FileUtils.rm_rf(@path)
495
- end
496
-
497
- test "write_page" do
498
- cd = commit_details
499
-
500
- @branch.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
501
- assert @branch.page("Bilbo")
502
- assert @wiki.page("Gollum")
503
-
504
- assert_equal 1, @wiki.repo.commits.size
505
- assert_equal 1, @branch.repo.commits.size
506
-
507
- assert_equal nil, @wiki.page("Bilbo")
508
- end
509
- end