Skip to content

Commit

Permalink
test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mendler committed Feb 9, 2009
1 parent 58ebe60 commit dadfd04
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 9 deletions.
2 changes: 1 addition & 1 deletion TODO.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Brainstorming...
- Code comments and rdoc generation
- Rspec and maybe some unit tests
- Automatic file extensions for wikitext files
- Preview
- LaTeX integration
- Captcha support
- Image support, Image gallery
- Breadcrumbs for tree browsing
- Get the shell escaping patch included in ruby-git
- Create a larsch-creole gem
- (DONE) Preview
- (DONE) Menu
- (DONE) Search
- (DONE) Edit uploaded files (overwrite)
Expand Down
15 changes: 15 additions & 0 deletions test/git_support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'test/unit'
require 'wiki'

module GitSupport
def setup
@repo_path = File.expand_path(File.join(File.dirname(__FILE__), '.test'))
@repo = Git.init(@repo_path)
page = Wiki::Page.new(@repo, 'init.txt')
page.write('This file is used to initialize the repository. It can be deleted.', 'Initialize Repository')
end

def teardown
FileUtils.rm_rf(@repo_path)
end
end
79 changes: 79 additions & 0 deletions test/test_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require 'git_support'

class TC_Object < Test::Unit::TestCase
include GitSupport

def test_find
assert_instance_of Wiki::Tree, Wiki::Object.find(@repo, '')
assert_instance_of Wiki::Tree, Wiki::Tree.find(@repo, '')
assert_nil Wiki::Page.find(@repo, '')

assert_instance_of Wiki::Tree, Wiki::Object.find(@repo, '/')
assert_instance_of Wiki::Tree, Wiki::Tree.find(@repo, '/')
assert_nil Wiki::Page.find(@repo, '/')

assert_instance_of Wiki::Page, Wiki::Object.find(@repo, 'init.txt')
assert_nil Wiki::Tree.find(@repo, 'init.txt')
assert_instance_of Wiki::Page, Wiki::Page.find(@repo, 'init.txt')

assert_instance_of Wiki::Tree, Wiki::Object.find(@repo, '/')
assert_instance_of Wiki::Tree, Wiki::Tree.find(@repo, '/')
assert_nil Wiki::Page.find(@repo, '/')

assert_instance_of Wiki::Tree, Wiki::Object.find(@repo, '/root')
assert_instance_of Wiki::Tree, Wiki::Tree.find(@repo, '/root')
assert_nil Wiki::Page.find(@repo, '/root')
end

def test_find!
assert_instance_of Wiki::Tree, Wiki::Object.find!(@repo, '/root')
assert_instance_of Wiki::Tree, Wiki::Tree.find!(@repo, '/root')
assert_raise Wiki::Object::NotFound do
Wiki::Page.find!(@repo, '/root')
end

assert_instance_of Wiki::Page, Wiki::Object.find!(@repo, '/init.txt')
assert_instance_of Wiki::Page, Wiki::Page.find!(@repo, '/init.txt')
assert_raise Wiki::Object::NotFound do
Wiki::Tree.find!(@repo, '/init.txt')
end

assert_raise Wiki::Object::NotFound do
Wiki::Object.find!(@repo, '/foo')
end
assert_raise Wiki::Object::NotFound do
Wiki::Page.find!(@repo, '/foo')
end
assert_raise Wiki::Object::NotFound do
Wiki::Tree.find!(@repo, '/foo')
end
end

def test_new?
assert !Wiki::Page.find(@repo, 'init.txt').new?
assert !Wiki::Tree.find(@repo, '').new?
assert Wiki::Page.new(@repo, 'new').new?
assert Wiki::Tree.new(@repo, 'new').new?
end

def test_type
assert Wiki::Page.find(@repo, 'init.txt').page?
assert Wiki::Tree.find(@repo, '').tree?
end

def test_name
assert_equal 'name.ext', Wiki::Object.new(@repo, '/path/name.ext').name
end

def test_pretty_name
assert_equal 'name', Wiki::Object.new(@repo, '/path/name.ext').pretty_name
end

def test_path
assert_equal 'path/name.ext', Wiki::Object.new(@repo, '/path/name.ext').path
end

def test_safe_name
assert_equal '._____-_0123456789abc', Wiki::Object.new(@repo, '.#+*?=-_0123456789abc').safe_name
end
end
9 changes: 9 additions & 0 deletions test/test_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'git_support'

class TC_Object < Test::Unit::TestCase
include GitSupport

def test_extension
assert_equal 'path/name.ext', Wiki::Page.new(@repo, '/path/name.ext').path
end
end
16 changes: 8 additions & 8 deletions wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def name
path
end

def pretty_name
name.gsub(/\.([^.]+)$/, '')
end

def safe_name
n = name
n = 'root' if n.blank?
Expand Down Expand Up @@ -284,9 +288,9 @@ def self.git_find(repo, path, commit)
class Page < Object
attr_writer :content

def find(repo, path, sha = nil)
def self.find(repo, path, sha = nil)
object = super(repo, path, sha)
object.page? ? object : nil
object && object.page? ? object : nil
end

def content
Expand Down Expand Up @@ -326,19 +330,15 @@ def extension
$1 || ''
end

def pretty_name
name.gsub(/\.([^.]+)$/, '')
end

def mime
@mime ||= Mime.by_extension(extension)
end
end

class Tree < Object
def find(repo, path, sha = nil)
def self.find(repo, path, sha = nil)
object = super(repo, path, sha)
object.tree? ? object : nil
object && object.tree? ? object : nil
end

def children
Expand Down

0 comments on commit dadfd04

Please sign in to comment.