Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mendler committed Feb 9, 2009
1 parent dadfd04 commit 205d113
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ desc 'Default Task'
task :default => :test

Rake::TestTask.new(:test) do |t|
# FIXME: Too many warnings because of ruby-git
t.warning = true
t.test_files = FileList['test/test_*.rb']
end
Expand Down
12 changes: 11 additions & 1 deletion TODO.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ Brainstorming...
- Captcha support
- Image support, Image gallery
- Breadcrumbs for tree browsing
- Get the shell escaping patch included in ruby-git
- Create a larsch-creole gem
- Wiki installation under subpath (path_info translation could be done
via rack middleware, generated links must be adapted)
- (DONE) Preview
- (DONE) Menu
- (DONE) Search
- (DONE) Edit uploaded files (overwrite)
- (DONE) Login
- (DONE) Editable user profile, change pw function
- (DONE, but could be a lot improved) RSS/Atom Changelog

ruby-git TODO
-------------

- Get shell escaping patch included
- Commits aren't parsed correctly
- Fix uninitialized variables ($VERBOSE = 1 in the tests)


10 changes: 9 additions & 1 deletion test/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
class TC_Object < Test::Unit::TestCase
include GitSupport

def test_path_check
assert_raise MessageError do
Wiki::Object.find(@repo, '#invalid#')
Wiki::Object.find(@repo, ' spaces ')
end
assert_nil Wiki::Object.find(@repo, 'spaces in the path')
end

def test_find
assert_instance_of Wiki::Tree, Wiki::Object.find(@repo, '')
assert_instance_of Wiki::Tree, Wiki::Tree.find(@repo, '')
Expand Down Expand Up @@ -74,6 +82,6 @@ def test_path
end

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

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

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

def test_write
page = Wiki::Page.new(@repo, 'test')
assert page.new?
assert_nil page.content
assert_nil page.current_content
page.write('old content', "message1\ntext", 'Author1 <author1@localhorst>')

assert_equal 'old content', page.content
assert_equal 'old content', page.current_content
assert !page.new?

assert_equal "message1\ntext", page.commit.message
assert_equal 'Author1', page.commit.author.name
assert_equal 'author1@localhorst', page.commit.author.email

page.content = 'new content'
assert_equal 'new content', page.content
assert_equal 'old content', page.current_content
page.save('message2', 'Author2 <author2@localhorst>')

assert_equal 'message2', page.commit.message
assert_equal 'Author2', page.commit.author.name
assert_equal 'author2@localhorst', page.commit.author.email

page = Wiki::Page.find!(@repo, 'test')
assert !page.new?
assert_equal 'new content', page.content

assert_equal 'message2', page.commit.message
assert_equal 'Author2', page.commit.author.name
assert_equal 'author2@localhorst', page.commit.author.email
end
end
23 changes: 18 additions & 5 deletions wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def initialize(path)
def self.find(repo, path, sha = nil)
path ||= ''
path = path.cleanpath
forbid_invalid_path(path)
commit = sha ? repo.gcommit(sha) : repo.log(1).path(path).first
object = Object.git_find(repo, path, commit)
return Page.new(repo, path, commit, object) if object.blob?
Expand Down Expand Up @@ -259,7 +260,8 @@ def diff(to)

def initialize(repo, path, commit = nil, object = nil)
path ||= ''
forbid('Invalid path' => !@path.blank? && @path !~ /^#{PATH_PATTERN}$/)
path = path.cleanpath
Object.forbid_invalid_path(path)
@repo = repo
@path = path.cleanpath
@commit = commit
Expand All @@ -268,6 +270,10 @@ def initialize(repo, path, commit = nil, object = nil)

protected

def self.forbid_invalid_path(path)
forbid('Invalid path' => !path.blank? && path !~ /^#{PATH_PATTERN}$/)
end

def self.git_find(repo, path, commit)
if commit
if path.blank?
Expand All @@ -288,6 +294,11 @@ def self.git_find(repo, path, commit)
class Page < Object
attr_writer :content

def initialize(repo, path, commit = nil, object = nil)
super(repo, path, commit, object)
@content = nil
end

def self.find(repo, path, sha = nil)
object = super(repo, path, sha)
object && object.page? ? object : nil
Expand Down Expand Up @@ -336,17 +347,19 @@ def mime
end

class Tree < Object
def initialize(repo, path, commit = nil, object = nil)
super(repo, path, commit, object)
@children = nil
end

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

def children
if !@children
@children = @object.trees.to_a.map {|x| Tree.new(repo, path/x[0], commit, x[1])}.sort {|a,b| a.name <=> b.name } +
@children ||= @object.trees.to_a.map {|x| Tree.new(repo, path/x[0], commit, x[1])}.sort {|a,b| a.name <=> b.name } +
@object.blobs.to_a.map {|x| Page.new(repo, path/x[0], commit, x[1])}.sort {|a,b| a.name <=> b.name }
end
@children
end

def pretty_name
Expand Down

0 comments on commit 205d113

Please sign in to comment.