Blob of spec/controllers/browse_controller_spec.rb (raw blob data)

1 require File.dirname(__FILE__) + '/../spec_helper'
2
3 describe BrowseController do
4 before(:each) do
5 @project = projects(:johans)
6 @repository = @project.repositories.first
7
8 Project.should_receive(:find_by_slug!).with(@project.slug) \
9 .and_return(@project)
10 @project.repositories.should_receive(:find_by_name!) \
11 .with(@repository.name).and_return(@repository)
12 @repository.stub!(:has_commits?).and_return(true)
13
14 @gitto = mock("Gitto mock", :null_object => true)
15 Gitorious::Gitto.should_receive(:new) \
16 .with(@repository.full_repository_path) \
17 .and_return(@gitto)
18 end
19
20 describe "#index" do
21 def do_get
22 get :index, :project_id => @project.slug, :repository_id => @repository.name
23 end
24
25 it "GETs successfully" do
26 do_get
27 flash[:notice].should == nil
28 response.should be_success
29 end
30
31 it "fetches the specified log entries" do
32 @gitto.should_receive(:log).with(BrowseController::LOGS_PER_PAGE) \
33 .and_return(commits=mock("logentrues"))
34 do_get
35 assigns[:commits].should == commits
36 end
37
38 it "assigns the tags for easy lookup" do
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"]})
171 do_get
172 assigns[:tags_per_sha].should == {"foo" => ["bar"]}
173 end
174 end
175
176 end