2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-20 08:56:41 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::WikisController do
|
2019-10-02 00:06:26 +00:00
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
2019-10-23 03:06:01 +00:00
|
|
|
let_it_be(:user) { project.owner }
|
|
|
|
let_it_be(:project_wiki) { ProjectWiki.new(project, user) }
|
|
|
|
let_it_be(:wiki) { project_wiki.wiki }
|
|
|
|
let_it_be(:wiki_title) { 'page title test' }
|
2018-07-22 06:48:12 +00:00
|
|
|
|
2018-07-31 06:08:19 +00:00
|
|
|
before do
|
|
|
|
create_page(wiki_title, 'hello world')
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page(wiki_title)
|
|
|
|
end
|
2018-07-22 06:48:12 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
describe 'GET #pages' do
|
|
|
|
subject do
|
|
|
|
get :pages, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }.merge(extra_params)
|
2019-08-01 05:54:52 +00:00
|
|
|
end
|
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
let(:extra_params) { {} }
|
2019-04-25 04:19:07 +00:00
|
|
|
|
|
|
|
it 'does not load the pages content' do
|
|
|
|
expect(controller).to receive(:load_wiki).and_return(project_wiki)
|
|
|
|
expect(project_wiki).to receive(:list_pages).twice.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2019-07-23 22:40:23 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
describe 'illegal params' do
|
|
|
|
shared_examples :a_bad_request do
|
|
|
|
it do
|
|
|
|
expect { subject }.to raise_error(ActionController::BadRequest)
|
|
|
|
end
|
2019-07-23 22:40:23 +00:00
|
|
|
end
|
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
describe ':sort' do
|
|
|
|
let(:extra_params) { { sort: 'wibble' } }
|
2019-07-23 22:40:23 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it_behaves_like :a_bad_request
|
2019-07-23 22:40:23 +00:00
|
|
|
end
|
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
describe ':direction' do
|
|
|
|
let(:extra_params) { { direction: 'wibble' } }
|
2018-07-22 06:48:12 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it_behaves_like :a_bad_request
|
2019-08-01 05:54:52 +00:00
|
|
|
end
|
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
describe ':show_children' do
|
|
|
|
let(:extra_params) { { show_children: 'wibble' } }
|
2019-08-01 05:54:52 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it_behaves_like :a_bad_request
|
2019-08-01 05:54:52 +00:00
|
|
|
end
|
2018-07-31 06:08:19 +00:00
|
|
|
end
|
2018-07-22 06:48:12 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
shared_examples 'sorting-and-nesting' do |sort_key, default_nesting|
|
|
|
|
context "the user is sorting by #{sort_key}" do
|
|
|
|
let(:extra_params) { sort_params.merge(nesting_params) }
|
|
|
|
let(:sort_params) { { sort: sort_key } }
|
|
|
|
let(:nesting_params) { {} }
|
2019-08-01 05:54:52 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
before do
|
|
|
|
subject
|
2019-08-01 05:54:52 +00:00
|
|
|
end
|
2018-10-17 15:47:05 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it "sets nesting to #{default_nesting} by default" do
|
|
|
|
expect(assigns :nesting).to eq default_nesting
|
|
|
|
end
|
2018-10-17 15:47:05 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it 'hides children if the default requires it' do
|
|
|
|
expect(assigns :show_children).to be(default_nesting != ProjectWiki::NESTING_CLOSED)
|
2018-12-19 11:51:07 +00:00
|
|
|
end
|
2018-12-06 21:22:39 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
ProjectWiki::NESTINGS.each do |nesting|
|
|
|
|
context "the user explicitly passes show_children = #{nesting}" do
|
|
|
|
let(:nesting_params) { { show_children: nesting } }
|
2018-12-06 21:22:39 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it 'sets nesting to the provided value' do
|
|
|
|
expect(assigns :nesting).to eq nesting
|
|
|
|
end
|
2018-10-17 15:47:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
context 'the user wants children hidden' do
|
|
|
|
let(:nesting_params) { { show_children: 'hidden' } }
|
2018-10-17 15:47:05 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
it 'hides children' do
|
|
|
|
expect(assigns :show_children).to be false
|
|
|
|
end
|
2018-10-17 15:47:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-07-31 06:08:19 +00:00
|
|
|
|
2019-10-23 03:06:01 +00:00
|
|
|
include_examples 'sorting-and-nesting', ProjectWiki::CREATED_AT_ORDER, ProjectWiki::NESTING_FLAT
|
|
|
|
include_examples 'sorting-and-nesting', ProjectWiki::TITLE_ORDER, ProjectWiki::NESTING_CLOSED
|
2018-07-31 06:08:19 +00:00
|
|
|
end
|
|
|
|
|
2018-07-22 06:48:12 +00:00
|
|
|
def create_page(name, content)
|
2018-07-31 06:08:19 +00:00
|
|
|
wiki.write_page(name, :markdown, content, commit_details(name))
|
2018-07-22 06:48:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def commit_details(name)
|
|
|
|
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}")
|
|
|
|
end
|
2018-07-31 06:08:19 +00:00
|
|
|
|
|
|
|
def destroy_page(title, dir = '')
|
|
|
|
page = wiki.page(title: title, dir: dir)
|
|
|
|
project_wiki.delete_page(page, "test commit")
|
|
|
|
end
|
2017-04-20 08:56:41 +00:00
|
|
|
end
|