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

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

153 lines
5.7 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Projects::RefsController, feature_category: :source_code_management do
let_it_be(:project) { create(:project, :repository) }
let(:user) { create(:user) }
2015-04-26 12:48:37 +05:30
before do
sign_in(user)
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2015-04-26 12:48:37 +05:30
end
2023-03-04 22:38:38 +05:30
describe 'GET #switch' do
using RSpec::Parameterized::TableSyntax
let(:id) { 'master' }
let(:params) do
{ destination: destination, namespace_id: project.namespace.to_param, project_id: project, id: id,
ref_type: ref_type }
end
subject { get :switch, params: params }
context 'when the use_ref_type_parameter feature flag is not enabled' do
before do
stub_feature_flags(use_ref_type_parameter: false)
end
where(:destination, :ref_type, :redirected_to) do
'tree' | nil | lazy { project_tree_path(project, id) }
'tree' | 'heads' | lazy { project_tree_path(project, id) }
'blob' | nil | lazy { project_blob_path(project, id) }
'blob' | 'heads' | lazy { project_blob_path(project, id) }
'graph' | nil | lazy { project_network_path(project, id) }
'graph' | 'heads' | lazy { project_network_path(project, id) }
'graphs' | nil | lazy { project_graph_path(project, id) }
'graphs' | 'heads' | lazy { project_graph_path(project, id) }
'find_file' | nil | lazy { project_find_file_path(project, id) }
'find_file' | 'heads' | lazy { project_find_file_path(project, id) }
'graphs_commits' | nil | lazy { commits_project_graph_path(project, id) }
'graphs_commits' | 'heads' | lazy { commits_project_graph_path(project, id) }
'badges' | nil | lazy { project_settings_ci_cd_path(project, ref: id) }
'badges' | 'heads' | lazy { project_settings_ci_cd_path(project, ref: id) }
'commits' | nil | lazy { project_commits_path(project, id) }
'commits' | 'heads' | lazy { project_commits_path(project, id) }
'somethingelse' | nil | lazy { project_commits_path(project, id) }
'somethingelse' | 'heads' | lazy { project_commits_path(project, id) }
end
with_them do
it 'redirects to destination' do
expect(subject).to redirect_to(redirected_to)
end
end
end
context 'when the use_ref_type_parameter feature flag is enabled' do
where(:destination, :ref_type, :redirected_to) do
'tree' | nil | lazy { project_tree_path(project, id) }
'tree' | 'heads' | lazy { project_tree_path(project, id) }
'blob' | nil | lazy { project_blob_path(project, id) }
'blob' | 'heads' | lazy { project_blob_path(project, id) }
'graph' | nil | lazy { project_network_path(project, id) }
'graph' | 'heads' | lazy { project_network_path(project, id, ref_type: 'heads') }
'graphs' | nil | lazy { project_graph_path(project, id) }
'graphs' | 'heads' | lazy { project_graph_path(project, id, ref_type: 'heads') }
'find_file' | nil | lazy { project_find_file_path(project, id) }
'find_file' | 'heads' | lazy { project_find_file_path(project, id) }
'graphs_commits' | nil | lazy { commits_project_graph_path(project, id) }
'graphs_commits' | 'heads' | lazy { commits_project_graph_path(project, id) }
'badges' | nil | lazy { project_settings_ci_cd_path(project, ref: id) }
'badges' | 'heads' | lazy { project_settings_ci_cd_path(project, ref: id) }
'commits' | nil | lazy { project_commits_path(project, id) }
'commits' | 'heads' | lazy { project_commits_path(project, id, ref_type: 'heads') }
nil | nil | lazy { project_commits_path(project, id) }
nil | 'heads' | lazy { project_commits_path(project, id, ref_type: 'heads') }
end
with_them do
it 'redirects to destination' do
expect(subject).to redirect_to(redirected_to)
end
end
end
end
2015-04-26 12:48:37 +05:30
describe 'GET #logs_tree' do
2020-05-24 23:13:21 +05:30
let(:path) { 'foo/bar/baz.html' }
2015-04-26 12:48:37 +05:30
def default_get(format = :html)
2015-09-11 14:41:01 +05:30
get :logs_tree,
2019-02-15 15:39:39 +05:30
params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: 'master',
2020-05-24 23:13:21 +05:30
path: path
2019-02-15 15:39:39 +05:30
},
2015-09-11 14:41:01 +05:30
format: format
2015-04-26 12:48:37 +05:30
end
2020-05-24 23:13:21 +05:30
def xhr_get(format = :html, params = {})
2019-02-15 15:39:39 +05:30
get :logs_tree, params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: 'master',
2020-05-24 23:13:21 +05:30
path: path,
2019-02-15 15:39:39 +05:30
format: format
2020-05-24 23:13:21 +05:30
}.merge(params), xhr: true
2015-04-26 12:48:37 +05:30
end
it 'never throws MissingTemplate' do
expect { default_get }.not_to raise_error
2018-03-17 18:26:18 +05:30
expect { xhr_get(:json) }.not_to raise_error
2015-04-26 12:48:37 +05:30
expect { xhr_get }.not_to raise_error
end
2020-07-28 23:09:34 +05:30
it 'renders 404 for HTML requests' do
2015-04-26 12:48:37 +05:30
xhr_get
expect(response).to be_not_found
end
2022-04-04 11:22:00 +05:30
context 'when ref is incorrect' do
it 'returns 404 page' do
xhr_get(:json, id: '.')
expect(response).to be_not_found
end
end
context 'when offset has an invalid format' do
it 'renders JSON' do
xhr_get(:json, offset: { wrong: :format })
expect(response).to be_successful
expect(json_response).to be_kind_of(Array)
end
end
2020-05-24 23:13:21 +05:30
context 'when json is requested' do
it 'renders JSON' do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
2019-07-07 11:18:12 +05:30
2020-05-24 23:13:21 +05:30
xhr_get(:json)
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
expect(response).to be_successful
expect(json_response).to be_kind_of(Array)
end
2018-03-17 18:26:18 +05:30
end
2015-04-26 12:48:37 +05:30
end
end