| |   |
| 7 | 7 | def index |
| 8 | 8 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 9 | 9 | @commits = @git.log(LOGS_PER_PAGE) |
| 10 | @tags_per_sha = @git.tags_by_sha |
| 11 | # TODO: Patch rails to keep track of what it responds to so we can DRY this up |
| 12 | @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom) |
| 13 | respond_to do |format| |
| 14 | format.html |
| 15 | format.atom |
| 16 | end |
| 10 | 17 | end |
| 11 | 18 | |
| 12 | | # def index |
| 13 | | # @git = Git.bare(@repository.full_repository_path) |
| 14 | | # @commits = @git.log(LOGS_PER_PAGE) |
| 15 | | # @tags_per_sha = returning({}) do |hash| |
| 16 | | # @git.tags.each do |tag| |
| 17 | | # hash[tag.sha] ||= [] |
| 18 | | # hash[tag.sha] << tag.name |
| 19 | | # end |
| 20 | | # end |
| 21 | | # # TODO: Patch rails to keep track of what it responds to so we can DRY this up |
| 22 | | # @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom) |
| 23 | | # respond_to do |format| |
| 24 | | # format.html |
| 25 | | # format.atom |
| 26 | | # end |
| 27 | | # end |
| 28 | | |
| 29 | 19 | def tree |
| 30 | | @git = Git.bare(@repository.full_repository_path) |
| 31 | | @tree = @git.gtree(params[:sha]) |
| 20 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 21 | @tree = @git.tree(params[:sha]) |
| 32 | 22 | end |
| 33 | 23 | |
| 34 | 24 | def commit |
| 35 | 25 | @diffmode = params[:diffmode] == "sidebyside" ? "sidebyside" : "inline" |
| 36 | | @git = Git.bare(@repository.full_repository_path) |
| 37 | | @commit = @git.gcommit(params[:sha]) |
| 26 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 27 | @commit = @git.commit(params[:sha]) |
| 38 | 28 | if @commit.parent |
| 39 | 29 | @diff = @git.diff(@commit.parent.sha || "", @commit.sha) |
| 40 | 30 | else |
| … | … | |
| 35 | 35 | end |
| 36 | 36 | |
| 37 | 37 | def diff |
| 38 | | @git = Git.bare(@repository.full_repository_path) |
| 38 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 39 | 39 | @diff = @git.diff(params[:sha], params[:other_sha]) |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | def blob |
| 43 | | @git = Git.bare(@repository.full_repository_path) |
| 44 | | @blob = @git.gblob(params[:sha]) |
| 43 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 44 | @blob = @git.blob(params[:sha]) |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | 47 | def raw |
| 48 | | @git = Git.bare(@repository.full_repository_path) |
| 49 | | @blob = @git.gblob(params[:sha]) |
| 48 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 49 | @blob = @git.blob(params[:sha]) |
| 50 | 50 | render :text => @blob.contents, :content_type => "text/plain" |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 53 | def log |
| 54 | | @git = Git.bare(@repository.full_repository_path) |
| 54 | @git = Gitorious::Gitto.new(@repository.full_repository_path) |
| 55 | 55 | skip = params[:page].blank? ? 0 : (params[:page].to_i-1) * LOGS_PER_PAGE |
| 56 | 56 | @commits = @git.log(LOGS_PER_PAGE, skip) |
| 57 | | @tags_per_sha = returning({}) do |hash| |
| 58 | | @git.tags.each do |tag| |
| 59 | | hash[tag.sha] ||= [] |
| 60 | | hash[tag.sha] << tag.name |
| 61 | | end |
| 62 | | end |
| 57 | @tags_per_sha = @git.tags_by_sha |
| 63 | 58 | # TODO: Patch rails to keep track of what it responds to so we can DRY this up |
| 64 | 59 | @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom) |
| 65 | 60 | respond_to do |format| |
| toggle raw diff |
--- a/app/controllers/browse_controller.rb
+++ b/app/controllers/browse_controller.rb
@@ -7,34 +7,24 @@ class BrowseController < ApplicationController
def index
@git = Gitorious::Gitto.new(@repository.full_repository_path)
@commits = @git.log(LOGS_PER_PAGE)
+ @tags_per_sha = @git.tags_by_sha
+ # TODO: Patch rails to keep track of what it responds to so we can DRY this up
+ @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
+ respond_to do |format|
+ format.html
+ format.atom
+ end
end
- # def index
- # @git = Git.bare(@repository.full_repository_path)
- # @commits = @git.log(LOGS_PER_PAGE)
- # @tags_per_sha = returning({}) do |hash|
- # @git.tags.each do |tag|
- # hash[tag.sha] ||= []
- # hash[tag.sha] << tag.name
- # end
- # end
- # # TODO: Patch rails to keep track of what it responds to so we can DRY this up
- # @atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
- # respond_to do |format|
- # format.html
- # format.atom
- # end
- # end
-
def tree
- @git = Git.bare(@repository.full_repository_path)
- @tree = @git.gtree(params[:sha])
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
+ @tree = @git.tree(params[:sha])
end
def commit
@diffmode = params[:diffmode] == "sidebyside" ? "sidebyside" : "inline"
- @git = Git.bare(@repository.full_repository_path)
- @commit = @git.gcommit(params[:sha])
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
+ @commit = @git.commit(params[:sha])
if @commit.parent
@diff = @git.diff(@commit.parent.sha || "", @commit.sha)
else
@@ -45,31 +35,26 @@ class BrowseController < ApplicationController
end
def diff
- @git = Git.bare(@repository.full_repository_path)
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
@diff = @git.diff(params[:sha], params[:other_sha])
end
def blob
- @git = Git.bare(@repository.full_repository_path)
- @blob = @git.gblob(params[:sha])
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
+ @blob = @git.blob(params[:sha])
end
def raw
- @git = Git.bare(@repository.full_repository_path)
- @blob = @git.gblob(params[:sha])
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
+ @blob = @git.blob(params[:sha])
render :text => @blob.contents, :content_type => "text/plain"
end
def log
- @git = Git.bare(@repository.full_repository_path)
+ @git = Gitorious::Gitto.new(@repository.full_repository_path)
skip = params[:page].blank? ? 0 : (params[:page].to_i-1) * LOGS_PER_PAGE
@commits = @git.log(LOGS_PER_PAGE, skip)
- @tags_per_sha = returning({}) do |hash|
- @git.tags.each do |tag|
- hash[tag.sha] ||= []
- hash[tag.sha] << tag.name
- end
- end
+ @tags_per_sha = @git.tags_by_sha
# TODO: Patch rails to keep track of what it responds to so we can DRY this up
@atom_auto_discovery_url = project_repository_formatted_browse_path(@project, @repository, :atom)
respond_to do |format| |
| |   |
| 2 | 2 | |
| 3 | 3 | describe BrowseController do |
| 4 | 4 | before(:each) do |
| 5 | | login_as :johan |
| 6 | 5 | @project = projects(:johans) |
| 7 | 6 | @repository = @project.repositories.first |
| 8 | 7 | |
| … | … | |
| 11 | 11 | .with(@repository.name).and_return(@repository) |
| 12 | 12 | @repository.stub!(:has_commits?).and_return(true) |
| 13 | 13 | |
| 14 | | @git_mock = mock("Git mock", :null_object => true) |
| 14 | @gitto = mock("Gitto mock", :null_object => true) |
| 15 | 15 | Gitorious::Gitto.should_receive(:new) \ |
| 16 | 16 | .with(@repository.full_repository_path) \ |
| 17 | | .and_return(@git_mock) |
| 17 | .and_return(@gitto) |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | | describe "index" do |
| 21 | | |
| 20 | describe "#index" do |
| 22 | 21 | def do_get |
| 23 | 22 | get :index, :project_id => @project.slug, :repository_id => @repository.name |
| 24 | 23 | end |
| … | … | |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | 31 | it "fetches the specified log entries" do |
| 32 | | @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues")) |
| 32 | @gitto.should_receive(:log).with(BrowseController::LOGS_PER_PAGE) \ |
| 33 | .and_return(commits=mock("logentrues")) |
| 33 | 34 | do_get |
| 34 | 35 | assigns[:commits].should == commits |
| 35 | 36 | end |
| 36 | 37 | |
| 37 | 38 | it "assigns the tags for easy lookup" do |
| 38 | | @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues")) |
| 39 | @gitto.should_receive(:log).with(BrowseController::LOGS_PER_PAGE) \ |
| 40 | .and_return(mock("logentrues")) |
| 41 | @gitto.should_receive(:tags_by_sha).and_return({"foo" => ["bar"]}) |
| 42 | do_get |
| 43 | assigns[:tags_per_sha].should == {"foo" => ["bar"]} |
| 44 | end |
| 45 | end |
| 46 | |
| 47 | describe "#tree" do |
| 48 | it "GETs successfully" do |
| 49 | tree_mock = mock("gtree") |
| 50 | @gitto.should_receive(:tree).and_return(tree_mock) |
| 51 | get :tree, :project_id => @project.slug, |
| 52 | :repository_id => @repository.name, :sha => "a"*40 |
| 53 | |
| 54 | response.should be_success |
| 55 | assigns[:git].should == @gitto |
| 56 | assigns[:tree].should == tree_mock |
| 57 | end |
| 58 | end |
| 59 | |
| 60 | describe "#commit" do |
| 61 | before(:each) do |
| 62 | @commit_mock = mock("commit") |
| 63 | @commit_mock.stub!(:sha).and_return("a"*40) |
| 64 | @commit_mock.stub!(:parent).and_return(@commit_mock) |
| 65 | @diff_mock = mock("diff") |
| 66 | @gitto.should_receive(:diff).with(@commit_mock.parent.sha, |
| 67 | @commit_mock.sha).and_return(@diff_mock) |
| 68 | @gitto.should_receive(:commit).with("a"*40).and_return(@commit_mock) |
| 69 | end |
| 70 | def do_get(opts={}) |
| 71 | get :commit, {:project_id => @project.slug, |
| 72 | :repository_id => @repository.name, :sha => "a"*40}.merge(opts) |
| 73 | end |
| 74 | it "gets the commit data" do |
| 75 | do_get |
| 76 | response.should be_success |
| 77 | assigns[:git].should == @gitto |
| 78 | assigns[:commit].should == @commit_mock |
| 79 | assigns[:diff].should == @diff_mock |
| 80 | end |
| 81 | |
| 82 | it "gets the comments for the commit" do |
| 83 | do_get |
| 84 | assigns[:comment_count].should == 0 |
| 85 | end |
| 86 | |
| 87 | it "defaults to 'inline' diffmode" do |
| 88 | do_get |
| 89 | assigns[:diffmode].should == "inline" |
| 90 | end |
| 91 | |
| 92 | it "sets sidebyside diffmode" do |
| 93 | do_get(:diffmode => "sidebyside") |
| 94 | assigns[:diffmode].should == "sidebyside" |
| 95 | end |
| 96 | end |
| 97 | |
| 98 | describe "#diff" do |
| 99 | it "diffs the sha's provided" do |
| 100 | diff_mock = mock("diff") |
| 101 | @gitto.should_receive(:diff).with("a"*40, "b"*40).and_return(diff_mock) |
| 102 | |
| 103 | get :diff, {:project_id => @project.slug, |
| 104 | :repository_id => @repository.name, :sha => "a"*40, :other_sha => "b"*40} |
| 105 | |
| 106 | response.should be_success |
| 107 | assigns[:git].should == @gitto |
| 108 | assigns[:diff].should == diff_mock |
| 109 | end |
| 110 | end |
| 111 | |
| 112 | describe "#blob" do |
| 113 | it "gets the blob data for the sha provided" do |
| 114 | blob_mock = mock("blob") |
| 115 | @gitto.should_receive(:blob).with("a"*40).and_return(blob_mock) |
| 116 | |
| 117 | get :blob, {:project_id => @project.slug, |
| 118 | :repository_id => @repository.name, :sha => "a"*40} |
| 119 | |
| 120 | response.should be_success |
| 121 | assigns[:git].should == @gitto |
| 122 | assigns[:blob].should == blob_mock |
| 123 | end |
| 124 | end |
| 125 | |
| 126 | describe "#raw" do |
| 127 | it "gets the blob data from the sha and renders it as text/plain" do |
| 128 | blob_mock = mock("blob") |
| 129 | blob_mock.stub!(:contents).and_return("blabla") |
| 130 | @gitto.should_receive(:blob).with("a"*40).and_return(blob_mock) |
| 131 | |
| 132 | get :raw, {:project_id => @project.slug, |
| 133 | :repository_id => @repository.name, :sha => "a"*40} |
| 134 | |
| 135 | response.should be_success |
| 136 | assigns[:git].should == @gitto |
| 137 | assigns[:blob].should == blob_mock |
| 138 | response.body.should == "blabla" |
| 139 | response.content_type.should == "text/plain" |
| 140 | end |
| 141 | end |
| 142 | |
| 143 | describe "#log" do |
| 144 | def do_get(opts = {}) |
| 145 | get :log, {:project_id => @project.slug, |
| 146 | :repository_id => @repository.name, :page => nil}.merge(opts) |
| 147 | end |
| 148 | |
| 149 | it "GETs page 1 successfully" do |
| 150 | @gitto.should_receive(:log).with(30, 0).and_return(mock("logentries")) |
| 151 | do_get |
| 152 | end |
| 153 | |
| 154 | it "GETs page 3 successfully" do |
| 155 | @gitto.should_receive(:log).with(30, 60).and_return(mock("logentries")) |
| 156 | do_get(:page => 3) |
| 157 | end |
| 158 | |
| 159 | it "GETs the commits successfully" do |
| 160 | commits = mock("logentries") |
| 161 | @gitto.should_receive(:log).with(30, 0).and_return(commits) |
| 162 | do_get |
| 163 | response.should be_success |
| 164 | assigns[:git].should == @gitto |
| 165 | assigns[:commits].should == commits |
| 166 | end |
| 167 | |
| 168 | it "assigns the tags for easy lookup" do |
| 169 | @gitto.should_receive(:log).with(30, 0).and_return(mock("logentries")) |
| 170 | @gitto.should_receive(:tags_by_sha).and_return({"foo" => ["bar"]}) |
| 39 | 171 | do_get |
| 40 | | assigns[:tags_per_sha].should == {:write => "me"} |
| 172 | assigns[:tags_per_sha].should == {"foo" => ["bar"]} |
| 41 | 173 | end |
| 42 | 174 | end |
| 43 | 175 | |
| toggle raw diff |
--- a/spec/controllers/browse_controller_spec.rb
+++ b/spec/controllers/browse_controller_spec.rb
@@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe BrowseController do
before(:each) do
- login_as :johan
@project = projects(:johans)
@repository = @project.repositories.first
@@ -12,14 +11,13 @@ describe BrowseController do
.with(@repository.name).and_return(@repository)
@repository.stub!(:has_commits?).and_return(true)
- @git_mock = mock("Git mock", :null_object => true)
+ @gitto = mock("Gitto mock", :null_object => true)
Gitorious::Gitto.should_receive(:new) \
.with(@repository.full_repository_path) \
- .and_return(@git_mock)
+ .and_return(@gitto)
end
- describe "index" do
-
+ describe "#index" do
def do_get
get :index, :project_id => @project.slug, :repository_id => @repository.name
end
@@ -31,15 +29,147 @@ describe BrowseController do
end
it "fetches the specified log entries" do
- @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues"))
+ @gitto.should_receive(:log).with(BrowseController::LOGS_PER_PAGE) \
+ .and_return(commits=mock("logentrues"))
do_get
assigns[:commits].should == commits
end
it "assigns the tags for easy lookup" do
- @git_mock.should_receive(:log).with(BrowseController::LOGS_PER_PAGE).and_return(commits=mock("logentrues"))
+ @gitto.should_receive(:log).with(BrowseController::LOGS_PER_PAGE) \
+ .and_return(mock("logentrues"))
+ @gitto.should_receive(:tags_by_sha).and_return({"foo" => ["bar"]})
+ do_get
+ assigns[:tags_per_sha].should == {"foo" => ["bar"]}
+ end
+ end
+
+ describe "#tree" do
+ it "GETs successfully" do
+ tree_mock = mock("gtree")
+ @gitto.should_receive(:tree).and_return(tree_mock)
+ get :tree, :project_id => @project.slug,
+ :repository_id => @repository.name, :sha => "a"*40
+
+ response.should be_success
+ assigns[:git].should == @gitto
+ assigns[:tree].should == tree_mock
+ end
+ end
+
+ describe "#commit" do
+ before(:each) do
+ @commit_mock = mock("commit")
+ @commit_mock.stub!(:sha).and_return("a"*40)
+ @commit_mock.stub!(:parent).and_return(@commit_mock)
+ @diff_mock = mock("diff")
+ @gitto.should_receive(:diff).with(@commit_mock.parent.sha,
+ @commit_mock.sha).and_return(@diff_mock)
+ @gitto.should_receive(:commit).with("a"*40).and_return(@commit_mock)
+ end
+ def do_get(opts={})
+ get :commit, {:project_id => @project.slug,
+ :repository_id => @repository.name, :sha => "a"*40}.merge(opts)
+ end
+ it "gets the commit data" do
+ do_get
+ response.should be_success
+ assigns[:git].should == @gitto
+ assigns[:commit].should == @commit_mock
+ assigns[:diff].should == @diff_mock
+ end
+
+ it "gets the comments for the commit" do
+ do_get
+ assigns[:comment_count].should == 0
+ end
+
+ it "defaults to 'inline' diffmode" do
+ do_get
+ assigns[:diffmode].should == "inline"
+ end
+
+ it "sets sidebyside diffmode" do
+ do_get(:diffmode => "sidebyside")
+ assigns[:diffmode].should == "sidebyside"
+ end
+ end
+
+ describe "#diff" do
+ it "diffs the sha's provided" do
+ diff_mock = mock("diff")
+ @gitto.should_receive(:diff).with("a"*40, "b"*40).and_return(diff_mock)
+
+ get :diff, {:project_id => @project.slug,
+ :repository_id => @repository.name, :sha => "a"*40, :other_sha => "b"*40}
+
+ response.should be_success
+ assigns[:git].should == @gitto
+ assigns[:diff].should == diff_mock
+ end
+ end
+
+ describe "#blob" do
+ it "gets the blob data for the sha provided" do
+ blob_mock = mock("blob")
+ @gitto.should_receive(:blob).with("a"*40).and_return(blob_mock)
+
+ get :blob, {:project_id => @project.slug,
+ :repository_id => @repository.name, :sha => "a"*40}
+
+ response.should be_success
+ assigns[:git].should == @gitto
+ assigns[:blob].should == blob_mock
+ end
+ end
+
+ describe "#raw" do
+ it "gets the blob data from the sha and renders it as text/plain" do
+ blob_mock = mock("blob")
+ blob_mock.stub!(:contents).and_return("blabla")
+ @gitto.should_receive(:blob).with("a"*40).and_return(blob_mock)
+
+ get :raw, {:project_id => @project.slug,
+ :repository_id => @repository.name, :sha => "a"*40}
+
+ response.should be_success
+ assigns[:git].should == @gitto
+ assigns[:blob].should == blob_mock
+ response.body.should == "blabla"
+ response.content_type.should == "text/plain"
+ end
+ end
+
+ describe "#log" do
+ def do_get(opts = {})
+ get :log, {:project_id => @project.slug,
+ :repository_id => @repository.name, :page => nil}.merge(opts)
+ end
+
+ it "GETs page 1 successfully" do
+ @gitto.should_receive(:log).with(30, 0).and_return(mock("logentries"))
+ do_get
+ end
+
+ it "GETs page 3 successfully" do
+ @gitto.should_receive(:log).with(30, 60).and_return(mock("logentries"))
+ do_get(:page => 3)
+ end
+
+ it "GETs the commits successfully" do
+ commits = mock("logentries")
+ @gitto.should_receive(:log).with(30, 0).and_return(commits)
+ do_get
+ response.should be_success
+ assigns[:git].should == @gitto
+ assigns[:commits].should == commits
+ end
+
+ it "assigns the tags for easy lookup" do
+ @gitto.should_receive(:log).with(30, 0).and_return(mock("logentries"))
+ @gitto.should_receive(:tags_by_sha).and_return({"foo" => ["bar"]})
do_get
- assigns[:tags_per_sha].should == {:write => "me"}
+ assigns[:tags_per_sha].should == {"foo" => ["bar"]}
end
end
|