gollum_rails 1.0.4 → 1.0.5

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.
@@ -27,6 +27,9 @@ module GollumRails
27
27
  # Gets / Sets the repository
28
28
  attr_accessor :repository
29
29
 
30
+ # Gets / Sets the init options
31
+ attr_accessor :options
32
+
30
33
  # Startup action for building wiki components
31
34
  #
32
35
  # Returns true or throws an exception if the path is invalid
@@ -39,7 +42,11 @@ module GollumRails
39
42
  initialize_wiki @repository
40
43
  end
41
44
  end
42
-
45
+ end
46
+
47
+ # Wiki startup options
48
+ def options=(options)
49
+ @options = options
43
50
  end
44
51
 
45
52
  # defines block builder for Rails initializer.
@@ -68,7 +75,7 @@ module GollumRails
68
75
  def initialize_wiki(path)
69
76
  if path_valid? path
70
77
  repository = Grit::Repo.new path.to_s
71
- GollumRails::Adapters::Gollum::Wiki.new repository
78
+ GollumRails::Adapters::Gollum::Wiki.new(repository, options || {})
72
79
  true
73
80
  else
74
81
  raise GollumInternalError, 'no repository path specified'
@@ -5,9 +5,15 @@ describe GollumRails::Adapters::Gollum::Connector do
5
5
  @class = GollumRails::Adapters::Gollum::Connector
6
6
  end
7
7
 
8
- it "should test the Wiki class connector" do
9
- @class.wiki_class.should == GollumRails::Adapters::Gollum::Wiki
8
+ it "should test the Wiki path connector" do
9
+ @class.wiki_path.should be_a String
10
10
  end
11
+ it "should test the Wiki options connector" do
12
+ @class.wiki_options.should be_a Hash
13
+ end
14
+ it "should test the Wiki options content" do
15
+ @class.wiki_options.should == {}
16
+ end
11
17
  it "should test the Page class connector" do
12
18
  @class.page_class.should == GollumRails::Adapters::Gollum::Page
13
19
  end
@@ -6,84 +6,24 @@ describe GollumRails::Adapters::Gollum::Page do
6
6
  :name => 'The Mosny',
7
7
  :email => 'mosny@zyg.li'
8
8
  }
9
-
10
- @location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
11
- @repo = Grit::Repo.init_bare @location
12
- @wiki = GollumRails::Adapters::Gollum::Wiki.new @repo
13
- @page = GollumRails::Adapters::Gollum::Page.new
14
9
  end
15
- it "should initialize the correct wiki" do
16
- location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
17
- repo = Grit::Repo.init_bare location
18
- wiki = GollumRails::Adapters::Gollum::Wiki.new repo
19
- page = GollumRails::Adapters::Gollum::Page.new
20
- page.wiki.should be_instance_of Gollum::Wiki
21
- end
22
- it "should create a new page" do
23
- location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
24
- repo = Grit::Repo.init_bare location
25
- wiki = GollumRails::Adapters::Gollum::Wiki.new repo
26
- page = GollumRails::Adapters::Gollum::Page.new
27
- page.new_page("testpage", "content",:markdown, @commit ).should be_instance_of Gollum::Page
28
- page.delete_page(@commit)
29
- end
30
-
31
- it "should delete an existing page" do
32
- page = @page.new_page 'testpage', 'content', :markdown, @commit
33
- @page.delete_page(@commit,page).should be_instance_of String
34
-
35
- @page.new_page 'testpage', 'content', :markdown, @commit
36
- @page.delete_page(@commit).should be_instance_of String
37
- end
38
- it "should update an existing page" do
39
- @page.new_page 'testpage', 'content', :markdown, @commit
40
- page = {}
41
- page[:name] = 'test'
42
- page[:format] = :markdown
43
- page[:content] = "content"
44
- @page.update_page(page, @commit)
45
-
46
- page = []
47
- expect{@page.update_page(page, @commit)}.to raise_error GollumRails::Adapters::Gollum::Error
48
-
49
- page = {}
50
- page[:content] = "test"
51
- @page.update_page(page, @commit).raw_data.should == page[:content]
52
-
53
- page = {}
54
- page[:name] = "test"
55
- @page.update_page(page, @commit).name.should == page[:name]
56
-
57
- page = {}
58
- page[:format] = :wiki
59
- @page.update_page(page, @commit).format.should == :mediawiki
60
-
61
-
62
-
63
- @page.delete_page(@commit)
64
- end
65
- it "should find a page" do
66
- @page.new_page 'content_page', 'content', :markdown, @commit
67
-
68
- @page.find_page("content_page")
69
- @page.delete_page(@commit)
70
- end
71
- it "should test the commit methods" do
72
- @page.new_page 'content_page', 'content', :markdown, @commit
73
- @page.page_last_edited_date.should be_instance_of Time
74
- @page.page_created.should be_instance_of Time
75
- @page.page_last_commit.should be_instance_of Grit::Commit
76
- @page.page_commit(@page.page.versions.first.id).should be_instance_of Grit::Commit
77
- @page.page_commit_date(@page.page.versions.first.id).should be_instance_of Time
78
- @page.page_first_commit.should be_instance_of Grit::Commit
79
- @page.delete_page(@commit)
80
- end
81
- it "should test the error throwing" do
82
- expect{@page.page_last_commit}.to raise_error GollumRails::Adapters::Gollum::Error
83
- expect{@page.page_first_commit}.to raise_error GollumRails::Adapters::Gollum::Error
84
- expect{@page.page_last_edited_date}.to raise_error GollumRails::Adapters::Gollum::Error
85
- expect{@page.page_created}.to raise_error GollumRails::Adapters::Gollum::Error
86
- expect{@page.page_commit(1)}.to raise_error GollumRails::Adapters::Gollum::Error
87
- expect{@page.page_commit_date(1)}.to raise_error GollumRails::Adapters::Gollum::Error
10
+ describe "Connector stuff" do
11
+ it "should have updated the page_class on initialize" do
12
+ adapter = GollumRails::Adapters::Gollum::Page.new
13
+ GollumRails::Adapters::Gollum::Connector.page_class.should == GollumRails::Adapters::Gollum::Page
14
+ end
15
+ end
16
+ describe "statically methods" do
17
+ it "is a hash" do
18
+ GollumRails::Adapters::Gollum::Page.parse_path('google/de').should be_a Hash
19
+ end
20
+ it "should equal" do
21
+ path1 = GollumRails::Adapters::Gollum::Page.parse_path('google/de')
22
+ path2 = GollumRails::Adapters::Gollum::Page.parse_path('/google/de')
23
+ path1.should == path2
24
+ end
25
+ it "adds a leading slash" do
26
+ GollumRails::Adapters::Gollum::Page.parse_path('google/de')[:path][0].should == '/'
27
+ end
88
28
  end
89
29
  end
@@ -2,79 +2,173 @@ require 'spec_helper'
2
2
 
3
3
  describe "Gollum Page" do
4
4
  before(:each) do
5
+ GollumRails::Setup.build do |config|
6
+ config.repository = File.join(File.dirname(__FILE__),'..','utils','wiki.git')
7
+ config.options={}
8
+ config.startup = true
9
+ end
10
+
5
11
  @commit = {
6
- :name => "flo",
7
- :message => "commit",
8
- :email => "mosny@zyg.li"
12
+ name: "flo",
13
+ message: "commit",
14
+ email: "mosny@zyg.li"
9
15
  }
10
16
  @call = {
11
- :name => "Goole",
12
- :content => "content data",
13
- :commit => @commit,
14
- :format => :markdown
17
+ name: "Goole",
18
+ content: "content data",
19
+ commit: @commit,
20
+ format: :markdown
15
21
  }
16
22
  end
23
+
17
24
  describe GollumRails::Page do
18
- class RailsModel < GollumRails::Page
25
+ class RailsModel < GollumRails::Page; end
19
26
 
27
+ describe "the creation of a page" do
28
+
29
+ before :each do
30
+ @rr = RailsModel.new(@call)
31
+ end
32
+
33
+ it "saves via .save" do
34
+ @rr.save.should be_a GollumRails::Page
35
+ end
36
+
20
37
 
21
- end
38
+ it "saves via .create" do
39
+ RailsModel.create(@call).should be_a GollumRails::Page
40
+ end
41
+
42
+
43
+ it "fails if invalid arguments are supplied via the ! create" do
44
+ args = {
45
+ name: "Gaming",
46
+ content: "content data",
47
+ commit: {},
48
+ format: :markdown
49
+ }
50
+ expect{RailsModel.create!(args)}.to raise_error StandardError #change this
51
+ end
52
+ it "has a history now" do
53
+ @rr.save
54
+ @rr.history.should be_a Array
55
+ end
56
+ it "outputs the raw_data" do
57
+ @rr.save
58
+ @rr.raw_data.should == @call[:content]
59
+ end
60
+ it "has the formatted data" do
61
+ @rr.save
62
+ @rr.html_data.should == 'content data'
63
+ end
64
+ it "was last changed by me" do
65
+ @rr.save
66
+ @rr.last_changed_by.should == 'flo <mosny@zyg.li>'
67
+ end
68
+ it "has a title" do
69
+ @rr.save
70
+ @rr.title.should == "Goole"
71
+ end
72
+ it "has a url" do
73
+ @rr.save
74
+ @rr.url.should =="Goole"
75
+ end
22
76
 
23
- it "should test the creation of a page" do
24
- rr = RailsModel.new(@call)
25
- rr.save.should be_instance_of Gollum::Page
26
- rr.save!.should be_instance_of Gollum::Page
27
- RailsModel.create(@call)
28
77
  end
29
78
 
30
- it "should test the update of a page" do
31
- rr = RailsModel.new @call
32
- cc = rr.save.should be_instance_of Gollum::Page
33
- rr.update_attributes({:name => "google", :format => :wiki}).should be_instance_of Gollum::Page
79
+ describe "the update of a page" do
80
+ before :each do
81
+ @rr = RailsModel.new(@call)
82
+ @rr.save
83
+ end
84
+
85
+ it { @rr.update_attributes({:name => "google", :format => :wiki}).should be_a Gollum::Page }
86
+
34
87
  end
35
-
36
- it "should test the deletion of a page" do
37
- rr = RailsModel.new @call
38
- cc = rr.save.should be_instance_of Gollum::Page
39
- rr.delete.should be_instance_of String
88
+ describe "method missings" do
89
+
90
+ it "should perform a normal find" do
91
+ RailsModel.find_by_name('Goole').should be_a GollumRails::Page
92
+
93
+
94
+ end
95
+
40
96
  end
41
97
 
42
- it "should test the finding of a page" do
43
- RailsModel.find('google').should be_instance_of Gollum::Page
44
-
45
- #invalid input
46
- RailsModel.find('<script type="text/javascript">alert(123);</script>').should be_nil
47
- end
48
- it "should test the preview" do
49
- rr = RailsModel.new :content => "# content", :name => "somepage"
50
- 100.times do
51
- rr.preview.should include("<h1>content<a class=\"anchor\" id=\"content\" href=\"#content\"></a></h1>")
98
+ describe "should test the deletion of a page" do
99
+ before :each do
100
+ @rr = RailsModel.new @call
101
+ @cc = @rr.save
102
+ end
103
+
104
+ it "should return a string" do
105
+ delete = @rr.delete
106
+ delete.should be_a String
107
+ end
108
+
109
+ it "should return a SHA1 hash" do
110
+ delete = @rr.delete
111
+ delete.length.should == 40
112
+ end
113
+
114
+ it "should also work was result from save" do
115
+ delete = @cc.delete
116
+ delete.should be_a String
117
+ end
118
+
119
+ it "should test the recreation" do
120
+ delete = @rr.delete
121
+ @rr.save.should be_a GollumRails::Page
122
+ @rr.delete.should be_a String
123
+
52
124
  end
53
125
  end
54
126
 
127
+
55
128
  it "should test exception methods" do
56
- create = RailsModel.create! @call
129
+ RailsModel.create @call
130
+ expect{RailsModel.create! @call}.to raise_error Gollum::DuplicatePageError
57
131
  end
58
132
 
59
- it "should test the supported formats" do
60
- RailsModel.format_supported?('ascii').should be_true
61
- RailsModel.format_supported?('markdown').should be_true
62
- RailsModel.format_supported?('github-markdown').should be_true
63
- RailsModel.format_supported?('rdoc').should be_true
64
- RailsModel.format_supported?('org').should be_true
65
- RailsModel.format_supported?('pod').should be_true
133
+ describe "supported formats" do
134
+ ['markdown', 'rdoc', 'org', 'pod'].each do |format|
135
+ it "should support #{format}" do
136
+ RailsModel.format_supported?(format).should be_true
137
+ end
138
+ end
139
+
66
140
  end
67
-
68
- it "should test getters" do
69
- rr = RailsModel.new @call
70
- rr.name.should == "Goole"
71
- rr.content.should == "content data"
72
- rr.commit.should be_instance_of Hash
73
- rr.commit.should == @commit
74
- rr.format.should == :markdown
75
- rr.save
76
- rr.page.should be_instance_of GollumRails::Adapters::Gollum::Page
141
+
142
+ describe "accessors" do
143
+ let(:rr){RailsModel.new @call}
144
+
145
+ it "should have a name" do
146
+ expect(rr.name).to match(/^Goole$/)
147
+ end
148
+
149
+ it "should have a content" do
150
+ expect(rr.content).to match(/^content\ data$/)
151
+ end
152
+
153
+ it "should have a commit which is a Hash" do
154
+ expect(rr.commit).to be_a Hash
155
+ end
156
+
157
+ it "should be @commit" do
158
+ expect(rr.commit).to be(@commit)
159
+ end
160
+
161
+ it "should have a format" do
162
+ expect(rr.format.to_s).to match('markdown')
163
+ end
164
+
165
+ it "should be a Gollum::Page after save" do
166
+ rr.save
167
+ expect(rr.gollum_page).to be_a Gollum::Page
168
+ end
169
+
77
170
  end
171
+
78
172
  it "should test setters" do
79
173
  rr = RailsModel.new
80
174
  rr.name=("google").should == "google"
@@ -82,12 +176,34 @@ describe "Gollum Page" do
82
176
  rr.content=("content").should == "content"
83
177
  rr.format=(:markdown).should == :markdown
84
178
  end
85
-
86
-
87
- it "should test find or initialize" do
88
- rr = RailsModel.new @call
89
- rr.save
90
- RailsModel.find_or_initialize_by_name(@call[:name], @commit).should be_instance_of Gollum::Page
179
+
180
+ it "tests the find method to return nil if no page was found" do
181
+ expect(RailsModel.find('whoooohoo')).to be_nil
182
+ end
183
+
184
+ it "tests the find method to return a gollum_rails:page if a page was found" do
185
+ expect(RailsModel.find('Goole')).to be_a GollumRails::Page
186
+ end
187
+
188
+ it 'should not be persisted on initialization or finding' do
189
+ init = RailsModel.find_or_initialize_by_name('totallybad', @commit)
190
+ expect(init.persisted?).to be_false
191
+ end
192
+
193
+ it "should find the page without a commit if it exists" do
194
+ expect(RailsModel.find_or_initialize_by_name("Goole").persisted?).to be_true
195
+ end
196
+
197
+ it "should find the page with a commit if it exists" do
198
+ expect(RailsModel.find_or_initialize_by_name("Goole", @commit).persisted?).to be_true
199
+ end
200
+
201
+ it "should be valid on initialization or finding" do
202
+ init = RailsModel.find_or_initialize_by_name('whoooohooo', @commit)
203
+ expect(init.valid?).to be_true
204
+
205
+ #RailsModel.find_or_initialize_by_name(@call[:name], @commit).should be_a GollumRails::Page
206
+
91
207
  end
92
208
  end
93
209
  describe "callbacks" do
@@ -136,16 +252,15 @@ describe "Gollum Page" do
136
252
  test = CallbackTest.new @call
137
253
  test.persisted?.should be_false
138
254
  test.save
139
- test.delete @commit
140
- test.save
141
- test.update_attributes @call
142
- test.persisted?.should be_true
143
255
  end
144
256
  end
145
257
  describe "rails extension" do
258
+
146
259
  it "should test fetch_all" do
147
- GollumRails::Page.all.length.should == 2
148
- GollumRails::Page.find_all.length.should == 2
260
+ GollumRails::Page.all.length.should == 1
261
+ end
262
+ it "should test all" do
263
+ GollumRails::Page.find_all.length.should == 1
149
264
  end
150
265
 
151
266
  end
@@ -157,29 +272,35 @@ describe "Gollum Page" do
157
272
  class Callbackt < GollumRails::Page
158
273
  validates_presence_of :name
159
274
  end
275
+
160
276
  cla = Callbackt.new @call
161
277
  cla.valid?.should be_true
162
278
  end
279
+
163
280
  class SugarBaby < GollumRails::Page
164
281
  validates_presence_of :name
165
282
  validates_length_of :name, :minimum => 20
166
283
  validates_length_of :format, :maximum => 14
167
284
  end
285
+
168
286
  it "should test string validation" do
169
287
  @call[:name] = "das ist zu lang"*10
170
288
  cla = SugarBaby.new @call
171
289
  cla.valid?.should be_true
172
290
  end
291
+
173
292
  it "should test the presence validator" do
174
293
  @call[:name] = [ ]
175
294
  bla = SugarBaby.new @call
176
295
  bla.valid?.should be_false
177
296
  end
297
+
178
298
  it "should test the length validator for name" do
179
299
  @call[:name] = "das"
180
300
  res = SugarBaby.new @call
181
301
  res.valid?.should be_false
182
302
  end
303
+
183
304
  it "should test the length validator for format" do
184
305
  @call[:format] = :toolongformatstringforvalidator
185
306
  res = SugarBaby.new @call
@@ -187,21 +308,131 @@ describe "Gollum Page" do
187
308
  end
188
309
 
189
310
  end
190
- describe "the thread safety" do
191
- class ThreadModel < GollumRails::Page
192
-
193
- end
194
- it "should save " do
195
- 100.times do |time|
196
- Thread.new do
197
- ThreadModel.new(@call)
198
- ThreadModel.save.should be_instance_of(Gollum::Page)
199
- ThreadModel.delete(@commit).length.should == 40
200
- end
201
- end
202
-
203
- end
204
-
311
+
312
+ describe "diffing commits" do
313
+ class CommitDiff < GollumRails::Page
314
+ end
315
+
316
+ it "should display the diff commit" do
317
+ commit = {
318
+ name: "flo",
319
+ message: "commit",
320
+ email: "mosny@zyg.li"
321
+ }
322
+ call = {
323
+ name: "a Page",
324
+ content: "my content",
325
+ commit: commit,
326
+ format: :markdown
327
+ }
328
+
329
+ res = CommitDiff.new call
330
+ res.save
331
+ res.update_attributes("content",nil,:markdown, @commit)
332
+ diff = res.compare_commits(res.history.first)
333
+ expect(diff).to be_a String
334
+ expect(diff).to match(/---/)
335
+ res.delete
336
+ end
337
+
338
+ end
339
+
340
+ describe "Filename" do
341
+ class Fns < GollumRails::Page
342
+ end
343
+ it "should assemble a filename" do
344
+ res = CommitDiff.new @call
345
+ expect(res.filename).to match(/^Goole\.md$/)
346
+ end
347
+ end
348
+
349
+ describe "Sub Page" do
350
+ class Fns < GollumRails::Page
351
+ end
352
+
353
+ it "should return nil if not persisted" do
354
+ res = CommitDiff.new @call
355
+ expect(res.sub_page?).to be_nil
356
+ end
357
+ it "should be true" do
358
+ res = CommitDiff.new @call.merge(name: '_aPage')
359
+ res.save
360
+ expect(res.sub_page?).to be_true
361
+ res.delete
362
+ end
363
+
364
+ it "should be false" do
365
+ res = CommitDiff.new @call
366
+ res.save
367
+ expect(res.sub_page?).to be_false
368
+ res.delete
369
+ end
370
+ end
371
+
372
+ describe "Current version" do
373
+ class Fns < GollumRails::Page
374
+ end
375
+
376
+ it "current version should have 7 digest" do
377
+ res = CommitDiff.new @call
378
+ res.save
379
+ expect(res.current_version.length).to be(7)
380
+ res.delete
381
+ end
382
+
383
+ it "should be nil if page has not been set" do
384
+ res = CommitDiff.new @call
385
+ expect(res.current_version).to be_nil
386
+ end
205
387
 
206
- end
388
+ it "should be the latest version of the page but shortened" do
389
+ res = CommitDiff.new @call
390
+ res.save
391
+ expect(res.gollum_page.version.to_s).to match(res.current_version)
392
+ res.delete
393
+ end
394
+ it "should display the long version" do
395
+ res = CommitDiff.new @call
396
+ res.save
397
+ expect(res.gollum_page.version.to_s).to match(/^#{res.current_version(true)}$/)
398
+ res.delete
399
+ end
400
+
401
+ end
402
+
403
+ describe 'History' do
404
+ class Fns < GollumRails::Page
405
+ end
406
+
407
+ it "history should return nil if no gollum_page was saved" do
408
+ res = Fns.new @call
409
+ expect(res.history).to be_nil
410
+ end
411
+
412
+ it "history should return the pages versions if there are changes" do
413
+ res = Fns.new @call
414
+ res.save
415
+ expect(res.history).to be_a Array
416
+ res.delete
417
+ end
418
+
419
+ end
420
+
421
+ # describe "the thread safety" do
422
+ # class ThreadModel < GollumRails::Page
423
+ #
424
+ # end
425
+ # it "should save " do
426
+ # 100.times do |time|
427
+ # Thread.new do
428
+ # ThreadModel.new(@call)
429
+ # ThreadModel.save.should be_a(GollumRails::Page)
430
+ # ThreadModel.delete(@commit).length.should == 40
431
+ # end
432
+ # end
433
+ #
434
+ # end
435
+
436
+
437
+ #end
207
438
  end