| 1 |
require File.dirname(__FILE__) + '/../spec_helper' |
| 2 |
|
| 3 |
describe TreesController do |
| 4 |
|
| 5 |
before(:each) do |
| 6 |
@project = projects(:johans) |
| 7 |
@repository = @project.repositories.first |
| 8 |
@repository.stub!(:full_repository_path).and_return(repo_path) |
| 9 |
|
| 10 |
Project.should_receive(:find_by_slug!).with(@project.slug) \ |
| 11 |
.and_return(@project) |
| 12 |
@project.repositories.should_receive(:find_by_name!) \ |
| 13 |
.with(@repository.name).and_return(@repository) |
| 14 |
@repository.stub!(:has_commits?).and_return(true) |
| 15 |
|
| 16 |
@git = mock("Grit mock", :null_object => true) |
| 17 |
@repository.stub!(:git).and_return(@git) |
| 18 |
@head = mock("master branch") |
| 19 |
@head.stub!(:name).and_return("master") |
| 20 |
@repository.stub!(:head_candidate).and_return(@head) |
| 21 |
end |
| 22 |
|
| 23 |
describe "#index" do |
| 24 |
it "redirects to the master head, if not :id given" do |
| 25 |
head = mock("a branch") |
| 26 |
head.stub!(:name).and_return("somebranch") |
| 27 |
@repository.should_receive(:head_candidate).and_return(head) |
| 28 |
|
| 29 |
get :index, :project_id => @project.slug, :repository_id => @repository.name |
| 30 |
response.should redirect_to(project_repository_tree_path(@project, @repository, "somebranch", [])) |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
describe "#show" do |
| 35 |
it "GETs successfully" do |
| 36 |
tree_mock = mock("tree") |
| 37 |
tree_mock.stub!(:id).and_return("123") |
| 38 |
@commit_mock = mock("commit") |
| 39 |
@commit_mock.stub!(:tree).and_return(tree_mock) |
| 40 |
@git.should_receive(:commit).with("a"*40).and_return(@commit_mock) |
| 41 |
@git.should_receive(:tree).with(tree_mock.id, ["foo/bar/"]).and_return(tree_mock) |
| 42 |
get :show, :project_id => @project.slug, |
| 43 |
:repository_id => @repository.name, :id => "a"*40, :path => ["foo", "bar"] |
| 44 |
|
| 45 |
response.should be_success |
| 46 |
assigns[:git].should == @git |
| 47 |
assigns[:tree].should == tree_mock |
| 48 |
end |
| 49 |
|
| 50 |
it "redirects to HEAD if provided sha was not found (backwards compat)" do |
| 51 |
@git.should_receive(:commit).with("a"*40).and_return(nil) |
| 52 |
get :show, :project_id => @project.slug, |
| 53 |
:repository_id => @repository.name, :id => "a"*40, :path => ["foo"] |
| 54 |
|
| 55 |
response.should redirect_to(project_repository_tree_path(@project, @repository, "HEAD", ["foo"])) |
| 56 |
end |
| 57 |
end |
| 58 |
|
| 59 |
describe "#archive" do |
| 60 |
def do_get(opts = {}) |
| 61 |
get :archive, {:project_id => @project.slug, |
| 62 |
:repository_id => @repository.name}.merge(opts) |
| 63 |
end |
| 64 |
|
| 65 |
it "archives the source tree" do |
| 66 |
do_get |
| 67 |
response.should be_success |
| 68 |
|
| 69 |
response.headers["type"].should == "application/x-gzip" |
| 70 |
response.headers["Content-Transfer-Encoding"].should == "binary" |
| 71 |
end |
| 72 |
end |
| 73 |
|
| 74 |
end |