gollum_rails 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09f7ee2859734417d3752763d1c3c1b3c162a8df
4
- data.tar.gz: b69cae667fa9c8ec7c81215133ca1062e741e76a
3
+ metadata.gz: 5dd7344f385aa410641d4306e45816ded6fcc3ab
4
+ data.tar.gz: 4c575604cbf42c6c261a282fe8bddba7d9e05b0e
5
5
  SHA512:
6
- metadata.gz: 3be4a36dd812402751dad7cdbdf2fe63fe4be10c11f3963ab8c20d470651184a2283c181439141cc101cf4428f89d4696dce2e452e1edb4e85a91b160fda3a78
7
- data.tar.gz: 68a520d6a40e235ed6fff4a37cd9a4b3bc78282c61bbc1b137b5d5b05538f05a40fde1af8460e63e1d378879515190121e9d575c25c8f9927f2490b9205dc932
6
+ metadata.gz: 6ac3f7568b4f3125dd80d0bf90126216d46defc5a06c304a1ee1a241dc2f9b96f1c208ed9fa0b92c7618e92d851e2012200ab768aafc4639eba09fd69f766f57
7
+ data.tar.gz: 4541dd32cf2e51123f88a4daa0970dcfa08b214099c05f86d65f7d07ec0c3a7c78fdcc5f76210ddf28635e8ff9274ed828cbe0b27cafabdfbbcdb22a97abf1ca
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- gollum_rails (1.0.0)
13
+ gollum_rails (1.0.1)
14
14
  activemodel (~> 3.2.13)
15
15
  gollum-lib (~> 1.0.0)
16
16
 
@@ -69,6 +69,7 @@ GEM
69
69
  i18n (0.6.1)
70
70
  journey (1.0.4)
71
71
  json (1.7.7)
72
+ json (1.7.7-java)
72
73
  mail (2.5.3)
73
74
  i18n (>= 0.4.0)
74
75
  mime-types (~> 1.16)
@@ -138,6 +139,7 @@ GEM
138
139
  yajl-ruby (1.1.0)
139
140
 
140
141
  PLATFORMS
142
+ java
141
143
  ruby
142
144
 
143
145
  DEPENDENCIES
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.0.1 5th April 2013
2
+ * added find_all and all for Page
3
+ * removed some unused functions
4
+ * added autoloading
5
+ * improved documentation
6
+ * improved code coverage
7
+
1
8
  # 1.0.0 3th April 2013
2
9
  * added validators
3
10
  * removed unused gems
data/Rakefile CHANGED
@@ -148,7 +148,7 @@ task :gemspec => :validate do
148
148
  split("\n").
149
149
  sort.
150
150
  reject { |file| file =~ /^\./ }.
151
- reject { |file| file =~ /^(doc|pkg|spec|Home\.md|\.gitattributes)/ }.
151
+ reject { |file| file =~ /^(doc|pkg|script|config|Home\.md|\.gitattributes)/ }.
152
152
  map { |file| " #{file}" }.
153
153
  join("\n")
154
154
 
data/gollum_rails.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.name = 'gollum_rails'
5
5
  s.rubyforge_project = s.name
6
6
 
7
- s.version = '1.0.0'
7
+ s.version = '1.0.1'
8
8
 
9
9
  s.summary = 'Combines the benefits from Gollum and Rails'
10
10
  s.description= 'Use all the benefits from Rails and combine them with the awesome Gollum wiki'
@@ -53,11 +53,25 @@ Gem::Specification.new do |s|
53
53
  lib/gollum_rails/adapters/gollum/error.rb
54
54
  lib/gollum_rails/adapters/gollum/page.rb
55
55
  lib/gollum_rails/adapters/gollum/wiki.rb
56
- lib/gollum_rails/initializer.rb
57
56
  lib/gollum_rails/modules/hash.rb
58
57
  lib/gollum_rails/modules/loader.rb
59
58
  lib/gollum_rails/page.rb
60
59
  lib/gollum_rails/setup.rb
60
+ spec/gollum_rails/adapters/activemodel/error_spec.rb
61
+ spec/gollum_rails/adapters/activemodel/naming_spec.rb
62
+ spec/gollum_rails/adapters/activemodel/validation_unused.rb
63
+ spec/gollum_rails/adapters/gollum/committer_spec.rb
64
+ spec/gollum_rails/adapters/gollum/connector_spec.rb
65
+ spec/gollum_rails/adapters/gollum/error_spec.rb
66
+ spec/gollum_rails/adapters/gollum/page_spec.rb
67
+ spec/gollum_rails/adapters/gollum/wiki_spec.rb
68
+ spec/gollum_rails/modules/hash_spec.rb
69
+ spec/gollum_rails/page_spec.rb
70
+ spec/gollum_rails/respository_spec.rb
71
+ spec/gollum_rails/setup_spec.rb
72
+ spec/gollum_rails/wiki_spec.rb
73
+ spec/spec.opts
74
+ spec/spec_helper.rb
61
75
  ]
62
76
  # = MANIFEST =
63
77
 
data/lib/gollum_rails.rb CHANGED
@@ -10,9 +10,11 @@ require 'gollum-lib'
10
10
  # * ...
11
11
  #
12
12
  module GollumRails
13
+ autoload :Page, 'gollum_rails/page'
14
+ autoload :Setup, 'gollum_rails/setup'
13
15
 
14
16
  # GollumRails version string
15
- VERSION = '1.0.0'
17
+ VERSION = '1.0.1'
16
18
 
17
19
  # Simplified error
18
20
  class Error < StandardError; end
@@ -27,8 +29,8 @@ end
27
29
 
28
30
  require File.expand_path '../gollum_rails/adapters/activemodel', __FILE__
29
31
  require File.expand_path '../gollum_rails/adapters/gollum', __FILE__
30
- require File.expand_path '../gollum_rails/setup', __FILE__
31
- require File.expand_path '../gollum_rails/page', __FILE__
32
+ #require File.expand_path '../gollum_rails/setup', __FILE__
33
+ #require File.expand_path '../gollum_rails/page', __FILE__
32
34
  # load extensions
33
35
  require File.expand_path '../gollum_rails/modules/loader', __FILE__
34
36
 
@@ -3,7 +3,6 @@ module GollumRails
3
3
 
4
4
  # Adapter class. To be documented
5
5
  module Adapters
6
-
7
6
  # ActiveModel improvements and own connectors
8
7
  #
9
8
  # including:
@@ -34,7 +33,7 @@ module GollumRails
34
33
  module ActiveModel
35
34
 
36
35
  # connector version
37
- VERSION="1.10.0"
36
+ VERSION="1.20.0"
38
37
  end
39
38
  end
40
39
  end
@@ -42,6 +41,3 @@ end
42
41
  require File.expand_path '../activemodel/boolean', __FILE__
43
42
  require File.expand_path '../activemodel/naming', __FILE__
44
43
  require File.expand_path '../activemodel/error', __FILE__
45
-
46
- # removed in 0.0.8
47
- #require File.expand_path '../activemodel/validation', __FILE__
@@ -10,8 +10,12 @@ module GollumRails
10
10
  # currently nothing implemented
11
11
  #
12
12
  module Gollum
13
+ autoload :Wiki, 'gollum_rails/adapters/gollum/wiki'
14
+ autoload :Page, 'gollum_rails/adapters/gollum/page'
15
+ autoload :Committer, 'gollum_rails/adapters/gollum/committer'
16
+ autoload :Error, 'gollum_rails/adapters/gollum/error'
13
17
  # connector version
14
- VERSION="1.0.1rc-1"
18
+ VERSION="1.0.3"
15
19
 
16
20
  # Gollum connector class, keeping defaults!
17
21
  #
@@ -63,8 +67,8 @@ module GollumRails
63
67
  end
64
68
  end
65
69
 
66
- require File.expand_path '../gollum/error', __FILE__
67
- require File.expand_path '../gollum/wiki', __FILE__
68
- require File.expand_path '../gollum/committer', __FILE__
69
- require File.expand_path '../gollum/page', __FILE__
70
+ #require File.expand_path '../gollum/error', __FILE__
71
+ #require File.expand_path '../gollum/wiki', __FILE__
72
+ #require File.expand_path '../gollum/committer', __FILE__
73
+ #require File.expand_path '../gollum/page', __FILE__
70
74
 
@@ -37,7 +37,74 @@ module GollumRails
37
37
  # Sets the validator
38
38
  attr_writer :validator
39
39
 
40
+ # Finds an existing page or creates it
41
+ #
42
+ # name - The name
43
+ # commit - Hash
44
+ #
45
+ # Returns self
46
+ def find_or_initialize_by_name(name, commit)
47
+ result_for_find = self.find(name)
48
+ self.create({:format => :markdown, :name => name, :content => ".", :commit => commit })
49
+ end
50
+
51
+ # Checks if the fileformat is supported
52
+ #
53
+ # format - String
54
+ #
55
+ # Returns true or false
56
+ def format_supported?(format)
57
+ supported = ['ascii', 'github-markdown','markdown', 'creole', 'org', 'pod', 'rdoc']
58
+ format.in?(supported)
59
+ end
60
+
61
+ # first creates an instance of itself and executes the save function.
62
+ #
63
+ # hash - Hash containing the page data
64
+ #
65
+ #
66
+ # Returns an instance of Gollum::Page or false
67
+ def create(hash)
68
+ page = Page.new hash
69
+ page.save
70
+ end
71
+
72
+
73
+ # calls `create` on current class. If returned value is nil an exception will be thrown
74
+ #
75
+ # hash - Hash containing the page data
76
+ #
77
+ #
78
+ # Returns an instance of Gollum::Page
79
+ def create!(hash)
80
+ action = self.create(hash)
81
+ action
82
+ end
83
+
84
+ # Finds a page based on the name and specified version
85
+ #
86
+ # name - the name of the page
87
+ #
88
+ # Return an instance of Gollum::Page
89
+ def find(name)
90
+ page = GollumRails::Adapters::Gollum::Page.new
91
+ page.find_page name
92
+ end
93
+
94
+ # Gets all pages in the wiki
95
+ def all
96
+ self.wiki.pages
97
+ end
98
+ alias_method :find_all, :all
99
+
100
+ # Gets the wiki instance
101
+ def wiki
102
+ @wiki || Adapters::Gollum::Connector.wiki_class
103
+ end
104
+
40
105
  end
106
+
107
+
41
108
  # Initializes a new Page
42
109
  #
43
110
  # attrs - Hash of attributes
@@ -55,8 +122,6 @@ module GollumRails
55
122
  # Setters
56
123
  #########
57
124
 
58
- # Sets the wiki instance
59
- attr_writer :wiki
60
125
 
61
126
  # Gets / Sets the pages name
62
127
  attr_accessor :name
@@ -64,52 +129,29 @@ module GollumRails
64
129
  # Gets / Sets the contents content
65
130
  attr_accessor :content
66
131
 
67
- # Sets the commit Hash
68
- attr_writer :commit
132
+ # Gets / Sets the commit Hash
133
+ attr_accessor :commit
69
134
 
70
135
  # Sets the format
71
136
  attr_writer :format
72
137
 
73
- # Sets the page
74
- attr_writer :page
75
138
 
76
139
  #########
77
140
  # Getters
78
141
  #########
79
142
 
80
- # Gets the wiki instance
81
- def wiki
82
- @wiki || Adapters::Gollum::Connector.wiki_class
83
- end
84
-
85
- # Need to implement the Committer connector (forgot it completely)
86
- # Gets the commit Hash from current object
87
- def commit
88
- @commit
89
- end
90
143
 
91
144
  # Gets the pages format
92
145
  def format
93
146
  @format.to_sym
94
147
  end
95
148
 
96
- # Gets the validator
97
- def self.validator
98
- @@validator ||= Adapters::ActiveModel::Validation.new
99
- end
100
149
 
101
150
  # Gets the page class
102
151
  def page
103
152
  @page ||= Adapters::Gollum::Connector.page_class.new
104
153
  end
105
154
 
106
- # Statically page getter
107
- #
108
- # DEPRECATED! Do not use
109
- def self.page
110
- Adapters::Gollum::Connector.page_class
111
- end
112
-
113
155
  #############
114
156
  # activemodel
115
157
  #############
@@ -137,10 +179,11 @@ module GollumRails
137
179
  # Returns an instance of Gollum::Page or false
138
180
  def save
139
181
  run_callbacks :save do
182
+ return false unless valid?
140
183
  begin
141
184
  page.new_page(name,content,format,commit)
142
185
  rescue ::Gollum::DuplicatePageError => e
143
- page.instance_variable_set "@page",page.find_page(name)
186
+ page.page = page.find_page(name)
144
187
  end
145
188
  return page.page
146
189
  end
@@ -152,30 +195,6 @@ module GollumRails
152
195
  # * implement full method!
153
196
  alias_method :save!, :save
154
197
 
155
- # first creates an instance of itself and executes the save function.
156
- #
157
- # hash - Hash containing the page data
158
- #
159
- #
160
- # Returns an instance of Gollum::Page or false
161
- def self.create(hash)
162
- page = Page.new hash
163
- page.save
164
- end
165
-
166
- # calls `create` on current class. If returned value is nil an exception will be thrown
167
- #
168
- # hash - Hash containing the page data
169
- #
170
- # TODO:
171
- # * much testing
172
- #
173
- # Returns an instance of Gollum::Page
174
- def self.create!(hash)
175
- action = self.create(hash)
176
- action
177
- end
178
-
179
198
  # Updates an existing page (or created)
180
199
  #
181
200
  # hash - Hash containing the attributes, you want to update
@@ -206,6 +225,8 @@ module GollumRails
206
225
  #
207
226
  #
208
227
  def persisted?
228
+ return true if page.page.instance_of?(::Gollum::Page)
229
+ return false
209
230
  end
210
231
  # Previews the page - Mostly used if you want to see what you do before saving
211
232
  #
@@ -219,40 +240,10 @@ module GollumRails
219
240
  #
220
241
  # Returns a String
221
242
  def preview(format=:markdown)
222
- preview = wiki.preview_page @name, @content, format
243
+ preview = self.class.wiki.preview_page @name, @content, format
223
244
  preview.formatted_data
224
245
  end
225
246
 
226
- # Finds a page based on the name and specified version
227
- #
228
- # name - the name of the page
229
- #
230
- # Return an instance of Gollum::Page
231
- def self.find(name)
232
- page = GollumRails::Adapters::Gollum::Page.new
233
- page.find_page name
234
- end
235
-
236
- # Finds an existing page or creates it
237
- #
238
- # name - The name
239
- # commit - Hash
240
- #
241
- # Returns self
242
- def self.find_or_initialize_by_name(name, commit)
243
- result_for_find = self.find(name)
244
- self.create({:format => :markdown, :name => name, :content => ".", :commit => commit })
245
- end
246
-
247
- # Checks if the fileformat is supported
248
- #
249
- # format - String
250
- #
251
- # Returns true or false
252
- def self.format_supported?(format)
253
- supported = ['ascii', 'github-markdown','markdown', 'creole', 'org', 'pod', 'rdoc']
254
- format.in?(supported)
255
- end
256
247
 
257
248
  #######
258
249
  private
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe GollumRails::Adapters::ActiveModel::Error do
4
+ before(:each) do
5
+ @error = GollumRails::Adapters::ActiveModel::Error
6
+
7
+ end
8
+ it "should throw a new error" do
9
+
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe GollumRails::Adapters::ActiveModel::Naming do
4
+ include GollumRails::Adapters::ActiveModel::Naming
5
+
6
+ before(:each) do
7
+ @model = GollumRails::Adapters::ActiveModel::Naming
8
+ end
9
+
10
+ it "should use _scores" do
11
+ class Blax < GollumRails::Adapters::ActiveModel::Naming::NameSpace
12
+ include GollumRails::Adapters::ActiveModel::Naming
13
+
14
+ def initialize
15
+ class_name.should == self.class.name
16
+ class_name.should == "Blax"
17
+ plural_filename_for_class(Blax).should == "blaxes"
18
+ singular_filename_for_class(Blax).should == "blax"
19
+
20
+ end
21
+
22
+ end
23
+
24
+ bla = Blax.new
25
+
26
+ end
27
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ describe GollumRails::Adapters::ActiveModel::Validation do
3
+ before(:each) do
4
+ @model = GollumRails::Adapters::ActiveModel::Validation.new
5
+
6
+ end
7
+ it "should object types" do
8
+ test = {}
9
+ test[:boolean] = true
10
+ test[:string] = "Stringity"
11
+ test[:integer] = 1
12
+ test[:hash] = {}
13
+ test[:array] = []
14
+ test[:object] = Object
15
+ @model.validate do |sm|
16
+ sm.test(test[:string], "type=String").should be_true
17
+ sm.test(test[:array], "type=Integer").should be_false
18
+ sm.test(test[:string], "type=Object").should be_true
19
+ sm.test(test[:hash], "type=String").should be_false
20
+ sm.test(test[:integer], "type=Integer").should be_true
21
+ sm.test(test[:integer], "type=Object").should be_true
22
+ sm.test(test[:boolean], "type=Object").should be_true
23
+ sm.test(test[:boolean], "type=Boolean").should be_true
24
+ sm.test(test[:boolean], "type=TrueClass").should be_true
25
+ sm.test(test[:boolean], "type=FalseClass").should be_false
26
+ sm.test(test[:object], "type=Object").should be_true
27
+ sm.test(test[:array], "type=Array").should be_true
28
+ sm.test(test[:array], "type=Boolean").should be_false
29
+ sm.test(test, "type=Hash").should be_true
30
+ end
31
+ end
32
+ it "should test module Boolean" do
33
+ @model.test(true, "type=Boolean").should be_true
34
+ @model.test(false, "type=Boolean").should be_true
35
+ @model.test(true, "type=TrueClass").should be_true
36
+ @model.test(false, "type=FalseClass").should be_true
37
+ end
38
+
39
+ it "should test the maxlen" do
40
+ @model.validate do |sm|
41
+ sm.test("stringvalue", "min=20").should be_false
42
+ sm.test("stringvalue", "max=200").should be_true
43
+ sm.test(1, "min=2").should be_false
44
+ sm.test(2, "max=4").should be_true
45
+ end
46
+ end
47
+ it "should test the presence validator" do
48
+ @model.validate do |sm|
49
+ sm.test([ ], "present=true").should be_false
50
+ sm.test(nil, "presence=true").should be_false
51
+ sm.test("test", "presence=true").should be_true
52
+ end
53
+ end
54
+ it "tests chaining" do
55
+ @model.validate do |sm|
56
+ sm.test("google.de", "type=String,presence=true").should be_true
57
+ sm.test("google.com", "type=Integer,presence=true").should be_false
58
+ sm.test([ ], "type=Object,presence=true").should be_false
59
+ sm.test("google.de", "type=String,min=1,max=20,presence=true").should be_true
60
+ sm.test("google.de", "type=String,min=20,max=40").should be_false
61
+ sm.test(1, "type=Integer,min=1,max=20").should be_true
62
+ end
63
+ end
64
+ it "should test error message output" do
65
+ preset = "google.de"
66
+ @model.test(preset, "min=20")
67
+ @model.error[:variable][0].should == "is too short (minimum is 20 characters)"
68
+
69
+ @model.test preset, "type=Integer"
70
+ @model.error[:type][0].should == "not a kind of given class Integer"
71
+
72
+ @model.test preset, "max=2"
73
+ #is too long (maximum is 2 characters)
74
+ @model.error[:variable][0].should == "is too long (maximum is 2 characters)"
75
+
76
+
77
+
78
+ end
79
+
80
+ it "should test the performance" do
81
+ @model.validate do |sm|
82
+ 100.times do
83
+ expect do
84
+ sm.test("veryshortstring", "presence=true,max=2,min=1")
85
+ end.to take_less_than(0.1).seconds
86
+ end
87
+ end
88
+ end
89
+
90
+ it "should test the blank param" do
91
+ @model.validate do |sm|
92
+ #sm.test("string")
93
+ end
94
+ end
95
+ it "should test errors" do
96
+ @model.validate do |sm|
97
+ expect{sm.test("string", "presence!string")}.to raise_error GollumRails::Adapters::ActiveModel::Error
98
+ sm.test("string", "nobla=tebla").should be_true
99
+ sm.test("string", "type=123!").should be_false
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe GollumRails::Adapters::Gollum::Connector do
4
+ before(:each) do
5
+ @class = GollumRails::Adapters::Gollum::Connector
6
+ end
7
+
8
+ it "should test the Wiki class connector" do
9
+ @class.wiki_class.should == GollumRails::Adapters::Gollum::Wiki
10
+ end
11
+ it "should test the Page class connector" do
12
+ @class.page_class.should == GollumRails::Adapters::Gollum::Page
13
+ end
14
+ it "should test the Committer class connector" do
15
+ @class.committer_class.should == GollumRails::Adapters::Gollum::Committer
16
+ end
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe GollumRails::Adapters::ActiveModel::Error do
4
+ it "should test the error throwing" do
5
+ expect{raise GollumRails::Adapters::ActiveModel::Error.new 'test', 'no'}.to raise_error GollumRails::Adapters::ActiveModel::Error
6
+ end
7
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ describe GollumRails::Adapters::Gollum::Page do
3
+ before(:each) do
4
+ @commit = {
5
+ :message => 'page action',
6
+ :name => 'The Mosny',
7
+ :email => 'mosny@zyg.li'
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
+ 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
88
+ end
89
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'grit'
3
+
4
+ describe GollumRails::Adapters::Gollum::Wiki do
5
+ before(:each) do
6
+ @location = "#{File.dirname(__FILE__)}/../../../utils/wiki.git"
7
+ @repo = Grit::Repo.init_bare @location
8
+ @wiki = GollumRails::Adapters::Gollum::Wiki.new @repo
9
+ end
10
+ it "should test initializer" do
11
+ wiki = GollumRails::Adapters::Gollum::Wiki.new @location
12
+ @wiki.git.should == @repo
13
+ wiki.git.should be_instance_of(String)
14
+ wiki.git.should == @location
15
+ end
16
+ it "should test the creation of a new wiki" do
17
+ wiki = GollumRails::Adapters::Gollum::Wiki.wiki @repo
18
+ wiki.git.should == @repo
19
+ wiki = GollumRails::Adapters::Gollum::Wiki.wiki @location
20
+ wiki.git.should == @location
21
+ GollumRails::Adapters::Gollum::Connector.wiki_class.should be_instance_of(::Gollum::Wiki)
22
+ end
23
+ it "should test the error throwing and forwarding" do
24
+ expect{GollumRails::Adapters::Gollum::Wiki.write_page}.to raise_error ArgumentError
25
+ end
26
+
27
+ end
@@ -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
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Gollum Page" do
4
+ before(:each) do
5
+ @commit = {
6
+ :name => "flo",
7
+ :message => "commit",
8
+ :email => "mosny@zyg.li"
9
+ }
10
+ @call = {
11
+ :name => "Goole",
12
+ :content => "content data",
13
+ :commit => @commit,
14
+ :format => :markdown
15
+ }
16
+ end
17
+ describe GollumRails::Page do
18
+ class RailsModel < GollumRails::Page
19
+
20
+
21
+ end
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)
28
+ end
29
+
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
34
+ 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
40
+ end
41
+
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>")
52
+ end
53
+ end
54
+
55
+ it "should test exception methods" do
56
+ create = RailsModel.create! @call
57
+ end
58
+
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
66
+ 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
77
+ end
78
+ it "should test setters" do
79
+ rr = RailsModel.new
80
+ rr.name=("google").should == "google"
81
+ rr.commit=(@commit).should == @commit
82
+ rr.content=("content").should == "content"
83
+ rr.format=(:markdown).should == :markdown
84
+ 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
91
+ end
92
+ end
93
+ describe "callbacks" do
94
+
95
+
96
+
97
+ it "should test the callback functions" do
98
+
99
+ class SaveCallback
100
+ def self.before_save( obj )
101
+ obj.name.should == "Goole"
102
+ end
103
+ end
104
+
105
+
106
+ class CallbackTest < GollumRails::Page
107
+
108
+ before_save ::SaveCallback
109
+ after_save :after_save
110
+ after_delete :after_delete
111
+ before_delete :before_delete
112
+ before_update :before_update
113
+ after_update :after_update
114
+
115
+ def after_save
116
+ @name.should == "Goole"
117
+ end
118
+ def before_update
119
+ @name.should == "Goole"
120
+ end
121
+
122
+ def after_update
123
+ @name.should == "Goole"
124
+ end
125
+
126
+ def before_delete
127
+ @name.should == "Goole"
128
+ end
129
+
130
+ def after_delete
131
+ @name.should == "Goole"
132
+ end
133
+
134
+ end
135
+
136
+ test = CallbackTest.new @call
137
+ test.persisted?.should be_false
138
+ test.save
139
+ test.delete @commit
140
+ test.save
141
+ test.update_attributes @call
142
+ test.persisted?.should be_true
143
+ end
144
+ end
145
+ describe "rails extension" do
146
+ it "should test fetch_all" do
147
+ GollumRails::Page.all.length.should == 2
148
+ GollumRails::Page.find_all.length.should == 2
149
+ end
150
+
151
+ end
152
+ describe "testing validation" do
153
+
154
+
155
+
156
+ it "should test the basic validation" do
157
+ class Callbackt < GollumRails::Page
158
+ validates_presence_of :name
159
+ end
160
+ cla = Callbackt.new @call
161
+ cla.valid?.should be_true
162
+ end
163
+ class SugarBaby < GollumRails::Page
164
+ validates_presence_of :name
165
+ validates_length_of :name, :minimum => 20
166
+ validates_length_of :format, :maximum => 14
167
+ end
168
+ it "should test string validation" do
169
+ @call[:name] = "das ist zu lang"*10
170
+ cla = SugarBaby.new @call
171
+ cla.valid?.should be_true
172
+ end
173
+ it "should test the presence validator" do
174
+ @call[:name] = [ ]
175
+ bla = SugarBaby.new @call
176
+ bla.valid?.should be_false
177
+ end
178
+ it "should test the length validator for name" do
179
+ @call[:name] = "das"
180
+ res = SugarBaby.new @call
181
+ res.valid?.should be_false
182
+ end
183
+ it "should test the length validator for format" do
184
+ @call[:format] = :toolongformatstringforvalidator
185
+ res = SugarBaby.new @call
186
+ res.valid?.should be_false
187
+ end
188
+
189
+ end
190
+
191
+ end
File without changes
@@ -0,0 +1,44 @@
1
+ # Setup testing
2
+ require 'spec_helper'
3
+ require 'rails'
4
+ describe GollumRails::Setup do
5
+ it "should setup the application" do
6
+ GollumRails::Setup.build do |setup|
7
+
8
+ # => The repository path to the
9
+ #
10
+ #
11
+ setup.repository = '.'
12
+
13
+ #setup.wiki.use = :default
14
+ setup.startup=(true).should be_true
15
+
16
+ setup.repository = nil
17
+ expect{setup.startup=true}.to raise_error GollumRails::GollumInternalError
18
+
19
+ end
20
+
21
+
22
+ end
23
+ class Bla < GollumRails::Page
24
+ end
25
+ it "should test the disable behavior" do
26
+ GollumRails::Adapters::Gollum::Connector.enabled = false
27
+
28
+ committer = {
29
+ :name => "Flo",
30
+ :message => "no",
31
+ :email => "mosny@zyg.li"
32
+ }
33
+
34
+ expect{Bla.new :name => "Default page", :commit => committer, :content => "#title \n ##body", :format => :markdown}.to raise_error GollumRails::GollumInternalError
35
+ end
36
+ it "should test the applications config" do
37
+ GollumRails::Setup.build do |config|
38
+ config.repository = :application
39
+
40
+ expect{setup.startup=true}.to raise_error
41
+ end
42
+ end
43
+
44
+ end
File without changes
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ require 'gollum_rails'
8
+
9
+
10
+ require 'benchmark'
11
+ RSpec::Matchers.define :take_less_than do |n|
12
+ chain :seconds do; end
13
+ match do |block|
14
+ @elapsed = Benchmark.realtime do
15
+ block.call
16
+ end
17
+ @elapsed <= n
18
+ end
19
+ end
20
+
21
+ RSpec.configure do |config|
22
+ config.treat_symbols_as_metadata_keys_with_true_values = true
23
+
24
+ config.backtrace_clean_patterns = [
25
+ /\/lib\d*\/ruby\//,
26
+ /bin\//,
27
+ /gems/,
28
+ /spec\/spec_helper\.rb/,
29
+ /lib\/rspec\/(core|expectations|matchers|mocks)/
30
+ ]
31
+ config.before(:each) do
32
+ GollumRails::Adapters::Gollum::Connector.enabled = true
33
+ end
34
+ config.full_backtrace= false # save the console
35
+ config.color_enabled= true # save your eyes
36
+ config.formatter = :documentation
37
+
38
+ config.mock_with :rr
39
+
40
+ config.before(:each) do
41
+ end
42
+
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Kasper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -124,11 +124,25 @@ files:
124
124
  - lib/gollum_rails/adapters/gollum/error.rb
125
125
  - lib/gollum_rails/adapters/gollum/page.rb
126
126
  - lib/gollum_rails/adapters/gollum/wiki.rb
127
- - lib/gollum_rails/initializer.rb
128
127
  - lib/gollum_rails/modules/hash.rb
129
128
  - lib/gollum_rails/modules/loader.rb
130
129
  - lib/gollum_rails/page.rb
131
130
  - lib/gollum_rails/setup.rb
131
+ - spec/gollum_rails/adapters/activemodel/error_spec.rb
132
+ - spec/gollum_rails/adapters/activemodel/naming_spec.rb
133
+ - spec/gollum_rails/adapters/activemodel/validation_unused.rb
134
+ - spec/gollum_rails/adapters/gollum/committer_spec.rb
135
+ - spec/gollum_rails/adapters/gollum/connector_spec.rb
136
+ - spec/gollum_rails/adapters/gollum/error_spec.rb
137
+ - spec/gollum_rails/adapters/gollum/page_spec.rb
138
+ - spec/gollum_rails/adapters/gollum/wiki_spec.rb
139
+ - spec/gollum_rails/modules/hash_spec.rb
140
+ - spec/gollum_rails/page_spec.rb
141
+ - spec/gollum_rails/respository_spec.rb
142
+ - spec/gollum_rails/setup_spec.rb
143
+ - spec/gollum_rails/wiki_spec.rb
144
+ - spec/spec.opts
145
+ - spec/spec_helper.rb
132
146
  homepage: http://gollum.zyg.li
133
147
  licenses:
134
148
  - AGPL
@@ -1,8 +0,0 @@
1
- module GollumRails
2
-
3
-
4
- # setup
5
- def setup(&block)
6
- end
7
-
8
- end