diff options
-rw-r--r-- | app/controllers/trees_controller.rb | 3 | ||||
-rw-r--r-- | spec/controllers/trees_controller_spec.rb | 29 |
2 files changed, 26 insertions, 6 deletions
diff --git a/app/controllers/trees_controller.rb b/app/controllers/trees_controller.rb index 192280b..66f35a0 100644 --- a/app/controllers/trees_controller.rb +++ b/app/controllers/trees_controller.rb @@ -32,7 +32,8 @@ class TreesController < ApplicationController redirect_to project_repository_tree_path(@project, @repository, branch_with_tree("HEAD", @path)) and return end - @root = Breadcrumb::Folder.new({:paths => @path, :head => @git.get_head(@ref), + head = @git.get_head(@ref) || Grit::Head.new(@commit.id_abbrev, @commit) + @root = Breadcrumb::Folder.new({:paths => @path, :head => head, :repository => @repository}) path = @path.blank? ? [] : ["#{@path.join("/")}/"] # FIXME: meh, this sux @tree = @git.tree(@commit.tree.id, path) diff --git a/spec/controllers/trees_controller_spec.rb b/spec/controllers/trees_controller_spec.rb index 971a253..822d8b8 100644 --- a/spec/controllers/trees_controller_spec.rb +++ b/spec/controllers/trees_controller_spec.rb @@ -58,25 +58,44 @@ describe TreesController do @commit_mock.stubs(:tree).returns(tree_mock) @git.expects(:commit).with("master").returns(@commit_mock) @git.expects(:tree).with(tree_mock.id, ["foo/bar/"]).returns(tree_mock) - @git.expects(:heads).returns(mock("head", :name => "master")) + @git.stubs(:get_head).returns(stub("head", :name => "master")) + get :show, :project_id => @project.to_param, :repository_id => @repository.to_param, :branch_and_path => ["master", "foo", "bar"] - + response.should be_success - assigns[:git].should == @git - assigns[:tree].should == tree_mock + assigns(:git).should == @git + assigns(:tree).should == tree_mock assigns(:ref).should == "master" assigns(:path).should == ["foo", "bar"] end it "redirects to HEAD if provided sha was not found (backwards compat)" do @git.expects(:commit).with("a"*40).returns(nil) - @git.expects(:heads).returns(mock("head", :name => "master")) + @git.stubs(:get_head).returns(stub("head", :name => "master")) get :show, :project_id => @project.slug, :repository_id => @repository.name, :branch_and_path => ["a"*40, "foo"] response.should redirect_to(project_repository_tree_path(@project, @repository, ["HEAD", "foo"])) end + + it "sets a pseudo-head if the tree ref is a sha" do + ref = "a"*20 + "1"*20 + tree_mock = mock("tree") + tree_mock.stubs(:id).returns("123") + @commit_mock = mock("commit") + @commit_mock.stubs(:tree).returns(tree_mock) + @commit_mock.stubs(:id_abbrev).returns(ref[0..7]) + @git.expects(:get_head).with(ref).returns(nil) + @git.expects(:commit).with(ref).returns(@commit_mock) + @git.expects(:tree).with(tree_mock.id, []).returns(tree_mock) + + get :show, :project_id => @project.to_param, + :repository_id => @repository.to_param, :branch_and_path => [ref] + + response.should be_success + assigns(:root).breadcrumb_parent.title.should == ref[0..7] + end end describe "#archive" do |