2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::ReleasesController do
|
2019-12-26 22:10:19 +05:30
|
|
|
let!(:project) { create(:project, :repository, :public) }
|
|
|
|
let!(:private_project) { create(:project, :repository, :private) }
|
|
|
|
let(:user) { developer }
|
|
|
|
let(:developer) { create(:user) }
|
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let!(:release_1) { create(:release, project: project, released_at: Time.zone.parse('2018-10-18')) }
|
|
|
|
let!(:release_2) { create(:release, project: project, released_at: Time.zone.parse('2019-10-19')) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'successful request' do
|
|
|
|
it 'renders a 200' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'not found' do
|
|
|
|
it 'renders 404' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'common access controls' do
|
2019-02-15 15:39:39 +05:30
|
|
|
it 'renders a 200' do
|
|
|
|
get_index
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context 'when the project is private' do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:project) { private_project }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a developer' do
|
|
|
|
let(:user) { developer }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'renders a 200 for a logged in developer' do
|
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
get_index
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'when user is an external user' do
|
|
|
|
let(:user) { create(:user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'renders a 404 when logged in but not in the project' do
|
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
get_index
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe 'GET #index' do
|
|
|
|
before do
|
|
|
|
get_index
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'as html' do
|
|
|
|
let(:format) { :html }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'returns a text/html content_type' do
|
|
|
|
expect(response.content_type).to eq 'text/html'
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
it_behaves_like 'common access controls'
|
|
|
|
|
|
|
|
context 'when the project is private and the user is not logged in' do
|
|
|
|
let(:project) { private_project }
|
|
|
|
|
|
|
|
it 'returns a redirect' do
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as json' do
|
|
|
|
let(:format) { :json }
|
|
|
|
|
|
|
|
it 'returns an application/json content_type' do
|
|
|
|
expect(response.content_type).to eq 'application/json'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the project's releases as JSON, ordered by released_at" do
|
|
|
|
expect(response.body).to eq([release_2, release_1].to_json)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'common access controls'
|
|
|
|
|
|
|
|
context 'when the project is private and the user is not logged in' do
|
|
|
|
let(:project) { private_project }
|
|
|
|
|
|
|
|
it 'returns a redirect' do
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #edit' do
|
|
|
|
subject do
|
|
|
|
get :edit, params: { namespace_id: project.namespace, project_id: project, tag: tag }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:release) { create(:release, project: project) }
|
|
|
|
let(:tag) { CGI.escape(release.tag) }
|
|
|
|
|
|
|
|
it_behaves_like 'successful request'
|
|
|
|
|
|
|
|
context 'when tag name contains slash' do
|
|
|
|
let!(:release) { create(:release, project: project, tag: 'awesome/v1.0') }
|
|
|
|
let(:tag) { CGI.escape(release.tag) }
|
|
|
|
|
|
|
|
it_behaves_like 'successful request'
|
|
|
|
|
|
|
|
it 'is accesible at a URL encoded path' do
|
|
|
|
expect(edit_project_release_path(project, release))
|
|
|
|
.to eq("/#{project.namespace.path}/#{project.name}/-/releases/awesome%252Fv1.0/edit")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when feature flag `release_edit_page` is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(release_edit_page: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when release does not exist' do
|
|
|
|
let!(:release) { }
|
|
|
|
let(:tag) { 'non-existent-tag' }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a reporter' do
|
|
|
|
let(:user) { reporter }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe 'GET #evidence' do
|
|
|
|
let(:tag_name) { "v1.1.0-evidence" }
|
|
|
|
let!(:release) { create(:release, :with_evidence, project: project, tag: tag_name) }
|
|
|
|
let(:tag) { CGI.escape(release.tag) }
|
|
|
|
let(:format) { :json }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
get :evidence, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
tag: tag,
|
|
|
|
format: format
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is a developer' do
|
|
|
|
it 'returns the correct evidence summary as a json' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response).to eq(release.evidence.summary)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the release was created before evidence existed' do
|
|
|
|
before do
|
|
|
|
release.evidence.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty json' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response).to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is a guest for the project' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is private' do
|
|
|
|
let(:project) { private_project }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is public' do
|
|
|
|
it_behaves_like 'successful request'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def get_index
|
2019-12-26 22:10:19 +05:30
|
|
|
get :index, params: { namespace_id: project.namespace, project_id: project, format: format }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|