2014-09-02 18:07:02 +05:30
|
|
|
require "spec_helper"
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe WikiPage do
|
|
|
|
let(:project) { create(:project) }
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:user) { project.owner }
|
|
|
|
let(:wiki) { ProjectWiki.new(project, user) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.new(wiki) }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '.group_by_directory' do
|
|
|
|
context 'when there are no pages' do
|
|
|
|
it 'returns an empty array' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(described_class.group_by_directory(nil)).to eq([])
|
|
|
|
expect(described_class.group_by_directory([])).to eq([])
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are pages' do
|
|
|
|
before do
|
|
|
|
create_page('dir_1/dir_1_1/page_3', 'content')
|
|
|
|
create_page('dir_1/page_2', 'content')
|
|
|
|
create_page('dir_2/page_5', 'content')
|
|
|
|
create_page('dir_2/page_4', 'content')
|
|
|
|
create_page('page_1', 'content')
|
|
|
|
end
|
|
|
|
let(:page_1) { wiki.find_page('page_1') }
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'returns an array with pages and directories' do
|
|
|
|
expected_grouped_entries = [page_1, dir_1, dir_1_1, dir_2]
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
grouped_entries = described_class.group_by_directory(wiki.pages)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array sorted by alphabetical position' do
|
|
|
|
# Directories and pages within directories are sorted alphabetically.
|
|
|
|
# Pages at root come before everything.
|
|
|
|
expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3',
|
|
|
|
'dir_2/page_4', 'dir_2/page_5']
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
grouped_entries = described_class.group_by_directory(wiki.pages)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
actual_order =
|
|
|
|
grouped_entries.map do |page_or_dir|
|
|
|
|
get_slugs(page_or_dir)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
.flatten
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(actual_order).to eq(expected_order)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.unhyphenize' do
|
|
|
|
it 'removes hyphens from a name' do
|
|
|
|
name = 'a-name--with-hyphens'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(described_class.unhyphenize(name)).to eq('a name with hyphens')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
describe "#initialize" do
|
|
|
|
context "when initialized with an existing gollum page" do
|
|
|
|
before do
|
|
|
|
create_page("test page", "test content")
|
2018-03-17 18:26:18 +05:30
|
|
|
@page = wiki.wiki.page(title: "test page")
|
2017-09-10 17:25:29 +05:30
|
|
|
@wiki_page = described_class.new(wiki, @page, true)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the slug attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.slug).to eq("test-page")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the title attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.title).to eq("test page")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the formatted content attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.content).to eq("test content")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the format attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.format).to eq(:markdown)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the message attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.message).to eq("test commit")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the version attribute" do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(@wiki_page.version).to be_a Gitlab::Git::WikiPageVersion
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validations" do
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
subject.attributes = { title: 'title', content: 'content' }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of title" do
|
|
|
|
subject.attributes.delete(:title)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.valid?).to be_falsey
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of content" do
|
|
|
|
subject.attributes.delete(:content)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.valid?).to be_falsey
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
@wiki_attr = { title: "Index", content: "Home Page", format: "markdown" }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
after do
|
|
|
|
destroy_page("Index")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid attributes" do
|
|
|
|
it "saves the wiki page" do
|
|
|
|
subject.create(@wiki_attr)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(wiki.find_page("Index")).not_to be_nil
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.create(@wiki_attr)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "dot in the title" do
|
|
|
|
let(:title) { 'Index v1.2.3' }
|
|
|
|
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
@wiki_attr = { title: title, content: "Home Page", format: "markdown" }
|
2015-04-26 12:48:37 +05:30
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
@page.update(content: "new content")
|
2015-04-26 12:48:37 +05:30
|
|
|
@page = wiki.find_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(@page.update(content: "more content")).to be_truthy
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '#create' do
|
|
|
|
shared_examples 'create method' do
|
|
|
|
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
|
|
|
|
|
|
|
|
destroy_page('New Page')
|
|
|
|
destroy_page('bar', 'foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'if the title is preceded by a / it is removed' do
|
|
|
|
create_page('/New Page', 'content')
|
|
|
|
|
|
|
|
expect(wiki.find_page('New Page')).not_to be_nil
|
|
|
|
|
|
|
|
destroy_page('New Page')
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when Gitaly is enabled' do
|
|
|
|
it_behaves_like 'create method'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when Gitaly is disabled', :skip_gitaly_mock do
|
|
|
|
it_behaves_like 'create method'
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe "#update" do
|
|
|
|
shared_examples 'update method' do
|
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
2014-09-02 18:07:02 +05:30
|
|
|
@page = wiki.find_page("Update")
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
after do
|
|
|
|
destroy_page(@page.title, @page.directory)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context "with valid attributes" do
|
|
|
|
it "updates the content of the page" do
|
|
|
|
new_content = "new content"
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@page.update(content: new_content)
|
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
|
|
|
|
expect(@page.content).to eq("new content")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "updates the title of the page" do
|
|
|
|
new_title = "Index v.1.2.4"
|
|
|
|
|
|
|
|
@page.update(title: new_title)
|
|
|
|
@page = wiki.find_page(new_title)
|
|
|
|
|
|
|
|
expect(@page.title).to eq(new_title)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it "returns true" do
|
|
|
|
expect(@page.update(content: "more content")).to be_truthy
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when renaming a page' do
|
|
|
|
it 'raises an error if the page already exists' do
|
|
|
|
create_page('Existing Page', 'content')
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
destroy_page('Existing Page')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the content and rename the file' do
|
|
|
|
new_title = 'Renamed Page'
|
|
|
|
new_content = 'updated content'
|
|
|
|
|
|
|
|
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
|
|
|
|
|
|
|
@page = wiki.find_page(new_title)
|
|
|
|
|
|
|
|
expect(@page).not_to be_nil
|
|
|
|
expect(@page.content).to eq new_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving a page' do
|
|
|
|
it 'raises an error if the page already exists' do
|
|
|
|
create_page('foo/Existing Page', 'content')
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
destroy_page('Existing Page', 'foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the content and moves the file' do
|
|
|
|
new_title = 'foo/Other Page'
|
|
|
|
new_content = 'new_content'
|
|
|
|
|
|
|
|
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
|
|
|
|
|
|
|
page = wiki.find_page(new_title)
|
|
|
|
|
|
|
|
expect(page).not_to be_nil
|
|
|
|
expect(page.content).to eq new_content
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in subdir' do
|
|
|
|
before do
|
|
|
|
create_page('foo/Existing Page', 'content')
|
|
|
|
@page = wiki.find_page('foo/Existing Page')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'moves the page to the root folder if the title is preceded by /', :skip_gitaly_mock 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'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing if it has the same title' do
|
|
|
|
original_path = @page.slug
|
|
|
|
|
|
|
|
expect(@page.update(title: 'Existing Page', content: 'new_content')).to be_truthy
|
|
|
|
expect(@page.slug).to eq original_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in root dir' do
|
|
|
|
it 'does nothing if the title is preceded by /' do
|
|
|
|
original_path = @page.slug
|
|
|
|
|
|
|
|
expect(@page.update(title: '/Update', content: 'new_content')).to be_truthy
|
|
|
|
expect(@page.slug).to eq original_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
page = wiki.find_page('Update')
|
|
|
|
expect(page.content).to eq 'content'
|
|
|
|
|
|
|
|
@page.title = 'Update'
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'when Gitaly is enabled' do
|
|
|
|
it_behaves_like 'update method'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitaly is disabled', :skip_gitaly_mock do
|
|
|
|
it_behaves_like 'update method'
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
|
|
|
before do
|
|
|
|
create_page("Delete Page", "content")
|
|
|
|
@page = wiki.find_page("Delete Page")
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "deletes the page" do
|
2014-09-02 18:07:02 +05:30
|
|
|
@page.delete
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(wiki.pages).to be_empty
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns true" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@page.delete).to eq(true)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#versions" do
|
2018-03-17 18:26:18 +05:30
|
|
|
shared_examples 'wiki page versions' do
|
|
|
|
let(:page) { wiki.find_page("Update") }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns instances of WikiPageVersion' do
|
|
|
|
expect(page.versions).to all( be_a(Gitlab::Git::WikiPageVersion) )
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when Gitaly is enabled' do
|
|
|
|
it_behaves_like 'wiki page versions'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when Gitaly is disabled', :disable_gitaly do
|
|
|
|
it_behaves_like 'wiki page versions'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#title" do
|
|
|
|
before do
|
|
|
|
create_page("Title", "content")
|
|
|
|
@page = wiki.find_page("Title")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Title")
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "replaces a hyphen to a space" do
|
2014-09-02 18:07:02 +05:30
|
|
|
@page.title = "Import-existing-repositories-into-GitLab"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@page.title).to eq("Import existing repositories into GitLab")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'unescapes html' do
|
|
|
|
@page.title = 'foo & bar'
|
|
|
|
|
|
|
|
expect(@page.title).to eq('foo & bar')
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#directory' do
|
|
|
|
context 'when the page is at the root directory' do
|
|
|
|
it 'returns an empty string' do
|
|
|
|
create_page('file', 'content')
|
|
|
|
page = wiki.find_page('file')
|
|
|
|
|
|
|
|
expect(page.directory).to eq('')
|
|
|
|
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')
|
|
|
|
|
|
|
|
expect(page.directory).to eq('dir_1/dir_1_1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '#historical?' do
|
|
|
|
before do
|
|
|
|
create_page('Update', 'content')
|
|
|
|
@page = wiki.find_page('Update')
|
2017-09-10 17:25:29 +05:30
|
|
|
3.times { |i| @page.update(content: "content #{i}") }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page('Update')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when requesting an old version' do
|
2018-03-17 18:26:18 +05:30
|
|
|
old_version = @page.versions.last.id
|
2016-04-02 18:10:28 +05:30
|
|
|
old_page = wiki.find_page('Update', old_version)
|
|
|
|
|
|
|
|
expect(old_page.historical?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when requesting latest version' do
|
2018-03-17 18:26:18 +05:30
|
|
|
latest_version = @page.versions.first.id
|
2016-04-02 18:10:28 +05:30
|
|
|
latest_page = wiki.find_page('Update', latest_version)
|
|
|
|
|
|
|
|
expect(latest_page.historical?).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when version is nil' do
|
|
|
|
latest_page = wiki.find_page('Update', nil)
|
|
|
|
|
|
|
|
expect(latest_page.historical?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
updated_wiki_page = original_wiki_page.update(content: "Updated content")
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(original_wiki_page).not_to eq(updated_wiki_page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(@page.last_commit_sha).to eq @page.last_version.sha
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'is changed after page updated' do
|
|
|
|
last_commit_sha_before_update = @page.last_commit_sha
|
|
|
|
|
|
|
|
@page.update(content: "new content")
|
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
|
|
|
|
expect(@page.last_commit_sha).not_to eq last_commit_sha_before_update
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '#formatted_content' do
|
|
|
|
shared_examples 'fetching page formatted content' do
|
|
|
|
it 'returns processed content of the page' do
|
|
|
|
subject.create({ title: "RDoc", content: "*bold*", format: "rdoc" })
|
|
|
|
page = wiki.find_page('RDoc')
|
|
|
|
|
|
|
|
expect(page.formatted_content).to eq("\n<p><strong>bold</strong></p>\n")
|
|
|
|
|
|
|
|
destroy_page('RDoc')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitaly wiki_page_formatted_data is enabled' do
|
|
|
|
it_behaves_like 'fetching page formatted content'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitaly wiki_page_formatted_data is disabled', :disable_gitaly do
|
|
|
|
it_behaves_like 'fetching page formatted content'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def remove_temp_repo(path)
|
|
|
|
FileUtils.rm_rf path
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_details
|
2018-03-17 18:26:18 +05:30
|
|
|
Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "test commit")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create_page(name, content)
|
|
|
|
wiki.wiki.write_page(name, :markdown, content, commit_details)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def destroy_page(title, dir = '')
|
|
|
|
page = wiki.wiki.page(title: title, dir: dir)
|
|
|
|
wiki.delete_page(page, "test commit")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|