2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe WikiPage do
|
2020-04-22 08:09:29 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2020-09-25 14:09:46 -04:00
|
|
|
let_it_be(:container) { create(:project) }
|
2020-07-30 14:09:39 -04:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
def create_wiki_page(attrs = {})
|
|
|
|
page = build_wiki_page(attrs)
|
|
|
|
|
|
|
|
page.create(message: (attrs[:message] || 'test commit'))
|
|
|
|
|
|
|
|
container.wiki.find_page(page.slug)
|
2020-07-30 14:09:39 -04:00
|
|
|
end
|
2020-02-13 07:08:49 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
def build_wiki_page(attrs = {})
|
|
|
|
wiki_page_attrs = { container: container, content: 'test content' }.merge(attrs)
|
|
|
|
|
|
|
|
build(:wiki_page, wiki_page_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki
|
|
|
|
container.wiki
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2020-04-14 23:09:11 -04:00
|
|
|
def disable_front_matter
|
|
|
|
stub_feature_flags(Gitlab::WikiPages::FrontMatterParser::FEATURE_FLAG => false)
|
|
|
|
end
|
|
|
|
|
2020-04-22 08:09:29 -04:00
|
|
|
def enable_front_matter_for(thing)
|
2020-05-13 05:08:37 -04:00
|
|
|
stub_feature_flags(Gitlab::WikiPages::FrontMatterParser::FEATURE_FLAG => thing)
|
2020-04-14 23:09:11 -04:00
|
|
|
end
|
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
# Use for groups of tests that do not modify their `subject`.
|
|
|
|
#
|
|
|
|
# include_context 'subject is persisted page', title: 'my title'
|
|
|
|
shared_context 'subject is persisted page' do |attrs = {}|
|
|
|
|
let_it_be(:persisted_page) { create_wiki_page(attrs) }
|
|
|
|
|
|
|
|
subject { persisted_page }
|
|
|
|
end
|
|
|
|
|
2020-04-14 23:09:11 -04:00
|
|
|
describe '#front_matter' do
|
2020-04-22 08:09:29 -04:00
|
|
|
let(:wiki_page) { create(:wiki_page, container: container, content: content) }
|
2020-04-14 23:09:11 -04:00
|
|
|
|
|
|
|
shared_examples 'a page without front-matter' do
|
|
|
|
it { expect(wiki_page).to have_attributes(front_matter: {}, content: content) }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a page with front-matter' do
|
|
|
|
let(:front_matter) { { title: 'Foo', slugs: %w[slug_a slug_b] } }
|
|
|
|
|
|
|
|
it { expect(wiki_page.front_matter).to eq(front_matter) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the wiki page has front matter' do
|
|
|
|
let(:content) do
|
|
|
|
<<~MD
|
|
|
|
---
|
|
|
|
title: Foo
|
|
|
|
slugs:
|
|
|
|
- slug_a
|
|
|
|
- slug_b
|
|
|
|
---
|
|
|
|
|
|
|
|
My actual content
|
|
|
|
MD
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a page with front-matter'
|
|
|
|
|
|
|
|
it 'strips the front matter from the content' do
|
|
|
|
expect(wiki_page.content.strip).to eq('My actual content')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the feature flag is off' do
|
|
|
|
before do
|
|
|
|
disable_front_matter
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a page without front-matter'
|
|
|
|
|
2020-04-22 08:09:29 -04:00
|
|
|
context 'but enabled for the container' do
|
2020-04-14 23:09:11 -04:00
|
|
|
before do
|
2020-04-22 08:09:29 -04:00
|
|
|
enable_front_matter_for(container)
|
2020-04-14 23:09:11 -04:00
|
|
|
end
|
|
|
|
|
2020-05-05 11:09:42 -04:00
|
|
|
it_behaves_like 'a page with front-matter'
|
2020-04-14 23:09:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the wiki page does not have front matter' do
|
|
|
|
let(:content) { 'My actual content' }
|
|
|
|
|
|
|
|
it_behaves_like 'a page without front-matter'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the wiki page has fenced blocks, but nothing in them' do
|
|
|
|
let(:content) do
|
|
|
|
<<~MD
|
|
|
|
---
|
|
|
|
---
|
|
|
|
|
|
|
|
My actual content
|
|
|
|
MD
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a page without front-matter'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the wiki page has invalid YAML type in fenced blocks' do
|
|
|
|
let(:content) do
|
|
|
|
<<~MD
|
|
|
|
---
|
|
|
|
this isn't YAML
|
|
|
|
---
|
|
|
|
|
|
|
|
My actual content
|
|
|
|
MD
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a page without front-matter'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the wiki page has a disallowed class in fenced block' do
|
|
|
|
let(:content) do
|
|
|
|
<<~MD
|
|
|
|
---
|
|
|
|
date: 2010-02-11 11:02:57
|
|
|
|
---
|
|
|
|
|
|
|
|
My actual content
|
|
|
|
MD
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a page without front-matter'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the wiki page has invalid YAML in fenced block' do
|
|
|
|
let(:content) do
|
|
|
|
<<~MD
|
|
|
|
---
|
|
|
|
invalid-use-of-reserved-indicator: @text
|
|
|
|
---
|
|
|
|
|
|
|
|
My actual content
|
|
|
|
MD
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a page without front-matter'
|
|
|
|
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
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page', title: 'test initialization'
|
2013-03-03 22:43:52 -05:00
|
|
|
|
|
|
|
it "sets the slug attribute" do
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(subject.slug).to eq("test-initialization")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the title attribute" do
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(subject.title).to eq("test initialization")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the formatted content attribute" do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.content).to eq("test content")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the format attribute" do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.format).to eq(:markdown)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the message attribute" do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.message).to eq("test commit")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the version attribute" do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.version).to be_a Gitlab::Git::WikiPageVersion
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validations" do
|
2020-09-25 14:09:46 -04:00
|
|
|
subject { build_wiki_page }
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
it "validates presence of title" do
|
|
|
|
subject.attributes.delete(:title)
|
2020-02-13 07:08:49 -05:00
|
|
|
|
|
|
|
expect(subject).not_to be_valid
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject.errors.messages).to eq(title: ["can't be blank"])
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2021-07-07 08:08:23 -04:00
|
|
|
it "does not validate presence of content" do
|
2013-03-03 22:43:52 -05:00
|
|
|
subject.attributes.delete(:content)
|
2020-02-13 07:08:49 -05:00
|
|
|
|
2021-07-07 08:08:23 -04:00
|
|
|
expect(subject).to be_valid
|
2020-02-13 07:08:49 -05:00
|
|
|
end
|
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
describe '#validate_content_size_limit' do
|
|
|
|
context 'with a new page' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(wiki_page_max_content_bytes: 10)
|
|
|
|
end
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
it 'accepts content below the limit' do
|
|
|
|
subject.attributes[:content] = 'a' * 10
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
it 'rejects content exceeding the limit' do
|
|
|
|
subject.attributes[:content] = 'a' * 11
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors.messages).to eq(
|
|
|
|
content: ['is too long (11 Bytes). The maximum size is 10 Bytes.']
|
|
|
|
)
|
|
|
|
end
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
it 'counts content size in bytes rather than characters' do
|
|
|
|
subject.attributes[:content] = '💩💩💩'
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors.messages).to eq(
|
|
|
|
content: ['is too long (12 Bytes). The maximum size is 10 Bytes.']
|
|
|
|
)
|
|
|
|
end
|
2020-07-17 11:09:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an existing page exceeding the limit' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page'
|
2020-07-30 14:09:39 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
stub_application_setting(wiki_page_max_content_bytes: 11)
|
|
|
|
end
|
2020-07-17 11:09:13 -04:00
|
|
|
|
|
|
|
it 'accepts content when it has not changed' do
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject).to be_valid
|
2020-07-17 11:09:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects content when it has changed' do
|
2020-07-30 14:09:39 -04:00
|
|
|
subject.attributes[:content] = 'a' * 12
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors.messages).to eq(
|
|
|
|
content: ['is too long (12 Bytes). The maximum size is 11 Bytes.']
|
|
|
|
)
|
2020-07-17 11:09:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
describe '#validate_path_limits' do
|
2020-04-14 23:09:11 -04:00
|
|
|
let(:max_title) { Gitlab::WikiPages::MAX_TITLE_BYTES }
|
|
|
|
let(:max_directory) { Gitlab::WikiPages::MAX_DIRECTORY_BYTES }
|
2020-02-13 07:08:49 -05:00
|
|
|
|
|
|
|
where(:character) do
|
|
|
|
['a', 'ä', '🙈']
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let(:size) { character.bytesize.to_f }
|
|
|
|
let(:valid_title) { character * (max_title / size).floor }
|
|
|
|
let(:valid_directory) { character * (max_directory / size).floor }
|
|
|
|
let(:invalid_title) { character * ((max_title + 1) / size).ceil }
|
|
|
|
let(:invalid_directory) { character * ((max_directory + 1) / size).ceil }
|
|
|
|
|
|
|
|
it 'accepts page titles below the limit' do
|
|
|
|
subject.title = valid_title
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts directories below the limit' do
|
|
|
|
subject.title = valid_directory + '/foo'
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts a path with page title and directory below the limit' do
|
|
|
|
subject.title = "#{valid_directory}/#{valid_title}"
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects page titles exceeding the limit' do
|
|
|
|
subject.title = invalid_title
|
|
|
|
|
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors[:title]).to contain_exactly(
|
2020-03-02 13:07:42 -05:00
|
|
|
"exceeds the limit of #{max_title} bytes"
|
2020-02-13 07:08:49 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects directories exceeding the limit' do
|
2020-03-02 13:07:42 -05:00
|
|
|
subject.title = "#{invalid_directory}/#{invalid_directory}2/foo"
|
2020-02-13 07:08:49 -05:00
|
|
|
|
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors[:title]).to contain_exactly(
|
2020-03-02 13:07:42 -05:00
|
|
|
"exceeds the limit of #{max_directory} bytes for directory name \"#{invalid_directory}\"",
|
|
|
|
"exceeds the limit of #{max_directory} bytes for directory name \"#{invalid_directory}2\""
|
2020-02-13 07:08:49 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects a page with both title and directory exceeding the limit' do
|
|
|
|
subject.title = "#{invalid_directory}/#{invalid_title}"
|
|
|
|
|
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors[:title]).to contain_exactly(
|
2020-03-02 13:07:42 -05:00
|
|
|
"exceeds the limit of #{max_title} bytes",
|
|
|
|
"exceeds the limit of #{max_directory} bytes for directory name \"#{invalid_directory}\""
|
2020-02-13 07:08:49 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an existing page title exceeding the limit' do
|
|
|
|
subject do
|
|
|
|
title = 'a' * (max_title + 1)
|
2020-04-27 05:09:51 -04:00
|
|
|
wiki.create_page(title, 'content')
|
2020-02-13 07:08:49 -05:00
|
|
|
wiki.find_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts the exceeding title length when unchanged' do
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the exceeding title length when changed' do
|
|
|
|
subject.title = 'b' * (max_title + 1)
|
|
|
|
|
|
|
|
expect(subject).not_to be_valid
|
|
|
|
expect(subject.errors).to include(:title)
|
|
|
|
end
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
2020-02-13 07:08:49 -05:00
|
|
|
let(:attributes) do
|
2018-11-07 03:01:59 -05:00
|
|
|
{
|
2020-09-25 14:09:46 -04:00
|
|
|
title: SecureRandom.hex,
|
2018-11-07 03:01:59 -05:00
|
|
|
content: "Home Page",
|
|
|
|
format: "markdown",
|
|
|
|
message: 'Custom Commit Message'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
let(:title) { attributes[:title] }
|
|
|
|
|
|
|
|
subject { build_wiki_page }
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
context "with valid attributes" do
|
|
|
|
it "saves the wiki page" do
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.create(attributes)
|
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(wiki.find_page(title)).not_to be_nil
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.create(attributes)).to eq(true)
|
2018-11-07 03:01:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves the wiki page with message' do
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.create(attributes)
|
2018-11-07 03:01:59 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(wiki.find_page(title).message).to eq 'Custom Commit Message'
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
2020-04-27 05:09:51 -04:00
|
|
|
|
|
|
|
it 'if the title is preceded by a / it is removed' do
|
|
|
|
subject.create(attributes.merge(title: '/New Page'))
|
|
|
|
|
|
|
|
expect(wiki.find_page('New Page')).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with invalid attributes" do
|
|
|
|
it 'does not create the page' do
|
2020-09-25 14:09:46 -04:00
|
|
|
expect { subject.create(title: '') }.not_to change { wiki.list_pages.length }
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 21:04:29 -04:00
|
|
|
describe "dot in the title" do
|
|
|
|
let(:title) { 'Index v1.2.3' }
|
|
|
|
|
|
|
|
describe "#create" do
|
2020-09-25 14:09:46 -04:00
|
|
|
subject { build_wiki_page }
|
2015-03-21 21:04:29 -04:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
it "saves the wiki page and returns true", :aggregate_failures do
|
|
|
|
attributes = { title: title, content: "Home Page", format: "markdown" }
|
2020-02-13 07:08:49 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(subject.create(attributes)).to eq(true)
|
|
|
|
expect(wiki.find_page(title)).not_to be_nil
|
2015-03-21 21:04:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
describe '#update' do
|
2020-09-25 14:09:46 -04:00
|
|
|
subject { create_wiki_page(title: title) }
|
|
|
|
|
|
|
|
it 'updates the content of the page and returns true', :aggregate_failures do
|
|
|
|
expect(subject.update(content: 'new content')).to be_truthy
|
2015-03-21 21:04:29 -04:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
page = wiki.find_page(title)
|
|
|
|
|
2020-04-14 23:09:11 -04:00
|
|
|
expect([subject.content, page.content]).to all(eq('new content'))
|
2015-03-21 21:04:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
describe "#update" do
|
2020-09-25 14:09:46 -04:00
|
|
|
let!(:original_title) { subject.title }
|
|
|
|
|
|
|
|
subject { create_wiki_page }
|
2013-03-03 22:43:52 -05:00
|
|
|
|
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"
|
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.update(content: new_content)
|
2020-09-25 14:09:46 -04:00
|
|
|
page = wiki.find_page(original_title)
|
2017-07-23 04:19:10 -04:00
|
|
|
|
2020-04-14 23:09:11 -04:00
|
|
|
expect([subject.content, page.content]).to all(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
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.update(title: new_title)
|
|
|
|
page = wiki.find_page(new_title)
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2020-04-14 23:09:11 -04:00
|
|
|
expect([subject.title, page.title]).to all(eq(new_title))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'updating front_matter' do
|
|
|
|
shared_examples 'able to update front-matter' do
|
|
|
|
it 'updates the wiki-page front-matter' do
|
|
|
|
content = subject.content
|
|
|
|
subject.update(front_matter: { slugs: ['x'] })
|
2020-09-25 14:09:46 -04:00
|
|
|
page = wiki.find_page(original_title)
|
2020-04-14 23:09:11 -04:00
|
|
|
|
|
|
|
expect([subject, page]).to all(
|
|
|
|
have_attributes(
|
|
|
|
front_matter: include(slugs: include('x')),
|
|
|
|
content: content
|
|
|
|
))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'able to update front-matter'
|
|
|
|
|
|
|
|
context 'the front matter is too long' do
|
|
|
|
let(:new_front_matter) do
|
|
|
|
{
|
|
|
|
title: generate(:wiki_page_title),
|
|
|
|
slugs: Array.new(51).map { FFaker::Lorem.characters(512) }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { subject.update(front_matter: new_front_matter) }.to raise_error(described_class::FrontMatterTooLong)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the front-matter feature flag is not enabled' do
|
|
|
|
before do
|
|
|
|
disable_front_matter
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the front-matter' do
|
|
|
|
content = subject.content
|
|
|
|
subject.update(front_matter: { slugs: ['x'] })
|
|
|
|
|
|
|
|
page = wiki.find_page(subject.title)
|
|
|
|
|
|
|
|
expect([subject, page]).to all(have_attributes(front_matter: be_empty, content: content))
|
|
|
|
end
|
|
|
|
|
2020-04-22 08:09:29 -04:00
|
|
|
context 'but it is enabled for the container' do
|
2020-04-14 23:09:11 -04:00
|
|
|
before do
|
2020-04-22 08:09:29 -04:00
|
|
|
enable_front_matter_for(container)
|
2020-04-14 23:09:11 -04:00
|
|
|
end
|
|
|
|
|
2020-05-05 11:09:42 -04:00
|
|
|
it_behaves_like 'able to update front-matter'
|
2020-04-14 23:09:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the wiki-page front-matter and content together' do
|
|
|
|
content = 'totally new content'
|
|
|
|
subject.update(content: content, front_matter: { slugs: ['x'] })
|
2020-09-25 14:09:46 -04:00
|
|
|
page = wiki.find_page(original_title)
|
2020-04-14 23:09:11 -04:00
|
|
|
|
|
|
|
expect([subject, page]).to all(
|
|
|
|
have_attributes(
|
|
|
|
front_matter: include(slugs: include('x')),
|
|
|
|
content: content
|
|
|
|
))
|
|
|
|
end
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns true" do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.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
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.update(content: 'more content', last_commit_sha: subject.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
|
2020-02-13 07:08:49 -05:00
|
|
|
expect { subject.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
|
2020-09-25 14:09:46 -04:00
|
|
|
existing_page = create_wiki_page
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
expect { subject.update(title: existing_page.title, content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
|
|
|
expect(subject.title).to eq original_title
|
|
|
|
expect(subject.content).to eq 'new_content' # We don't revert the content
|
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
|
|
|
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
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.update(title: new_title, content: new_content)).to be_truthy
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
page = wiki.find_page(new_title)
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2020-02-13 07:08:49 -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
|
2020-04-27 05:09:51 -04:00
|
|
|
wiki.create_page('foo/Existing Page', 'content')
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
expect { subject.update(title: 'foo/Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(subject.title).to eq original_title
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.content).to eq 'new_content'
|
2018-11-20 07:29:56 -05:00
|
|
|
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
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.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
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
describe 'in subdir' do
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'moves the page to the root folder if the title is preceded by /' do
|
2020-09-25 14:09:46 -04:00
|
|
|
page = create_wiki_page(title: 'foo/Existing Page')
|
|
|
|
|
|
|
|
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
|
2020-09-25 14:09:46 -04:00
|
|
|
page = create_wiki_page(title: 'foo/Another Existing Page')
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
original_path = page.slug
|
|
|
|
|
|
|
|
expect(page.update(title: 'Another 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
|
2020-02-13 07:08:49 -05:00
|
|
|
original_path = subject.slug
|
2018-02-07 11:33:12 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(subject.update(title: "/#{subject.title}", content: 'new_content')).to be_truthy
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.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
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.update(title: '', content: 'new_content')).to be_falsey
|
|
|
|
expect(subject.content).to eq 'new_content'
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
page = wiki.find_page(original_title)
|
2018-11-20 07:29:56 -05:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(page.content).to eq 'test content'
|
2018-11-20 07:29:56 -05:00
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
describe "#delete" do
|
2020-09-25 14:09:46 -04:00
|
|
|
it "deletes the page and returns true", :aggregate_failures do
|
|
|
|
page = create_wiki_page
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
expect do
|
|
|
|
expect(page.delete).to eq(true)
|
|
|
|
end.to change { wiki.list_pages.length }.by(-1)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#versions" do
|
2021-05-14 08:10:58 -04:00
|
|
|
let(:subject) { create_wiki_page }
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns an array of all commits for the page" do
|
2021-05-14 08:10:58 -04:00
|
|
|
expect do
|
|
|
|
3.times { |i| subject.update(content: "content #{i}") }
|
|
|
|
end.to change { subject.versions.count }.by(3)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
describe '#title_changed?' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
2020-02-13 07:08:49 -05:00
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
let_it_be(:unsaved_page) { build_wiki_page(title: 'test page') }
|
|
|
|
let_it_be(:existing_page) { create_wiki_page(title: 'test page') }
|
|
|
|
let_it_be(:directory_page) { create_wiki_page(title: 'parent directory/child page') }
|
|
|
|
let_it_be(:page_with_special_characters) { create_wiki_page(title: 'test+page') }
|
2021-04-22 14:10:13 -04:00
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
let(:untitled_page) { described_class.new(wiki) }
|
2017-08-30 11:16:08 -04:00
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
where(:page, :title, :changed) do
|
2020-03-12 17:09:45 -04:00
|
|
|
:untitled_page | nil | false
|
|
|
|
:untitled_page | 'new title' | true
|
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
:unsaved_page | nil | true
|
|
|
|
:unsaved_page | 'test page' | true
|
|
|
|
:unsaved_page | 'test-page' | true
|
|
|
|
:unsaved_page | 'test+page' | true
|
|
|
|
:unsaved_page | 'new title' | true
|
2020-03-12 17:09:45 -04:00
|
|
|
|
|
|
|
:existing_page | nil | false
|
|
|
|
:existing_page | 'test page' | false
|
|
|
|
:existing_page | 'test-page' | false
|
|
|
|
:existing_page | '/test page' | false
|
|
|
|
:existing_page | '/test-page' | false
|
2020-06-05 17:08:27 -04:00
|
|
|
:existing_page | 'test+page' | true
|
2020-03-12 17:09:45 -04:00
|
|
|
:existing_page | ' test page ' | true
|
|
|
|
:existing_page | 'new title' | true
|
|
|
|
:existing_page | 'new-title' | true
|
|
|
|
|
|
|
|
:directory_page | nil | false
|
|
|
|
:directory_page | 'parent directory/child page' | false
|
|
|
|
:directory_page | 'parent-directory/child page' | false
|
|
|
|
:directory_page | 'parent-directory/child-page' | false
|
|
|
|
:directory_page | 'child page' | false
|
|
|
|
:directory_page | 'child-page' | false
|
|
|
|
:directory_page | '/child page' | true
|
|
|
|
:directory_page | 'parent directory/other' | true
|
|
|
|
:directory_page | 'parent-directory/other' | true
|
|
|
|
:directory_page | 'parent-directory / child-page' | true
|
|
|
|
:directory_page | 'other directory/child page' | true
|
|
|
|
:directory_page | 'other-directory/child page' | true
|
2020-06-05 17:08:27 -04:00
|
|
|
|
|
|
|
:page_with_special_characters | nil | false
|
|
|
|
:page_with_special_characters | 'test+page' | false
|
|
|
|
:page_with_special_characters | 'test-page' | true
|
|
|
|
:page_with_special_characters | 'test page' | true
|
2020-03-03 10:08:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns the expected value' do
|
|
|
|
subject = public_send(page)
|
|
|
|
subject.title = title if title
|
2017-08-30 11:16:08 -04:00
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
expect(subject.title_changed?).to be(changed)
|
|
|
|
end
|
2017-08-30 11:16:08 -04:00
|
|
|
end
|
2014-04-09 01:14:16 -04:00
|
|
|
end
|
|
|
|
|
2020-07-17 11:09:13 -04:00
|
|
|
describe '#content_changed?' do
|
|
|
|
context 'with a new page' do
|
2020-09-25 14:09:46 -04:00
|
|
|
subject { build_wiki_page }
|
2020-07-17 11:09:13 -04:00
|
|
|
|
|
|
|
it 'returns true if content is set' do
|
|
|
|
subject.attributes[:content] = 'new'
|
|
|
|
|
|
|
|
expect(subject.content_changed?).to be(true)
|
|
|
|
end
|
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
it 'returns false if content is blank' do
|
|
|
|
subject.attributes[:content] = ' '
|
2020-07-17 11:09:13 -04:00
|
|
|
|
2020-07-30 14:09:39 -04:00
|
|
|
expect(subject.content_changed?).to be(false)
|
2020-07-17 11:09:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an existing page' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page'
|
2020-07-17 11:09:13 -04:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.content_changed?).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if content is set to the same value' do
|
|
|
|
subject.attributes[:content] = 'test content'
|
|
|
|
|
|
|
|
expect(subject.content_changed?).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true if content is changed' do
|
|
|
|
subject.attributes[:content] = 'new'
|
|
|
|
|
|
|
|
expect(subject.content_changed?).to be(true)
|
|
|
|
end
|
2020-07-30 14:09:39 -04:00
|
|
|
|
|
|
|
it 'returns true if content is changed to a blank string' do
|
|
|
|
subject.attributes[:content] = ' '
|
|
|
|
|
|
|
|
expect(subject.content_changed?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if only the newline format has changed' do
|
|
|
|
expect(subject.page).to receive(:text_data).and_return("foo\nbar")
|
|
|
|
|
|
|
|
subject.attributes[:content] = "foo\r\nbar"
|
|
|
|
|
|
|
|
expect(subject.content_changed?).to be(false)
|
|
|
|
end
|
2020-07-17 11:09:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-03 00:01:57 -04:00
|
|
|
describe '#path' do
|
|
|
|
it 'returns the path when persisted' do
|
2020-09-25 14:09:46 -04:00
|
|
|
existing_page = create_wiki_page(title: 'path test')
|
|
|
|
|
|
|
|
expect(existing_page.path).to eq('path-test.md')
|
2019-10-03 00:01:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when not persisted' do
|
2020-09-25 14:09:46 -04:00
|
|
|
unsaved_page = build_wiki_page(title: 'path test')
|
|
|
|
|
|
|
|
expect(unsaved_page.path).to be_nil
|
2019-10-03 00:01:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-18 18:22:20 -05:00
|
|
|
describe '#directory' do
|
|
|
|
context 'when the page is at the root directory' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page', title: 'directory test'
|
2016-12-18 18:22:20 -05:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
it 'returns an empty string' do
|
|
|
|
expect(subject.directory).to eq('')
|
2016-12-18 18:22:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the page is inside an actual directory' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page', title: 'dir_1/dir_1_1/directory test'
|
2016-12-18 18:22:20 -05:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
it 'returns the full directory hierarchy' do
|
|
|
|
expect(subject.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
|
2021-05-14 08:10:58 -04:00
|
|
|
let!(:container) { create(:project) }
|
|
|
|
|
|
|
|
subject { create_wiki_page }
|
2018-10-15 15:07:02 -04:00
|
|
|
|
2021-05-14 08:10:58 -04:00
|
|
|
let(:wiki) { subject.wiki }
|
2020-02-13 07:08:49 -05:00
|
|
|
let(:old_version) { subject.versions.last.id }
|
|
|
|
let(:old_page) { wiki.find_page(subject.title, old_version) }
|
|
|
|
let(:latest_version) { subject.versions.first.id }
|
|
|
|
let(:latest_page) { wiki.find_page(subject.title, latest_version) }
|
2016-01-27 08:42:31 -05:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
before do
|
|
|
|
3.times { |i| subject.update(content: "content #{i}") }
|
2016-01-27 08:42:31 -05:00
|
|
|
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
|
2020-04-01 17:07:56 -04:00
|
|
|
expect(latest_page).to receive(:version) { nil }
|
|
|
|
|
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
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
describe '#persisted?' do
|
|
|
|
it 'returns true for a persisted page' do
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(create_wiki_page).to be_persisted
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for an unpersisted page' do
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(build_wiki_page).not_to be_persisted
|
2020-04-27 05:09:51 -04: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
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(build_wiki_page.to_partial_path).to eq('../shared/wikis/wiki_page')
|
2016-12-26 20:51:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-30 08:26:30 -05:00
|
|
|
describe '#==' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page'
|
2016-12-30 08:26:30 -05:00
|
|
|
|
|
|
|
it 'returns true for identical wiki page' do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject).to eq(subject)
|
2016-12-30 08:26:30 -05:00
|
|
|
end
|
|
|
|
|
2020-03-19 08:09:33 -04:00
|
|
|
it 'returns true for updated wiki page' do
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.update(content: "Updated content")
|
2020-09-25 14:09:46 -04:00
|
|
|
updated_page = wiki.find_page(subject.slug)
|
2020-02-13 07:08:49 -05:00
|
|
|
|
|
|
|
expect(updated_page).not_to be_nil
|
2020-03-19 08:09:33 -04:00
|
|
|
expect(updated_page).to eq(subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for a completely different wiki page' do
|
|
|
|
other_page = create(:wiki_page)
|
|
|
|
|
|
|
|
expect(subject.slug).not_to eq(other_page.slug)
|
2020-04-22 08:09:29 -04:00
|
|
|
expect(subject.container).not_to eq(other_page.container)
|
2020-03-19 08:09:33 -04:00
|
|
|
expect(subject).not_to eq(other_page)
|
|
|
|
end
|
|
|
|
|
2020-04-22 08:09:29 -04:00
|
|
|
it 'returns false for page with different slug on same container' do
|
2020-09-25 14:09:46 -04:00
|
|
|
other_page = create_wiki_page
|
2020-03-19 08:09:33 -04:00
|
|
|
|
|
|
|
expect(subject.slug).not_to eq(other_page.slug)
|
2020-04-22 08:09:29 -04:00
|
|
|
expect(subject.container).to eq(other_page.container)
|
2020-03-19 08:09:33 -04:00
|
|
|
expect(subject).not_to eq(other_page)
|
|
|
|
end
|
|
|
|
|
2020-05-05 11:09:42 -04:00
|
|
|
it 'returns false for page with the same slug on a different container' do
|
2020-09-25 14:09:46 -04:00
|
|
|
other_page = create(:wiki_page, title: subject.slug)
|
2020-03-19 08:09:33 -04:00
|
|
|
|
2020-04-22 08:09:29 -04:00
|
|
|
expect(subject.slug).to eq(other_page.slug)
|
|
|
|
expect(subject.container).not_to eq(other_page.container)
|
2020-03-19 08:09:33 -04:00
|
|
|
expect(subject).not_to eq(other_page)
|
2016-12-30 08:26:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-27 09:00:06 -04:00
|
|
|
describe '#last_commit_sha' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page'
|
2017-07-27 09:00:06 -04:00
|
|
|
|
|
|
|
it 'returns commit sha' do
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.last_commit_sha).to eq subject.last_version.sha
|
2017-07-27 09:00:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is changed after page updated' do
|
2020-02-13 07:08:49 -05:00
|
|
|
last_commit_sha_before_update = subject.last_commit_sha
|
2017-07-27 09:00:06 -04:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.update(content: "new content")
|
2020-09-25 14:09:46 -04:00
|
|
|
page = wiki.find_page(subject.title)
|
2017-07-27 09:00:06 -04:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(page.last_commit_sha).not_to eq last_commit_sha_before_update
|
2017-07-27 09:00:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-25 13:05:59 -04:00
|
|
|
describe '#hook_attrs' do
|
2020-09-25 14:09:46 -04:00
|
|
|
subject { build_wiki_page }
|
|
|
|
|
2018-07-17 05:38:09 -04:00
|
|
|
it 'adds absolute urls for images in the content' do
|
2020-02-13 07:08:49 -05:00
|
|
|
subject.attributes[:content] = 'test![WikiPage_Image](/uploads/abc/WikiPage_Image.png)'
|
2016-08-25 13:05:59 -04:00
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
expect(subject.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
|
|
|
|
|
2020-05-11 23:09:31 -04:00
|
|
|
describe '#version_commit_timestamp' do
|
|
|
|
context 'for a new page' do
|
|
|
|
it 'returns nil' do
|
2020-09-25 14:09:46 -04:00
|
|
|
expect(build_wiki_page.version_commit_timestamp).to be_nil
|
2020-05-11 23:09:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for page that exists' do
|
|
|
|
it 'returns the timestamp of the commit' do
|
2020-09-25 14:09:46 -04:00
|
|
|
existing_page = create_wiki_page
|
|
|
|
|
2020-05-11 23:09:31 -04:00
|
|
|
expect(existing_page.version_commit_timestamp).to eq(existing_page.version.commit.committed_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-02 11:09:08 -04:00
|
|
|
describe '#diffs' do
|
2020-09-25 14:09:46 -04:00
|
|
|
include_context 'subject is persisted page'
|
2020-07-02 11:09:08 -04:00
|
|
|
|
|
|
|
it 'returns a diff instance' do
|
|
|
|
diffs = subject.diffs(foo: 'bar')
|
|
|
|
|
|
|
|
expect(diffs).to be_a(Gitlab::Diff::FileCollection::WikiPage)
|
|
|
|
expect(diffs.diffable).to be_a(Commit)
|
|
|
|
expect(diffs.diffable.id).to eq(subject.version.id)
|
|
|
|
expect(diffs.project).to be(subject.wiki)
|
|
|
|
expect(diffs.diff_options).to include(
|
|
|
|
expanded: true,
|
|
|
|
paths: [subject.path],
|
|
|
|
foo: 'bar'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|