2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-06 23:27:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::PagesController do
|
2017-04-06 23:27:35 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-29 06:15:19 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-04-06 23:27:35 -04:00
|
|
|
|
|
|
|
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-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
|
|
|
|
2022-07-25 11:10:30 -04:00
|
|
|
describe 'GET new' do
|
2017-04-06 23:27:35 -04:00
|
|
|
it 'returns 200 status' do
|
2022-07-25 11:10:30 -04:00
|
|
|
get :new, params: request_params
|
2017-04-06 23:27:35 -04:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
2017-08-29 06:15:19 -04:00
|
|
|
|
|
|
|
context 'when the project is in a subgroup' do
|
|
|
|
let(:group) { create(:group, :nested) }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
|
2018-12-03 06:05:38 -05:00
|
|
|
it 'returns a 200 status code' do
|
2022-07-25 11:10:30 -04:00
|
|
|
get :new, params: request_params
|
2017-08-29 06:15:19 -04:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-29 06:15:19 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
|
|
|
|
2022-07-25 11:10:30 -04:00
|
|
|
describe 'GET show' do
|
|
|
|
subject { get :show, params: request_params }
|
|
|
|
|
|
|
|
context 'when the project does not have onboarding complete' do
|
|
|
|
before do
|
|
|
|
project.pages_metadatum.update_attribute(:deployed, false)
|
|
|
|
project.pages_metadatum.update_attribute(:onboarding_complete, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to #new' do
|
|
|
|
expect(subject).to redirect_to(action: 'new')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project does have onboarding complete' do
|
|
|
|
before do
|
|
|
|
project.pages_metadatum.update_attribute(:onboarding_complete, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 status' do
|
|
|
|
expect(subject).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is in a subgroup' do
|
|
|
|
let(:group) { create(:group, :nested) }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
it 'returns a 200 status code' do
|
|
|
|
expect(subject).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pages is disabled' do
|
|
|
|
let(:project) { create(:project, :pages_disabled) }
|
|
|
|
|
|
|
|
it 'renders the disabled view' do
|
|
|
|
expect(subject).to render_template :disabled
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-06 23:27:35 -04:00
|
|
|
describe 'DELETE destroy' do
|
|
|
|
it 'returns 302 status' do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: request_params
|
2017-04-06 23:27:35 -04:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
2019-02-25 06:43:19 -05:00
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 status' do
|
|
|
|
delete :destroy, params: request_params
|
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-02-25 06:43:19 -05:00
|
|
|
end
|
|
|
|
end
|
2017-04-06 23:27:35 -04:00
|
|
|
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
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: request_params
|
2017-04-06 23:27:35 -04:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
it 'returns 404 status' do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: request_params
|
2017-04-06 23:27:35 -04:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-03 03:07:03 -05:00
|
|
|
|
|
|
|
describe 'PATCH update' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2018-06-19 16:47:58 -04:00
|
|
|
project: { pages_https_only: 'false' }
|
2018-01-03 03:07:03 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:update_service) { double(execute: { status: :success }) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Projects::UpdateService).to receive(:new) { update_service }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 302 status' do
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :update, params: request_params
|
2018-01-03 03:07:03 -05:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects back to the pages settings' do
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :update, params: request_params
|
2018-01-03 03:07:03 -05:00
|
|
|
|
|
|
|
expect(response).to redirect_to(project_pages_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls the update service' do
|
|
|
|
expect(Projects::UpdateService)
|
|
|
|
.to receive(:new)
|
2018-06-19 16:47:58 -04:00
|
|
|
.with(project, user, ActionController::Parameters.new(request_params[:project]).permit!)
|
2018-01-03 03:07:03 -05:00
|
|
|
.and_return(update_service)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :update, params: request_params
|
2018-01-03 03:07:03 -05:00
|
|
|
end
|
2019-12-20 04:24:38 -05:00
|
|
|
|
|
|
|
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-01-03 03:07:03 -05:00
|
|
|
end
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|