Commit 5865587138fb7118563f5404f869db59887cfe5a

Merge commit 'krawek/refactor-repo-specs'

* commit 'krawek/refactor-repo-specs':
Refactored GitBackend
Refactored specs for Repository and Trees Controller

Commit diff

spec/controllers/trees_controller_spec.rb

 
6363 end
6464
6565 it "archives the source tree" do
66 @git.should_receive(:commit).and_return(true)
67 @git.should_receive(:archive_tar_gz).and_return("the data")
6668 do_get
6769 response.should be_success
6870
toggle raw diff

spec/models/git_backend_spec.rb

 
1212 FileUtils.mkdir_p(@repository.full_repository_path, :mode => 0755)
1313 end
1414
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
3315 it "creates a bare git repository" do
3416 path = @repository.full_repository_path
3517 FileUtils.should_receive(:mkdir_p).with(path, :mode => 0750).and_return(true)
3618 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
4020 GitBackend.should_receive(:execute_command).with(
4121 %Q{GIT_DIR="#{path}" git-update-server-info}
4222 ).and_return(true)
2828 source_path = @repository.full_repository_path
2929 target_path = repositories(:johans).full_repository_path
3030 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
3432 GitBackend.should_receive(:execute_command).with(
3533 %Q{GIT_DIR="#{target_path}" git-update-server-info}
3634 ).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
3940 GitBackend.clone(target_path, source_path)
40# File.exist?(File.join(target_path, "hooks")).should == false
4141 end
4242
4343 it "deletes a git repository" do
toggle raw diff

spec/models/repository_spec.rb

 
1515 }.merge(opts))
1616 end
1717
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
3518 it "should have valid associations" do
3619 @repository.should have_valid_associations
3720 end
107107 target = @repository
108108 target_path = @repository.full_repository_path
109109
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,
111113 source.full_repository_path).and_return(true)
114 Repository.should_receive(:create_hooks).and_return(true)
112115
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"
115123
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
122142 end
123143
124144 it "deletes a repository" do
toggle raw diff