debian-mirror-gitlab/spec/controllers/projects/pages_controller_spec.rb

228 lines
6.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Projects::PagesController, feature_category: :pages do
2017-08-17 22:00:37 +05:30
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
2023-05-27 22:25:52 +05:30
stub_config(pages: {
enabled: true,
external_https: true,
access_control: false
})
2017-08-17 22:00:37 +05:30
sign_in(user)
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-08-17 22:00:37 +05:30
end
2022-08-27 11:52:29 +05:30
describe 'GET new' do
2017-08-17 22:00:37 +05:30
it 'returns 200 status' do
2022-08-27 11:52:29 +05:30
get :new, params: request_params
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +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
2022-08-27 11:52:29 +05:30
get :new, params: request_params
2018-03-17 18:26:18 +05:30
2020-03-13 15:44:24 +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
2022-08-27 11:52:29 +05:30
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-08-17 22:00:37 +05:30
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-13 15:44:24 +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-13 15:44:24 +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-13 15:44:24 +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-13 15:44:24 +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
2023-05-27 22:25:52 +05:30
context 'when updating pages_https_only' do
let(:request_params) do
{
namespace_id: project.namespace,
project_id: project,
project: { pages_https_only: 'true' }
}
end
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
it 'updates project field and redirects back to the pages settings' do
project.update!(pages_https_only: false)
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
expect { patch :update, params: request_params }
.to change { project.reload.pages_https_only }
.from(false).to(true)
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(project_pages_path(project))
end
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
context 'when it fails to update' do
it 'adds an error message' do
expect_next_instance_of(Projects::UpdateService) do |service|
expect(service)
.to receive(:execute)
.and_return(status: :error, message: 'some error happened')
end
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
expect { patch :update, params: request_params }
.not_to change { project.reload.pages_https_only }
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
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
2023-05-27 22:25:52 +05:30
context 'when updating pages_unique_domain' do
let(:request_params) do
{
namespace_id: project.namespace,
project_id: project,
project: {
project_setting_attributes: {
pages_unique_domain_enabled: 'true'
}
}
}
end
2018-05-09 12:01:36 +05:30
2023-05-27 22:25:52 +05:30
before do
create(:project_setting, project: project, pages_unique_domain_enabled: false)
end
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
context 'with pages_unique_domain feature flag disabled' do
it 'does not update pages unique domain' do
stub_feature_flags(pages_unique_domain: false)
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
expect { patch :update, params: request_params }
.not_to change { project.project_setting.reload.pages_unique_domain_enabled }
end
end
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
context 'with pages_unique_domain feature flag enabled' do
before do
stub_feature_flags(pages_unique_domain: true)
end
it 'updates pages_https_only and pages_unique_domain and redirects back to pages settings' do
expect { patch :update, params: request_params }
.to change { project.project_setting.reload.pages_unique_domain_enabled }
.from(false).to(true)
expect(project.project_setting.pages_unique_domain).not_to be_nil
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(project_pages_path(project))
end
context 'when it fails to update' do
it 'adds an error message' do
expect_next_instance_of(Projects::UpdateService) do |service|
expect(service)
.to receive(:execute)
.and_return(status: :error, message: 'some error happened')
end
expect { patch :update, params: request_params }
.not_to change { project.project_setting.reload.pages_unique_domain_enabled }
expect(response).to redirect_to(project_pages_path(project))
expect(flash[:alert]).to eq('some error happened')
end
end
2020-03-13 15:44:24 +05:30
end
end
2018-05-09 12:01:36 +05:30
end
2017-08-17 22:00:37 +05:30
end