fix tests for normalize_dir
This commit is contained in:
@@ -32,7 +32,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns an unbaked Grit::Blob instance.
|
# Returns an unbaked Grit::Blob instance.
|
||||||
def blob(repo)
|
def blob(repo)
|
||||||
@blob ||= Grit::Blob.create(repo,
|
@blob ||= Grit::Blob.create(repo,
|
||||||
:id => @sha, :name => name, :size => @size)
|
:id => @sha, :name => name, :size => @size)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ module Gollum
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Normalizes a given directory name for searching through tree paths.
|
# Normalizes a given directory name for searching through tree paths.
|
||||||
# Ensures that a directory begins with a slash, or
|
# Ensures that a directory begins with a slash, or
|
||||||
#
|
#
|
||||||
# normalize_dir("") # => ""
|
# normalize_dir("") # => ""
|
||||||
# normalize_dir(".") # => ""
|
# normalize_dir(".") # => ""
|
||||||
@@ -64,12 +64,13 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# dir - String directory name.
|
# dir - String directory name.
|
||||||
#
|
#
|
||||||
# Returns a normalized String directory name, or nil if no directory
|
# Returns a normalized String directory name, or nil if no directory
|
||||||
# is given.
|
# is given.
|
||||||
def self.normalize_dir(dir)
|
def self.normalize_dir(dir)
|
||||||
|
return '' if dir =~ /^.:\/$/
|
||||||
if dir
|
if dir
|
||||||
dir = ::File.expand_path(dir, '/')
|
dir = ::File.expand_path(dir, '/')
|
||||||
dir = '' if (dir == '/' || dir =~ /^.:\/$/)
|
dir = '' if dir == '/'
|
||||||
end
|
end
|
||||||
dir
|
dir
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ context "Page" do
|
|||||||
assert_equal "", Gollum::BlobEntry.normalize_dir("")
|
assert_equal "", Gollum::BlobEntry.normalize_dir("")
|
||||||
assert_equal "", Gollum::BlobEntry.normalize_dir(".")
|
assert_equal "", Gollum::BlobEntry.normalize_dir(".")
|
||||||
assert_equal "", Gollum::BlobEntry.normalize_dir("/")
|
assert_equal "", Gollum::BlobEntry.normalize_dir("/")
|
||||||
|
assert_equal "", Gollum::BlobEntry.normalize_dir("c:/")
|
||||||
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("foo")
|
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("foo")
|
||||||
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo")
|
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user