1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::CommitsController, feature_category: :source_code_management do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:repository) { project.repository }
let_it_be(:user) { create(:user) }
before do
project.add_maintainer(user)
end
context 'signed in' do
before do
sign_in(user)
end
describe "GET commits_root" do
context "no ref is provided" do
it 'redirects to the default branch of the project' do
get :commits_root, params: { namespace_id: project.namespace, project_id: project }
expect(response).to redirect_to project_commits_path(project)
end
end
end
describe "GET show" do
render_views
context 'with file path' do
before do
get :show, params: { namespace_id: project.namespace, project_id: project, id: id }
end
context "valid branch, valid file" do
let(:id) { 'master/README.md' }
it { is_expected.to respond_with(:success) }
end
context "HEAD, valid file" do
let(:id) { 'HEAD/README.md' }
it { is_expected.to respond_with(:success) }
end
context "valid branch, invalid file" do
let(:id) { 'master/invalid-path.rb' }
it { is_expected.to respond_with(:not_found) }
end
context "invalid branch, valid file" do
let(:id) { 'invalid-branch/README.md' }
it { is_expected.to respond_with(:not_found) }
end
context "branch with invalid format, valid file" do
let(:id) { 'branch with space/README.md' }
it { is_expected.to respond_with(:not_found) }
end
end
context "with an invalid limit" do
let(:id) { "master/README.md" }
it "uses the default limit" do
expect_any_instance_of(Repository).to receive(:commits).with(
"master",
path: "README.md",
limit: described_class::COMMITS_DEFAULT_LIMIT,
offset: 0
).and_call_original
get :show, params: { namespace_id: project.namespace, project_id: project, id: id, limit: "foo" }
expect(response).to be_successful
end
context 'when limit is a hash' do
it 'uses the default limit' do
expect_any_instance_of(Repository).to receive(:commits).with(
"master",
path: "README.md",
limit: described_class::COMMITS_DEFAULT_LIMIT,
offset: 0
).and_call_original
get :show, params: {
namespace_id: project.namespace,
project_id: project,
id: id,
limit: { 'broken' => 'value' }
}
expect(response).to be_successful
end
end
end
it 'loads tags for commits' do
expect_next_instance_of(CommitCollection) do |collection|
expect(collection).to receive(:load_tags)
end
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master/README.md' }
expect(response).to have_gitlab_http_status(:ok)
end
context 'when tag has a non-ASCII encoding' do
before do
repository.add_tag(user, 'tést', 'master')
end
it 'does not raise an exception' do
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master' }
expect(response).to have_gitlab_http_status(:ok)
end
end
context "when the ref name ends in .atom" do
context "when the ref does not exist with the suffix" do
before do
get :show, params: { namespace_id: project.namespace, project_id: project, id: "master.atom" }
end
it "renders as atom" do
expect(response).to be_successful
expect(response.media_type).to eq('application/atom+xml')
end
it 'renders summary with type=html' do
expect(response.body).to include('<summary type="html">')
end
end
context "when the ref exists with the suffix" do
before do
commit = project.repository.commit('master')
allow_any_instance_of(Repository).to receive(:commit).and_call_original
allow_any_instance_of(Repository).to receive(:commit).with('master.atom').and_return(commit)
get :show, params: {
namespace_id: project.namespace,
project_id: project,
id: "master.atom"
}
end
it "renders as HTML" do
expect(response).to be_successful
expect(response.media_type).to eq('text/html')
end
end
context 'when the ref does not exist' do
before do
get(:show, params: {
namespace_id: project.namespace,
project_id: project,
id: 'unknown.atom'
})
end
it 'returns 404 page' do
expect(response).to be_not_found
end
end
end
context 'with markdown cache' do
it 'preloads markdown cache for commits' do
expect(Commit).to receive(:preload_markdown_cache!).and_call_original
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master/README.md' }
end
end
end
describe "GET /commits/:id/signatures" do
render_views
before do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original unless id.include?(' ')
get :signatures, params: {
namespace_id: project.namespace,
project_id: project,
id: id
}, format: :json
end
context "valid branch" do
let(:id) { 'master' }
it { is_expected.to respond_with(:success) }
end
context "invalid branch format" do
let(:id) { 'some branch' }
it { is_expected.to respond_with(:not_found) }
end
end
end
end
|