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

81 lines
3.1 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require "spec_helper"
describe Projects::RepositoriesController do
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2015-04-26 12:48:37 +05:30
describe "GET archive" do
2016-06-02 11:05:42 +05:30
context 'as a guest' do
it 'responds with redirect in correct format' do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, id: "master" }, format: "zip"
2015-04-26 12:48:37 +05:30
2016-11-03 12:29:30 +05:30
expect(response.header["Content-Type"]).to start_with('text/html')
2016-06-02 11:05:42 +05:30
expect(response).to be_redirect
end
2015-04-26 12:48:37 +05:30
end
2016-06-02 11:05:42 +05:30
context 'as a user' do
let(:user) { create(:user) }
2015-04-26 12:48:37 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2016-06-02 11:05:42 +05:30
sign_in(user)
2015-04-26 12:48:37 +05:30
end
it "uses Gitlab::Workhorse" do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, id: "master" }, format: "zip"
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
2016-06-02 11:05:42 +05:30
end
2018-05-09 12:01:36 +05:30
it 'responds with redirect to the short name archive if fully qualified' do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, id: "master/#{project.path}-master" }, format: "zip"
2018-05-09 12:01:36 +05:30
expect(assigns(:ref)).to eq("master")
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
it 'handles legacy queries with no ref' do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project }, format: "zip"
2018-05-09 12:01:36 +05:30
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
it 'handles legacy queries with the ref specified as ref in params' do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, ref: 'feature' }, format: 'zip'
2018-05-09 12:01:36 +05:30
expect(response).to have_gitlab_http_status(200)
expect(assigns(:ref)).to eq('feature')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
it 'handles legacy queries with the ref specified as id in params' do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, id: 'feature' }, format: 'zip'
2018-05-09 12:01:36 +05:30
expect(response).to have_gitlab_http_status(200)
expect(assigns(:ref)).to eq('feature')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
it 'prioritizes the id param over the ref param when both are specified' do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, id: 'feature', ref: 'feature_conflict' }, format: 'zip'
2018-05-09 12:01:36 +05:30
expect(response).to have_gitlab_http_status(200)
expect(assigns(:ref)).to eq('feature')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
2016-06-02 11:05:42 +05:30
context "when the service raises an error" do
before do
allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed")
end
it "renders Not Found" do
2019-02-15 15:39:39 +05:30
get :archive, params: { namespace_id: project.namespace, project_id: project, id: "master" }, format: "zip"
2015-04-26 12:48:37 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
2015-04-26 12:48:37 +05:30
end
end
end
end