gollum_rails 1.0.6 → 1.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Hash do
4
+ before(:each) do
5
+ @hash_a = {:a => "b", :b => "c"}
6
+ @hash_b = {a: "b", b: "c"}
7
+ end
8
+ it "should initialize a new hash" do
9
+ @hash_a.should be_instance_of(Hash)
10
+ @hash_b.should be_instance_of(Hash)
11
+ @hash_b.should == @hash_a
12
+ @hash_b.a.should == @hash_b[:a]
13
+ @hash_b.b.should == @hash_b[:b]
14
+ @hash_b.a.should == @hash_a.a
15
+ @hash_b.b.should == @hash_a.b
16
+ end
17
+ it "should change the value by method missing" do
18
+
19
+ @hash_c = {:hooh => "c", :tripple => {:d => "d"}}
20
+ @hash_d = Hash.new
21
+ expect{@hash_d.x}.to raise_error
22
+ #@hash_a.d.to_s.should == "{ d: 'd', x: 'Hash.new' }"
23
+ #@hash_a.d.should be_instance_of(Hash)
24
+ #puts @hash_a.d
25
+ #expect{@hash_a.hash = {d:"d"}}.to be_equal Hash['{:a=>"b", :b=>"c", "b"=>[3], :d=>"d"}']
26
+ #puts @hash_a
27
+ #@hash_a.a = "other"
28
+ #puts @hash_a
29
+ #expect{@hash_a.a = "other"}.to be_equal "other"
30
+ end
31
+ end
@@ -2,173 +2,79 @@ 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
-
11
5
  @commit = {
12
- name: "flo",
13
- message: "commit",
14
- email: "mosny@zyg.li"
6
+ :name => "flo",
7
+ :message => "commit",
8
+ :email => "mosny@zyg.li"
15
9
  }
16
10
  @call = {
17
- name: "Goole",
18
- content: "content data",
19
- commit: @commit,
20
- format: :markdown
11
+ :name => "Goole",
12
+ :content => "content data",
13
+ :commit => @commit,
14
+ :format => :markdown
21
15
  }
22
16
  end
23
-
24
17
  describe GollumRails::Page do
25
- class RailsModel < GollumRails::Page; end
18
+ class RailsModel < GollumRails::Page
26
19
 
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
-
37
20
 
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
21
+ end
76
22
 
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)
77
28
  end
78
29
 
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
-
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
87
34
  end
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
-
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
96
40
  end
97
41
 
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
-
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>")
124
52
  end
125
53
  end
126
54
 
127
-
128
55
  it "should test exception methods" do
129
- RailsModel.create @call
130
- expect{RailsModel.create! @call}.to raise_error Gollum::DuplicatePageError
56
+ create = RailsModel.create! @call
131
57
  end
132
58
 
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
-
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
140
66
  end
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
-
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
170
77
  end
171
-
172
78
  it "should test setters" do
173
79
  rr = RailsModel.new
174
80
  rr.name=("google").should == "google"
@@ -176,34 +82,12 @@ describe "Gollum Page" do
176
82
  rr.content=("content").should == "content"
177
83
  rr.format=(:markdown).should == :markdown
178
84
  end
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
-
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
207
91
  end
208
92
  end
209
93
  describe "callbacks" do
@@ -252,15 +136,16 @@ describe "Gollum Page" do
252
136
  test = CallbackTest.new @call
253
137
  test.persisted?.should be_false
254
138
  test.save
139
+ test.delete @commit
140
+ test.save
141
+ test.update_attributes @call
142
+ test.persisted?.should be_true
255
143
  end
256
144
  end
257
145
  describe "rails extension" do
258
-
259
146
  it "should test fetch_all" do
260
- GollumRails::Page.all.length.should == 1
261
- end
262
- it "should test all" do
263
- GollumRails::Page.find_all.length.should == 1
147
+ GollumRails::Page.all.length.should == 2
148
+ GollumRails::Page.find_all.length.should == 2
264
149
  end
265
150
 
266
151
  end
@@ -272,35 +157,29 @@ describe "Gollum Page" do
272
157
  class Callbackt < GollumRails::Page
273
158
  validates_presence_of :name
274
159
  end
275
-
276
160
  cla = Callbackt.new @call
277
161
  cla.valid?.should be_true
278
162
  end
279
-
280
163
  class SugarBaby < GollumRails::Page
281
164
  validates_presence_of :name
282
165
  validates_length_of :name, :minimum => 20
283
166
  validates_length_of :format, :maximum => 14
284
167
  end
285
-
286
168
  it "should test string validation" do
287
169
  @call[:name] = "das ist zu lang"*10
288
170
  cla = SugarBaby.new @call
289
171
  cla.valid?.should be_true
290
172
  end
291
-
292
173
  it "should test the presence validator" do
293
174
  @call[:name] = [ ]
294
175
  bla = SugarBaby.new @call
295
176
  bla.valid?.should be_false
296
177
  end
297
-
298
178
  it "should test the length validator for name" do
299
179
  @call[:name] = "das"
300
180
  res = SugarBaby.new @call
301
181
  res.valid?.should be_false
302
182
  end
303
-
304
183
  it "should test the length validator for format" do
305
184
  @call[:format] = :toolongformatstringforvalidator
306
185
  res = SugarBaby.new @call
@@ -308,131 +187,21 @@ describe "Gollum Page" do
308
187
  end
309
188
 
310
189
  end
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
190
+ describe "the thread safety" do
191
+ class ThreadModel < GollumRails::Page
387
192
 
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
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
+
205
+
206
+ end
438
207
  end