require 'repertoire/repository' require 'repertoire/media/types/hg' require 'spec_helper' require 'helpers/repository' describe Repository do describe "name" do before(:all) do @host = 'www.example.com' @url_prefix = "http://#{@host}" end it "should return a repository name from a URI" do Repository.name("#{@url_prefix}/repo").should == 'repo' end it "should ignore trunk/ postfixes" do Repository.name("#{@url_prefix}/repo/trunk").should == 'repo' end it "should ignore .git postfixes" do Repository.name("#{@url_prefix}/repo.git").should == 'repo' end it "should use the hostname if the URI path is empty" do Repository.name(@url_prefix).should == @host end it "should use the hostname if the URI path is the root" do Repository.name("#{@url_prefix}/").should == @host end it "should use the hostname if the URI path becomes empty" do Repository.name("#{@url_prefix}/trunk").should == @host end it "should prevent against directory traversal" do Repository.name("#{@url_prefix}/..").should == @host end end describe "file access" do before(:all) do @repo = Repository.new(REPOSITORY_PATH,Media::Hg) end it "should have paths" do paths = @repo.glob('**/*').map { |path| File.basename(path) } paths.include?('file.txt').should == true paths.include?('dir').should == true paths.include?('file2.txt').should == true end it "should have top level files" do @repo.files.map { |path| File.basename(path) }.should == [ 'file.txt' ] end it "should have top level directories" do @repo.directories.map { |path| File.basename(path) }.should == [ 'dir' ] end end it "should be able to guess the media typa from the path" do repo = Repository.new(REPOSITORY_PATH) repo.media.should == Media::Hg end it "should provide the media name of the repository" do repo = Repository.new(REPOSITORY_PATH,Media::Hg) repo.media_name.should == :hg end end