| |   |
| 12 | 12 | FileUtils.mkdir_p(@repository.full_repository_path, :mode => 0755) |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | | def push_something |
| 16 | | path = File.join(Dir.tmpdir, "gitorious.test") |
| 17 | | FileUtils.mkpath(path) |
| 18 | | |
| 19 | | Dir.chdir(path) do |
| 20 | | File.open("something", "w") do |file| |
| 21 | | file << "dummy #{rand}\n" |
| 22 | | end |
| 23 | | |
| 24 | | git = Grit::Git.new(File.join(path, ".git")) |
| 25 | | git.init({}, "--shared") |
| 26 | | git.add({}, "something") |
| 27 | | git.commit({:m => true}, "message") |
| 28 | | git.push({:all => true}, @repository.full_repository_path) |
| 29 | | end |
| 30 | | end |
| 31 | | |
| 32 | | |
| 33 | 15 | it "creates a bare git repository" do |
| 34 | 16 | path = @repository.full_repository_path |
| 35 | 17 | FileUtils.should_receive(:mkdir_p).with(path, :mode => 0750).and_return(true) |
| 36 | 18 | FileUtils.should_receive(:touch).with(File.join(path, "git-daemon-export-ok")) |
| 37 | | # GitBackend.should_receive(:execute_command).with( |
| 38 | | # %Q{chmod +x #{File.join(path, "hooks/post-update")}} |
| 39 | | # ).and_return(true) |
| 19 | |
| 40 | 20 | GitBackend.should_receive(:execute_command).with( |
| 41 | 21 | %Q{GIT_DIR="#{path}" git-update-server-info} |
| 42 | 22 | ).and_return(true) |
| … | … | |
| 28 | 28 | source_path = @repository.full_repository_path |
| 29 | 29 | target_path = repositories(:johans).full_repository_path |
| 30 | 30 | FileUtils.should_receive(:touch).with(File.join(target_path, "git-daemon-export-ok")) |
| 31 | | # GitBackend.should_receive(:execute_command).with( |
| 32 | | # %Q{chmod +x #{File.join(target_path, "hooks/post-update")}} |
| 33 | | # ).and_return(true) |
| 31 | |
| 34 | 32 | GitBackend.should_receive(:execute_command).with( |
| 35 | 33 | %Q{GIT_DIR="#{target_path}" git-update-server-info} |
| 36 | 34 | ).and_return(true) |
| 37 | | |
| 38 | | push_something |
| 35 | |
| 36 | git = mock("Grit::Git instance") |
| 37 | Grit::Git.should_receive(:new).and_return(git) |
| 38 | git.should_receive(:clone) |
| 39 | |
| 39 | 40 | GitBackend.clone(target_path, source_path) |
| 40 | | # File.exist?(File.join(target_path, "hooks")).should == false |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | 43 | it "deletes a git repository" do |
| toggle raw diff |
--- a/spec/models/git_backend_spec.rb
+++ b/spec/models/git_backend_spec.rb
@@ -12,31 +12,11 @@ describe GitBackend do
FileUtils.mkdir_p(@repository.full_repository_path, :mode => 0755)
end
- def push_something
- path = File.join(Dir.tmpdir, "gitorious.test")
- FileUtils.mkpath(path)
-
- Dir.chdir(path) do
- File.open("something", "w") do |file|
- file << "dummy #{rand}\n"
- end
-
- git = Grit::Git.new(File.join(path, ".git"))
- git.init({}, "--shared")
- git.add({}, "something")
- git.commit({:m => true}, "message")
- git.push({:all => true}, @repository.full_repository_path)
- end
- 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)
FileUtils.should_receive(:touch).with(File.join(path, "git-daemon-export-ok"))
-# GitBackend.should_receive(:execute_command).with(
-# %Q{chmod +x #{File.join(path, "hooks/post-update")}}
-# ).and_return(true)
+
GitBackend.should_receive(:execute_command).with(
%Q{GIT_DIR="#{path}" git-update-server-info}
).and_return(true)
@@ -48,16 +28,16 @@ describe GitBackend do
source_path = @repository.full_repository_path
target_path = repositories(:johans).full_repository_path
FileUtils.should_receive(:touch).with(File.join(target_path, "git-daemon-export-ok"))
-# GitBackend.should_receive(:execute_command).with(
-# %Q{chmod +x #{File.join(target_path, "hooks/post-update")}}
-# ).and_return(true)
+
GitBackend.should_receive(:execute_command).with(
%Q{GIT_DIR="#{target_path}" git-update-server-info}
).and_return(true)
-
- push_something
+
+ git = mock("Grit::Git instance")
+ Grit::Git.should_receive(:new).and_return(git)
+ git.should_receive(:clone)
+
GitBackend.clone(target_path, source_path)
-# File.exist?(File.join(target_path, "hooks")).should == false
end
it "deletes a git repository" do |
| |   |
| 15 | 15 | }.merge(opts)) |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | | def push_something |
| 19 | | path = File.join(Dir.tmpdir, "gitorious.test") |
| 20 | | FileUtils.mkpath(path) |
| 21 | | |
| 22 | | Dir.chdir(path) do |
| 23 | | File.open("something", "w") do |file| |
| 24 | | file << "dummy #{rand}\n" |
| 25 | | end |
| 26 | | |
| 27 | | git = Grit::Git.new(File.join(path, ".git")) |
| 28 | | git.init({}, "--shared") |
| 29 | | git.add({}, "something") |
| 30 | | git.commit({:m => true}, "message") |
| 31 | | git.push({:all => true}, @repository.full_repository_path) |
| 32 | | end |
| 33 | | end |
| 34 | | |
| 35 | 18 | it "should have valid associations" do |
| 36 | 19 | @repository.should have_valid_associations |
| 37 | 20 | end |
| … | … | |
| 107 | 107 | target = @repository |
| 108 | 108 | target_path = @repository.full_repository_path |
| 109 | 109 | |
| 110 | | Repository.git_backend.should_receive(:clone).with(target.full_repository_path, |
| 110 | git_backend = mock("Git backend") |
| 111 | Repository.should_receive(:git_backend).and_return(git_backend) |
| 112 | git_backend.should_receive(:clone).with(target.full_repository_path, |
| 111 | 113 | source.full_repository_path).and_return(true) |
| 114 | Repository.should_receive(:create_hooks).and_return(true) |
| 112 | 115 | |
| 113 | | push_something |
| 114 | | Repository.clone_git_repository(target.gitdir, source.gitdir) |
| 116 | Repository.clone_git_repository(target.gitdir, source.gitdir).should be_true |
| 117 | end |
| 118 | |
| 119 | it "should create the hooks" do |
| 120 | hooks = "/path/to/hooks" |
| 121 | path = "/path/to/repository" |
| 122 | base_path = "#{RAILS_ROOT}/data/hooks" |
| 115 | 123 | |
| 116 | | Dir.chdir(target_path) do |
| 117 | | hooks = File.join(target_path, "hooks") |
| 118 | | File.exist?(hooks).should == true |
| 119 | | File.symlink?(hooks).should == true |
| 120 | | File.symlink?(File.expand_path(File.readlink(hooks))).should == true |
| 121 | | end |
| 124 | File.should_receive(:join).ordered.with(GitoriousConfig["repository_base_path"], ".hooks").and_return(hooks) |
| 125 | |
| 126 | Dir.should_receive(:chdir).ordered.with(path).and_yield(nil) |
| 127 | |
| 128 | File.should_receive(:symlink?).ordered.with(hooks).and_return(false) |
| 129 | File.should_receive(:exist?).ordered.with(hooks).and_return(false) |
| 130 | FileUtils.should_receive(:ln_s).ordered.with(base_path, hooks) |
| 131 | |
| 132 | local_hooks = "/path/to/local/hooks" |
| 133 | File.should_receive(:join).ordered.with(path, "hooks").and_return(local_hooks) |
| 134 | |
| 135 | File.should_receive(:exist?).ordered.with(local_hooks).and_return(true) |
| 136 | |
| 137 | File.should_receive(:join).with(path, "description").ordered |
| 138 | |
| 139 | File.should_receive(:open).ordered.and_return(true) |
| 140 | |
| 141 | Repository.create_hooks(path).should be_true |
| 122 | 142 | end |
| 123 | 143 | |
| 124 | 144 | it "deletes a repository" do |
| toggle raw diff |
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -15,23 +15,6 @@ describe Repository do
}.merge(opts))
end
- def push_something
- path = File.join(Dir.tmpdir, "gitorious.test")
- FileUtils.mkpath(path)
-
- Dir.chdir(path) do
- File.open("something", "w") do |file|
- file << "dummy #{rand}\n"
- end
-
- git = Grit::Git.new(File.join(path, ".git"))
- git.init({}, "--shared")
- git.add({}, "something")
- git.commit({:m => true}, "message")
- git.push({:all => true}, @repository.full_repository_path)
- end
- end
-
it "should have valid associations" do
@repository.should have_valid_associations
end
@@ -124,18 +107,38 @@ describe Repository do
target = @repository
target_path = @repository.full_repository_path
- Repository.git_backend.should_receive(:clone).with(target.full_repository_path,
+ git_backend = mock("Git backend")
+ Repository.should_receive(:git_backend).and_return(git_backend)
+ git_backend.should_receive(:clone).with(target.full_repository_path,
source.full_repository_path).and_return(true)
+ Repository.should_receive(:create_hooks).and_return(true)
- push_something
- Repository.clone_git_repository(target.gitdir, source.gitdir)
+ Repository.clone_git_repository(target.gitdir, source.gitdir).should be_true
+ end
+
+ it "should create the hooks" do
+ hooks = "/path/to/hooks"
+ path = "/path/to/repository"
+ base_path = "#{RAILS_ROOT}/data/hooks"
- Dir.chdir(target_path) do
- hooks = File.join(target_path, "hooks")
- File.exist?(hooks).should == true
- File.symlink?(hooks).should == true
- File.symlink?(File.expand_path(File.readlink(hooks))).should == true
- end
+ File.should_receive(:join).ordered.with(GitoriousConfig["repository_base_path"], ".hooks").and_return(hooks)
+
+ Dir.should_receive(:chdir).ordered.with(path).and_yield(nil)
+
+ File.should_receive(:symlink?).ordered.with(hooks).and_return(false)
+ File.should_receive(:exist?).ordered.with(hooks).and_return(false)
+ FileUtils.should_receive(:ln_s).ordered.with(base_path, hooks)
+
+ local_hooks = "/path/to/local/hooks"
+ File.should_receive(:join).ordered.with(path, "hooks").and_return(local_hooks)
+
+ File.should_receive(:exist?).ordered.with(local_hooks).and_return(true)
+
+ File.should_receive(:join).with(path, "description").ordered
+
+ File.should_receive(:open).ordered.and_return(true)
+
+ Repository.create_hooks(path).should be_true
end
it "deletes a repository" do |