1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# encoding: utf-8
#--
# Copyright (C) 2009 Johan Sørensen <johan@johansorensen.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
require 'tmpdir'
require File.dirname(__FILE__) + '/../test_helper'
class GitBackendTest < ActiveSupport::TestCase
def setup
@repository = Repository.new({
:name => "foo",
:owner => projects(:johans),
:user => users(:johan)
})
FileUtils.mkdir_p(@repository.full_repository_path, :mode => 0755)
end
should "creates a bare git repository" do
path = @repository.full_repository_path
FileUtils.expects(:mkdir_p).with(path, :mode => 0750).returns(true)
FileUtils.expects(:touch).with(File.join(path, "git-daemon-export-ok"))
GitBackend.expects(:execute_command).with(
%Q{GIT_DIR="#{path}" git update-server-info}
).returns(true)
GitBackend.create(path)
end
should "clones an existing repos into a bare one" do
source_path = @repository.full_repository_path
target_path = repositories(:johans).full_repository_path
FileUtils.expects(:touch).with(File.join(target_path, "git-daemon-export-ok"))
GitBackend.expects(:execute_command).with(
%Q{GIT_DIR="#{target_path}" git update-server-info}
).returns(true)
git = mock("Grit::Git instance")
Grit::Git.expects(:new).returns(git)
git.expects(:clone)
GitBackend.clone(target_path, source_path)
end
should "deletes a git repository" do
base_path = "/base/path"
repos_path = base_path + "/repo"
GitoriousConfig.expects(:[]).with("repository_base_path").returns(base_path)
FileUtils.expects(:rm_rf).with(repos_path).returns(true)
GitBackend.delete!(repos_path)
end
should "knows if a repos has commits" do
path = @repository.full_repository_path
dir_mock = mock("Dir mock")
Dir.expects(:[]).with(File.join(path, "refs/heads/*")).returns(dir_mock)
dir_mock.expects(:size).returns(0)
assert !GitBackend.repository_has_commits?(path), 'GitBackend.repository_has_commits?(path) should be false'
end
should "knows if a repos has commits, if there's more than 0 heads" do
path = @repository.full_repository_path
dir_mock = mock("Dir mock")
Dir.expects(:[]).with(File.join(path, "refs/heads/*")).returns(dir_mock)
dir_mock.expects(:size).returns(1)
assert GitBackend.repository_has_commits?(path), 'GitBackend.repository_has_commits?(path) should be true'
end
end
|