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

106 lines
2.4 KiB
Ruby
Raw Normal View History

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)
project.add_master(user)
end
describe 'GET show' do
it 'returns 200 status' do
get :show, request_params
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
end
context 'when the project is in a subgroup' do
let(:group) { create(:group, :nested) }
let(:project) { create(:project, namespace: group) }
it 'returns a 404 status code' do
get :show, request_params
expect(response).to have_gitlab_http_status(404)
end
2017-08-17 22:00:37 +05:30
end
end
describe 'DELETE destroy' do
it 'returns 302 status' do
delete :destroy, request_params
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(302)
2017-08-17 22:00:37 +05:30
end
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
get :show, request_params
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2017-08-17 22:00:37 +05:30
end
end
describe 'DELETE destroy' do
it 'returns 404 status' do
delete :destroy, request_params
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
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,
project: { pages_https_only: false }
}
end
let(:update_service) { double(execute: { status: :success }) }
before do
allow(Projects::UpdateService).to receive(:new) { update_service }
end
it 'returns 302 status' do
patch :update, request_params
expect(response).to have_gitlab_http_status(:found)
end
it 'redirects back to the pages settings' do
patch :update, request_params
expect(response).to redirect_to(project_pages_path(project))
end
it 'calls the update service' do
expect(Projects::UpdateService)
.to receive(:new)
.with(project, user, request_params[:project])
.and_return(update_service)
patch :update, request_params
end
end
2017-08-17 22:00:37 +05:30
end