2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Projects::Tags::ReleasesController do
|
2019-02-15 15:39:39 +05:30
|
|
|
let!(:project) { create(:project, :repository) }
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:release) { create(:release, project: project) }
|
|
|
|
let!(:tag) { release.tag }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #edit' do
|
|
|
|
it 'initializes a new release' do
|
|
|
|
tag_id = release.tag
|
2020-06-23 00:09:42 +05:30
|
|
|
project.releases.destroy_all # rubocop: disable Cop/DestroyAll
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
response = get :edit, params: { namespace_id: project.namespace, project_id: project, tag_id: tag_id }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
release = assigns(:release)
|
|
|
|
expect(release).not_to be_nil
|
|
|
|
expect(release).not_to be_persisted
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves an existing release' do
|
2019-07-31 22:56:46 +05:30
|
|
|
response = get :edit, params: { namespace_id: project.namespace, project_id: project, tag_id: release.tag }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
release = assigns(:release)
|
|
|
|
expect(release).not_to be_nil
|
|
|
|
expect(release).to be_persisted
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
|
|
|
it 'updates release note description' do
|
2019-07-31 22:56:46 +05:30
|
|
|
response = update_release(release.tag, "description updated")
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
release = project.releases.find_by(tag: tag)
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(release.description).to eq("description updated")
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it 'creates a release if one does not exist' do
|
|
|
|
tag_without_release = create_new_tag
|
|
|
|
|
|
|
|
expect do
|
|
|
|
update_release(tag_without_release.name, "a new release")
|
|
|
|
end.to change { project.releases.count }.by(1)
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the release name, sha, and author for a new release' do
|
|
|
|
tag_without_release = create_new_tag
|
|
|
|
|
|
|
|
response = update_release(tag_without_release.name, "a new release")
|
|
|
|
|
|
|
|
release = project.releases.find_by(tag: tag_without_release.name)
|
|
|
|
expect(release.name).to eq(tag_without_release.name)
|
|
|
|
expect(release.sha).to eq(tag_without_release.target_commit.sha)
|
|
|
|
expect(release.author.id).to eq(user.id)
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'does not delete release when description is empty' do
|
|
|
|
expect do
|
|
|
|
update_release(tag, "")
|
|
|
|
end.not_to change { project.releases.count }
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(release.reload.description).to eq("")
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing when description is empty and the tag does not have a release' do
|
|
|
|
tag_without_release = create_new_tag
|
|
|
|
|
|
|
|
expect do
|
|
|
|
update_release(tag_without_release.name, "")
|
|
|
|
end.not_to change { project.releases.count }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def create_new_tag
|
|
|
|
project.repository.add_tag(user, 'mytag', 'master')
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_release(tag_id, description)
|
2019-02-15 15:39:39 +05:30
|
|
|
put :update, params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
2019-07-31 22:56:46 +05:30
|
|
|
tag_id: tag_id,
|
2019-02-15 15:39:39 +05:30
|
|
|
release: { description: description }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|