Further repo browser/Dolt integration work
[gitorious:pkong23s-mainline.git] / test / micro / gitorious / dolt / repository_resolver_test.rb
1 # encoding: utf-8
2 #--
3 #   Copyright (C) 2011-2012 Gitorious AS
4 #
5 #   This program is free software: you can redistribute it and/or modify
6 #   it under the terms of the GNU Affero General Public License as published by
7 #   the Free Software Foundation, either version 3 of the License, or
8 #   (at your option) any later version.
9 #
10 #   This program is distributed in the hope that it will be useful,
11 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #   GNU Affero General Public License for more details.
14 #
15 #   You should have received a copy of the GNU Affero General Public License
16 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #++
18 require "fast_test_helper"
19 require "gitorious/dolt/repository_resolver"
20
21 class StubRepository
22   def self.full_repository_path=(path)
23     @full_repository_path = path
24   end
25
26   def self.full_repository_path
27     @full_repository_path
28   end
29
30   def self.find_by_path(name)
31     repo = Repository.new
32     repo.name = name
33     repo.full_repository_path = full_repository_path
34     repo
35   end
36 end
37
38 class RepositoryResolverTest < MiniTest::Shoulda
39   describe Gitorious::Dolt::RepositoryResolver do
40     it "exposes repository presenter as meta" do
41       StubRepository.full_repository_path = Rails.root.realpath.to_s
42       resolver = Gitorious::Dolt::RepositoryResolver.new(StubRepository)
43       repository = resolver.resolve("mainline")
44
45       assert_equal "mainline", repository.meta.name
46     end
47
48     it "raises error if repository doesn't exist" do
49       StubRepository.full_repository_path = "/tmp"
50       resolver = Gitorious::Dolt::RepositoryResolver.new(StubRepository)
51
52       assert_raises Rugged::RepositoryError do
53         repository = resolver.resolve("mainline")
54       end
55     end
56   end
57 end