Commit bbdd5ee1e0825224d0b8c72d41d526f1e666830f

GitBackend spec moved to lib/ specs (since it is not a model)

Commit diff

spec/lib/git_backend_spec.rb

 
1require File.dirname(__FILE__) + '/../spec_helper'
2
3describe GitBackend do
4 before(:each) do
5 @repository = Repository.new({
6 :name => "foo",
7 :project => projects(:johans),
8 :user => users(:johan)
9 })
10 end
11
12 it "creates a bare git repository" do
13 path = @repository.full_repository_path
14 FileUtils.should_receive(:mkdir_p).with(path, :mode => 0750).and_return(true)
15 Dir.should_receive(:chdir).with(path).and_yield(path)
16 Git.should_receive(:init).with(path, :repository => path).and_return(true)
17 FileUtils.should_receive(:touch).with(File.join(path, "git-daemon-export-ok"))
18
19 GitBackend.create(path)
20 end
21
22 it "clones an existing repos into a bare one" do
23 source_path = @repository.full_repository_path
24 target_path = repositories(:johans).full_repository_path
25 Git.should_receive(:clone).with(source_path, target_path, :bare => true).and_return(true)
26 FileUtils.should_receive(:touch).with(File.join(target_path, "git-daemon-export-ok"))
27
28 GitBackend.clone(target_path, source_path)
29 end
30
31 it "deletes a git repository" do
32 path = @repository.full_repository_path
33 FileUtils.should_receive(:rm_rf).with(path).and_return(true)
34 GitBackend.delete!(path)
35 end
36
37 it "knows if a repos has commits" do
38 path = @repository.full_repository_path
39 dir_mock = mock("Dir mock")
40 Dir.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
41 dir_mock.should_receive(:size).and_return(0)
42 GitBackend.repository_has_commits?(path).should == false
43 end
44
45 it "knows if a repos has commits, if there's more than 0 heads" do
46 path = @repository.full_repository_path
47 dir_mock = mock("Dir mock")
48 Dir.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
49 dir_mock.should_receive(:size).and_return(1)
50 GitBackend.repository_has_commits?(path).should == true
51 end
52
53end
toggle raw diff

spec/models/git_backend_spec.rb

 
0require File.dirname(__FILE__) + '/../spec_helper'
1
2describe GitBackend do
3 before(:each) do
4 @repository = Repository.new({
5 :name => "foo",
6 :project => projects(:johans),
7 :user => users(:johan)
8 })
9 end
10
11 it "creates a bare git repository" do
12 path = @repository.full_repository_path
13 FileUtils.should_receive(:mkdir_p).with(path, :mode => 0750).and_return(true)
14 Dir.should_receive(:chdir).with(path).and_yield(path)
15 Git.should_receive(:init).with(path, :repository => path).and_return(true)
16 FileUtils.should_receive(:touch).with(File.join(path, "git-daemon-export-ok"))
17
18 GitBackend.create(path)
19 end
20
21 it "clones an existing repos into a bare one" do
22 source_path = @repository.full_repository_path
23 target_path = repositories(:johans).full_repository_path
24 Git.should_receive(:clone).with(source_path, target_path, :bare => true).and_return(true)
25 FileUtils.should_receive(:touch).with(File.join(target_path, "git-daemon-export-ok"))
26
27 GitBackend.clone(target_path, source_path)
28 end
29
30 it "deletes a git repository" do
31 path = @repository.full_repository_path
32 FileUtils.should_receive(:rm_rf).with(path).and_return(true)
33 GitBackend.delete!(path)
34 end
35
36 it "knows if a repos has commits" do
37 path = @repository.full_repository_path
38 dir_mock = mock("Dir mock")
39 Dir.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
40 dir_mock.should_receive(:size).and_return(0)
41 GitBackend.repository_has_commits?(path).should == false
42 end
43
44 it "knows if a repos has commits, if there's more than 0 heads" do
45 path = @repository.full_repository_path
46 dir_mock = mock("Dir mock")
47 Dir.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
48 dir_mock.should_receive(:size).and_return(1)
49 GitBackend.repository_has_commits?(path).should == true
50 end
51
52end
toggle raw diff