| |   |
| 1 | require File.dirname(__FILE__) + '/../spec_helper' |
| 2 | |
| 3 | describe 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 | |
| 53 | end |
| toggle raw diff |
--- /dev/null
+++ b/spec/lib/git_backend_spec.rb
@@ -0,0 +1,53 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe GitBackend do
+ before(:each) do
+ @repository = Repository.new({
+ :name => "foo",
+ :project => projects(:johans),
+ :user => users(:johan)
+ })
+ end
+
+ it "creates a bare git repository" do
+ path = @repository.full_repository_path
+ FileUtils.should_receive(:mkdir_p).with(path, :mode => 0750).and_return(true)
+ Dir.should_receive(:chdir).with(path).and_yield(path)
+ Git.should_receive(:init).with(path, :repository => path).and_return(true)
+ FileUtils.should_receive(:touch).with(File.join(path, "git-daemon-export-ok"))
+
+ GitBackend.create(path)
+ end
+
+ it "clones an existing repos into a bare one" do
+ source_path = @repository.full_repository_path
+ target_path = repositories(:johans).full_repository_path
+ Git.should_receive(:clone).with(source_path, target_path, :bare => true).and_return(true)
+ FileUtils.should_receive(:touch).with(File.join(target_path, "git-daemon-export-ok"))
+
+ GitBackend.clone(target_path, source_path)
+ end
+
+ it "deletes a git repository" do
+ path = @repository.full_repository_path
+ FileUtils.should_receive(:rm_rf).with(path).and_return(true)
+ GitBackend.delete!(path)
+ end
+
+ it "knows if a repos has commits" do
+ path = @repository.full_repository_path
+ dir_mock = mock("Dir mock")
+ Dir.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
+ dir_mock.should_receive(:size).and_return(0)
+ GitBackend.repository_has_commits?(path).should == false
+ end
+
+ it "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.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
+ dir_mock.should_receive(:size).and_return(1)
+ GitBackend.repository_has_commits?(path).should == true
+ end
+
+end
\ No newline at end of file |
| |   |
| 0 | | require File.dirname(__FILE__) + '/../spec_helper' |
| 1 | | |
| 2 | | describe 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 | | |
| 52 | | end |
| toggle raw diff |
--- a/spec/models/git_backend_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-describe GitBackend do
- before(:each) do
- @repository = Repository.new({
- :name => "foo",
- :project => projects(:johans),
- :user => users(:johan)
- })
- end
-
- it "creates a bare git repository" do
- path = @repository.full_repository_path
- FileUtils.should_receive(:mkdir_p).with(path, :mode => 0750).and_return(true)
- Dir.should_receive(:chdir).with(path).and_yield(path)
- Git.should_receive(:init).with(path, :repository => path).and_return(true)
- FileUtils.should_receive(:touch).with(File.join(path, "git-daemon-export-ok"))
-
- GitBackend.create(path)
- end
-
- it "clones an existing repos into a bare one" do
- source_path = @repository.full_repository_path
- target_path = repositories(:johans).full_repository_path
- Git.should_receive(:clone).with(source_path, target_path, :bare => true).and_return(true)
- FileUtils.should_receive(:touch).with(File.join(target_path, "git-daemon-export-ok"))
-
- GitBackend.clone(target_path, source_path)
- end
-
- it "deletes a git repository" do
- path = @repository.full_repository_path
- FileUtils.should_receive(:rm_rf).with(path).and_return(true)
- GitBackend.delete!(path)
- end
-
- it "knows if a repos has commits" do
- path = @repository.full_repository_path
- dir_mock = mock("Dir mock")
- Dir.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
- dir_mock.should_receive(:size).and_return(0)
- GitBackend.repository_has_commits?(path).should == false
- end
-
- it "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.should_receive(:[]).with(File.join(path, "refs/heads/*")).and_return(dir_mock)
- dir_mock.should_receive(:size).and_return(1)
- GitBackend.repository_has_commits?(path).should == true
- end
-
-end
\ No newline at end of file |