2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-26 15:31:25 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe Projects::TagsController do
|
2017-01-25 21:44:33 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-07-26 15:31:25 +00:00
|
|
|
let!(:release) { create(:release, project: project) }
|
|
|
|
let!(:invalid_release) { create(:release, project: project, tag: 'does-not-exist') }
|
2020-06-16 15:08:32 +00:00
|
|
|
let(:user) { create(:user) }
|
2016-07-26 15:31:25 +00:00
|
|
|
|
|
|
|
describe 'GET index' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :index, params: { namespace_id: project.namespace.to_param, project_id: project }
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-07-26 15:31:25 +00:00
|
|
|
|
|
|
|
it 'returns the tags for the page' do
|
2019-11-22 15:06:39 +00:00
|
|
|
expect(assigns(:tags).map(&:name)).to include('v1.1.0', 'v1.0.0')
|
2016-07-26 15:31:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns releases matching those tags' do
|
|
|
|
expect(assigns(:releases)).to include(release)
|
|
|
|
expect(assigns(:releases)).not_to include(invalid_release)
|
|
|
|
end
|
|
|
|
end
|
2016-10-05 16:13:49 +00:00
|
|
|
|
|
|
|
describe 'GET show' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, id: id }
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-10-05 16:13:49 +00:00
|
|
|
|
|
|
|
context "valid tag" do
|
|
|
|
let(:id) { 'v1.0.0' }
|
2019-12-19 00:08:01 +00:00
|
|
|
|
2016-10-05 16:13:49 +00:00
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "invalid tag" do
|
|
|
|
let(:id) { 'latest' }
|
2019-12-19 00:08:01 +00:00
|
|
|
|
2016-10-05 16:13:49 +00:00
|
|
|
it { is_expected.to respond_with(:not_found) }
|
|
|
|
end
|
|
|
|
end
|
2018-11-28 19:06:02 +00:00
|
|
|
|
|
|
|
context 'private project with token authentication' do
|
|
|
|
let(:private_project) { create(:project, :repository, :private) }
|
|
|
|
|
2019-11-08 15:06:21 +00:00
|
|
|
it_behaves_like 'authenticates sessionless user', :index, :atom, ignore_incrementing: true do
|
2018-11-28 19:06:02 +00:00
|
|
|
before do
|
|
|
|
default_params.merge!(project_id: private_project, namespace_id: private_project.namespace)
|
|
|
|
|
|
|
|
private_project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'public project with token authentication' do
|
|
|
|
let(:public_project) { create(:project, :repository, :public) }
|
|
|
|
|
|
|
|
it_behaves_like 'authenticates sessionless user', :index, :atom, public: true do
|
|
|
|
before do
|
|
|
|
default_params.merge!(project_id: public_project, namespace_id: public_project.namespace)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-16 15:08:32 +00:00
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:release_description) { nil }
|
|
|
|
let(:request) do
|
|
|
|
post(:create, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
tag_name: '1.0',
|
|
|
|
ref: 'master',
|
|
|
|
release_description: release_description
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates tag' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(project.repository.find_tag('1.0')).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: remove this with the release creation moved to it's own form https://gitlab.com/gitlab-org/gitlab/-/issues/214245
|
|
|
|
context 'when release description is set' do
|
|
|
|
let(:release_description) { 'some release description' }
|
|
|
|
|
|
|
|
it 'creates tag and release' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(project.repository.find_tag('1.0')).to be_present
|
|
|
|
|
|
|
|
release = project.releases.find_by_tag!('1.0')
|
|
|
|
|
|
|
|
expect(release).to be_present
|
|
|
|
expect(release.description).to eq(release_description)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes the last pipeline for evidence creation', :sidekiq_inline do
|
|
|
|
sha = project.repository.commit('master').sha
|
|
|
|
create(:ci_empty_pipeline, sha: sha, project: project) # old pipeline
|
|
|
|
pipeline = create(:ci_empty_pipeline, sha: sha, project: project)
|
|
|
|
|
|
|
|
# simulating pipeline creation by new tag
|
|
|
|
expect_any_instance_of(Repository).to receive(:add_tag).and_wrap_original do |m, *args|
|
|
|
|
create(:ci_empty_pipeline, sha: sha, project: project)
|
|
|
|
m.call(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect_next_instance_of(Releases::CreateEvidenceService, anything, pipeline: pipeline) do |service|
|
|
|
|
expect(service).to receive(:execute).and_call_original
|
|
|
|
end
|
|
|
|
|
|
|
|
request
|
|
|
|
|
|
|
|
release = project.releases.find_by_tag!('1.0')
|
|
|
|
|
|
|
|
expect(release).to be_present
|
|
|
|
expect(release.description).to eq(release_description)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-07-26 15:31:25 +00:00
|
|
|
end
|