debian-mirror-gitlab/spec/lib/gitlab/git/wiki_spec.rb

122 lines
3.5 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Git::Wiki do
2018-12-13 13:39:08 +05:30
using RSpec::Parameterized::TableSyntax
2018-03-17 18:26:18 +05:30
let(:project) { create(:project) }
2022-04-04 11:22:00 +05:30
let(:user) { project.first_owner }
2018-03-17 18:26:18 +05:30
let(:project_wiki) { ProjectWiki.new(project, user) }
2018-12-13 13:39:08 +05:30
subject(:wiki) { project_wiki.wiki }
2018-03-17 18:26:18 +05:30
2018-11-18 11:00:15 +05:30
describe '#pages' do
before do
create_page('page1', 'content')
create_page('page2', 'content2')
end
after do
destroy_page('page1')
destroy_page('page2')
end
it 'returns all the pages' do
2019-07-31 22:56:46 +05:30
expect(subject.list_pages.count).to eq(2)
expect(subject.list_pages.first.title).to eq 'page1'
expect(subject.list_pages.last.title).to eq 'page2'
2018-11-18 11:00:15 +05:30
end
it 'returns only one page' do
2019-07-31 22:56:46 +05:30
pages = subject.list_pages(limit: 1)
2018-11-18 11:00:15 +05:30
expect(pages.count).to eq(1)
expect(pages.first.title).to eq 'page1'
end
end
2018-11-08 19:23:39 +05:30
describe '#page' do
2018-03-17 18:26:18 +05:30
before do
create_page('page1', 'content')
create_page('foo/page1', 'content foo/page1')
end
after do
destroy_page('page1')
destroy_page('page1', 'foo')
end
it 'returns the right page' do
2022-05-07 20:08:51 +05:30
page = subject.page(title: 'page1', dir: '')
expect(page.url_path).to eq 'page1'
expect(page.raw_data).to eq 'content'
page = subject.page(title: 'page1', dir: 'foo')
expect(page.url_path).to eq 'foo/page1'
expect(page.raw_data).to eq 'content foo/page1'
2018-03-17 18:26:18 +05:30
end
2021-01-03 14:25:43 +05:30
it 'returns nil for invalid arguments' do
expect(subject.page(title: '')).to be_nil
expect(subject.page(title: 'foo', version: ':')).to be_nil
end
2022-05-07 20:08:51 +05:30
it 'does not return content if load_content param is set to false' do
page = subject.page(title: 'page1', dir: '', load_content: false)
expect(page.url_path).to eq 'page1'
expect(page.raw_data).to be_empty
end
2018-03-17 18:26:18 +05:30
end
2018-12-13 13:39:08 +05:30
describe '#preview_slug' do
where(:title, :format, :expected_slug) do
'The Best Thing' | :markdown | 'The-Best-Thing'
'The Best Thing' | :md | 'The-Best-Thing'
'The Best Thing' | :txt | 'The-Best-Thing'
'A Subject/Title Here' | :txt | 'A-Subject/Title-Here'
'A subject' | :txt | 'A-subject'
'A 1/B 2/C 3' | :txt | 'A-1/B-2/C-3'
'subject/title' | :txt | 'subject/title'
'subject/title.md' | :txt | 'subject/title.md'
'foo<bar>+baz' | :txt | 'foo-bar--baz'
'foo%2Fbar' | :txt | 'foo%2Fbar'
'' | :markdown | '.md'
'' | :md | '.md'
'' | :txt | '.txt'
end
with_them do
subject { wiki.preview_slug(title, format) }
2019-07-31 22:56:46 +05:30
let(:gitaly_slug) { wiki.list_pages.first }
2018-12-13 13:39:08 +05:30
it { is_expected.to eq(expected_slug) }
it 'matches the slug generated by gitaly' do
skip('Gitaly cannot generate a slug for an empty title') unless title.present?
create_page(title, 'content', format: format)
2019-07-31 22:56:46 +05:30
gitaly_slug = wiki.list_pages.first.url_path
2018-12-13 13:39:08 +05:30
is_expected.to eq(gitaly_slug)
end
end
end
def create_page(name, content, format: :markdown)
wiki.write_page(name, format, content, commit_details(name))
2018-03-17 18:26:18 +05:30
end
def commit_details(name)
2018-10-15 14:42:47 +05:30
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}")
2018-03-17 18:26:18 +05:30
end
def destroy_page(title, dir = '')
2018-12-13 13:39:08 +05:30
page = wiki.page(title: title, dir: dir)
2018-03-17 18:26:18 +05:30
project_wiki.delete_page(page, "test commit")
end
end