2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe WikiPage do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2013-03-03 22:43:52 -05:00
|
|
|
let(:user) { project.owner }
|
2014-04-09 07:35:58 -04:00
|
|
|
let(:wiki) { ProjectWiki.new(project, user) }
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
subject { described_class.new(wiki) }
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2016-12-17 13:38:26 -05:00
|
|
|
describe '.group_by_directory' do
|
2016-12-15 23:12:21 -05:00
|
|
|
context 'when there are no pages' do
|
2016-12-26 17:12:15 -05:00
|
|
|
it 'returns an empty array' do
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.group_by_directory(nil)).to eq([])
|
|
|
|
expect(described_class.group_by_directory([])).to eq([])
|
2016-12-15 23:12:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are pages' do
|
2016-12-17 13:38:26 -05:00
|
|
|
before do
|
2016-12-18 23:34:35 -05:00
|
|
|
create_page('dir_1/dir_1_1/page_3', 'content')
|
2019-04-04 12:28:56 -04:00
|
|
|
create_page('page_1', 'content')
|
2016-12-17 13:38:26 -05:00
|
|
|
create_page('dir_1/page_2', 'content')
|
2019-04-12 09:25:17 -04:00
|
|
|
create_page('dir_2', 'page with dir name')
|
2016-12-18 23:34:35 -05:00
|
|
|
create_page('dir_2/page_5', 'content')
|
2019-04-04 12:28:56 -04:00
|
|
|
create_page('page_6', 'content')
|
2016-12-18 23:34:35 -05:00
|
|
|
create_page('dir_2/page_4', 'content')
|
2016-12-17 13:38:26 -05:00
|
|
|
end
|
2019-04-04 12:28:56 -04:00
|
|
|
|
2016-12-26 17:12:15 -05:00
|
|
|
let(:page_1) { wiki.find_page('page_1') }
|
2019-04-04 12:28:56 -04:00
|
|
|
let(:page_6) { wiki.find_page('page_6') }
|
2019-04-12 09:25:17 -04:00
|
|
|
let(:page_dir_2) { wiki.find_page('dir_2') }
|
2019-04-04 12:28:56 -04:00
|
|
|
|
2016-12-26 17:12:15 -05:00
|
|
|
let(:dir_1) do
|
|
|
|
WikiDirectory.new('dir_1', [wiki.find_page('dir_1/page_2')])
|
|
|
|
end
|
|
|
|
let(:dir_1_1) do
|
|
|
|
WikiDirectory.new('dir_1/dir_1_1', [wiki.find_page('dir_1/dir_1_1/page_3')])
|
|
|
|
end
|
|
|
|
let(:dir_2) do
|
|
|
|
pages = [wiki.find_page('dir_2/page_5'),
|
|
|
|
wiki.find_page('dir_2/page_4')]
|
|
|
|
WikiDirectory.new('dir_2', pages)
|
|
|
|
end
|
2016-12-17 13:38:26 -05:00
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
context "#list_pages" do
|
|
|
|
context 'sort by title' do
|
|
|
|
let(:grouped_entries) { described_class.group_by_directory(wiki.list_pages) }
|
|
|
|
let(:expected_grouped_entries) { [dir_1_1, dir_1, page_dir_2, dir_2, page_1, page_6] }
|
|
|
|
|
|
|
|
it 'returns an array with pages and directories' do
|
|
|
|
grouped_entries.each_with_index do |page_or_dir, i|
|
|
|
|
expected_page_or_dir = expected_grouped_entries[i]
|
|
|
|
expected_slugs = get_slugs(expected_page_or_dir)
|
|
|
|
slugs = get_slugs(page_or_dir)
|
|
|
|
|
|
|
|
expect(slugs).to match_array(expected_slugs)
|
|
|
|
end
|
2019-04-04 12:28:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
context 'sort by created_at' do
|
|
|
|
let(:grouped_entries) { described_class.group_by_directory(wiki.list_pages(sort: 'created_at')) }
|
|
|
|
let(:expected_grouped_entries) { [dir_1_1, page_1, dir_1, page_dir_2, dir_2, page_6] }
|
2016-12-15 23:12:21 -05:00
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
it 'returns an array with pages and directories' do
|
|
|
|
grouped_entries.each_with_index do |page_or_dir, i|
|
|
|
|
expected_page_or_dir = expected_grouped_entries[i]
|
|
|
|
expected_slugs = get_slugs(expected_page_or_dir)
|
|
|
|
slugs = get_slugs(page_or_dir)
|
2019-04-04 12:28:56 -04:00
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
expect(slugs).to match_array(expected_slugs)
|
|
|
|
end
|
2019-04-04 12:28:56 -04:00
|
|
|
end
|
2016-12-17 13:38:26 -05:00
|
|
|
end
|
2016-12-18 23:34:35 -05:00
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
it 'returns an array with retained order with directories at the top' do
|
|
|
|
expected_order = ['dir_1/dir_1_1/page_3', 'dir_1/page_2', 'dir_2', 'dir_2/page_4', 'dir_2/page_5', 'page_1', 'page_6']
|
2016-12-18 23:34:35 -05:00
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
grouped_entries = described_class.group_by_directory(wiki.list_pages)
|
2016-12-18 23:34:35 -05:00
|
|
|
|
2019-04-25 00:19:07 -04:00
|
|
|
actual_order =
|
|
|
|
grouped_entries.map do |page_or_dir|
|
|
|
|
get_slugs(page_or_dir)
|
|
|
|
end
|
|
|
|
.flatten
|
|
|
|
expect(actual_order).to eq(expected_order)
|
|
|
|
end
|
2016-12-18 23:34:35 -05:00
|
|
|
end
|
2016-12-15 23:12:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-29 22:07:31 -05:00
|
|
|
describe '.unhyphenize' do
|
|
|
|
it 'removes hyphens from a name' do
|
|
|
|
name = 'a-name--with-hyphens'
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
expect(described_class.unhyphenize(name)).to eq('a name with hyphens')
|
2017-01-29 22:07:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
describe "#initialize" do
|
2018-10-01 23:21:46 -04:00
|
|
|
context "when initialized with an existing page" do
|
2013-03-03 22:43:52 -05:00
|
|
|
before do
|
|
|
|
create_page("test page", "test content")
|
2017-10-03 12:58:33 -04:00
|
|
|
@page = wiki.wiki.page(title: "test page")
|
2017-07-25 13:09:00 -04:00
|
|
|
@wiki_page = described_class.new(wiki, @page, true)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the slug attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.slug).to eq("test-page")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the title attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.title).to eq("test page")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the formatted content attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.content).to eq("test content")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the format attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.format).to eq(:markdown)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the message attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.message).to eq("test commit")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the version attribute" do
|
2017-10-03 12:58:33 -04:00
|
|
|
expect(@wiki_page.version).to be_a Gitlab::Git::WikiPageVersion
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validations" do
|
|
|
|
before do
|
2015-06-22 14:41:00 -04:00
|
|
|
subject.attributes = { title: 'title', content: 'content' }
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of title" do
|
|
|
|
subject.attributes.delete(:title)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(subject.valid?).to be_falsey
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of content" do
|
|
|
|
subject.attributes.delete(:content)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(subject.valid?).to be_falsey
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
2018-11-07 03:01:59 -05:00
|
|
|
let(:wiki_attr) do
|
|
|
|
{
|
|
|
|
title: "Index",
|
|
|
|
content: "Home Page",
|
|
|
|
format: "markdown",
|
|
|
|
message: 'Custom Commit Message'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
after do
|
|
|
|
destroy_page("Index")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid attributes" do
|
|
|
|
it "saves the wiki page" do
|
2018-11-07 03:01:59 -05:00
|
|
|
subject.create(wiki_attr)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(wiki.find_page("Index")).not_to be_nil
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2018-11-07 03:01:59 -05:00
|
|
|
expect(subject.create(wiki_attr)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves the wiki page with message' do
|
|
|
|
subject.create(wiki_attr)
|
|
|
|
|
|
|
|
expect(wiki.find_page("Index").message).to eq 'Custom Commit Message'
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 21:04:29 -04:00
|
|
|
describe "dot in the title" do
|
|
|
|
let(:title) { 'Index v1.2.3' }
|
|
|
|
|
|
|
|
before do
|
2015-06-22 14:41:00 -04:00
|
|
|
@wiki_attr = { title: title, content: "Home Page", format: "markdown" }
|
2015-03-21 21:04:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
after do
|
|
|
|
destroy_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid attributes" do
|
|
|
|
it "saves the wiki page" do
|
|
|
|
subject.create(@wiki_attr)
|
|
|
|
expect(wiki.find_page(title)).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.create(@wiki_attr)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
before do
|
|
|
|
create_page(title, "content")
|
|
|
|
@page = wiki.find_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "updates the content of the page" do
|
2017-07-23 04:19:10 -04:00
|
|
|
@page.update(content: "new content")
|
2015-03-21 21:04:29 -04:00
|
|
|
@page = wiki.find_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2017-07-23 04:19:10 -04:00
|
|
|
expect(@page.update(content: "more content")).to be_truthy
|
2015-03-21 21:04:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-07 11:33:12 -05:00
|
|
|
describe '#create' do
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'with valid attributes' do
|
|
|
|
it 'raises an error if a page with the same path already exists' do
|
|
|
|
create_page('New Page', 'content')
|
|
|
|
create_page('foo/bar', 'content')
|
|
|
|
expect { create_page('New Page', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
|
|
|
|
expect { create_page('foo/bar', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
destroy_page('New Page')
|
|
|
|
destroy_page('bar', 'foo')
|
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'if the title is preceded by a / it is removed' do
|
|
|
|
create_page('/New Page', 'content')
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(wiki.find_page('New Page')).not_to be_nil
|
|
|
|
|
|
|
|
destroy_page('New Page')
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
end
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
describe "#update" do
|
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
|
|
|
@page = wiki.find_page("Update")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
after do
|
|
|
|
destroy_page(@page.title, @page.directory)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context "with valid attributes" do
|
|
|
|
it "updates the content of the page" do
|
|
|
|
new_content = "new content"
|
|
|
|
|
|
|
|
@page.update(content: new_content)
|
2013-03-03 22:43:52 -05:00
|
|
|
@page = wiki.find_page("Update")
|
2017-07-23 04:19:10 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page.content).to eq("new content")
|
2017-07-23 04:19:10 -04:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "updates the title of the page" do
|
|
|
|
new_title = "Index v.1.2.4"
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
@page.update(title: new_title)
|
|
|
|
@page = wiki.find_page(new_title)
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page.title).to eq(new_title)
|
|
|
|
end
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns true" do
|
|
|
|
expect(@page.update(content: "more content")).to be_truthy
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2017-03-04 09:03:14 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'with same last commit sha' do
|
|
|
|
it 'returns true' do
|
|
|
|
expect(@page.update(content: 'more content', last_commit_sha: @page.last_commit_sha)).to be_truthy
|
2017-03-04 09:03:14 -05:00
|
|
|
end
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2017-03-04 09:03:14 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'with different last commit sha' do
|
|
|
|
it 'raises exception' do
|
|
|
|
expect { @page.update(content: 'more content', last_commit_sha: 'xxx') }.to raise_error(WikiPage::PageChangedError)
|
2017-03-04 09:03:14 -05:00
|
|
|
end
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'when renaming a page' do
|
|
|
|
it 'raises an error if the page already exists' do
|
|
|
|
create_page('Existing Page', 'content')
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect { @page.update(title: 'Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
|
|
|
expect(@page.title).to eq 'Update'
|
|
|
|
expect(@page.content).to eq 'new_content'
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
destroy_page('Existing Page')
|
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'updates the content and rename the file' do
|
|
|
|
new_title = 'Renamed Page'
|
|
|
|
new_content = 'updated content'
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
@page = wiki.find_page(new_title)
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page).not_to be_nil
|
|
|
|
expect(@page.content).to eq new_content
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'when moving a page' do
|
|
|
|
it 'raises an error if the page already exists' do
|
|
|
|
create_page('foo/Existing Page', 'content')
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect { @page.update(title: 'foo/Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
|
|
|
expect(@page.title).to eq 'Update'
|
|
|
|
expect(@page.content).to eq 'new_content'
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
destroy_page('Existing Page', 'foo')
|
|
|
|
end
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'updates the content and moves the file' do
|
|
|
|
new_title = 'foo/Other Page'
|
|
|
|
new_content = 'new_content'
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
page = wiki.find_page(new_title)
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(page).not_to be_nil
|
|
|
|
expect(page.content).to eq new_content
|
|
|
|
end
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'in subdir' do
|
|
|
|
before do
|
|
|
|
create_page('foo/Existing Page', 'content')
|
|
|
|
@page = wiki.find_page('foo/Existing Page')
|
|
|
|
end
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'moves the page to the root folder if the title is preceded by /' do
|
|
|
|
expect(@page.slug).to eq 'foo/Existing-Page'
|
|
|
|
expect(@page.update(title: '/Existing Page', content: 'new_content')).to be_truthy
|
|
|
|
expect(@page.slug).to eq 'Existing-Page'
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'does nothing if it has the same title' do
|
|
|
|
original_path = @page.slug
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page.update(title: 'Existing Page', content: 'new_content')).to be_truthy
|
|
|
|
expect(@page.slug).to eq original_path
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'in root dir' do
|
|
|
|
it 'does nothing if the title is preceded by /' do
|
|
|
|
original_path = @page.slug
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(@page.update(title: '/Update', content: 'new_content')).to be_truthy
|
|
|
|
expect(@page.slug).to eq original_path
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context "with invalid attributes" do
|
|
|
|
it 'aborts update if title blank' do
|
|
|
|
expect(@page.update(title: '', content: 'new_content')).to be_falsey
|
|
|
|
expect(@page.content).to eq 'new_content'
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
page = wiki.find_page('Update')
|
|
|
|
expect(page.content).to eq 'content'
|
|
|
|
|
|
|
|
@page.title = 'Update'
|
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
|
|
|
before do
|
|
|
|
create_page("Delete Page", "content")
|
|
|
|
@page = wiki.find_page("Delete Page")
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "deletes the page" do
|
2013-03-03 22:43:52 -05:00
|
|
|
@page.delete
|
2019-04-25 00:19:07 -04:00
|
|
|
expect(wiki.list_pages).to be_empty
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns true" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@page.delete).to eq(true)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#versions" do
|
2018-11-20 07:29:56 -05:00
|
|
|
let(:page) { wiki.find_page("Update") }
|
2018-01-02 03:23:39 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
|
|
|
end
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
after do
|
|
|
|
destroy_page("Update")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns an array of all commits for the page" do
|
|
|
|
3.times { |i| page.update(content: "content #{i}") }
|
|
|
|
|
|
|
|
expect(page.versions.count).to eq(4)
|
2018-11-20 05:36:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'returns instances of WikiPageVersion' do
|
|
|
|
expect(page.versions).to all( be_a(Gitlab::Git::WikiPageVersion) )
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-09 01:14:16 -04:00
|
|
|
describe "#title" do
|
|
|
|
before do
|
|
|
|
create_page("Title", "content")
|
|
|
|
@page = wiki.find_page("Title")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Title")
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "replaces a hyphen to a space" do
|
2014-04-09 01:14:16 -04:00
|
|
|
@page.title = "Import-existing-repositories-into-GitLab"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@page.title).to eq("Import existing repositories into GitLab")
|
2014-04-09 01:14:16 -04:00
|
|
|
end
|
2017-08-30 11:16:08 -04:00
|
|
|
|
|
|
|
it 'unescapes html' do
|
|
|
|
@page.title = 'foo & bar'
|
|
|
|
|
|
|
|
expect(@page.title).to eq('foo & bar')
|
|
|
|
end
|
2014-04-09 01:14:16 -04:00
|
|
|
end
|
|
|
|
|
2016-12-18 18:22:20 -05:00
|
|
|
describe '#directory' do
|
|
|
|
context 'when the page is at the root directory' do
|
2016-12-26 23:05:53 -05:00
|
|
|
it 'returns an empty string' do
|
2016-12-18 18:22:20 -05:00
|
|
|
create_page('file', 'content')
|
|
|
|
page = wiki.find_page('file')
|
|
|
|
|
2016-12-26 23:05:53 -05:00
|
|
|
expect(page.directory).to eq('')
|
2016-12-18 18:22:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the page is inside an actual directory' do
|
|
|
|
it 'returns the full directory hierarchy' do
|
|
|
|
create_page('dir_1/dir_1_1/file', 'content')
|
|
|
|
page = wiki.find_page('dir_1/dir_1_1/file')
|
|
|
|
|
2016-12-26 23:05:53 -05:00
|
|
|
expect(page.directory).to eq('dir_1/dir_1_1')
|
2016-12-18 18:22:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-27 08:42:31 -05:00
|
|
|
describe '#historical?' do
|
2018-10-15 15:07:02 -04:00
|
|
|
let(:page) { wiki.find_page('Update') }
|
|
|
|
let(:old_version) { page.versions.last.id }
|
|
|
|
let(:old_page) { wiki.find_page('Update', old_version) }
|
|
|
|
let(:latest_version) { page.versions.first.id }
|
|
|
|
let(:latest_page) { wiki.find_page('Update', latest_version) }
|
|
|
|
|
2016-01-27 08:42:31 -05:00
|
|
|
before do
|
|
|
|
create_page('Update', 'content')
|
|
|
|
@page = wiki.find_page('Update')
|
2017-07-23 04:19:10 -04:00
|
|
|
3.times { |i| @page.update(content: "content #{i}") }
|
2016-01-27 08:42:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page('Update')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when requesting an old version' do
|
2018-10-15 15:07:02 -04:00
|
|
|
expect(old_page.historical?).to be_truthy
|
2016-01-27 08:42:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when requesting latest version' do
|
2018-10-15 15:07:02 -04:00
|
|
|
expect(latest_page.historical?).to be_falsy
|
2016-01-27 08:42:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when version is nil' do
|
2018-10-15 15:07:02 -04:00
|
|
|
expect(latest_page.historical?).to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when the last version is nil' do
|
|
|
|
expect(old_page).to receive(:last_version) { nil }
|
|
|
|
|
|
|
|
expect(old_page.historical?).to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when the version is nil' do
|
|
|
|
expect(old_page).to receive(:version) { nil }
|
2016-01-27 08:42:31 -05:00
|
|
|
|
2018-10-15 15:07:02 -04:00
|
|
|
expect(old_page.historical?).to be_falsy
|
2016-01-27 08:42:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-26 20:51:34 -05:00
|
|
|
describe '#to_partial_path' do
|
|
|
|
it 'returns the relative path to the partial to be used' do
|
|
|
|
page = build(:wiki_page)
|
|
|
|
|
|
|
|
expect(page.to_partial_path).to eq('projects/wikis/wiki_page')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-30 08:26:30 -05:00
|
|
|
describe '#==' do
|
|
|
|
let(:original_wiki_page) { create(:wiki_page) }
|
|
|
|
|
|
|
|
it 'returns true for identical wiki page' do
|
|
|
|
expect(original_wiki_page).to eq(original_wiki_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for updated wiki page' do
|
2017-07-23 04:19:10 -04:00
|
|
|
updated_wiki_page = original_wiki_page.update(content: "Updated content")
|
2016-12-30 08:26:30 -05:00
|
|
|
expect(original_wiki_page).not_to eq(updated_wiki_page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-27 09:00:06 -04:00
|
|
|
describe '#last_commit_sha' do
|
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns commit sha' do
|
2017-11-17 06:48:32 -05:00
|
|
|
expect(@page.last_commit_sha).to eq @page.last_version.sha
|
2017-07-27 09:00:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is changed after page updated' do
|
|
|
|
last_commit_sha_before_update = @page.last_commit_sha
|
|
|
|
|
2017-07-23 04:19:10 -04:00
|
|
|
@page.update(content: "new content")
|
2017-07-27 09:00:06 -04:00
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
|
|
|
|
expect(@page.last_commit_sha).not_to eq last_commit_sha_before_update
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-24 11:52:44 -05:00
|
|
|
describe '#formatted_content' do
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'returns processed content of the page' do
|
|
|
|
subject.create({ title: "RDoc", content: "*bold*", format: "rdoc" })
|
|
|
|
page = wiki.find_page('RDoc')
|
2018-01-24 11:52:44 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(page.formatted_content).to eq("\n<p><strong>bold</strong></p>\n")
|
2018-01-25 10:24:11 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
destroy_page('RDoc')
|
2018-01-24 11:52:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-25 13:05:59 -04:00
|
|
|
describe '#hook_attrs' do
|
2018-07-17 05:38:09 -04:00
|
|
|
it 'adds absolute urls for images in the content' do
|
2016-08-25 13:05:59 -04:00
|
|
|
create_page("test page", "test![WikiPage_Image](/uploads/abc/WikiPage_Image.png)")
|
2018-07-17 05:38:09 -04:00
|
|
|
page = wiki.wiki.page(title: "test page")
|
|
|
|
wiki_page = described_class.new(wiki, page, true)
|
2016-08-25 13:05:59 -04:00
|
|
|
|
2018-07-17 05:38:09 -04:00
|
|
|
expect(wiki_page.hook_attrs['content']).to eq("test![WikiPage_Image](#{Settings.gitlab.url}/uploads/abc/WikiPage_Image.png)")
|
2016-08-25 13:05:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 12:24:53 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def remove_temp_repo(path)
|
|
|
|
FileUtils.rm_rf path
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_details
|
2018-04-18 13:50:56 -04:00
|
|
|
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "test commit")
|
2014-07-31 12:24:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_page(name, content)
|
|
|
|
wiki.wiki.write_page(name, :markdown, content, commit_details)
|
|
|
|
end
|
|
|
|
|
2018-02-05 12:17:21 -05:00
|
|
|
def destroy_page(title, dir = '')
|
|
|
|
page = wiki.wiki.page(title: title, dir: dir)
|
2017-10-31 06:38:15 -04:00
|
|
|
wiki.delete_page(page, "test commit")
|
2014-07-31 12:24:53 -04:00
|
|
|
end
|
2016-12-26 17:12:15 -05:00
|
|
|
|
|
|
|
def get_slugs(page_or_dir)
|
|
|
|
if page_or_dir.is_a? WikiPage
|
|
|
|
[page_or_dir.slug]
|
|
|
|
else
|
|
|
|
page_or_dir.pages.present? ? page_or_dir.pages.map(&:slug) : []
|
|
|
|
end
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|