2018-12-17 04:53:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-08 15:32:08 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::ReleasesController do
|
2020-06-24 14:09:03 -04:00
|
|
|
include AccessMatchersForController
|
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
let!(:project) { create(:project, :repository, :public) }
|
|
|
|
let_it_be(:private_project) { create(:project, :repository, :private) }
|
|
|
|
let_it_be(:developer) { create(:user) }
|
|
|
|
let_it_be(:reporter) { create(:user) }
|
2021-02-01 19:09:14 -05:00
|
|
|
let_it_be(:guest) { create(:user) }
|
2020-03-24 08:09:42 -04:00
|
|
|
let_it_be(:user) { developer }
|
2021-04-06 05:09:03 -04:00
|
|
|
|
2019-10-28 17:06:24 -04:00
|
|
|
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')) }
|
2016-12-08 15:32:08 -05:00
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
|
|
|
project.add_reporter(reporter)
|
2021-02-01 19:09:14 -05:00
|
|
|
project.add_guest(guest)
|
2019-10-31 23:06:26 -04:00
|
|
|
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
|
|
|
|
|
2019-10-28 17:06:24 -04:00
|
|
|
shared_examples 'common access controls' do
|
2018-12-17 04:53:17 -05:00
|
|
|
it 'renders a 200' do
|
|
|
|
get_index
|
2016-12-08 15:32:08 -05:00
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-08 15:32:08 -05:00
|
|
|
end
|
|
|
|
|
2018-12-17 04:53:17 -05:00
|
|
|
context 'when the project is private' do
|
2019-10-28 17:06:24 -04:00
|
|
|
let(:project) { private_project }
|
2018-12-17 04:53:17 -05:00
|
|
|
|
2019-10-28 17:06:24 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-12-17 04:53:17 -05:00
|
|
|
end
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
context 'when user is a developer' do
|
|
|
|
let(:user) { developer }
|
|
|
|
|
|
|
|
it 'renders a 200 for a logged in developer' do
|
|
|
|
sign_in(user)
|
2016-12-08 15:32:08 -05:00
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
get_index
|
2016-12-08 15:32:08 -05:00
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-10-31 23:06:26 -04:00
|
|
|
end
|
2018-12-17 04:53:17 -05:00
|
|
|
end
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
context 'when user is an external user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'renders a 404 when logged in but not in the project' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get_index
|
2018-12-17 04:53:17 -05:00
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-10-31 23:06:26 -04:00
|
|
|
end
|
2018-12-17 04:53:17 -05:00
|
|
|
end
|
2016-12-08 15:32:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-28 17:06:24 -04:00
|
|
|
describe 'GET #index' do
|
|
|
|
before do
|
|
|
|
get_index
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as html' do
|
|
|
|
let(:format) { :html }
|
|
|
|
|
|
|
|
it 'returns a text/html content_type' do
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'text/html'
|
2019-10-28 17:06:24 -04:00
|
|
|
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 }
|
|
|
|
|
2019-10-30 17:07:58 -04:00
|
|
|
it 'returns a redirect' do
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
2019-10-28 17:06:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as json' do
|
|
|
|
let(:format) { :json }
|
|
|
|
|
|
|
|
it 'returns an application/json content_type' do
|
2020-12-02 10:09:37 -05:00
|
|
|
expect(response.media_type).to eq 'application/json'
|
2019-10-28 17:06:24 -04:00
|
|
|
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 }
|
|
|
|
|
2019-11-08 10:06:21 -05:00
|
|
|
it 'returns a redirect' do
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
2019-10-28 17:06:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
describe 'GET #new' do
|
|
|
|
let(:request) do
|
|
|
|
get :new, params: { namespace_id: project.namespace, project_id: project }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { request }.to be_denied_for(:reporter).of(project) }
|
|
|
|
it { expect { request }.to be_allowed_for(:developer).of(project) }
|
|
|
|
end
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
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
|
|
|
|
|
2020-01-29 13:08:47 -05:00
|
|
|
let(:release) { create(:release, project: project) }
|
2019-10-31 23:06:26 -04:00
|
|
|
let(:tag) { CGI.escape(release.tag) }
|
|
|
|
|
|
|
|
it_behaves_like 'successful request'
|
|
|
|
|
|
|
|
context 'when tag name contains slash' do
|
2020-01-29 13:08:47 -05:00
|
|
|
let(:release) { create(:release, project: project, tag: 'awesome/v1.0') }
|
2019-10-31 23:06:26 -04:00
|
|
|
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 release does not exist' do
|
|
|
|
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'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-29 13:08:47 -05:00
|
|
|
describe 'GET #show' do
|
|
|
|
subject do
|
|
|
|
get :show, 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(project_release_path(project, release))
|
|
|
|
.to eq("/#{project.namespace.path}/#{project.name}/-/releases/awesome%252Fv1.0")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when release does not exist' do
|
|
|
|
let(:tag) { 'non-existent-tag' }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
2021-02-01 19:09:14 -05:00
|
|
|
|
|
|
|
context 'when user is a guest' do
|
|
|
|
let(:project) { private_project }
|
|
|
|
let(:user) { guest }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
2020-01-29 13:08:47 -05:00
|
|
|
end
|
|
|
|
|
2020-11-12 10:09:09 -05:00
|
|
|
# `GET #downloads` is addressed in spec/requests/projects/releases_controller_spec.rb
|
2020-03-04 07:07:52 -05:00
|
|
|
|
2018-12-17 04:53:17 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_index
|
2019-10-28 17:06:24 -04:00
|
|
|
get :index, params: { namespace_id: project.namespace, project_id: project, format: format }
|
2016-12-08 15:32:08 -05:00
|
|
|
end
|
|
|
|
end
|