gollum 1.0.1 → 1.1.0

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.

@@ -18,6 +18,12 @@ def testpath(path)
18
18
  File.join(TEST_DIR, path)
19
19
  end
20
20
 
21
+ def commit_details
22
+ { :message => "Did something at #{Time.now}",
23
+ :name => "Tom Preston-Werner",
24
+ :email => "tom@github.com" }
25
+ end
26
+
21
27
  # test/spec/mini 3
22
28
  # http://gist.github.com/25455
23
29
  # chris@ozmm.org
@@ -26,7 +32,7 @@ def context(*args, &block)
26
32
  return super unless (name = args.first) && block
27
33
  require 'test/unit'
28
34
  klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
29
- def self.test(name, &block)
35
+ def self.test(name, &block)
30
36
  define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
31
37
  end
32
38
  def self.xtest(*args) end
@@ -11,8 +11,15 @@ context "File" do
11
11
  end
12
12
 
13
13
  test "existing file" do
14
- file = @wiki.file("Mordor/todo.txt")
14
+ commit = @wiki.repo.commits.first
15
+ file = @wiki.file("Mordor/todo.txt")
15
16
  assert_equal "[ ] Write section on Ents\n", file.raw_data
16
- assert_equal @wiki.repo.commits.first.id, file.version.id
17
+ assert_equal 'todo.txt', file.name
18
+ assert_equal commit.id, file.version.id
19
+ assert_equal commit.author.name, file.version.author.name
20
+ end
21
+
22
+ test "accessing tree" do
23
+ assert_nil @wiki.file("Mordor")
17
24
  end
18
25
  end
@@ -6,10 +6,6 @@ context "Markup" do
6
6
  FileUtils.rm_rf(@path)
7
7
  Grit::Repo.init_bare(@path)
8
8
  @wiki = Gollum::Wiki.new(@path)
9
-
10
- @commit = { :message => "Add stuff",
11
- :name => "Tom Preston-Werner",
12
- :email => "tom@github.com" }
13
9
  end
14
10
 
15
11
  teardown do
@@ -17,12 +13,18 @@ context "Markup" do
17
13
  end
18
14
 
19
15
  test "formats page from Wiki#pages" do
20
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", @commit)
16
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
21
17
  assert @wiki.pages[0].formatted_data
22
18
  end
23
19
 
20
+ #########################################################################
21
+ #
22
+ # Links
23
+ #
24
+ #########################################################################
25
+
24
26
  test "double page links no space" do
25
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", @commit)
27
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
26
28
 
27
29
  # "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a><a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
28
30
  page = @wiki.page("Bilbo Baggins")
@@ -41,7 +43,7 @@ context "Markup" do
41
43
  end
42
44
 
43
45
  test "double page links with space" do
44
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]] [[Bar]] b", @commit)
46
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]] [[Bar]] b", commit_details)
45
47
 
46
48
  # "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a> <a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
47
49
  page = @wiki.page("Bilbo Baggins")
@@ -60,7 +62,7 @@ context "Markup" do
60
62
  end
61
63
 
62
64
  test "page link" do
63
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", @commit)
65
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", commit_details)
64
66
 
65
67
  page = @wiki.page("Bilbo Baggins")
66
68
  output = page.formatted_data
@@ -69,8 +71,18 @@ context "Markup" do
69
71
  assert_match /\>Bilbo Baggins\</, output
70
72
  end
71
73
 
74
+ test "adds nofollow to links on historical pages" do
75
+ sha1 = @wiki.write_page("Sauron", :markdown, "a [[b]] c", commit_details)
76
+ page = @wiki.page("Sauron")
77
+ sha2 = @wiki.update_page(page, page.name, :markdown, "c [[b]] a", commit_details)
78
+ regx = /rel="nofollow"/
79
+ assert_no_match regx, page.formatted_data
80
+ assert_match regx, @wiki.page(page.name, sha1).formatted_data
81
+ assert_match regx, @wiki.page(page.name, sha2).formatted_data
82
+ end
83
+
72
84
  test "absent page link" do
73
- @wiki.write_page("Tolkien", :markdown, "a [[J. R. R. Tolkien]]'s b", @commit)
85
+ @wiki.write_page("Tolkien", :markdown, "a [[J. R. R. Tolkien]]'s b", commit_details)
74
86
 
75
87
  page = @wiki.page("Tolkien")
76
88
  output = page.formatted_data
@@ -80,41 +92,76 @@ context "Markup" do
80
92
  end
81
93
 
82
94
  test "page link with custom base path" do
83
- ["/wiki", "/wiki/"].each do |path|
95
+ ["/wiki", "/wiki/"].each_with_index do |path, i|
96
+ name = "Bilbo Baggins #{i}"
84
97
  @wiki = Gollum::Wiki.new(@path, :base_path => path)
85
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", @commit)
98
+ @wiki.write_page(name, :markdown, "a [[#{name}]] b", commit_details)
86
99
 
87
- page = @wiki.page("Bilbo Baggins")
100
+ page = @wiki.page(name)
88
101
  output = page.formatted_data
89
- assert_match /class="internal present"/, output
90
- assert_match /href="\/wiki\/Bilbo-Baggins"/, output
91
- assert_match /\>Bilbo Baggins\</, output
102
+ assert_match /class="internal present"/, output
103
+ assert_match /href="\/wiki\/Bilbo-Baggins-\d"/, output
104
+ assert_match /\>Bilbo Baggins \d\</, output
92
105
  end
93
106
  end
94
107
 
108
+ test "page link with included #" do
109
+ @wiki.write_page("Precious #1", :markdown, "a [[Precious #1]] b", commit_details)
110
+ page = @wiki.page('Precious #1')
111
+ output = page.formatted_data
112
+ assert_match /class="internal present"/, output
113
+ assert_match /href="\/Precious-%231"/, output
114
+ end
115
+
116
+ test "page link with extra #" do
117
+ @wiki.write_page("Potato", :markdown, "a [[Potato#1]] b", commit_details)
118
+ page = @wiki.page('Potato')
119
+ output = page.formatted_data
120
+ assert_match /class="internal present"/, output
121
+ assert_match /href="\/Potato#1"/, output
122
+ end
123
+
95
124
  test "external page link" do
96
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", @commit)
125
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
97
126
 
98
127
  page = @wiki.page("Bilbo Baggins")
99
128
  assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
100
129
  end
101
130
 
131
+ #########################################################################
132
+ #
133
+ # Images
134
+ #
135
+ #########################################################################
136
+
102
137
  test "image with http url" do
103
138
  ['http', 'https'].each do |scheme|
104
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", @commit)
139
+ name = "Bilbo Baggins #{scheme}"
140
+ @wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", commit_details)
105
141
 
106
- page = @wiki.page("Bilbo Baggins")
142
+ page = @wiki.page(name)
107
143
  output = page.formatted_data
108
144
  assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg" /> b</p>}, output
109
145
  end
110
146
  end
111
147
 
148
+ test "image with extension in caps with http url" do
149
+ ['http', 'https'].each do |scheme|
150
+ name = "Bilbo Baggins #{scheme}"
151
+ @wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.JPG]] b", commit_details)
152
+
153
+ page = @wiki.page(name)
154
+ output = page.formatted_data
155
+ assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.JPG" /> b</p>}, output
156
+ end
157
+ end
158
+
112
159
  test "image with absolute path" do
113
160
  @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
114
161
  index = @wiki.repo.index
115
162
  index.add("alpha.jpg", "hi")
116
163
  index.commit("Add alpha.jpg")
117
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", @commit)
164
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
118
165
 
119
166
  page = @wiki.page("Bilbo Baggins")
120
167
  assert_equal %{<p>a <img src="/wiki/alpha.jpg" /><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
@@ -203,17 +250,29 @@ context "Markup" do
203
250
  relative_image(content, output)
204
251
  end
205
252
 
253
+ test "absolute image with frame" do
254
+ content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb"
255
+ 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>"
256
+ relative_image(content, output)
257
+ end
258
+
206
259
  test "image with frame and alt" do
207
260
  content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb"
208
261
  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>"
209
262
  relative_image(content, output)
210
263
  end
211
264
 
265
+ #########################################################################
266
+ #
267
+ # File links
268
+ #
269
+ #########################################################################
270
+
212
271
  test "file link with absolute path" do
213
272
  index = @wiki.repo.index
214
273
  index.add("alpha.jpg", "hi")
215
274
  index.commit("Add alpha.jpg")
216
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Alpha|/alpha.jpg]] b", @commit)
275
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Alpha|/alpha.jpg]] b", commit_details)
217
276
 
218
277
  page = @wiki.page("Bilbo Baggins")
219
278
  output = Gollum::Markup.new(page).render
@@ -240,6 +299,12 @@ context "Markup" do
240
299
  assert_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
241
300
  end
242
301
 
302
+ #########################################################################
303
+ #
304
+ # Code
305
+ #
306
+ #########################################################################
307
+
243
308
  test "code blocks" do
244
309
  content = "a\n\n```ruby\nx = 1\n```\n\nb"
245
310
  output = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
@@ -288,6 +353,12 @@ context "Markup" do
288
353
  compare(content, output)
289
354
  end
290
355
 
356
+ #########################################################################
357
+ #
358
+ # Various
359
+ #
360
+ #########################################################################
361
+
291
362
  test "escaped wiki link" do
292
363
  content = "a '[[Foo]], b"
293
364
  output = "<p>a [[Foo]], b</p>"
@@ -309,18 +380,30 @@ context "Markup" do
309
380
  compare(content, output, 'org')
310
381
  end
311
382
 
312
- test "tex block syntax" do
383
+ #########################################################################
384
+ #
385
+ # TeX
386
+ #
387
+ #########################################################################
388
+
389
+ test "TeX block syntax" do
313
390
  content = 'a \[ a^2 \] b'
314
391
  output = "<p>a <script type=\"math/tex; mode=display\">a^2</script> b</p>"
315
392
  compare(content, output, 'md')
316
393
  end
317
394
 
318
- test "tex inline syntax" do
395
+ test "TeX inline syntax" do
319
396
  content = 'a \( a^2 \) b'
320
397
  output = "<p>a <script type=\"math/tex\">a^2</script> b</p>"
321
398
  compare(content, output, 'md')
322
399
  end
323
400
 
401
+ #########################################################################
402
+ #
403
+ # Helpers
404
+ #
405
+ #########################################################################
406
+
324
407
  def compare(content, output, ext = "md", regexes = [])
325
408
  index = @wiki.repo.index
326
409
  index.add("Bilbo-Baggins.#{ext}", content)
@@ -341,8 +424,9 @@ context "Markup" do
341
424
  index.add("greek/Bilbo-Baggins.md", content)
342
425
  index.commit("Add alpha.jpg")
343
426
 
427
+ @wiki.clear_cache
344
428
  page = @wiki.page("Bilbo Baggins")
345
429
  rendered = Gollum::Markup.new(page).render
346
430
  assert_equal output, rendered
347
431
  end
348
- end
432
+ end
@@ -1,3 +1,4 @@
1
+ # ~*~ encoding: utf-8 ~*~
1
2
  require File.join(File.dirname(__FILE__), *%w[helper])
2
3
 
3
4
  context "Page" do
@@ -109,4 +110,9 @@ context "Page" do
109
110
  footer = @wiki.page("_Footer")
110
111
  assert_nil footer.footer
111
112
  end
112
- end
113
+
114
+ test "cannot convert non string to human readable page title" do
115
+ assert_equal '', Gollum::Page.cname(nil)
116
+ assert_equal '', Gollum::Page.cname(3)
117
+ end
118
+ end
@@ -35,9 +35,54 @@ context "Wiki" do
35
35
  test "list pages" do
36
36
  pages = @wiki.pages
37
37
  assert_equal \
38
- %w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile My-Precious.md),
38
+ %w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile My-Precious.md),
39
39
  pages.map { |p| p.filename }.sort
40
40
  end
41
+
42
+ test "counts pages" do
43
+ assert_equal 4, @wiki.size
44
+ end
45
+
46
+ test "normalizes commit hash" do
47
+ commit = {:message => 'abc'}
48
+ name = @wiki.repo.config['user.name']
49
+ email = @wiki.repo.config['user.email']
50
+ assert_equal({:message => 'abc', :name => name, :email => email},
51
+ @wiki.normalize_commit(commit.dup))
52
+
53
+ commit[:name] = 'bob'
54
+ commit[:email] = ''
55
+ assert_equal({:message => 'abc', :name => 'bob', :email => email},
56
+ @wiki.normalize_commit(commit.dup))
57
+
58
+ commit[:email] = 'foo@bar.com'
59
+ assert_equal({:message => 'abc', :name => 'bob', :email => 'foo@bar.com'},
60
+ @wiki.normalize_commit(commit.dup))
61
+ end
62
+
63
+ test "#tree_map_for caches ref and tree" do
64
+ assert @wiki.ref_map.empty?
65
+ assert @wiki.tree_map.empty?
66
+ @wiki.tree_map_for 'master'
67
+ assert_equal({"master"=>"60f12f4254f58801b9ee7db7bca5fa8aeefaa56b"}, @wiki.ref_map)
68
+
69
+ map = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b']
70
+ assert_equal 'Bilbo-Baggins.md', map[0].path
71
+ assert_equal '', map[0].dir
72
+ assert_equal map[0].path, map[0].name
73
+ assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
74
+ assert_equal '/Mordor', map[3].dir
75
+ assert_equal 'Eye-Of-Sauron.md', map[3].name
76
+ end
77
+
78
+ test "#tree_map_for only caches tree for commit" do
79
+ assert @wiki.tree_map.empty?
80
+ @wiki.tree_map_for '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
81
+ assert @wiki.ref_map.empty?
82
+
83
+ entry = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
84
+ assert_equal 'Bilbo-Baggins.md', entry.path
85
+ end
41
86
  end
42
87
 
43
88
  context "Wiki page previewing" do
@@ -64,48 +109,48 @@ context "Wiki page writing" do
64
109
  end
65
110
 
66
111
  test "write_page" do
67
- commit = { :message => "Gollum page",
68
- :name => "Tom Preston-Werner",
69
- :email => "tom@github.com" }
70
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
112
+ cd = commit_details
113
+ @wiki.write_page("Gollum", :markdown, "# Gollum", cd)
71
114
  assert_equal 1, @wiki.repo.commits.size
72
- assert_equal "Gollum page", @wiki.repo.commits.first.message
73
- assert_equal "Tom Preston-Werner", @wiki.repo.commits.first.author.name
74
- assert_equal "tom@github.com", @wiki.repo.commits.first.author.email
115
+ assert_equal cd[:message], @wiki.repo.commits.first.message
116
+ assert_equal cd[:name], @wiki.repo.commits.first.author.name
117
+ assert_equal cd[:email], @wiki.repo.commits.first.author.email
75
118
  assert @wiki.page("Gollum")
76
119
 
77
- @wiki.write_page("Bilbo", :markdown, "# Bilbo", commit)
120
+ @wiki.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
78
121
  assert_equal 2, @wiki.repo.commits.size
79
122
  assert @wiki.page("Bilbo")
80
123
  assert @wiki.page("Gollum")
81
124
  end
82
125
 
126
+ test "is not allowed to overwrite file" do
127
+ @wiki.write_page("Abc-Def", :markdown, "# Gollum", commit_details)
128
+ assert_raises Gollum::DuplicatePageError do
129
+ @wiki.write_page("ABC DEF", :textile, "# Gollum", commit_details)
130
+ end
131
+ end
132
+
83
133
  test "update_page" do
84
- commit = { :message => "Gollum page",
85
- :name => "Tom Preston-Werner",
86
- :email => "tom@github.com" }
87
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
134
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
88
135
 
89
136
  page = @wiki.page("Gollum")
90
- @wiki.update_page(page, page.name, :markdown, "# Gollum2", commit)
137
+ cd = commit_details
138
+ @wiki.update_page(page, page.name, :markdown, "# Gollum2", cd)
91
139
 
92
140
  assert_equal 2, @wiki.repo.commits.size
93
141
  assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
94
- assert_equal "Gollum page", @wiki.repo.commits.first.message
95
- assert_equal "Tom Preston-Werner", @wiki.repo.commits.first.author.name
96
- assert_equal "tom@github.com", @wiki.repo.commits.first.author.email
142
+ assert_equal cd[:message], @wiki.repo.commits.first.message
143
+ assert_equal cd[:name], @wiki.repo.commits.first.author.name
144
+ assert_equal cd[:email], @wiki.repo.commits.first.author.email
97
145
  end
98
146
 
99
147
  test "update page with format change" do
100
- commit = { :message => "Gollum page",
101
- :name => "Tom Preston-Werner",
102
- :email => "tom@github.com" }
103
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
148
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
104
149
 
105
150
  assert_equal :markdown, @wiki.page("Gollum").format
106
151
 
107
152
  page = @wiki.page("Gollum")
108
- @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit)
153
+ @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
109
154
 
110
155
  assert_equal 2, @wiki.repo.commits.size
111
156
  assert_equal :textile, @wiki.page("Gollum").format
@@ -113,30 +158,24 @@ context "Wiki page writing" do
113
158
  end
114
159
 
115
160
  test "update page with name change" do
116
- commit = { :message => "Gollum page",
117
- :name => "Tom Preston-Werner",
118
- :email => "tom@github.com" }
119
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
161
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
120
162
 
121
163
  assert_equal :markdown, @wiki.page("Gollum").format
122
164
 
123
165
  page = @wiki.page("Gollum")
124
- @wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit)
166
+ @wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit_details)
125
167
 
126
168
  assert_equal 2, @wiki.repo.commits.size
127
169
  assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
128
170
  end
129
171
 
130
172
  test "update page with name and format change" do
131
- commit = { :message => "Gollum page",
132
- :name => "Tom Preston-Werner",
133
- :email => "tom@github.com" }
134
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
173
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
135
174
 
136
175
  assert_equal :markdown, @wiki.page("Gollum").format
137
176
 
138
177
  page = @wiki.page("Gollum")
139
- @wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit)
178
+ @wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit_details)
140
179
 
141
180
  assert_equal 2, @wiki.repo.commits.size
142
181
  assert_equal :textile, @wiki.page("Smeagol").format
@@ -144,17 +183,13 @@ context "Wiki page writing" do
144
183
  end
145
184
 
146
185
  test "update nested page with format change" do
147
- commit = { :message => "Gollum page",
148
- :name => "Tom Preston-Werner",
149
- :email => "tom@github.com" }
150
-
151
186
  index = @wiki.repo.index
152
187
  index.add("lotr/Gollum.md", "# Gollum")
153
188
  index.commit("Add nested page")
154
189
 
155
190
  page = @wiki.page("Gollum")
156
191
  assert_equal :markdown, @wiki.page("Gollum").format
157
- @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit)
192
+ @wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
158
193
 
159
194
  page = @wiki.page("Gollum")
160
195
  assert_equal "lotr/Gollum.textile", page.path
@@ -163,23 +198,16 @@ context "Wiki page writing" do
163
198
  end
164
199
 
165
200
  test "delete root page" do
166
- commit = { :message => "Gollum page",
167
- :name => "Tom Preston-Werner",
168
- :email => "tom@github.com" }
169
- @wiki.write_page("Gollum", :markdown, "# Gollum", commit)
201
+ @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
170
202
 
171
203
  page = @wiki.page("Gollum")
172
- @wiki.delete_page(page, commit)
204
+ @wiki.delete_page(page, commit_details)
173
205
 
174
206
  assert_equal 2, @wiki.repo.commits.size
175
207
  assert_nil @wiki.page("Gollum")
176
208
  end
177
209
 
178
210
  test "delete nested page" do
179
- commit = { :message => "Gollum page",
180
- :name => "Tom Preston-Werner",
181
- :email => "tom@github.com" }
182
-
183
211
  index = @wiki.repo.index
184
212
  index.add("greek/Bilbo-Baggins.md", "hi")
185
213
  index.add("Gollum.md", "hi")
@@ -187,7 +215,7 @@ context "Wiki page writing" do
187
215
 
188
216
  page = @wiki.page("Bilbo-Baggins")
189
217
  assert page
190
- @wiki.delete_page(page, commit)
218
+ @wiki.delete_page(page, commit_details)
191
219
 
192
220
  assert_equal 2, @wiki.repo.commits.size
193
221
  assert_nil @wiki.page("Bilbo-Baggins")
@@ -198,4 +226,59 @@ context "Wiki page writing" do
198
226
  teardown do
199
227
  FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
200
228
  end
201
- end
229
+ end
230
+
231
+ context "Wiki sync with working directory" do
232
+ setup do
233
+ @path = testpath('examples/wdtest')
234
+ Grit::Repo.init(@path)
235
+ @wiki = Gollum::Wiki.new(@path)
236
+ end
237
+
238
+ test "write a page" do
239
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
240
+ assert_equal "Hi", File.read(File.join(@path, "New-Page.md"))
241
+ end
242
+
243
+ test "update a page with same name and format" do
244
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
245
+ page = @wiki.page("New Page")
246
+ @wiki.update_page(page, page.name, page.format, "Bye", commit_details)
247
+ assert_equal "Bye", File.read(File.join(@path, "New-Page.md"))
248
+ end
249
+
250
+ test "update a page with different name and same format" do
251
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
252
+ page = @wiki.page("New Page")
253
+ @wiki.update_page(page, "New Page 2", page.format, "Bye", commit_details)
254
+ assert_equal "Bye", File.read(File.join(@path, "New-Page-2.md"))
255
+ assert !File.exist?(File.join(@path, "New-Page.md"))
256
+ end
257
+
258
+ test "update a page with same name and different format" do
259
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
260
+ page = @wiki.page("New Page")
261
+ @wiki.update_page(page, page.name, :textile, "Bye", commit_details)
262
+ assert_equal "Bye", File.read(File.join(@path, "New-Page.textile"))
263
+ assert !File.exist?(File.join(@path, "New-Page.md"))
264
+ end
265
+
266
+ test "update a page with different name and different format" do
267
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
268
+ page = @wiki.page("New Page")
269
+ @wiki.update_page(page, "New Page 2", :textile, "Bye", commit_details)
270
+ assert_equal "Bye", File.read(File.join(@path, "New-Page-2.textile"))
271
+ assert !File.exist?(File.join(@path, "New-Page.md"))
272
+ end
273
+
274
+ test "delete a page" do
275
+ @wiki.write_page("New Page", :markdown, "Hi", commit_details)
276
+ page = @wiki.page("New Page")
277
+ @wiki.delete_page(page, commit_details)
278
+ assert !File.exist?(File.join(@path, "New-Page.md"))
279
+ end
280
+
281
+ teardown do
282
+ FileUtils.rm_r(@path)
283
+ end
284
+ end