debian-mirror-gitlab/spec/controllers/projects/commits_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

214 lines
6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Projects::CommitsController, feature_category: :source_code_management do
2023-07-09 08:55:56 +05:30
let_it_be(:project) { create(:project, :repository) }
let_it_be(:repository) { project.repository }
let_it_be(:user) { create(:user) }
2014-09-02 18:07:02 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
end
2018-11-29 20:51:05 +05:30
context 'signed in' do
before do
sign_in(user)
end
describe "GET commits_root" do
context "no ref is provided" do
2019-07-07 11:18:12 +05:30
it 'redirects to the default branch of the project' do
2023-05-27 22:25:52 +05:30
get :commits_root, params: { namespace_id: project.namespace, project_id: project }
2018-11-18 11:00:15 +05:30
2018-11-29 20:51:05 +05:30
expect(response).to redirect_to project_commits_path(project)
end
2018-11-18 11:00:15 +05:30
end
end
2014-09-02 18:07:02 +05:30
2018-11-29 20:51:05 +05:30
describe "GET show" do
render_views
2018-03-17 18:26:18 +05:30
2018-11-29 20:51:05 +05:30
context 'with file path' do
before do
2023-05-27 22:25:52 +05:30
get :show, params: { namespace_id: project.namespace, project_id: project, id: id }
2018-11-29 20:51:05 +05:30
end
2018-03-17 18:26:18 +05:30
2018-11-29 20:51:05 +05:30
context "valid branch, valid file" do
let(:id) { 'master/README.md' }
2018-03-17 18:26:18 +05:30
2018-11-29 20:51:05 +05:30
it { is_expected.to respond_with(:success) }
end
2018-03-17 18:26:18 +05:30
2023-06-20 00:43:36 +05:30
context "HEAD, valid file" do
let(:id) { 'HEAD/README.md' }
it { is_expected.to respond_with(:success) }
end
2018-11-29 20:51:05 +05:30
context "valid branch, invalid file" do
let(:id) { 'master/invalid-path.rb' }
2018-03-17 18:26:18 +05:30
2018-11-29 20:51:05 +05:30
it { is_expected.to respond_with(:not_found) }
end
2018-03-17 18:26:18 +05:30
2018-11-29 20:51:05 +05:30
context "invalid branch, valid file" do
let(:id) { 'invalid-branch/README.md' }
2016-11-03 12:29:30 +05:30
2018-11-29 20:51:05 +05:30
it { is_expected.to respond_with(:not_found) }
end
2019-02-15 15:39:39 +05:30
context "branch with invalid format, valid file" do
let(:id) { 'branch with space/README.md' }
it { is_expected.to respond_with(:not_found) }
end
2018-03-17 18:26:18 +05:30
end
2021-12-11 22:18:48 +05:30
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
2023-05-27 22:25:52 +05:30
get :show, params: { namespace_id: project.namespace, project_id: project, id: id, limit: "foo" }
2021-12-11 22:18:48 +05:30
expect(response).to be_successful
end
2022-04-04 11:22:00 +05:30
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
2023-05-27 22:25:52 +05:30
get :show, params: {
2022-04-04 11:22:00 +05:30
namespace_id: project.namespace,
project_id: project,
id: id,
limit: { 'broken' => 'value' }
2023-05-27 22:25:52 +05:30
}
2022-04-04 11:22:00 +05:30
expect(response).to be_successful
end
end
2021-12-11 22:18:48 +05:30
end
2023-05-27 22:25:52 +05:30
it 'loads tags for commits' do
expect_next_instance_of(CommitCollection) do |collection|
expect(collection).to receive(:load_tags)
end
2023-07-09 08:55:56 +05:30
2023-05-27 22:25:52 +05:30
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master/README.md' }
2023-07-09 08:55:56 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
2023-05-27 22:25:52 +05:30
2023-07-09 08:55:56 +05:30
context 'when tag has a non-ASCII encoding' do
2023-05-27 22:25:52 +05:30
before do
2023-07-09 08:55:56 +05:30
repository.add_tag(user, 'tést', 'master')
2023-05-27 22:25:52 +05:30
end
2023-07-09 08:55:56 +05:30
it 'does not raise an exception' do
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master' }
2023-05-27 22:25:52 +05:30
2023-07-09 08:55:56 +05:30
expect(response).to have_gitlab_http_status(:ok)
2023-05-27 22:25:52 +05:30
end
end
2018-11-29 20:51:05 +05:30
context "when the ref name ends in .atom" do
context "when the ref does not exist with the suffix" do
before do
2023-05-27 22:25:52 +05:30
get :show, params: { namespace_id: project.namespace, project_id: project, id: "master.atom" }
2018-11-29 20:51:05 +05:30
end
it "renders as atom" do
2019-12-04 20:38:33 +05:30
expect(response).to be_successful
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq('application/atom+xml')
2018-11-29 20:51:05 +05:30
end
it 'renders summary with type=html' do
expect(response.body).to include('<summary type="html">')
end
2018-03-17 18:26:18 +05:30
end
2016-11-03 12:29:30 +05:30
2018-11-29 20:51:05 +05:30
context "when the ref exists with the suffix" do
before do
commit = project.repository.commit('master')
2018-03-17 18:26:18 +05:30
2018-11-29 20:51:05 +05:30
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)
2023-05-27 22:25:52 +05:30
get :show, params: {
namespace_id: project.namespace,
project_id: project,
id: "master.atom"
}
2018-11-29 20:51:05 +05:30
end
it "renders as HTML" do
2019-12-04 20:38:33 +05:30
expect(response).to be_successful
2021-02-22 17:27:13 +05:30
expect(response.media_type).to eq('text/html')
2018-11-29 20:51:05 +05:30
end
2018-03-17 18:26:18 +05:30
end
2022-04-04 11:22:00 +05:30
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
2016-11-03 12:29:30 +05:30
end
2022-07-23 23:45:48 +05:30
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
2018-11-29 20:51:05 +05:30
end
2019-02-15 15:39:39 +05:30
describe "GET /commits/:id/signatures" do
render_views
before do
2019-07-07 11:18:12 +05:30
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original unless id.include?(' ')
2023-05-27 22:25:52 +05:30
get :signatures, params: {
namespace_id: project.namespace,
project_id: project,
id: id
}, format: :json
2019-02-15 15:39:39 +05:30
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
2018-11-29 20:51:05 +05:30
end
2014-09-02 18:07:02 +05:30
end