2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::PagesController do
|
|
|
|
let(:user) { create(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project, :public) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
|
|
|
|
sign_in(user)
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET show' do
|
|
|
|
it 'returns 200 status' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: request_params
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is in a subgroup' do
|
|
|
|
let(:group) { create(:group, :nested) }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
it 'returns a 200 status code' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: request_params
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
it 'returns 302 status' do
|
2019-02-15 15:39:39 +05:30
|
|
|
delete :destroy, params: request_params
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 status' do
|
|
|
|
delete :destroy, params: request_params
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'pages disabled' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.pages).to receive(:enabled).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET show' do
|
|
|
|
it 'returns 404 status' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: request_params
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
it 'returns 404 status' do
|
2019-02-15 15:39:39 +05:30
|
|
|
delete :destroy, params: request_params
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
describe 'PATCH update' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2018-11-08 19:23:39 +05:30
|
|
|
project: { pages_https_only: 'false' }
|
2018-05-09 12:01:36 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:update_service) { double(execute: { status: :success }) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Projects::UpdateService).to receive(:new) { update_service }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 302 status' do
|
2019-02-15 15:39:39 +05:30
|
|
|
patch :update, params: request_params
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects back to the pages settings' do
|
2019-02-15 15:39:39 +05:30
|
|
|
patch :update, params: request_params
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
expect(response).to redirect_to(project_pages_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls the update service' do
|
|
|
|
expect(Projects::UpdateService)
|
|
|
|
.to receive(:new)
|
2018-11-08 19:23:39 +05:30
|
|
|
.with(project, user, ActionController::Parameters.new(request_params[:project]).permit!)
|
2018-05-09 12:01:36 +05:30
|
|
|
.and_return(update_service)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
patch :update, params: request_params
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
context 'when update_service returns an error message' do
|
|
|
|
let(:update_service) { double(execute: { status: :error, message: 'some error happened' }) }
|
|
|
|
|
|
|
|
it 'adds an error message' do
|
|
|
|
patch :update, params: request_params
|
|
|
|
|
|
|
|
expect(response).to redirect_to(project_pages_path(project))
|
|
|
|
expect(flash[:alert]).to eq('some error happened')
|
|
|
|
end
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|