Commit 258aa3c05106ac14a545cfa08a8276989da6a529

Refactored specs for Repository and Trees Controller

Signed-off-by: David A. Cuadrado <krawek@gmail.com>
  
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
  
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